]> sigrok.org Git - libsigrok.git/commitdiff
python: Adding callback can fail, and refcount must be incremented.
authorMartin Ling <redacted>
Wed, 17 Apr 2013 12:59:30 +0000 (13:59 +0100)
committerMartin Ling <redacted>
Wed, 17 Apr 2013 12:59:30 +0000 (13:59 +0100)
bindings/python/sigrok/core/lowlevel.i

index eaf02a0e82fd4fcef8186c9b17fff7597ed6adf7..28abd50d7850ee8cb280adf5c74ca93835910955 100644 (file)
@@ -54,15 +54,21 @@ void sr_datafeed_python_callback(const struct sr_dev_inst *sdi,
     PyGILState_Release(gstate);
 }
 
-void sr_session_datafeed_python_callback_add(PyObject *cb)
+int sr_session_datafeed_python_callback_add(PyObject *cb)
 {
+    int ret;
+
     if (!PyCallable_Check(cb))
-        PyErr_SetString(PyExc_TypeError, "Object passed is not callable");
-    else
-        sr_session_datafeed_callback_add(
+        return SR_ERR_ARG;
+    else {
+        ret = sr_session_datafeed_callback_add(
             sr_datafeed_python_callback, cb);
+        if (ret == SR_OK)
+            Py_XINCREF(cb);
+        return ret;
+    }
 }
 
 %}
 
-void sr_session_datafeed_python_callback_add(PyObject *cb);
+int sr_session_datafeed_python_callback_add(PyObject *cb);