diff options
author | Bert Vermeulen <bert@biot.com> | 2013-11-07 22:38:47 +0100 |
---|---|---|
committer | Bert Vermeulen <bert@biot.com> | 2013-11-14 22:12:59 +0100 |
commit | 0b9224604aa166775a6693efba215a33ce594b70 (patch) | |
tree | 648e7e639667799b324291b19885b562a377357e /type_decoder.c | |
parent | 4f75f1c1dfdec362514884ac4335c080b48b3d78 (diff) | |
download | libsigrokdecode-0b9224604aa166775a6693efba215a33ce594b70.tar.gz libsigrokdecode-0b9224604aa166775a6693efba215a33ce594b70.zip |
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.
Diffstat (limited to 'type_decoder.c')
-rw-r--r-- | type_decoder.c | 25 |
1 files changed, 15 insertions, 10 deletions
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; } |