]> sigrok.org Git - libsigrokdecode.git/commitdiff
type_decoder: update .samplenum before ending .wait() with EOFError
authorGerhard Sittig <redacted>
Mon, 3 Oct 2022 16:23:34 +0000 (18:23 +0200)
committerGerhard Sittig <redacted>
Mon, 3 Oct 2022 19:29:51 +0000 (21:29 +0200)
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.

type_decoder.c

index 6c6eab6b22f584cbcbb0324431cd53e7a0e988fd..cf7ec8e7c383b40b502201e4034b4b9b98e0a8de 100644 (file)
@@ -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);