From: Martin Ling Date: Wed, 17 Apr 2013 12:59:30 +0000 (+0100) Subject: python: Adding callback can fail, and refcount must be incremented. X-Git-Tag: dsupstream~115 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a25932e08c6b7424fec07bb2295fadd613294075;p=libsigrok.git python: Adding callback can fail, and refcount must be incremented. --- diff --git a/bindings/python/sigrok/core/lowlevel.i b/bindings/python/sigrok/core/lowlevel.i index eaf02a0e..28abd50d 100644 --- a/bindings/python/sigrok/core/lowlevel.i +++ b/bindings/python/sigrok/core/lowlevel.i @@ -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);