From 0b9224604aa166775a6693efba215a33ce594b70 Mon Sep 17 00:00:00 2001 From: Bert Vermeulen Date: Thu, 7 Nov 2013 22:38:47 +0100 Subject: [PATCH] Split annotation-specific output to another struct struct srd_proto_data was supposed to be independent of the output type, but a field specific to annotations snuck in there. --- libsigrokdecode.h.in | 5 ++++- type_decoder.c | 25 +++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/libsigrokdecode.h.in b/libsigrokdecode.h.in index cec6def..3beff35 100644 --- a/libsigrokdecode.h.in +++ b/libsigrokdecode.h.in @@ -255,9 +255,12 @@ struct srd_proto_data { uint64_t start_sample; uint64_t end_sample; struct srd_pd_output *pdo; - int ann_format; void *data; }; +struct srd_proto_data_annotation { + int ann_format; + char **ann_text; +}; typedef void (*srd_pd_output_callback_t)(struct srd_proto_data *pdata, void *cb_data); diff --git a/type_decoder.c b/type_decoder.c index a35dc3d..bf4a6b1 100644 --- a/type_decoder.c +++ b/type_decoder.c @@ -30,11 +30,13 @@ static const char *OUTPUT_TYPES[] = { }; static int convert_annotation(struct srd_decoder_inst *di, PyObject *obj, - int *ann_format, char ***ann) + struct srd_proto_data *pdata) { PyObject *py_tmp; struct srd_pd_output *pdo; - int ann_id; + struct srd_proto_data_annotation *pda; + int ann_format; + char **ann_text; /* Should be a list of [annotation format, [string, ...]]. */ if (!PyList_Check(obj) && !PyTuple_Check(obj)) { @@ -61,14 +63,12 @@ static int convert_annotation(struct srd_decoder_inst *di, PyObject *obj, "first element was not an integer.", di->decoder->name); return SRD_ERR_PYTHON; } - - ann_id = PyLong_AsLong(py_tmp); - if (!(pdo = g_slist_nth_data(di->decoder->annotations, ann_id))) { + ann_format = PyLong_AsLong(py_tmp); + if (!(pdo = g_slist_nth_data(di->decoder->annotations, ann_format))) { srd_err("Protocol decoder %s submitted data to unregistered " - "annotation format %d.", di->decoder->name, ann_id); + "annotation format %d.", di->decoder->name, ann_format); return SRD_ERR_PYTHON; } - *ann_format = ann_id; /* Second element must be a list. */ py_tmp = PyList_GetItem(obj, 1); @@ -77,12 +77,18 @@ static int convert_annotation(struct srd_decoder_inst *di, PyObject *obj, "second element was not a list.", di->decoder->name); return SRD_ERR_PYTHON; } - if (py_strlist_to_char(py_tmp, ann) != SRD_OK) { + if (py_strlist_to_char(py_tmp, &ann_text) != SRD_OK) { srd_err("Protocol decoder %s submitted annotation list, but " "second element was malformed.", di->decoder->name); return SRD_ERR_PYTHON; } + if (!(pda = g_try_malloc(sizeof(struct srd_proto_data_annotation)))) + return SRD_ERR_MALLOC; + pda->ann_format = ann_format; + pda->ann_text = ann_text; + pdata->data = pda; + return SRD_OK; } @@ -137,8 +143,7 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args) /* Annotations are only fed to callbacks. */ if ((cb = srd_pd_output_callback_find(di->sess, pdo->output_type))) { /* Annotations need converting from PyObject. */ - if (convert_annotation(di, py_data, &pdata->ann_format, - (char ***)&pdata->data) != SRD_OK) { + if (convert_annotation(di, py_data, pdata) != SRD_OK) { /* An error was already logged. */ break; } -- 2.30.2