[Python-checkins] cpython: remove support for compiling on systems without getcwd()

benjamin.peterson python-checkins at python.org
Sat Aug 24 04:03:03 CEST 2013


http://hg.python.org/cpython/rev/de99ace69609
changeset:   85359:de99ace69609
user:        Benjamin Peterson <benjamin at python.org>
date:        Fri Aug 23 21:01:48 2013 -0500
summary:
  remove support for compiling on systems without getcwd()

Do we need a fallback implementation of getcwd() from 1991 that claims to
support "really old Unix systems"? I don't think so.

files:
  Lib/test/test_posix.py |  58 ++++++++++----------
  Misc/NEWS              |   2 +
  Modules/posixmodule.c  |   8 --
  Python/getcwd.c        |  83 ------------------------------
  configure              |  13 ----
  configure.ac           |   2 +-
  pyconfig.h.in          |   3 -
  7 files changed, 31 insertions(+), 138 deletions(-)


diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -664,41 +664,39 @@
             self.assertEqual(type(v), item_type)
 
     def test_getcwd_long_pathnames(self):
-        if hasattr(posix, 'getcwd'):
-            dirname = 'getcwd-test-directory-0123456789abcdef-01234567890abcdef'
-            curdir = os.getcwd()
-            base_path = os.path.abspath(support.TESTFN) + '.getcwd'
+        dirname = 'getcwd-test-directory-0123456789abcdef-01234567890abcdef'
+        curdir = os.getcwd()
+        base_path = os.path.abspath(support.TESTFN) + '.getcwd'
 
-            try:
-                os.mkdir(base_path)
-                os.chdir(base_path)
-            except:
-#               Just returning nothing instead of the SkipTest exception,
-#               because the test results in Error in that case.
-#               Is that ok?
-#                raise unittest.SkipTest("cannot create directory for testing")
-                return
+        try:
+            os.mkdir(base_path)
+            os.chdir(base_path)
+        except:
+            #  Just returning nothing instead of the SkipTest exception, because
+            #  the test results in Error in that case.  Is that ok?
+            #  raise unittest.SkipTest("cannot create directory for testing")
+            return
 
-                def _create_and_do_getcwd(dirname, current_path_length = 0):
-                    try:
-                        os.mkdir(dirname)
-                    except:
-                        raise unittest.SkipTest("mkdir cannot create directory sufficiently deep for getcwd test")
+            def _create_and_do_getcwd(dirname, current_path_length = 0):
+                try:
+                    os.mkdir(dirname)
+                except:
+                    raise unittest.SkipTest("mkdir cannot create directory sufficiently deep for getcwd test")
 
-                    os.chdir(dirname)
-                    try:
-                        os.getcwd()
-                        if current_path_length < 1027:
-                            _create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1)
-                    finally:
-                        os.chdir('..')
-                        os.rmdir(dirname)
+                os.chdir(dirname)
+                try:
+                    os.getcwd()
+                    if current_path_length < 1027:
+                        _create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1)
+                finally:
+                    os.chdir('..')
+                    os.rmdir(dirname)
 
-                _create_and_do_getcwd(dirname)
+            _create_and_do_getcwd(dirname)
 
-            finally:
-                os.chdir(curdir)
-                support.rmtree(base_path)
+        finally:
+            os.chdir(curdir)
+            support.rmtree(base_path)
 
     @unittest.skipUnless(hasattr(posix, 'getgrouplist'), "test needs posix.getgrouplist()")
     @unittest.skipUnless(hasattr(pwd, 'getpwuid'), "test needs pwd.getpwuid()")
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@
 Core and Builtins
 -----------------
 
+- Remove supporting for compiling on systems without getcwd().
+
 - Issue #18774: Remove last bits of GNU PTH thread code and thread_pth.h.
 
 - Issue #18771: Add optimization to set object lookups to reduce the cost
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -140,21 +140,18 @@
 /* Various compilers have only certain posix functions */
 /* XXX Gosh I wish these were all moved into pyconfig.h */
 #if defined(__WATCOMC__) && !defined(__QNX__)           /* Watcom compiler */
-#define HAVE_GETCWD     1
 #define HAVE_OPENDIR    1
 #define HAVE_SYSTEM     1
 #include <process.h>
 #else
 #ifdef __BORLANDC__             /* Borland compiler */
 #define HAVE_EXECV      1
-#define HAVE_GETCWD     1
 #define HAVE_OPENDIR    1
 #define HAVE_PIPE       1
 #define HAVE_SYSTEM     1
 #define HAVE_WAIT       1
 #else
 #ifdef _MSC_VER         /* Microsoft compiler */
-#define HAVE_GETCWD     1
 #define HAVE_GETPPID    1
 #define HAVE_GETLOGIN   1
 #define HAVE_SPAWNV     1
@@ -174,7 +171,6 @@
 #if defined(__USLC__) && defined(__SCO_VERSION__)       /* SCO UDK Compiler */
 #define HAVE_FORK1      1
 #endif
-#define HAVE_GETCWD     1
 #define HAVE_GETEGID    1
 #define HAVE_GETEUID    1
 #define HAVE_GETGID     1
@@ -3179,7 +3175,6 @@
 #endif /* HAVE_LCHOWN */
 
 
-#ifdef HAVE_GETCWD
 static PyObject *
 posix_getcwd(int use_bytes)
 {
@@ -3251,7 +3246,6 @@
 {
     return posix_getcwd(1);
 }
-#endif
 
 #if ((!defined(HAVE_LINK)) && defined(MS_WINDOWS))
 #define HAVE_LINK 1
@@ -10710,12 +10704,10 @@
 #ifdef HAVE_CTERMID
     {"ctermid",         posix_ctermid, METH_NOARGS, posix_ctermid__doc__},
 #endif
-#ifdef HAVE_GETCWD
     {"getcwd",          (PyCFunction)posix_getcwd_unicode,
     METH_NOARGS, posix_getcwd__doc__},
     {"getcwdb",         (PyCFunction)posix_getcwd_bytes,
     METH_NOARGS, posix_getcwdb__doc__},
-#endif
 #if defined(HAVE_LINK) || defined(MS_WINDOWS)
     {"link",            (PyCFunction)posix_link,
                         METH_VARARGS | METH_KEYWORDS,
diff --git a/Python/getcwd.c b/Python/getcwd.c
deleted file mode 100644
--- a/Python/getcwd.c
+++ /dev/null
@@ -1,83 +0,0 @@
-
-/* Two PD getcwd() implementations.
-   Author: Guido van Rossum, CWI Amsterdam, Jan 1991, <guido at cwi.nl>. */
-
-#include <stdio.h>
-#include <errno.h>
-
-#ifdef HAVE_GETWD
-
-/* Version for BSD systems -- use getwd() */
-
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
-
-#ifndef MAXPATHLEN
-#if defined(PATH_MAX) && PATH_MAX > 1024
-#define MAXPATHLEN PATH_MAX
-#else
-#define MAXPATHLEN 1024
-#endif
-#endif
-
-extern char *getwd(char *);
-
-char *
-getcwd(char *buf, int size)
-{
-    char localbuf[MAXPATHLEN+1];
-    char *ret;
-
-    if (size <= 0) {
-        errno = EINVAL;
-        return NULL;
-    }
-    ret = getwd(localbuf);
-    if (ret != NULL && strlen(localbuf) >= (size_t)size) {
-        errno = ERANGE;
-        return NULL;
-    }
-    if (ret == NULL) {
-        errno = EACCES; /* Most likely error */
-        return NULL;
-    }
-    strncpy(buf, localbuf, size);
-    return buf;
-}
-
-#else /* !HAVE_GETWD */
-
-/* Version for really old UNIX systems -- use pipe from pwd */
-
-#ifndef PWD_CMD
-#define PWD_CMD "/bin/pwd"
-#endif
-
-char *
-getcwd(char *buf, int size)
-{
-    FILE *fp;
-    char *p;
-    int sts;
-    if (size <= 0) {
-        errno = EINVAL;
-        return NULL;
-    }
-    if ((fp = popen(PWD_CMD, "r")) == NULL)
-        return NULL;
-    if (fgets(buf, size, fp) == NULL || (sts = pclose(fp)) != 0) {
-        errno = EACCES; /* Most likely error */
-        return NULL;
-    }
-    for (p = buf; *p != '\n'; p++) {
-        if (*p == '\0') {
-            errno = ERANGE;
-            return NULL;
-        }
-    }
-    *p = '\0';
-    return buf;
-}
-
-#endif /* !HAVE_GETWD */
diff --git a/configure b/configure
--- a/configure
+++ b/configure
@@ -11379,19 +11379,6 @@
 
 fi
 
-ac_fn_c_check_func "$LINENO" "getcwd" "ac_cv_func_getcwd"
-if test "x$ac_cv_func_getcwd" = xyes; then :
-  $as_echo "#define HAVE_GETCWD 1" >>confdefs.h
-
-else
-  case " $LIBOBJS " in
-  *" getcwd.$ac_objext "* ) ;;
-  *) LIBOBJS="$LIBOBJS getcwd.$ac_objext"
- ;;
-esac
-
-fi
-
 ac_fn_c_check_func "$LINENO" "strdup" "ac_cv_func_strdup"
 if test "x$ac_cv_func_strdup" = xyes; then :
   $as_echo "#define HAVE_STRDUP 1" >>confdefs.h
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -3094,7 +3094,7 @@
 # check for long file support functions
 AC_CHECK_FUNCS(fseek64 fseeko fstatvfs ftell64 ftello statvfs)
 
-AC_REPLACE_FUNCS(dup2 getcwd strdup)
+AC_REPLACE_FUNCS(dup2 strdup)
 AC_CHECK_FUNCS(getpgrp, 
   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>]], [[getpgrp(0);]])],
     [AC_DEFINE(GETPGRP_HAVE_ARG, 1, [Define if getpgrp() must be called as getpgrp(0).])],
diff --git a/pyconfig.h.in b/pyconfig.h.in
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -317,9 +317,6 @@
 /* Define if you have the getaddrinfo function. */
 #undef HAVE_GETADDRINFO
 
-/* Define to 1 if you have the `getcwd' function. */
-#undef HAVE_GETCWD
-
 /* Define this if you have flockfile(), getc_unlocked(), and funlockfile() */
 #undef HAVE_GETC_UNLOCKED
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list