Py_Initialize();
/* Installed decoders. */
- if ((ret = add_modulepath(DECODERS_DIR)) != SRD_OK) {
+ if ((ret = srd_decoder_searchpath_add(DECODERS_DIR)) != SRD_OK) {
Py_Finalize();
return ret;
}
/* Path specified by the user. */
if (path) {
- if ((ret = add_modulepath(path)) != SRD_OK) {
+ if ((ret = srd_decoder_searchpath_add(path)) != SRD_OK) {
Py_Finalize();
return ret;
}
/* Environment variable overrides everything, for debugging. */
if ((env_path = getenv("SIGROKDECODE_DIR"))) {
- if ((ret = add_modulepath(env_path)) != SRD_OK) {
+ if ((ret = srd_decoder_searchpath_add(env_path)) != SRD_OK) {
Py_Finalize();
return ret;
}
*
* @return SRD_OK upon success, a (negative) error code otherwise.
*/
-SRD_PRIV int add_modulepath(const char *path)
+SRD_PRIV int srd_decoder_searchpath_add(const char *path)
{
PyObject *py_cur_path, *py_item;
GString *new_path;
Py_XDECREF(py_dec_options);
g_free(key);
if (PyErr_Occurred())
- catch_exception("Stray exception in srd_inst_set_options().");
+ srd_exception_catch("Stray exception in srd_inst_option_set().");
return ret;
}
/* Create a new instance of this decoder class. */
if (!(di->py_inst = PyObject_CallObject(dec->py_dec, NULL))) {
if (PyErr_Occurred())
- catch_exception("failed to create %s instance: ",
- decoder_id);
+ srd_exception_catch("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'.");
- catch_exception("Protocol decoder instance %s: ",
- di->inst_id);
+ srd_exception_catch("Protocol decoder instance %s: ",
+ di->inst_id);
return SRD_ERR_PYTHON;
}
if (!(py_res = PyObject_CallMethodObjArgs(di->py_inst,
py_name, args, NULL))) {
- catch_exception("Protocol decoder instance %s: ",
- di->inst_id);
+ srd_exception_catch("Protocol decoder instance %s: ",
+ di->inst_id);
return SRD_ERR_PYTHON;
}
if (!(py_res = PyObject_CallMethod(di->py_inst, "decode",
"KKO", logic->start_samplenum,
end_samplenum, logic))) {
- catch_exception("Protocol decoder instance %s: ",
- di->inst_id);
+ srd_exception_catch("Protocol decoder instance %s: ",
+ di->inst_id);
return SRD_ERR_PYTHON; /* TODO: More specific error? */
}
Py_DecRef(py_res);
}
/* This is the backend function to Python sigrokdecode.add() call. */
-SRD_PRIV int pd_add(struct srd_decoder_inst *di, int output_type,
- const char *proto_id)
+SRD_PRIV int srd_inst_pd_output_add(struct srd_decoder_inst *di,
+ int output_type, const char *proto_id)
{
struct srd_pd_output *pdo;
/* Import the Python module. */
if (!(d->py_mod = PyImport_ImportModule(module_name))) {
- catch_exception("Import of '%s' failed.", module_name);
+ srd_exception_catch("Import of '%s' failed.", module_name);
goto err_out;
}
return NULL;
if (!(py_str = PyObject_GetAttrString(dec->py_mod, "__doc__"))) {
- catch_exception("");
+ srd_exception_catch("");
return NULL;
}
#include <glib.h>
#include <frameobject.h> /* Python header not pulled in by default. */
-SRD_PRIV void catch_exception(const char *format, ...)
+SRD_PRIV void srd_exception_catch(const char *format, ...)
{
PyObject *etype, *evalue, *etb, *py_str;
PyTracebackObject *py_tb;
/*--- controller.c ----------------------------------------------------------*/
-SRD_PRIV int add_modulepath(const char *path);
+SRD_PRIV int srd_decoder_searchpath_add(const char *path);
SRD_PRIV int srd_inst_start(struct srd_decoder_inst *di, PyObject *args);
SRD_PRIV int srd_inst_decode(uint64_t start_samplenum,
const struct srd_decoder_inst *dec,
const uint8_t *inbuf, uint64_t inbuflen);
SRD_PRIV void srd_inst_free(struct srd_decoder_inst *di);
SRD_PRIV void srd_inst_free_all(GSList *stack);
-SRD_PRIV int pd_add(struct srd_decoder_inst *di, int output_type,
- const char *output_id);
+SRD_PRIV int srd_inst_pd_output_add(struct srd_decoder_inst *di,
+ int output_type, const char *output_id);
/*--- decoder.c -------------------------------------------------------------*/
/*--- exception.c -----------------------------------------------------------*/
-SRD_PRIV void catch_exception(const char *format, ...);
+SRD_PRIV void srd_exception_catch(const char *format, ...);
/*--- log.c -----------------------------------------------------------------*/
if (!(py_res = PyObject_CallMethod(
next_di->py_inst, "decode", "KKO", start_sample,
end_sample, data))) {
- catch_exception("Calling %s decode(): ",
- next_di->inst_id);
+ srd_exception_catch("Calling %s decode(): ",
+ next_di->inst_id);
}
Py_XDECREF(py_res);
}
return NULL;
}
- pdo_id = pd_add(di, output_type, proto_id);
+ pdo_id = srd_inst_pd_output_add(di, output_type, proto_id);
if (pdo_id < 0)
Py_RETURN_NONE;
else
}
if (!(py_str = PyObject_GetAttrString((PyObject *)py_obj, attr))) {
- catch_exception("");
+ srd_exception_catch("");
return SRD_ERR_PYTHON;
}
Py_XDECREF(py_encstr);
if (PyErr_Occurred()) {
- catch_exception("string conversion failed");
+ srd_exception_catch("string conversion failed");
}
return ret;