From f74def684253964fa03edb55f155dfbb5122b1bf Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Mon, 28 Sep 2009 16:37:14 +0300 Subject: [PATCH] Push rpm.signalsCaught() to python level - only implement the bare minimum in C by adding a thin wrapper for rpmsqIsCaught(), the rest can easily be done in python --- python/rpm/__init__.py | 8 ++++++++ python/rpmmodule.c | 33 +++++---------------------------- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/python/rpm/__init__.py b/python/rpm/__init__.py index ca501c6..de0f683 100644 --- a/python/rpm/__init__.py +++ b/python/rpm/__init__.py @@ -54,3 +54,11 @@ def readHeaderFromFD(fd): offset = None return (h, offset) + +def signalsCaught(siglist): + caught = [] + for sig in siglist: + if signalCaught(sig): + caught.append(sig) + + return caught diff --git a/python/rpmmodule.c b/python/rpmmodule.c index ce3d848..3748e87 100644 --- a/python/rpmmodule.c +++ b/python/rpmmodule.c @@ -38,35 +38,12 @@ static PyObject * archScore(PyObject * self, PyObject * args, PyObject * kwds) return Py_BuildValue("i", score); } -static PyObject * signalsCaught(PyObject * self, PyObject * check) +static PyObject * signalCaught(PyObject *self, PyObject *o) { - PyObject *caught, *o; - int llen; - int signum, i; - sigset_t newMask, oldMask; + int signo; + if (!PyArg_Parse(o, "i", &signo)) return NULL; - if (!PyList_Check(check)) { - PyErr_SetString(PyExc_TypeError, "list expected"); - return NULL; - } - - llen = PyList_Size(check); - caught = PyList_New(0); - - /* block signals while checking for them */ - (void) sigfillset(&newMask); - (void) sigprocmask(SIG_BLOCK, &newMask, &oldMask); - - for (i = 0; i < llen; i++) { - o = PyList_GetItem(check, i); - signum = PyInt_AsLong(o); - if (rpmsqIsCaught(signum) > 0) { - PyList_Append(caught, o); - } - } - (void) sigprocmask(SIG_SETMASK, &oldMask, NULL); - - return caught; + return PyBool_FromLong(rpmsqIsCaught(signo)); } static PyObject * checkSignals(PyObject * self, PyObject * args) @@ -149,7 +126,7 @@ static PyMethodDef rpmModuleMethods[] = { { "archscore", (PyCFunction) archScore, METH_VARARGS|METH_KEYWORDS, NULL }, - { "signalsCaught", (PyCFunction) signalsCaught, METH_O, + { "signalCaught", (PyCFunction) signalCaught, METH_O, NULL }, { "checkSignals", (PyCFunction) checkSignals, METH_VARARGS, NULL }, -- 2.7.4