@@ -146,6 +146,7 @@ corresponding Unix manual entries for more information on calls.";
146146#undef HAVE_UTIME_H
147147#define HAVE_WAITPID
148148/* #undef HAVE_GETCWD */
149+ #define UNION_WAIT /* This should really be checked for by autoconf */
149150#endif
150151
151152#ifdef HAVE_UNISTD_H
@@ -255,6 +256,23 @@ extern int lstat Py_PROTO((const char *, struct stat *));
255256#include <io.h>
256257#endif /* OS2 */
257258
259+ #ifdef UNION_WAIT
260+ /* Emulate some macros on systems that have a union instead of macros */
261+
262+ #ifndef WIFEXITED
263+ #define WIFEXITED (u_wait ) (!(u_wait).w_termsig && !(u_wait).w_coredump)
264+ #endif
265+
266+ #ifndef WEXITSTATUS
267+ #define WEXITSTATUS (u_wait ) (WIFEXITED(u_wait)?((u_wait).w_retcode):-1)
268+ #endif
269+
270+ #ifndef WTERMSIG
271+ #define WTERMSIG (u_wait ) ((u_wait).w_termsig)
272+ #endif
273+
274+ #endif /* UNION_WAIT */
275+
258276/* Return a dictionary corresponding to the POSIX environment table */
259277
260278#if !defined(_MSC_VER ) && ( !defined(__WATCOMC__ ) || defined(__QNX__ ) )
@@ -1986,20 +2004,25 @@ posix_waitpid(self, args)
19862004 PyObject * self ;
19872005 PyObject * args ;
19882006{
1989- int pid , options , sts = 0 ;
2007+ int pid , options ;
2008+ #ifdef UNION_WAIT
2009+ union wait status ;
2010+ #define status_i (status.w_status)
2011+ #else
2012+ int status ;
2013+ #define status_i status
2014+ #endif
2015+ status_i = 0 ;
2016+
19902017 if (!PyArg_Parse (args , "(ii)" , & pid , & options ))
19912018 return NULL ;
19922019 Py_BEGIN_ALLOW_THREADS
1993- #ifdef NeXT
1994- pid = wait4 (pid , (union wait * )& sts , options , NULL );
1995- #else
1996- pid = waitpid (pid , & sts , options );
1997- #endif
2020+ pid = wait4 (pid , & status , options , NULL );
19982021 Py_END_ALLOW_THREADS
19992022 if (pid == -1 )
20002023 return posix_error ();
20012024 else
2002- return Py_BuildValue ("ii ", pid , sts );
2025+ return Py_BuildValue ("ii ", pid , status_i );
20032026}
20042027#endif /* HAVE_WAITPID */
20052028
@@ -2015,17 +2038,21 @@ posix_wait(self, args)
20152038 PyObject * args ;
20162039{
20172040 int pid , sts ;
2018- Py_BEGIN_ALLOW_THREADS
2019- #ifdef NeXT
2020- pid = wait (( union wait * ) & sts );
2041+ #ifdef UNION_WAIT
2042+ union wait status ;
2043+ #define status_i (status.w_status)
20212044#else
2022- pid = wait (& sts );
2045+ int status ;
2046+ #define status_i status
20232047#endif
2048+ status_i = 0 ;
2049+ Py_BEGIN_ALLOW_THREADS
2050+ pid = wait (& status );
20242051 Py_END_ALLOW_THREADS
20252052 if (pid == -1 )
20262053 return posix_error ();
20272054 else
2028- return Py_BuildValue ("ii ", pid , sts );
2055+ return Py_BuildValue ("ii ", pid , status_i );
20292056}
20302057#endif
20312058
@@ -2821,9 +2848,16 @@ posix_WIFSTOPPED(self, args)
28212848 PyObject * self ;
28222849 PyObject * args ;
28232850{
2824- int status = 0 ;
2851+ #ifdef UNION_WAIT
2852+ union wait status ;
2853+ #define status_i (status.w_status)
2854+ #else
2855+ int status ;
2856+ #define status_i status
2857+ #endif
2858+ status_i = 0 ;
28252859
2826- if (!PyArg_Parse (args , "i" , & status ))
2860+ if (!PyArg_Parse (args , "i" , & status_i ))
28272861 {
28282862 return NULL ;
28292863 }
@@ -2842,9 +2876,16 @@ posix_WIFSIGNALED(self, args)
28422876 PyObject * self ;
28432877 PyObject * args ;
28442878{
2845- int status = 0 ;
2879+ #ifdef UNION_WAIT
2880+ union wait status ;
2881+ #define status_i (status.w_status)
2882+ #else
2883+ int status ;
2884+ #define status_i status
2885+ #endif
2886+ status_i = 0 ;
28462887
2847- if (!PyArg_Parse (args , "i" , & status ))
2888+ if (!PyArg_Parse (args , "i" , & status_i ))
28482889 {
28492890 return NULL ;
28502891 }
@@ -2863,9 +2904,16 @@ posix_WIFEXITED(self, args)
28632904 PyObject * self ;
28642905 PyObject * args ;
28652906{
2866- int status = 0 ;
2907+ #ifdef UNION_WAIT
2908+ union wait status ;
2909+ #define status_i (status.w_status)
2910+ #else
2911+ int status ;
2912+ #define status_i status
2913+ #endif
2914+ status_i = 0 ;
28672915
2868- if (!PyArg_Parse (args , "i" , & status ))
2916+ if (!PyArg_Parse (args , "i" , & status_i ))
28692917 {
28702918 return NULL ;
28712919 }
@@ -2874,7 +2922,7 @@ posix_WIFEXITED(self, args)
28742922}
28752923#endif /* WIFEXITED */
28762924
2877- #ifdef WIFSTOPPED
2925+ #ifdef WEXITSTATUS
28782926static char posix_WEXITSTATUS__doc__ [] =
28792927"WEXITSTATUS(status) -> integer\n\
28802928See Unix documentation." ;
@@ -2884,9 +2932,16 @@ posix_WEXITSTATUS(self, args)
28842932 PyObject * self ;
28852933 PyObject * args ;
28862934{
2887- int status = 0 ;
2935+ #ifdef UNION_WAIT
2936+ union wait status ;
2937+ #define status_i (status.w_status)
2938+ #else
2939+ int status ;
2940+ #define status_i status
2941+ #endif
2942+ status_i = 0 ;
28882943
2889- if (!PyArg_Parse (args , "i" , & status ))
2944+ if (!PyArg_Parse (args , "i" , & status_i ))
28902945 {
28912946 return NULL ;
28922947 }
@@ -2905,9 +2960,16 @@ posix_WTERMSIG(self, args)
29052960 PyObject * self ;
29062961 PyObject * args ;
29072962{
2908- int status = 0 ;
2963+ #ifdef UNION_WAIT
2964+ union wait status ;
2965+ #define status_i (status.w_status)
2966+ #else
2967+ int status ;
2968+ #define status_i status
2969+ #endif
2970+ status_i = 0 ;
29092971
2910- if (!PyArg_Parse (args , "i" , & status ))
2972+ if (!PyArg_Parse (args , "i" , & status_i ))
29112973 {
29122974 return NULL ;
29132975 }
@@ -2926,9 +2988,16 @@ posix_WSTOPSIG(self, args)
29262988 PyObject * self ;
29272989 PyObject * args ;
29282990{
2929- int status = 0 ;
2991+ #ifdef UNION_WAIT
2992+ union wait status ;
2993+ #define status_i (status.w_status)
2994+ #else
2995+ int status ;
2996+ #define status_i status
2997+ #endif
2998+ status_i = 0 ;
29302999
2931- if (!PyArg_Parse (args , "i" , & status ))
3000+ if (!PyArg_Parse (args , "i" , & status_i ))
29323001 {
29333002 return NULL ;
29343003 }
0 commit comments