except_out:
srd_exception_catch("Failed to get %s list of %s decoder",
attr, d->name);
+
err_out:
g_slist_free_full(pdchl, &channel_free);
Py_XDECREF(py_channellist);
py_values = PyDict_GetItemString(py_opt, "values");
if (py_values) {
- /* A default is required if a list of values is
- * given, since it's used to verify their type. */
+ /*
+ * A default is required if a list of values is
+ * given, since it's used to verify their type.
+ */
if (!o->def) {
srd_err("No default for option '%s'.", o->id);
goto err_out;
except_out:
srd_exception_catch("Failed to get %s decoder options", d->name);
+
err_out:
g_slist_free_full(options, &decoder_option_free);
Py_XDECREF(py_opts);
return SRD_ERR_PYTHON;
}
-/* Convert annotation class attribute to GSList of char **.
- */
+/* Convert annotation class attribute to GSList of char **. */
static int get_annotations(struct srd_decoder *dec)
{
PyObject *py_annlist, *py_ann;
except_out:
srd_exception_catch("Failed to get %s decoder annotations", dec->name);
+
err_out:
g_slist_free_full(annotations, (GDestroyNotify)&g_strfreev);
Py_XDECREF(py_annlist);
return SRD_ERR_PYTHON;
}
-/* Convert annotation_rows to GSList of 'struct srd_decoder_annotation_row'.
- */
+/* Convert annotation_rows to GSList of 'struct srd_decoder_annotation_row'. */
static int get_annotation_rows(struct srd_decoder *dec)
{
PyObject *py_ann_rows, *py_ann_row, *py_ann_classes, *py_item;
except_out:
srd_exception_catch("Failed to get %s decoder annotation rows",
dec->name);
+
err_out:
g_slist_free_full(annotation_rows, &annotation_row_free);
Py_XDECREF(py_ann_rows);
return SRD_ERR_PYTHON;
}
-/* Convert binary classes to GSList of char **.
- */
+/* Convert binary classes to GSList of char **. */
static int get_binary_classes(struct srd_decoder *dec)
{
PyObject *py_bin_classes, *py_bin_class;
except_out:
srd_exception_catch("Failed to get %s decoder binary classes",
dec->name);
+
err_out:
g_slist_free_full(bin_classes, (GDestroyNotify)&g_strfreev);
Py_XDECREF(py_bin_classes);
return SRD_ERR_PYTHON;
}
-/* Check whether the Decoder class defines the named method.
- */
+/* Check whether the Decoder class defines the named method. */
static int check_method(PyObject *py_dec, const char *mod_name,
const char *method_name)
{
goto err_out;
}
- /* Check Decoder class for required methods.
- */
+ /* Check Decoder class for required methods. */
+
if (check_method(d->py_dec, module_name, "start") != SRD_OK) {
fail_txt = "no 'start()' method";
goto err_out;
module_name, fail_txt);
}
fail_txt = NULL;
+
err_out:
if (fail_txt)
srd_err("Failed to load decoder %s: %s", module_name, fail_txt);
const gchar *direntry;
if (!(dir = g_dir_open(path, 0, NULL))) {
- /* Not really fatal */
- /* Try zipimport method too */
+ /* Not really fatal. Try zipimport method too. */
srd_decoder_load_all_zip_path(path);
return;
}
- /* This ignores errors returned by srd_decoder_load(). That
+ /*
+ * This ignores errors returned by srd_decoder_load(). That
* function will have logged the cause, but in any case we
- * want to continue anyway. */
+ * want to continue anyway.
+ */
while ((direntry = g_dir_read_name(dir)) != NULL) {
/* The directory name is the module name (e.g. "i2c"). */
srd_decoder_load(direntry);
}
g_dir_close(dir);
-
}
/**
PyErr_Clear();
srd_dbg("Failed to stringify object.");
}
+
return str;
}
PyErr_Clear();
srd_dbg("Failed to get object attribute %s.", attr);
}
+
return str;
}
return ret;
}
-/* Helper GComparefunc for g_slist_find_custom() in srd_inst_channel_set_all() */
+/* Helper GComparefunc for g_slist_find_custom() in srd_inst_channel_set_all(). */
static gint compare_channel_id(const struct srd_channel *pdch,
const char *channel_id)
{
srd_dbg("%s: Resetting decoder state.", di->inst_id);
- /*
- * Reset internal state of the decoder.
- */
+ /* Reset internal state of the decoder. */
condition_list_free(di);
match_array_free(di);
di->abs_start_samplenum = 0;
if (di->want_wait_terminate)
return SRD_ERR_TERM_REQ;
+
return SRD_OK;
}
* calls like they would for newly constructed decoder stacks.
*
* @param di The decoder instance to call. Must not be NULL.
+ *
* @return SRD_OK upon success, a (negative) error code otherwise.
+ *
* @private
*/
SRD_PRIV int srd_inst_terminate_reset(struct srd_decoder_inst *di)
}
PyGILState_Release(gstate);
- /*
- * Pass the "restart" request to all stacked decoders.
- */
+ /* Pass the "restart" request to all stacked decoders. */
for (l = di->next_di; l; l = l->next) {
ret = srd_inst_terminate_reset(l->data);
if (ret != SRD_OK)
struct srd_pd_output *pdo;
PyGILState_STATE gstate;
- srd_dbg("Freeing instance %s", di->inst_id);
+ srd_dbg("Freeing instance %s.", di->inst_id);
srd_inst_join_decode_thread(di);
PyGILState_Release(gstate);
return mod;
+
err_out:
Py_XDECREF(mod);
srd_exception_catch("Failed to initialize module");
return NULL;
}
+
/** @endcond */
/** @private */
SRD_PRIV int session_is_valid(struct srd_session *sess)
{
-
if (!sess || sess->session_id < 1)
return SRD_ERR;
*/
SRD_API int srd_session_new(struct srd_session **sess)
{
-
if (!sess) {
srd_err("Invalid session pointer.");
return SRD_ERR_ARG;
if (ret != SRD_OK)
return ret;
}
+
return SRD_OK;
}
if (g_file_test(decdir, G_FILE_TEST_IS_DIR))
ret = srd_decoder_searchpath_add(decdir);
else
- ret = SRD_OK; /* just ignore non-existing directory */
+ ret = SRD_OK; /* Just ignore non-existing directory. */
g_free(decdir);
/* Locations relative to the XDG system data directories. */
sys_datadirs = g_get_system_data_dirs();
for (i = g_strv_length((char **)sys_datadirs); i > 0; i--) {
- ret = searchpath_add_xdg_dir(sys_datadirs[i-1]);
+ ret = searchpath_add_xdg_dir(sys_datadirs[i - 1]);
if (ret != SRD_OK) {
Py_Finalize();
return ret;
PyObject_HEAD
} srd_Decoder;
-/* This is only used for nicer srd_dbg() output.
- */
+/* This is only used for nicer srd_dbg() output. */
static const char *output_type_name(unsigned int idx)
{
static const char names[][16] = {
"OUTPUT_META",
"(invalid)"
};
+
return names[MIN(idx, G_N_ELEMENTS(names) - 1)];
}
Py_XDECREF(py_res);
}
if ((cb = srd_pd_output_callback_find(di->sess, pdo->output_type))) {
- /* Frontends aren't really supposed to get Python
- * callbacks, but it's useful for testing. */
+ /*
+ * Frontends aren't really supposed to get Python
+ * callbacks, but it's useful for testing.
+ */
pdata.data = py_data;
cb->cb(&pdata, cb->cb_data);
}
const GVariantType *meta_type_gv;
int output_type;
char *proto_id, *meta_name, *meta_descr;
- char *keywords[] = {"output_type", "proto_id", "meta", NULL};
+ char *keywords[] = { "output_type", "proto_id", "meta", NULL };
PyGILState_STATE gstate;
gboolean is_meta;
GSList *l;
goto err;
}
- /* Default to instance id, which defaults to class id. */
+ /* Default to instance ID, which defaults to class ID. */
proto_id = di->inst_id;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|s(Oss)", keywords,
&output_type, &proto_id,
}
static PyMethodDef Decoder_methods[] = {
- {"put", Decoder_put, METH_VARARGS,
- "Accepts a dictionary with the following keys: startsample, endsample, data"},
- {"register", (PyCFunction)Decoder_register, METH_VARARGS|METH_KEYWORDS,
- "Register a new output stream"},
- {"wait", Decoder_wait, METH_VARARGS,
- "Wait for one or more conditions to occur"},
- {"has_channel", Decoder_has_channel, METH_VARARGS,
- "Report whether a channel was supplied"},
+ { "put", Decoder_put, METH_VARARGS,
+ "Accepts a dictionary with the following keys: startsample, endsample, data" },
+ { "register", (PyCFunction)Decoder_register, METH_VARARGS|METH_KEYWORDS,
+ "Register a new output stream" },
+ { "wait", Decoder_wait, METH_VARARGS,
+ "Wait for one or more conditions to occur" },
+ { "has_channel", Decoder_has_channel, METH_VARARGS,
+ "Report whether a channel was supplied" },
{NULL, NULL, 0, NULL}
};
}
if (!var)
srd_exception_catch("Failed to extract string value");
-
} else if (PyLong_Check(py_obj)) { /* integer */
int64_t val;
var = g_variant_new_int64(val);
else
srd_exception_catch("Failed to extract integer value");
-
} else if (PyFloat_Check(py_obj)) { /* float */
double val;
var = g_variant_new_double(val);
else
srd_exception_catch("Failed to extract float value");
-
} else {
srd_err("Failed to extract value of unsupported type.");
}