diff options
author | Bert Vermeulen <bert@biot.com> | 2012-01-20 22:23:27 +0100 |
---|---|---|
committer | Bert Vermeulen <bert@biot.com> | 2012-01-21 15:06:21 +0100 |
commit | 11ea8ae1b2279566125978766735a26252dff412 (patch) | |
tree | 1affb222c19d38a3f42d5b30629bce8b45b33aa6 /decoder.c | |
parent | d42fc6ee118ff673cef1c4ffbce0c7f603519f63 (diff) | |
download | libsigrokdecode-11ea8ae1b2279566125978766735a26252dff412.tar.gz libsigrokdecode-11ea8ae1b2279566125978766735a26252dff412.zip |
srd: decoder class structure check belongs in module loader
Diffstat (limited to 'decoder.c')
-rw-r--r-- | decoder.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -75,12 +75,12 @@ struct srd_decoder *srd_get_decoder_by_id(const char *id) */ int srd_load_decoder(const char *name, struct srd_decoder **dec) { - PyObject *py_basedec, *py_method, *py_annlist, *py_ann; + PyObject *py_basedec, *py_method, *py_attr, *py_annlist, *py_ann; struct srd_decoder *d; int alen, ret, i; char **ann; - py_basedec = py_method = NULL; + py_basedec = py_method = py_attr = NULL; srd_dbg("decoder: %s: loading module '%s'", __func__, name); @@ -150,6 +150,17 @@ int srd_load_decoder(const char *name, struct srd_decoder **dec) } Py_DecRef(py_method); + /* If present, options must be a dictionary. */ + if (PyObject_HasAttrString(d->py_dec, "options")) { + py_attr = PyObject_GetAttrString(d->py_dec, "options"); + if (!PyDict_Check(py_attr)) { + srd_err("Protocol decoder %s options attribute is not " + "a dictionary.", d->name); + goto err_out; + } + Py_DecRef(py_attr); + } + if (py_attr_as_str(d->py_dec, "id", &(d->id)) != SRD_OK) goto err_out; |