Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3a7dffa

Browse files
committed
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.
1 parent 12d5e0f commit 3a7dffa

7 files changed

Lines changed: 34 additions & 141 deletions

File tree

Lib/test/test_posix.py

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -664,41 +664,39 @@ def test_environ(self):
664664
self.assertEqual(type(v), item_type)
665665

666666
def test_getcwd_long_pathnames(self):
667-
if hasattr(posix, 'getcwd'):
668-
dirname = 'getcwd-test-directory-0123456789abcdef-01234567890abcdef'
669-
curdir = os.getcwd()
670-
base_path = os.path.abspath(support.TESTFN) + '.getcwd'
667+
dirname = 'getcwd-test-directory-0123456789abcdef-01234567890abcdef'
668+
curdir = os.getcwd()
669+
base_path = os.path.abspath(support.TESTFN) + '.getcwd'
671670

672-
try:
673-
os.mkdir(base_path)
674-
os.chdir(base_path)
675-
except:
676-
# Just returning nothing instead of the SkipTest exception,
677-
# because the test results in Error in that case.
678-
# Is that ok?
679-
# raise unittest.SkipTest("cannot create directory for testing")
680-
return
681-
682-
def _create_and_do_getcwd(dirname, current_path_length = 0):
683-
try:
684-
os.mkdir(dirname)
685-
except:
686-
raise unittest.SkipTest("mkdir cannot create directory sufficiently deep for getcwd test")
687-
688-
os.chdir(dirname)
689-
try:
690-
os.getcwd()
691-
if current_path_length < 1027:
692-
_create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1)
693-
finally:
694-
os.chdir('..')
695-
os.rmdir(dirname)
696-
697-
_create_and_do_getcwd(dirname)
671+
try:
672+
os.mkdir(base_path)
673+
os.chdir(base_path)
674+
except:
675+
# Just returning nothing instead of the SkipTest exception, because
676+
# the test results in Error in that case. Is that ok?
677+
# raise unittest.SkipTest("cannot create directory for testing")
678+
return
698679

699-
finally:
700-
os.chdir(curdir)
701-
support.rmtree(base_path)
680+
def _create_and_do_getcwd(dirname, current_path_length = 0):
681+
try:
682+
os.mkdir(dirname)
683+
except:
684+
raise unittest.SkipTest("mkdir cannot create directory sufficiently deep for getcwd test")
685+
686+
os.chdir(dirname)
687+
try:
688+
os.getcwd()
689+
if current_path_length < 1027:
690+
_create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1)
691+
finally:
692+
os.chdir('..')
693+
os.rmdir(dirname)
694+
695+
_create_and_do_getcwd(dirname)
696+
697+
finally:
698+
os.chdir(curdir)
699+
support.rmtree(base_path)
702700

703701
@unittest.skipUnless(hasattr(posix, 'getgrouplist'), "test needs posix.getgrouplist()")
704702
@unittest.skipUnless(hasattr(pwd, 'getpwuid'), "test needs pwd.getpwuid()")

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Projected Release date: 2013-09-08
1010
Core and Builtins
1111
-----------------
1212

13+
- Remove supporting for compiling on systems without getcwd().
14+
1315
- Issue #18774: Remove last bits of GNU PTH thread code and thread_pth.h.
1416

1517
- Issue #18771: Add optimization to set object lookups to reduce the cost

Modules/posixmodule.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,18 @@ corresponding Unix manual entries for more information on calls.");
140140
/* Various compilers have only certain posix functions */
141141
/* XXX Gosh I wish these were all moved into pyconfig.h */
142142
#if defined(__WATCOMC__) && !defined(__QNX__) /* Watcom compiler */
143-
#define HAVE_GETCWD 1
144143
#define HAVE_OPENDIR 1
145144
#define HAVE_SYSTEM 1
146145
#include <process.h>
147146
#else
148147
#ifdef __BORLANDC__ /* Borland compiler */
149148
#define HAVE_EXECV 1
150-
#define HAVE_GETCWD 1
151149
#define HAVE_OPENDIR 1
152150
#define HAVE_PIPE 1
153151
#define HAVE_SYSTEM 1
154152
#define HAVE_WAIT 1
155153
#else
156154
#ifdef _MSC_VER /* Microsoft compiler */
157-
#define HAVE_GETCWD 1
158155
#define HAVE_GETPPID 1
159156
#define HAVE_GETLOGIN 1
160157
#define HAVE_SPAWNV 1
@@ -174,7 +171,6 @@ corresponding Unix manual entries for more information on calls.");
174171
#if defined(__USLC__) && defined(__SCO_VERSION__) /* SCO UDK Compiler */
175172
#define HAVE_FORK1 1
176173
#endif
177-
#define HAVE_GETCWD 1
178174
#define HAVE_GETEGID 1
179175
#define HAVE_GETEUID 1
180176
#define HAVE_GETGID 1
@@ -3179,7 +3175,6 @@ posix_lchown(PyObject *self, PyObject *args)
31793175
#endif /* HAVE_LCHOWN */
31803176

31813177

3182-
#ifdef HAVE_GETCWD
31833178
static PyObject *
31843179
posix_getcwd(int use_bytes)
31853180
{
@@ -3251,7 +3246,6 @@ posix_getcwd_bytes(PyObject *self)
32513246
{
32523247
return posix_getcwd(1);
32533248
}
3254-
#endif
32553249

32563250
#if ((!defined(HAVE_LINK)) && defined(MS_WINDOWS))
32573251
#define HAVE_LINK 1
@@ -10710,12 +10704,10 @@ static PyMethodDef posix_methods[] = {
1071010704
#ifdef HAVE_CTERMID
1071110705
{"ctermid", posix_ctermid, METH_NOARGS, posix_ctermid__doc__},
1071210706
#endif
10713-
#ifdef HAVE_GETCWD
1071410707
{"getcwd", (PyCFunction)posix_getcwd_unicode,
1071510708
METH_NOARGS, posix_getcwd__doc__},
1071610709
{"getcwdb", (PyCFunction)posix_getcwd_bytes,
1071710710
METH_NOARGS, posix_getcwdb__doc__},
10718-
#endif
1071910711
#if defined(HAVE_LINK) || defined(MS_WINDOWS)
1072010712
{"link", (PyCFunction)posix_link,
1072110713
METH_VARARGS | METH_KEYWORDS,

Python/getcwd.c

Lines changed: 0 additions & 83 deletions
This file was deleted.

configure

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11379,19 +11379,6 @@ esac
1137911379

1138011380
fi
1138111381

11382-
ac_fn_c_check_func "$LINENO" "getcwd" "ac_cv_func_getcwd"
11383-
if test "x$ac_cv_func_getcwd" = xyes; then :
11384-
$as_echo "#define HAVE_GETCWD 1" >>confdefs.h
11385-
11386-
else
11387-
case " $LIBOBJS " in
11388-
*" getcwd.$ac_objext "* ) ;;
11389-
*) LIBOBJS="$LIBOBJS getcwd.$ac_objext"
11390-
;;
11391-
esac
11392-
11393-
fi
11394-
1139511382
ac_fn_c_check_func "$LINENO" "strdup" "ac_cv_func_strdup"
1139611383
if test "x$ac_cv_func_strdup" = xyes; then :
1139711384
$as_echo "#define HAVE_STRDUP 1" >>confdefs.h

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3094,7 +3094,7 @@ AC_CHECK_FUNCS(memmove)
30943094
# check for long file support functions
30953095
AC_CHECK_FUNCS(fseek64 fseeko fstatvfs ftell64 ftello statvfs)
30963096

3097-
AC_REPLACE_FUNCS(dup2 getcwd strdup)
3097+
AC_REPLACE_FUNCS(dup2 strdup)
30983098
AC_CHECK_FUNCS(getpgrp,
30993099
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>]], [[getpgrp(0);]])],
31003100
[AC_DEFINE(GETPGRP_HAVE_ARG, 1, [Define if getpgrp() must be called as getpgrp(0).])],

pyconfig.h.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,6 @@
317317
/* Define if you have the getaddrinfo function. */
318318
#undef HAVE_GETADDRINFO
319319

320-
/* Define to 1 if you have the `getcwd' function. */
321-
#undef HAVE_GETCWD
322-
323320
/* Define this if you have flockfile(), getc_unlocked(), and funlockfile() */
324321
#undef HAVE_GETC_UNLOCKED
325322

0 commit comments

Comments
 (0)