Push rpm.signalsCaught() to python level
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 28 Sep 2009 13:37:14 +0000 (16:37 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 28 Sep 2009 13:37:14 +0000 (16:37 +0300)
- 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
python/rpmmodule.c

index ca501c6..de0f683 100644 (file)
@@ -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
index ce3d848..3748e87 100644 (file)
@@ -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 },