diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2017-03-05 18:31:18 +0100 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2017-06-21 17:45:14 +0200 |
commit | 6e19f3257d896cfa8c1afffbdbf58a88fa3b9327 (patch) | |
tree | 772a59006fc3d9369f094a16c9f59810d40e9c73 /type_decoder.c | |
parent | 96e1cee7eb34f5ff5b6da6011ab89ad8bc1ac794 (diff) | |
download | libsigrokdecode-6e19f3257d896cfa8c1afffbdbf58a88fa3b9327.tar.gz libsigrokdecode-6e19f3257d896cfa8c1afffbdbf58a88fa3b9327.zip |
decoder: Accept more forms of "unconditional wait()" (None, no args)
The Decoder.wait() method expects a list of dicts, or as a special form
a single dict, to specify the conditions to wait for. An empty dict or
an empty list mean "unconditional wait", requesting the very next sample.
Accept None as well as no arguments at all in Decoder.wait() calls. This
shall better reflect the intent and slightly unobfuscate PD code, as well
as avoid creation of potentially expensive Python objects at the call site.
Diffstat (limited to 'type_decoder.c')
-rw-r--r-- | type_decoder.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/type_decoder.c b/type_decoder.c index d7b690f..231a893 100644 --- a/type_decoder.c +++ b/type_decoder.c @@ -529,14 +529,22 @@ static int set_new_condition_list(PyObject *self, PyObject *args) return SRD_ERR; } - /* Parse the argument of self.wait() into 'py_conds'. */ - if (!PyArg_ParseTuple(args, "O", &py_conds)) { + /* + * Parse the argument of self.wait() into 'py_conds', and check + * the data type. The argument is optional, None is assumed in + * its absence. None or an empty dict or an empty list mean that + * there is no condition, and the next available sample shall + * get returned to the caller. + */ + py_conds = Py_None; + if (!PyArg_ParseTuple(args, "|O", &py_conds)) { /* Let Python raise this exception. */ return SRD_ERR; } - - /* Check whether 'py_conds' is a dict or a list. */ - if (PyList_Check(py_conds)) { + if (py_conds == Py_None) { + /* 'py_conds' is None. */ + return 9999; + } else if (PyList_Check(py_conds)) { /* 'py_conds' is a list. */ py_conditionlist = py_conds; num_conditions = PyList_Size(py_conditionlist); |