summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2022-10-03 18:23:34 +0200
committerGerhard Sittig <gerhard.sittig@gmx.net>2022-10-03 21:29:51 +0200
commit27a86cefb655ecdfb8d912a5388fe8768b264ff5 (patch)
tree6a45ceb607302f690688b7e827f08a08d24681c7
parent1105c425345961fa527a7994845bc487b1c7bdf5 (diff)
downloadlibsigrokdecode-27a86cefb655ecdfb8d912a5388fe8768b264ff5.tar.gz
libsigrokdecode-27a86cefb655ecdfb8d912a5388fe8768b264ff5.zip
type_decoder: update .samplenum before ending .wait() with EOFError
When the protocol decoder's input data is exhausted, then the .wait() method will raise the EOFError exception. Python decoders can catch this exception and handle the condition. For proper annotation emission it is essential that the self.samplenum value corresponds to the last position in the input stream. Update it before returning from the .wait() call.
-rw-r--r--type_decoder.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/type_decoder.c b/type_decoder.c
index 6c6eab6..cf7ec8e 100644
--- a/type_decoder.c
+++ b/type_decoder.c
@@ -1098,6 +1098,11 @@ static PyObject *Decoder_wait(PyObject *self, PyObject *args)
* when the sample data is exhausted.
*/
if (di->communicate_eof) {
+ /* Advance self.samplenum to the (absolute) last sample number. */
+ py_samplenum = PyLong_FromUnsignedLongLong(di->abs_cur_samplenum);
+ PyObject_SetAttrString(di->py_inst, "samplenum", py_samplenum);
+ Py_DECREF(py_samplenum);
+ /* Raise an EOFError Python exception. */
srd_dbg("%s: %s: Raising EOF from wait().",
di->inst_id, __func__);
g_mutex_unlock(&di->data_mutex);