+ g_slist_free_full(annotation_rows, &annotation_row_free);
+ Py_XDECREF(py_ann_rows);
+ PyGILState_Release(gstate);
+
+ return SRD_ERR_PYTHON;
+}
+
+/* Convert binary classes to GSList of char **. */
+static int get_binary_classes(struct srd_decoder *dec)
+{
+ PyObject *py_bin_classes, *py_bin_class;
+ GSList *bin_classes;
+ char **bin;
+ ssize_t bin_idx;
+ PyGILState_STATE gstate;
+
+ gstate = PyGILState_Ensure();
+
+ if (!PyObject_HasAttrString(dec->py_dec, "binary")) {
+ PyGILState_Release(gstate);
+ return SRD_OK;
+ }
+
+ bin_classes = NULL;
+
+ py_bin_classes = PyObject_GetAttrString(dec->py_dec, "binary");
+ if (!py_bin_classes)
+ goto except_out;
+
+ if (!PyTuple_Check(py_bin_classes)) {
+ srd_err("Protocol decoder %s binary classes should "
+ "be a tuple.", dec->name);
+ goto err_out;
+ }
+
+ bin_idx = PyTuple_Size(py_bin_classes);
+ while (bin_idx--) {
+ py_bin_class = PyTuple_GetItem(py_bin_classes, bin_idx);
+ if (!py_bin_class)
+ goto except_out;
+
+ if (!PyTuple_Check(py_bin_class)
+ || PyTuple_Size(py_bin_class) != 2) {
+ srd_err("Protocol decoder %s binary classes should "
+ "consist only of tuples of 2 elements.",
+ dec->name);
+ goto err_out;
+ }
+ if (py_strseq_to_char(py_bin_class, &bin) != SRD_OK)
+ goto err_out;
+
+ bin_classes = g_slist_prepend(bin_classes, bin);
+ }
+ dec->binary = bin_classes;
+ Py_DECREF(py_bin_classes);
+ PyGILState_Release(gstate);
+
+ return SRD_OK;
+
+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);
+ PyGILState_Release(gstate);
+
+ return SRD_ERR_PYTHON;
+}
+
+/* Convert logic_output_channels to GSList of 'struct srd_decoder_logic_output_channel'. */
+static int get_logic_output_channels(struct srd_decoder *dec)
+{
+ PyObject *py_logic_out_chs, *py_logic_out_ch, *py_item;
+ GSList *logic_out_chs;
+ struct srd_decoder_logic_output_channel *logic_out_ch;
+ ssize_t i;
+ PyGILState_STATE gstate;
+
+ gstate = PyGILState_Ensure();
+
+ if (!PyObject_HasAttrString(dec->py_dec, "logic_output_channels")) {
+ PyGILState_Release(gstate);
+ return SRD_OK;
+ }
+
+ logic_out_chs = NULL;
+
+ py_logic_out_chs = PyObject_GetAttrString(dec->py_dec, "logic_output_channels");
+ if (!py_logic_out_chs)
+ goto except_out;
+
+ if (!PyTuple_Check(py_logic_out_chs)) {
+ srd_err("Protocol decoder %s logic_output_channels "
+ "must be a tuple.", dec->name);
+ goto err_out;
+ }
+
+ for (i = PyTuple_Size(py_logic_out_chs) - 1; i >= 0; i--) {
+ py_logic_out_ch = PyTuple_GetItem(py_logic_out_chs, i);
+ if (!py_logic_out_ch)
+ goto except_out;
+
+ if (!PyTuple_Check(py_logic_out_ch) || PyTuple_Size(py_logic_out_ch) != 2) {
+ srd_err("Protocol decoder %s logic_output_channels "
+ "must contain only tuples of 2 elements.",
+ dec->name);
+ goto err_out;
+ }
+ logic_out_ch = g_malloc0(sizeof(*logic_out_ch));
+ /* Add to list right away so it doesn't get lost. */
+ logic_out_chs = g_slist_prepend(logic_out_chs, logic_out_ch);
+
+ py_item = PyTuple_GetItem(py_logic_out_ch, 0);
+ if (!py_item)
+ goto except_out;
+ if (py_str_as_str(py_item, &logic_out_ch->id) != SRD_OK)
+ goto err_out;
+
+ py_item = PyTuple_GetItem(py_logic_out_ch, 1);
+ if (!py_item)
+ goto except_out;
+ if (py_str_as_str(py_item, &logic_out_ch->desc) != SRD_OK)
+ goto err_out;
+ }
+ dec->logic_output_channels = logic_out_chs;
+ Py_DECREF(py_logic_out_chs);
+ PyGILState_Release(gstate);