]> sigrok.org Git - libsigrokdecode.git/commitdiff
srd: decoder class structure check belongs in module loader
authorBert Vermeulen <redacted>
Fri, 20 Jan 2012 21:23:27 +0000 (22:23 +0100)
committerBert Vermeulen <redacted>
Sat, 21 Jan 2012 14:06:21 +0000 (15:06 +0100)
controller.c
decoder.c

index ebda088932ea4885f5b834c81e0b914773ee137e..fa67004b22caf0b35e3014ea22d52eeac3c51101 100644 (file)
@@ -186,11 +186,6 @@ int srd_instance_set_options(struct srd_decoder_instance *di,
        py_dec_options = py_dec_optkeys = py_di_options = py_optval = NULL;
        py_optlist = py_classval = NULL;
        py_dec_options = PyObject_GetAttrString(di->decoder->py_dec, "options");
-       if (!PyDict_Check(py_dec_options)) {
-               srd_err("Protocol decoder %s options is not a dictionary.",
-                               di->decoder->name);
-               goto err_out;
-       }
 
        /* All of these are synthesized objects, so they're good. */
        py_dec_optkeys = PyDict_Keys(py_dec_options);
index 6651642f08fcd08b9be461d693f70020e6dcdb6c..5b9223c630812599548e0dcebfeac1a5104161b0 100644 (file)
--- a/decoder.c
+++ b/decoder.c
@@ -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;