Py_XDECREF(py_dec_options);
if (key)
g_free(key);
- if (PyErr_Occurred()) {
- srd_dbg("srd: stray exception!");
- PyErr_Print();
- PyErr_Clear();
- }
+ if (PyErr_Occurred())
+ catch_exception("srd: stray exception in srd_instance_set_options()");
return ret;
}
/* Create a new instance of this decoder class. */
if (!(di->py_instance = PyObject_CallObject(dec->py_dec, NULL))) {
if (PyErr_Occurred())
- PyErr_Print();
+ catch_exception("failed to create %s instance: ", decoder_id);
g_free(di->dec_probemap);
g_free(di);
return NULL;
if (!(py_name = PyUnicode_FromString("start"))) {
srd_err("Unable to build python object for 'start'.");
- if (PyErr_Occurred())
- PyErr_Print();
+ catch_exception("Protocol decoder instance %s: ", di->instance_id);
return SRD_ERR_PYTHON;
}
if (!(py_res = PyObject_CallMethodObjArgs(di->py_instance,
py_name, args, NULL))) {
- if (PyErr_Occurred())
- PyErr_Print();
+ catch_exception("Protocol decoder instance %s: ", di->instance_id);
return SRD_ERR_PYTHON;
}
end_samplenum = start_samplenum + inbuflen / di->data_unitsize;
if (!(py_res = PyObject_CallMethod(di->py_instance, "decode",
"KKO", logic->start_samplenum, end_samplenum, logic))) {
- if (PyErr_Occurred())
- PyErr_Print(); /* Returns void. */
-
+ catch_exception("Protocol decoder instance %s: ", di->instance_id);
return SRD_ERR_PYTHON; /* TODO: More specific error? */
}
Py_DecRef(py_res);
/* Import the Python module. */
if (!(d->py_mod = PyImport_ImportModule(name))) {
- /* TODO: Report exception message/traceback to err/dbg. */
- srd_warn("srd: import of '%s' failed.", name);
- PyErr_Print();
- PyErr_Clear();
+ catch_exception("import of '%s' failed.", name);
goto err_out;
}
/* Get the 'Decoder' class as Python object. */
if (!(d->py_dec = PyObject_GetAttrString(d->py_mod, "Decoder"))) {
/* This generated an AttributeError exception. */
- PyErr_Print();
PyErr_Clear();
srd_err("Decoder class not found in protocol decoder %s.", name);
goto err_out;
return NULL;
if (!(py_str = PyObject_GetAttrString(dec->py_mod, "__doc__"))) {
- PyErr_Clear();
+ catch_exception("");
return NULL;
}
/* The decoder name is the PD directory name (e.g. "i2c"). */
decodername = g_strdup(direntry);
- /* TODO: Error handling. Use g_try_malloc(). */
- if (!(dec = malloc(sizeof(struct srd_decoder)))) {
- Py_Finalize(); /* Returns void. */
+ if (!(dec = g_try_malloc(sizeof(struct srd_decoder))))
return SRD_ERR_MALLOC;
- }
- /* Load the decoder. */
- /* TODO: Warning if loading fails for a decoder. */
if ((ret = srd_load_decoder(decodername, &dec)) == SRD_OK) {
/* Append it to the list of supported/loaded decoders. */
pd_list = g_slist_append(pd_list, dec);
for (l = srd_list_decoders(); l; l = l->next) {
dec = l->data;
- /* TODO: Error handling. */
srd_unload_decoder(dec);
}
Py_XINCREF(next_di->py_instance);
if (!(py_res = PyObject_CallMethod(next_di->py_instance, "decode",
"KKO", start_sample, end_sample, data))) {
- if (PyErr_Occurred())
- PyErr_Print();
+ catch_exception("calling %s decode(): ", next_di->instance_id);
}
Py_XDECREF(py_res);
}
int output_type, pdo_id;
if (!(di = get_di_by_decobject(self))) {
- srd_dbg("srd: %s():%d decoder instance not found", __func__, __LINE__);
+ srd_dbg("srd: decoder instance not found");
PyErr_SetString(PyExc_Exception, "decoder instance not found");
return NULL;
}
if (!PyArg_ParseTuple(args, "is", &output_type, &proto_id)) {
- if (PyErr_Occurred())
- PyErr_Print();
+ catch_exception("");
return NULL;
}
}
if (!(py_str = PyObject_GetAttrString(py_obj, attr))) {
- /* TODO: report exception message/traceback to err/dbg */
- PyErr_Clear();
+ catch_exception("");
return SRD_ERR_PYTHON;
}
Py_XDECREF(py_encstr);
if (PyErr_Occurred()) {
- srd_dbg("srd: string conversion failed");
- /* TODO: dump exception to srd_dbg */
- PyErr_Clear();
+ catch_exception("string conversion failed");
}
return ret;