summaryrefslogtreecommitdiffstats
path: root/Modules/signalmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-05-04 11:20:35 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-05-04 11:20:35 (GMT)
commit35b300c5fd8406c0e05bc2a1e7e07e6db848571e (patch)
tree42d58a0b8cd807e58b0c26d5bb91614dcb1af9cf /Modules/signalmodule.c
parent6fd49e152ae173e4f89d5d547b828fa8af4072f2 (diff)
downloadcpython-35b300c5fd8406c0e05bc2a1e7e07e6db848571e.zip
cpython-35b300c5fd8406c0e05bc2a1e7e07e6db848571e.tar.gz
cpython-35b300c5fd8406c0e05bc2a1e7e07e6db848571e.tar.bz2
Issue #8407: signal.pthread_sigmask() returns a set instead of a list
Update the doc. Refactor also related tests.
Diffstat (limited to 'Modules/signalmodule.c')
-rw-r--r--Modules/signalmodule.c61
1 files changed, 35 insertions, 26 deletions
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index 387dc8c..c8626ad 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -552,37 +552,18 @@ error:
return result;
}
-static PyObject *
-signal_pthread_sigmask(PyObject *self, PyObject *args)
+static PyObject*
+sigset_to_set(sigset_t mask)
{
- int how, sig;
- PyObject *signals, *result, *signum;
- sigset_t mask, previous;
- int err;
-
- if (!PyArg_ParseTuple(args, "iO:pthread_sigmask", &how, &signals))
- return NULL;
-
- if (iterable_to_sigset(signals, &mask))
- return NULL;
+ PyObject *signum, *result;
+ int sig;
- err = pthread_sigmask(how, &mask, &previous);
- if (err != 0) {
- errno = err;
- PyErr_SetFromErrno(PyExc_RuntimeError);
- return NULL;
- }
-
- /* if signals was unblocked, signal handlers have been called */
- if (PyErr_CheckSignals())
- return NULL;
-
- result = PyList_New(0);
+ result = PySet_New(0);
if (result == NULL)
return NULL;
for (sig = 1; sig < NSIG; sig++) {
- if (sigismember(&previous, sig) != 1)
+ if (sigismember(&mask, sig) != 1)
continue;
/* Handle the case where it is a member by adding the signal to
@@ -595,7 +576,7 @@ signal_pthread_sigmask(PyObject *self, PyObject *args)
Py_DECREF(result);
return NULL;
}
- if (PyList_Append(result, signum) == -1) {
+ if (PySet_Add(result, signum) == -1) {
Py_DECREF(signum);
Py_DECREF(result);
return NULL;
@@ -605,6 +586,34 @@ signal_pthread_sigmask(PyObject *self, PyObject *args)
return result;
}
+static PyObject *
+signal_pthread_sigmask(PyObject *self, PyObject *args)
+{
+ int how;
+ PyObject *signals;
+ sigset_t mask, previous;
+ int err;
+
+ if (!PyArg_ParseTuple(args, "iO:pthread_sigmask", &how, &signals))
+ return NULL;
+
+ if (iterable_to_sigset(signals, &mask))
+ return NULL;
+
+ err = pthread_sigmask(how, &mask, &previous);
+ if (err != 0) {
+ errno = err;
+ PyErr_SetFromErrno(PyExc_RuntimeError);
+ return NULL;
+ }
+
+ /* if signals was unblocked, signal handlers have been called */
+ if (PyErr_CheckSignals())
+ return NULL;
+
+ return sigset_to_set(previous);
+}
+
PyDoc_STRVAR(signal_pthread_sigmask_doc,
"pthread_sigmask(how, mask) -> old mask\n\
\n\