summaryrefslogtreecommitdiffstats
path: root/Modules/signalmodule.c
diff options
context:
space:
mode:
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\