From 106c1a0e7a38f59191182069debd4eb7490f9bad Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Tue, 23 Apr 2002 15:58:02 +0000 Subject: [PATCH] WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New. isatty(), WIFEXITED(), WIFSIGNALED(), WIFSTOPPED(): Changed to return bools instead of ints. --- Doc/lib/libos.tex | 44 +++++++++++++++++++--- Modules/posixmodule.c | 86 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 113 insertions(+), 17 deletions(-) diff --git a/Doc/lib/libos.tex b/Doc/lib/libos.tex index 7e677c9069b..e56f24e89ca 100644 --- a/Doc/lib/libos.tex +++ b/Doc/lib/libos.tex @@ -420,8 +420,8 @@ Availability: \UNIX. \end{funcdesc} \begin{funcdesc}{isatty}{fd} -Return \code{1} if the file descriptor \var{fd} is open and connected to a -tty(-like) device, else \code{0}. +Return \code{True} if the file descriptor \var{fd} is open and +connected to a tty(-like) device, else \code{False}. Availability: \UNIX. \end{funcdesc} @@ -1225,24 +1225,56 @@ process status is available immediately. Availability: \UNIX. \end{datadesc} +\begin{datadesc}{WCONTINUED} +This option causes child processes to be reported if they have been +continued from a job control stop since their status was last +reported. +Availability: Some \UNIX{} systems. +\versionadded{2.3} +\end{datadesc} + +\begin{datadesc}{WUNTRACED} +This option causes child processes to be reported if they have been +stopped but their current state has not been reported since they were +stopped. +Availability: \UNIX. +\versionadded{2.3} +\end{datadesc} + The following functions take a process status code as returned by \function{system()}, \function{wait()}, or \function{waitpid()} as a parameter. They may be used to determine the disposition of a process. +\begin{funcdesc}{WCOREDUMP}{status} +Returns \code{True} if a core dump was generated for the process, +otherwise it returns \code{False}. +Availability: \UNIX. +\versionadded{2.3} +\end{funcdesc} + +\begin{funcdesc}{WIFCONTINUED}{status} +Returns \code{True} if the process has been continued from a job +control stop, otherwise it returns \code{False}. +Availability: \UNIX. +\versionadded{2.3} +\end{funcdesc} + \begin{funcdesc}{WIFSTOPPED}{status} -Return true if the process has been stopped. +Returns \code{True} if the process has been stopped, otherwise it +returns \code{False}. Availability: \UNIX. \end{funcdesc} \begin{funcdesc}{WIFSIGNALED}{status} -Return true if the process exited due to a signal. +Returns \code{True} if the process exited due to a signal, otherwise +it returns \code{False}. Availability: \UNIX. \end{funcdesc} \begin{funcdesc}{WIFEXITED}{status} -Return true if the process exited using the \manpage{exit}{2} system -call. +Returns \code{True} if the process exited using the \manpage{exit}{2} +system call, otherwise it returns \code{False}. Availability: \UNIX. \end{funcdesc} diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index fb35b1a1bae..03622b75352 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -4529,8 +4529,8 @@ posix_fdopen(PyObject *self, PyObject *args) } static char posix_isatty__doc__[] = -"isatty(fd) -> Boolean\n\ -Return true if the file descriptor 'fd' is an open file descriptor\n\ +"isatty(fd) -> bool\n\ +Return True if the file descriptor 'fd' is an open file descriptor\n\ connected to the slave end of a terminal."; static PyObject * @@ -4539,7 +4539,7 @@ posix_isatty(PyObject *self, PyObject *args) int fd; if (!PyArg_ParseTuple(args, "i:isatty", &fd)) return NULL; - return Py_BuildValue("i", isatty(fd)); + return PyBool_FromLong(isatty(fd)); } #ifdef HAVE_PIPE @@ -4823,10 +4823,65 @@ posix_strerror(PyObject *self, PyObject *args) #ifdef HAVE_SYS_WAIT_H +#ifdef WCOREDUMP +static char posix_WCOREDUMP__doc__[] = +"WCOREDUMP(status) -> bool\n\ +Return True if the process returning 'status' was dumped to a core file."; + +static PyObject * +posix_WCOREDUMP(PyObject *self, PyObject *args) +{ +#ifdef UNION_WAIT + union wait status; +#define status_i (status.w_status) +#else + int status; +#define status_i status +#endif + status_i = 0; + + if (!PyArg_ParseTuple(args, "i:WCOREDUMP", &status_i)) + { + return NULL; + } + + return PyBool_FromLong(WCOREDUMP(status)); +#undef status_i +} +#endif /* WCOREDUMP */ + +#ifdef WIFCONTINUED +static char posix_WIFCONTINUED__doc__[] = +"WIFCONTINUED(status) -> bool\n\ +Return True if the process returning 'status' was continued from a\n\ +job control stop."; + +static PyObject * +posix_WCONTINUED(PyObject *self, PyObject *args) +{ +#ifdef UNION_WAIT + union wait status; +#define status_i (status.w_status) +#else + int status; +#define status_i status +#endif + status_i = 0; + + if (!PyArg_ParseTuple(args, "i:WCONTINUED", &status_i)) + { + return NULL; + } + + return PyBool_FromLong(WCONTINUED(status)); +#undef status_i +} +#endif /* WIFCONTINUED */ + #ifdef WIFSTOPPED static char posix_WIFSTOPPED__doc__[] = -"WIFSTOPPED(status) -> Boolean\n\ -Return true if the process returning 'status' was stopped."; +"WIFSTOPPED(status) -> bool\n\ +Return True if the process returning 'status' was stopped."; static PyObject * posix_WIFSTOPPED(PyObject *self, PyObject *args) @@ -4845,15 +4900,15 @@ posix_WIFSTOPPED(PyObject *self, PyObject *args) return NULL; } - return Py_BuildValue("i", WIFSTOPPED(status)); + return PyBool_FromLong(WIFSTOPPED(status)); #undef status_i } #endif /* WIFSTOPPED */ #ifdef WIFSIGNALED static char posix_WIFSIGNALED__doc__[] = -"WIFSIGNALED(status) -> Boolean\n\ -Return true if the process returning 'status' was terminated by a signal."; +"WIFSIGNALED(status) -> bool\n\ +Return True if the process returning 'status' was terminated by a signal."; static PyObject * posix_WIFSIGNALED(PyObject *self, PyObject *args) @@ -4872,14 +4927,14 @@ posix_WIFSIGNALED(PyObject *self, PyObject *args) return NULL; } - return Py_BuildValue("i", WIFSIGNALED(status)); + return PyBool_FromLong(WIFSIGNALED(status)); #undef status_i } #endif /* WIFSIGNALED */ #ifdef WIFEXITED static char posix_WIFEXITED__doc__[] = -"WIFEXITED(status) -> Boolean\n\ +"WIFEXITED(status) -> bool\n\ Return true if the process returning 'status' exited using the exit()\n\ system call."; @@ -4900,7 +4955,7 @@ posix_WIFEXITED(PyObject *self, PyObject *args) return NULL; } - return Py_BuildValue("i", WIFEXITED(status)); + return PyBool_FromLong(WIFEXITED(status)); #undef status_i } #endif /* WIFEXITED */ @@ -6407,6 +6462,9 @@ static PyMethodDef posix_methods[] = { {"fdatasync", posix_fdatasync, METH_O, posix_fdatasync__doc__}, #endif #ifdef HAVE_SYS_WAIT_H +#ifdef WCOREDUMP + {"WCOREDUMP", posix_WCOREDUMP, METH_VARARGS, posix_WCOREDUMP__doc__}, +#endif /* WCOREDUMP */ #ifdef WIFSTOPPED {"WIFSTOPPED", posix_WIFSTOPPED, METH_VARARGS, posix_WIFSTOPPED__doc__}, #endif /* WIFSTOPPED */ @@ -6541,9 +6599,15 @@ all_ins(PyObject *d) #ifdef TMP_MAX if (ins(d, "TMP_MAX", (long)TMP_MAX)) return -1; #endif +#ifdef WCONTINUED + if (ins(d, "WCONTINUED", (long)WCONTINUED)) return -1; +#endif #ifdef WNOHANG if (ins(d, "WNOHANG", (long)WNOHANG)) return -1; #endif +#ifdef WUNTRACED + if (ins(d, "WUNTRACED", (long)WUNTRACED)) return -1; +#endif #ifdef O_RDONLY if (ins(d, "O_RDONLY", (long)O_RDONLY)) return -1; #endif