# HG changeset patch # User Emmanuel Gil Peyrot # Date 1422831747 -3600 # Mon Feb 02 00:02:27 2015 +0100 # Node ID f1e76ee8c98a6f1399c39f760367db5368835cb1 # Parent 582aabcce2fd2d05e9b880dad3507da0c8735955 Issue #22623: Add missing guards for some POSIX functions, and don’t harcode their support. diff -r 582aabcce2fd -r f1e76ee8c98a Modules/_posixsubprocess.c --- a/Modules/_posixsubprocess.c Sun Feb 01 19:47:25 2015 +0100 +++ b/Modules/_posixsubprocess.c Mon Feb 02 00:02:27 2015 +0100 @@ -286,6 +286,10 @@ #else /* NOT (defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)) */ +#if !defined(HAVE_OPENDIR) +#error opendir() has to be supported on !Linux +#endif /* HAVE_OPENDIR */ + /* Close all open file descriptors from start_fd and higher. * Do not close any in the sorted py_fds_to_keep list. diff -r 582aabcce2fd -r f1e76ee8c98a Modules/clinic/pwdmodule.c.h --- a/Modules/clinic/pwdmodule.c.h Sun Feb 01 19:47:25 2015 +0100 +++ b/Modules/clinic/pwdmodule.c.h Mon Feb 02 00:02:27 2015 +0100 @@ -2,6 +2,8 @@ preserve [clinic start generated code]*/ +#if defined(HAVE_GETPWUID) + PyDoc_STRVAR(pwd_getpwuid__doc__, "getpwuid($module, uidobj, /)\n" "--\n" @@ -13,6 +15,14 @@ #define PWD_GETPWUID_METHODDEF \ {"getpwuid", (PyCFunction)pwd_getpwuid, METH_O, pwd_getpwuid__doc__}, +#endif /* defined(HAVE_GETPWUID) */ + +#ifndef PWD_GETPWUID_METHODDEF + #define PWD_GETPWUID_METHODDEF +#endif /* !defined(PWD_GETPWUID_METHODDEF) */ + +#if defined(HAVE_GETPWNAM) + PyDoc_STRVAR(pwd_getpwnam__doc__, "getpwnam($module, arg, /)\n" "--\n" @@ -43,6 +53,12 @@ return return_value; } +#endif /* defined(HAVE_GETPWNAM) */ + +#ifndef PWD_GETPWNAM_METHODDEF + #define PWD_GETPWNAM_METHODDEF +#endif /* !defined(PWD_GETPWNAM_METHODDEF) */ + #if defined(HAVE_GETPWENT) PyDoc_STRVAR(pwd_getpwall__doc__, @@ -70,4 +86,4 @@ #ifndef PWD_GETPWALL_METHODDEF #define PWD_GETPWALL_METHODDEF #endif /* !defined(PWD_GETPWALL_METHODDEF) */ -/*[clinic end generated code: output=2e23f920020a750a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=75f01430a2e6c4fb input=a9049054013a1b77]*/ diff -r 582aabcce2fd -r f1e76ee8c98a Modules/faulthandler.c --- a/Modules/faulthandler.c Sun Feb 01 19:47:25 2015 +0100 +++ b/Modules/faulthandler.c Mon Feb 02 00:02:27 2015 +0100 @@ -821,7 +821,7 @@ SetErrorMode(mode | SEM_NOGPFAULTERRORBOX); #endif -#ifdef HAVE_SYS_RESOURCE_H +#ifdef HAVE_GETRLIMIT struct rlimit rl; /* Disable creation of core dump */ diff -r 582aabcce2fd -r f1e76ee8c98a Modules/posixmodule.c --- a/Modules/posixmodule.c Sun Feb 01 19:47:25 2015 +0100 +++ b/Modules/posixmodule.c Mon Feb 02 00:02:27 2015 +0100 @@ -144,33 +144,22 @@ #include #else #ifdef _MSC_VER /* Microsoft compiler */ +#define HAVE_ACCESS 1 #define HAVE_GETPPID 1 #define HAVE_GETLOGIN 1 #define HAVE_SPAWNV 1 #define HAVE_EXECV 1 #define HAVE_PIPE 1 #define HAVE_SYSTEM 1 +#define HAVE_UMASK 1 #define HAVE_CWAIT 1 #define HAVE_FSYNC 1 #define fsync _commit #else /* Unix functions that the configure script doesn't check for */ -#define HAVE_EXECV 1 -#define HAVE_FORK 1 #if defined(__USLC__) && defined(__SCO_VERSION__) /* SCO UDK Compiler */ #define HAVE_FORK1 1 #endif -#define HAVE_GETEGID 1 -#define HAVE_GETEUID 1 -#define HAVE_GETGID 1 -#define HAVE_GETPPID 1 -#define HAVE_GETUID 1 -#define HAVE_KILL 1 -#define HAVE_OPENDIR 1 -#define HAVE_PIPE 1 -#define HAVE_SYSTEM 1 -#define HAVE_WAIT 1 -#define HAVE_TTYNAME 1 #endif /* _MSC_VER */ #endif /* ! __WATCOMC__ || __QNX__ */ @@ -2820,6 +2809,7 @@ } +#ifdef HAVE_ACCESS /*[clinic input] os.access -> bool @@ -2990,6 +2980,7 @@ return return_value; } +#endif /* HAVE_ACCESS */ #ifndef F_OK #define F_OK 0 @@ -3063,7 +3054,7 @@ posix_error(); return ret; } -#endif +#endif /* HAVE_TTYNAME */ #ifdef HAVE_CTERMID /*[clinic input] @@ -4585,7 +4576,11 @@ return list; } /* end of _listdir_windows_no_opendir */ -#else /* thus POSIX, ie: not (MS_WINDOWS and not HAVE_OPENDIR) */ +#else /* thus POSIX, ie: not MS_WINDOWS or HAVE_OPENDIR */ + +#if !defined(HAVE_OPENDIR) && !defined(HAVE_FDOPENDIR) +#error One of opendir() and fdopendir() should be supported +#endif /* HAVE_OPENDIR && HAVE_FDOPENDIR */ static PyObject * _posix_listdir(path_t *path, PyObject *list) @@ -5720,6 +5715,7 @@ #endif /* HAVE_SYSTEM */ +#ifdef HAVE_UMASK /*[clinic input] os.umask @@ -5766,6 +5762,7 @@ return posix_error(); return PyLong_FromLong((long)i); } +#endif /* HAVE_UMASK */ #ifdef MS_WINDOWS @@ -7718,6 +7715,7 @@ #endif /* HAVE_SCHED_RR_GET_INTERVAL */ +#ifdef HAVE_SCHED_YIELD /*[clinic input] os.sched_yield @@ -7750,6 +7748,7 @@ return posix_error(); Py_RETURN_NONE; } +#endif /* HAVE_SCHED_YIELD */ #ifdef HAVE_SCHED_SETAFFINITY /* The minimum number of CPUs allocated in a cpu_set_t */ @@ -16445,6 +16444,10 @@ dump buffer [clinic start generated code]*/ +#ifndef OS_ACCESS_METHODDEF + #define OS_ACCESS_METHODDEF +#endif /* !defined(OS_ACCESS_METHODDEF) */ + #ifndef OS_TTYNAME_METHODDEF #define OS_TTYNAME_METHODDEF #endif /* !defined(OS_TTYNAME_METHODDEF) */ @@ -16533,6 +16536,10 @@ #define OS_SYSTEM_METHODDEF #endif /* !defined(OS_SYSTEM_METHODDEF) */ +#ifndef OS_UMASK_METHODDEF + #define OS_UMASK_METHODDEF +#endif /* !defined(OS_UMASK_METHODDEF) */ + #ifndef OS_UNAME_METHODDEF #define OS_UNAME_METHODDEF #endif /* !defined(OS_UNAME_METHODDEF) */ @@ -16920,7 +16927,7 @@ #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF #define OS_SET_HANDLE_INHERITABLE_METHODDEF #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */ -/*[clinic end generated code: output=52a6140b0b052ce6 input=524ce2e021e4eba6]*/ +/*[clinic end generated code: output=4c739e611e983acb input=524ce2e021e4eba6]*/ static PyMethodDef posix_methods[] = { diff -r 582aabcce2fd -r f1e76ee8c98a Modules/pwdmodule.c --- a/Modules/pwdmodule.c Sun Feb 01 19:47:25 2015 +0100 +++ b/Modules/pwdmodule.c Mon Feb 02 00:02:27 2015 +0100 @@ -94,6 +94,7 @@ return v; } +#ifdef HAVE_GETPWUID /*[clinic input] pwd.getpwuid @@ -129,7 +130,9 @@ } return mkpwent(p); } +#endif /* HAVE_GETPWUID */ +#ifdef HAVE_GETPWNAM /*[clinic input] pwd.getpwnam @@ -163,6 +166,7 @@ Py_DECREF(bytes); return retval; } +#endif /* HAVE_GETPWNAM */ #ifdef HAVE_GETPWENT /*[clinic input] @@ -195,14 +199,12 @@ endpwent(); return d; } -#endif +#endif /* HAVE_GETPWENT */ static PyMethodDef pwd_methods[] = { PWD_GETPWUID_METHODDEF PWD_GETPWNAM_METHODDEF -#ifdef HAVE_GETPWENT PWD_GETPWALL_METHODDEF -#endif {NULL, NULL} /* sentinel */ }; diff -r 582aabcce2fd -r f1e76ee8c98a Modules/timemodule.c --- a/Modules/timemodule.c Sun Feb 01 19:47:25 2015 +0100 +++ b/Modules/timemodule.c Mon Feb 02 00:02:27 2015 +0100 @@ -957,7 +957,7 @@ return PyFloat_FromDouble(total * 1e-7); #else -#if defined(HAVE_SYS_RESOURCE_H) +#if defined(HAVE_GETRUSAGE) struct rusage ru; #endif #ifdef HAVE_TIMES @@ -991,7 +991,7 @@ } #endif -#if defined(HAVE_SYS_RESOURCE_H) +#if defined(HAVE_GETRUSAGE) if (getrusage(RUSAGE_SELF, &ru) == 0) { double total; total = ru.ru_utime.tv_sec + ru.ru_utime.tv_usec * 1e-6; diff -r 582aabcce2fd -r f1e76ee8c98a configure --- a/configure Sun Feb 01 19:47:25 2015 +0100 +++ b/configure Mon Feb 02 00:02:27 2015 +0100 @@ -10694,27 +10694,27 @@ fi # checks for library functions -for ac_func in alarm accept4 setitimer getitimer bind_textdomain_codeset chown \ +for ac_func in access alarm accept4 setitimer getitimer bind_textdomain_codeset chown \ clock confstr ctermid dup3 execv faccessat fchmod fchmodat fchown fchownat \ fexecve fdopendir fork fpathconf fstatat ftime ftruncate futimesat \ - futimens futimes gai_strerror getentropy \ - getgrouplist getgroups getlogin getloadavg getpeername getpgid getpid \ - getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \ - if_nameindex \ + futimens futimes gai_strerror getentropy geteuid getgid \ + getgrouplist getgroups getlogin getloadavg getpeername getpgid getpid getppid \ + getpriority getresgid getresuid getrlimit getpwent getpwnam getpwuid getspnam \ + getspent getsid getuid getwd if_nameindex \ initgroups kill killpg lchmod lchown lockf linkat lstat lutimes mmap \ memrchr mbrtowc mkdirat mkfifo \ - mkfifoat mknod mknodat mktime mremap nice openat pathconf pause pipe2 plock poll \ + mkfifoat mknod mknodat mktime mremap nice openat opendir pathconf pause pipe pipe2 plock poll \ posix_fallocate posix_fadvise pread \ pthread_init pthread_kill putenv pwrite readlink readlinkat readv realpath renameat \ select sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid \ setgid sethostname \ setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setpriority setuid setvbuf \ sched_get_priority_max sched_setaffinity sched_setscheduler sched_setparam \ - sched_rr_get_interval \ + sched_rr_get_interval sched_yield \ sigaction sigaltstack siginterrupt sigpending sigrelse \ sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy symlinkat sync \ - sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ - truncate uname unlinkat unsetenv utimensat utimes waitid waitpid wait3 wait4 \ + sysconf system tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ + truncate ttyname umask uname unlinkat unsetenv utimensat utimes wait waitid waitpid wait3 wait4 \ wcscoll wcsftime wcsxfrm wmemcmp writev _getpty do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` diff -r 582aabcce2fd -r f1e76ee8c98a configure.ac --- a/configure.ac Sun Feb 01 19:47:25 2015 +0100 +++ b/configure.ac Mon Feb 02 00:02:27 2015 +0100 @@ -3001,27 +3001,27 @@ fi # checks for library functions -AC_CHECK_FUNCS(alarm accept4 setitimer getitimer bind_textdomain_codeset chown \ +AC_CHECK_FUNCS(access alarm accept4 setitimer getitimer bind_textdomain_codeset chown \ clock confstr ctermid dup3 execv faccessat fchmod fchmodat fchown fchownat \ fexecve fdopendir fork fpathconf fstatat ftime ftruncate futimesat \ - futimens futimes gai_strerror getentropy \ - getgrouplist getgroups getlogin getloadavg getpeername getpgid getpid \ - getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \ - if_nameindex \ + futimens futimes gai_strerror getentropy geteuid getgid \ + getgrouplist getgroups getlogin getloadavg getpeername getpgid getpid getppid \ + getpriority getresgid getresuid getrlimit getpwent getpwnam getpwuid getspnam \ + getspent getsid getuid getwd if_nameindex \ initgroups kill killpg lchmod lchown lockf linkat lstat lutimes mmap \ memrchr mbrtowc mkdirat mkfifo \ - mkfifoat mknod mknodat mktime mremap nice openat pathconf pause pipe2 plock poll \ + mkfifoat mknod mknodat mktime mremap nice openat opendir pathconf pause pipe pipe2 plock poll \ posix_fallocate posix_fadvise pread \ pthread_init pthread_kill putenv pwrite readlink readlinkat readv realpath renameat \ select sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid \ setgid sethostname \ setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setpriority setuid setvbuf \ sched_get_priority_max sched_setaffinity sched_setscheduler sched_setparam \ - sched_rr_get_interval \ + sched_rr_get_interval sched_yield \ sigaction sigaltstack siginterrupt sigpending sigrelse \ sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy symlinkat sync \ - sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ - truncate uname unlinkat unsetenv utimensat utimes waitid waitpid wait3 wait4 \ + sysconf system tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ + truncate ttyname umask uname unlinkat unsetenv utimensat utimes wait waitid waitpid wait3 wait4 \ wcscoll wcsftime wcsxfrm wmemcmp writev _getpty) AC_CHECK_DECL(dirfd, diff -r 582aabcce2fd -r f1e76ee8c98a pyconfig.h.in --- a/pyconfig.h.in Sun Feb 01 19:47:25 2015 +0100 +++ b/pyconfig.h.in Mon Feb 02 00:02:27 2015 +0100 @@ -40,6 +40,9 @@ /* Define to 1 if you have the `accept4' function. */ #undef HAVE_ACCEPT4 +/* Define to 1 if you have the `access' function. */ +#undef HAVE_ACCESS + /* Define to 1 if you have the `acosh' function. */ #undef HAVE_ACOSH @@ -338,6 +341,12 @@ /* Define to 1 if you have the `getentropy' function. */ #undef HAVE_GETENTROPY +/* Define to 1 if you have the `geteuid' function. */ +#undef HAVE_GETEUID + +/* Define to 1 if you have the `getgid' function. */ +#undef HAVE_GETGID + /* Define to 1 if you have the `getgrouplist' function. */ #undef HAVE_GETGROUPLIST @@ -386,18 +395,30 @@ /* Define to 1 if you have the `getpid' function. */ #undef HAVE_GETPID +/* Define to 1 if you have the `getppid' function. */ +#undef HAVE_GETPPID + /* Define to 1 if you have the `getpriority' function. */ #undef HAVE_GETPRIORITY /* Define to 1 if you have the `getpwent' function. */ #undef HAVE_GETPWENT +/* Define to 1 if you have the `getpwnam' function. */ +#undef HAVE_GETPWNAM + +/* Define to 1 if you have the `getpwuid' function. */ +#undef HAVE_GETPWUID + /* Define to 1 if you have the `getresgid' function. */ #undef HAVE_GETRESGID /* Define to 1 if you have the `getresuid' function. */ #undef HAVE_GETRESUID +/* Define to 1 if you have the `getrlimit' function. */ +#undef HAVE_GETRLIMIT + /* Define to 1 if you have the `getsid' function. */ #undef HAVE_GETSID @@ -410,6 +431,9 @@ /* Define to 1 if you have the `gettimeofday' function. */ #undef HAVE_GETTIMEOFDAY +/* Define to 1 if you have the `getuid' function. */ +#undef HAVE_GETUID + /* Define to 1 if you have the `getwd' function. */ #undef HAVE_GETWD @@ -612,6 +636,9 @@ /* Define to 1 if you have the `openat' function. */ #undef HAVE_OPENAT +/* Define to 1 if you have the `opendir' function. */ +#undef HAVE_OPENDIR + /* Define to 1 if you have the `openpty' function. */ #undef HAVE_OPENPTY @@ -624,6 +651,9 @@ /* Define to 1 if you have the `pause' function. */ #undef HAVE_PAUSE +/* Define to 1 if you have the `pipe' function. */ +#undef HAVE_PIPE + /* Define to 1 if you have the `pipe2' function. */ #undef HAVE_PIPE2 @@ -744,6 +774,9 @@ /* Define to 1 if you have the `sched_setscheduler' function. */ #undef HAVE_SCHED_SETSCHEDULER +/* Define to 1 if you have the `sched_yield' function. */ +#undef HAVE_SCHED_YIELD + /* Define to 1 if you have the `select' function. */ #undef HAVE_SELECT @@ -941,6 +974,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYSEXITS_H +/* Define to 1 if you have the `system' function. */ +#undef HAVE_SYSTEM + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_AUDIOIO_H @@ -1085,6 +1121,9 @@ /* Define to 1 if you have the `truncate' function. */ #undef HAVE_TRUNCATE +/* Define to 1 if you have the `ttyname' function. */ +#undef HAVE_TTYNAME + /* Define to 1 if you don't have `tm_zone' but do have the external array `tzname'. */ #undef HAVE_TZNAME @@ -1101,6 +1140,9 @@ /* Define to 1 if the system has the type `uintptr_t'. */ #undef HAVE_UINTPTR_T +/* Define to 1 if you have the `umask' function. */ +#undef HAVE_UMASK + /* Define to 1 if you have the `uname' function. */ #undef HAVE_UNAME @@ -1130,6 +1172,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UTIME_H +/* Define to 1 if you have the `wait' function. */ +#undef HAVE_WAIT + /* Define to 1 if you have the `wait3' function. */ #undef HAVE_WAIT3