void process_handler (zbar_image_t *zimg, const void *userdata) { zbarProcessor *self = (zbarProcessor*)userdata; assert(self); assert(self->handler); assert(self->closure); zbarImage *img = zbar_image_get_userdata(zimg); if(!img || img->zimg != zimg) { img = zbarImage_FromImage(zimg); if(!img) { PyErr_NoMemory(); return; } } else Py_INCREF(img); PyObject *args = PyTuple_New(3); Py_INCREF(self); Py_INCREF(self->closure); PyTuple_SET_ITEM(args, 0, (PyObject*)self); PyTuple_SET_ITEM(args, 1, (PyObject*)img); PyTuple_SET_ITEM(args, 2, self->closure); PyObject *junk = PyObject_Call(self->handler, args, NULL); Py_XDECREF(junk); Py_DECREF(args); }
void process_handler (zbar_image_t *zimg, const void *userdata) { PyGILState_STATE gstate; gstate = PyGILState_Ensure(); zbarProcessor *self = (zbarProcessor*)userdata; assert(self); assert(self->handler); assert(self->closure); zbarImage *img = zbar_image_get_userdata(zimg); if(!img || img->zimg != zimg) { img = zbarImage_FromImage(zimg); if(!img) { PyErr_NoMemory(); goto done; } } else Py_INCREF(img); PyObject *args = PyTuple_New(3); Py_INCREF(self); Py_INCREF(self->closure); PyTuple_SET_ITEM(args, 0, (PyObject*)self); PyTuple_SET_ITEM(args, 1, (PyObject*)img); PyTuple_SET_ITEM(args, 2, self->closure); PyObject *junk = PyObject_Call(self->handler, args, NULL); if(junk) Py_DECREF(junk); else { PySys_WriteStderr("in ZBar Processor data_handler:\n"); assert(PyErr_Occurred()); PyErr_Print(); } Py_DECREF(args); done: PyGILState_Release(gstate); }