@@ -3816,7 +3816,7 @@ Return the current process id");
38163816static PyObject *
38173817posix_getpid (PyObject * self , PyObject * noargs )
38183818{
3819- return PyInt_FromLong (( long ) getpid ());
3819+ return PyLong_FromPid ( getpid ());
38203820}
38213821
38223822
@@ -3870,13 +3870,13 @@ Call the system call getpgid().");
38703870static PyObject *
38713871posix_getpgid (PyObject * self , PyObject * args )
38723872{
3873- int pid , pgid ;
3874- if (!PyArg_ParseTuple (args , "i :getpgid" , & pid ))
3873+ pid_t pid , pgid ;
3874+ if (!PyArg_ParseTuple (args , PARSE_PID " :getpgid" , & pid ))
38753875 return NULL ;
38763876 pgid = getpgid (pid );
38773877 if (pgid < 0 )
38783878 return posix_error ();
3879- return PyInt_FromLong (( long ) pgid );
3879+ return PyLong_FromPid ( pgid );
38803880}
38813881#endif /* HAVE_GETPGID */
38823882
@@ -3890,9 +3890,9 @@ static PyObject *
38903890posix_getpgrp (PyObject * self , PyObject * noargs )
38913891{
38923892#ifdef GETPGRP_HAVE_ARG
3893- return PyInt_FromLong (( long ) getpgrp (0 ));
3893+ return PyLong_FromPid ( getpgrp (0 ));
38943894#else /* GETPGRP_HAVE_ARG */
3895- return PyInt_FromLong (( long ) getpgrp ());
3895+ return PyLong_FromPid ( getpgrp ());
38963896#endif /* GETPGRP_HAVE_ARG */
38973897}
38983898#endif /* HAVE_GETPGRP */
@@ -3926,7 +3926,7 @@ Return the parent's process id.");
39263926static PyObject *
39273927posix_getppid (PyObject * self , PyObject * noargs )
39283928{
3929- return PyInt_FromLong (getppid ());
3929+ return PyLong_FromPid (getppid ());
39303930}
39313931#endif
39323932
@@ -4015,8 +4015,13 @@ Kill a process group with a signal.");
40154015static PyObject *
40164016posix_killpg (PyObject * self , PyObject * args )
40174017{
4018- int pgid , sig ;
4019- if (!PyArg_ParseTuple (args , "ii:killpg" , & pgid , & sig ))
4018+ int sig ;
4019+ pid_t pgid ;
4020+ /* XXX some man pages make the `pgid` parameter an int, others
4021+ a pid_t. Since getpgrp() returns a pid_t, we assume killpg should
4022+ take the same type. Moreover, pid_t is always at least as wide as
4023+ int (else compilation of this module fails), which is safe. */
4024+ if (!PyArg_ParseTuple (args , PARSE_PID "i:killpg" , & pgid , & sig ))
40204025 return NULL ;
40214026 if (killpg (pgid , sig ) == -1 )
40224027 return posix_error ();
@@ -6181,8 +6186,9 @@ Set the process group associated with the terminal given by a fd.");
61816186static PyObject *
61826187posix_tcsetpgrp (PyObject * self , PyObject * args )
61836188{
6184- int fd , pgid ;
6185- if (!PyArg_ParseTuple (args , "ii:tcsetpgrp" , & fd , & pgid ))
6189+ int fd ;
6190+ pid_t pgid ;
6191+ if (!PyArg_ParseTuple (args , "i" PARSE_PID ":tcsetpgrp" , & fd , & pgid ))
61866192 return NULL ;
61876193 if (tcsetpgrp (fd , pgid ) < 0 )
61886194 return posix_error ();
0 commit comments