summaryrefslogtreecommitdiff
path: root/type_decoder.c
AgeCommit message (Collapse)Author
2022-11-24type_decoder: silence print format warnings, greppable messagesGerhard Sittig
Silence printf(3) format warnings. Python's data types should be considered opaque, size (and signedness) are usually unknown, as is the relation to standard C language print format specs. Unbreak long messages which were spread across several source code text lines. This complies to Linux style guides. Being able to find diagnostics messages that were reported by users in sources is more important than sticking to an arbitrary text line length.
2022-11-24nit: break a long line in different ways, unobfuscate parameter groupingGerhard Sittig
Break a rather long line for a Python method call at a different location, to better reflect the parameter groups which organize for the method to get called, and those which pass parameters to that called method. This commit also splits the actual action and its check for successful execution into separate C language statements.
2022-10-03type_decoder: update .samplenum before ending .wait() with EOFErrorGerhard Sittig
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.
2021-12-26session: introduce the public "send EOF" API routineGerhard Sittig
Introduce the public srd_session_send_eof() routine which is backed by the internal srd_inst_send_eof() helper. Applications can tell decoders when the input stream of sample data is exhausted, so that decoders can optionally "flush" their previously accumulated information when desired. Previous implementations just kept decoders in blocking .wait() calls and somehow terminated them at arbitrary times afterwards. When EOF is sent to the decoder session, then calls to the .wait() method which typically are done from .decode() or its descendents will end with an EOFError Python exception. Termination of .decode() with the EOFError exception is non-fatal for backwards compatibility and to keep the convenience for current decoder implementations. Decoders can either catch the exception, or use context managers, or do nothing. This API extension is motivated by research for bug #1581 and provides the infrastructure to address bug #292. Decoders need to remain careful, and should not claim that protocol activities would have completed when their end condition was not even seen in the capture. Marking incomplete activities with warnings is the most appropriate reaction.
2021-12-26type_decoder: eliminate explicit string length spec for literalsGerhard Sittig
Rephrase the 'names[]' array declaration in output_type_name() to avoid the necessity of guessing what the maximum length of the literals might be during future maintenance. Developers need not care when the compiler can handle this detail.
2021-12-26type_decoder: use ALL_ZERO for sentinels in method/member tablesGerhard Sittig
Avoid the full listing of all-zero struct members in sentinel items of object methods and class properties tables. Use the ALL_ZERO phrase instead which better reflects what's intended, and reliably silences warnings should structs' lengths differ across Python versions.
2021-12-26type_decoder: update and extend Decoder base class doc stringsGerhard Sittig
Some doc strings have become outdated, update them. Some doc strings were terse, extend them. Ideally protocol decoder authors would be able to use the builtin documentation to answer questions on data types and arguments order. This implementation isn't there yet, needs more work.
2021-12-26type_decoder: move Python doc strings to method implementationsGerhard Sittig
Move Python doc strings to the location where methods and classes get implemented. This improves awareness during maintenance, and allows for longer text phrases without obfuscating the registration code path. This commit does not alter the content of existing doc strings, only moves their location. And keeps related items together when long decls span multiple text lines (function name and arguments list, args and kw args), to improve/keep readability.
2021-03-07decoder: increment Python object reference for .has_channel() resultGerhard Sittig
This fixes bug #1671. Reported-By: Ivan Wick
2021-02-13Rename logic_class to logic_group and output as group-wise RLESoeren Apel
2021-02-13Add initial OUTPUT_LOGIC support.Uwe Hermann
Protocol decoders can now declare an arbitrary number of logic output channels with a fixed assumed samplerate each.
2020-05-22Use PyLong_FromUnsignedLongLong() where needed.Uwe Hermann
There were a few places where PyLong_FromLong() was used for uint64_t numbers. Properly use PyLong_FromUnsignedLongLong() there, and also fix a few additional size/signedness issues while we're here. Reported (and partial patch provided) by "The Count" on Bugzilla, thanks! This fixes bug #1499.
2020-05-21type_decoder.c: Workaround for a compiler warning.Uwe Hermann
type_decoder.c:1040:16: warning: cast between incompatible function types from ‘PyObject * (*)(PyObject *, PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *, struct _object *)’} to ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *)’} [-Wcast-function-type] 1040 | { "register", (PyCFunction)Decoder_register, METH_VARARGS|METH_KEYWORDS, | ^
2019-11-24decoder: accept skip count 0 (onewire_link, usb_signalling)Gerhard Sittig
A recent commit tightened the check for acceptable 'skip' sample counts. This broke the onewire_link and usb_signalling decoders' test sequences, which no longer pass with a minimum count of one. Relax the condition and accept a count of zero. This breaks gpib again for low total sample count option values, but this needs to get addressed differently.
2019-11-24decoder: internal 'always false' term, handle invalid skip and channelGerhard Sittig
Introduce an "always false" type for .wait() terms. Map invalid counts of skip conditions (zero or negative numbers) as well as invalid channel references for level/edge conditions to this type which never matches. Keep this "always false" term type an internal detail of the common support code. This is most robust and least intrusive at the same time, it keeps the existing API, and simplifies the implementation of Python decoders for rare edge cases (optional input signals or optional features, handling of initial samples at the very start of a capture). This commit passes sample counts internally in a signed data type. This is essential for proper operation, and the loss of one bit out of 64 shall not be considered a severe limitation. This fixes bug #1444.
2019-11-23Avoid using Py_IncRef/Py_DecRef for consistency.Uwe Hermann
We currently use a mix of Py_IncRef/Py_DecRef and Py_XINCREF/Py_XDECREF or Py_INCREF/Py_DECREF in the code-base. Only use the latter variants for the time being (for consistency).
2019-11-19Fix multiple PyObject_SetAttrString() related leaks.Uwe Hermann
This fixes bug #1374.
2018-10-13Various log message improvements.Uwe Hermann
2018-10-13log: Use human-readable output type name everywhere.Uwe Hermann
2018-10-13Decoder_put(): Add more info to OTUPUT_PYTHON log messages.Uwe Hermann
2018-10-06type_decoder.c: Fix trailing whitespace.Uwe Hermann
2018-05-19Decoder_put(): Avoid a g_malloc()/g_free() pair per binary out.Uwe Hermann
2018-05-19Decoder_put(): Avoid a g_malloc()/g_free() pair per annotation.Uwe Hermann
2018-05-18srd_inst_find_by_obj(): Minor performance improvement.Uwe Hermann
Handle the most common case of one session and one decoder first so we can exit early. This has a small, but measurable performance benefit.
2018-05-18srd_*inst_find_by_obj(): Suggest inlining for performance reasons.Uwe Hermann
This has a small, but measurable performance benefit.
2018-05-18srd_*inst_find_by_obj(): Move functions, make them static.Uwe Hermann
These functions are only used in type_decoder.c. Move them there and make them static.
2018-05-18convert_meta(): Use g_variant_type_equal().Uwe Hermann
2018-05-18Random whitespace/cosmetic/consistency fixes.Uwe Hermann
2018-05-17type_decoder.c: Fix a compiler warning (-Wswitch-default).Uwe Hermann
type_decoder.c: In function ‘get_term_type’: type_decoder.c:486:2: warning: switch missing default case [-Wswitch-default] switch (v[0]) { ^~~~~~
2018-05-16type_decoder.c: Drop unneeded g_free() NULL check.Uwe Hermann
2018-05-16type_decoder.c: Fix a scan-build warning.Uwe Hermann
type_decoder.c:836:3: warning: Value stored to 'ret' is never read ret = process_samples_until_condition_match(di, &found_match); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2018-05-16type_decoder.c: Fix a memory leak reported by scan-build.Uwe Hermann
type_decoder.c:206:2: warning: Potential leak of memory pointed to by 'pdb' PyGILState_Release(gstate); ^~~~~~~~~~~~~~~~~~
2018-05-16type_decoder.c: Fix a memory leak reported by scan-build.Uwe Hermann
type_decoder.c:197:10: warning: Potential leak of memory pointed to by 'pdb' return SRD_ERR_MALLOC; ^~~~~~~~~~~~~~
2018-05-15Convert some g_malloc0() to g_malloc().Uwe Hermann
For the converted calls there's no requirement for all struct fields being memset()'d to zero, or all struct fields are explicitly set later anyway.
2018-05-15get_current_pinvalues(): Slightly simplify a code chunk.Uwe Hermann
2018-05-09type_decoder.c: Drop incorrect Py_DECREF() calls.Uwe Hermann
2018-05-09type_decoder: Fixup memory leak in Decoder.put() (meta, python)Uwe Hermann
This fixes parts of bug #329.
2018-05-09type_decoder: fixup memory leak in Decoder.put() (annotation, binary)Gerhard Sittig
The text presentation of decoder annotations' payload data was allocated but not freed. As were the byte strings of binary output. Fix it. This fixes parts of bug #329.
2018-04-20Decoder_register(): Drop an overly verbose log message.Uwe Hermann
2018-03-31Decoder: check for duplicate register() calls in common backend codeGerhard Sittig
Future implementations might call decoders' start() routine several times, which makes them call register() again. It's desirable that the common backend code copes with this condition, such that (the multitude of) decoder implementations need not work around a specific constraint.
2018-03-31decoder: rephrase .has_channel() argument parse logicGerhard Sittig
Have the Python C API check the argument type and do the type conversion already. Raise an IndexError exception when the range check fails.
2018-03-07Minor whitespace/typo fixes.Uwe Hermann
2017-06-30self.put(): Eliminate an unneeded malloc/free pair.Uwe Hermann
2017-06-30Acquire/release the Python GIL where needed to avoid threading issues.Uwe Hermann
With these additions, frontends can now call libsigrokdecode API functions from different threads without running into threading issues. The backend releases the GIL when it is performing tasks that might take a while and it doesn't need to run Python/C API calls during that time. This allows frontends to run multiple PD stacks (in multiple frontend threads) "at the same time" in a time-sharing, "interlocked" manner. Whenever one of the decoders is inside e.g. self.wait() it releases the GIL and thus allows other decoders to do some work in the mean time. The user-visible effect is that for use-cases such as running 3 different decoder stacks at the same time for an acquisition, the user will not have to wait for PD 1 to finish decoding, then wait for PD 2 to finish decoding, and only *then* being able to see annotations from PD 3. Instead, all three PDs will decode some chunks of data from time to time, thus the user is able to inspect annotations from all 3 PDs while the acquisition and decoding is still going on.
2017-06-21decoder: Accept more forms of "unconditional wait()" (None, no args)Gerhard Sittig
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.
2017-06-21decoder: Unbreak execution of Decoder.wait() with empty conditionGerhard Sittig
The Decoder.wait() method works as expected when non-empty conditions are specified by the caller. For empty conditions the implementation was incomplete, and ended up in an infinite loop because the sample number got stuck in the current location. Code review revealed more issues like not getting more input data chunks when needed. Detect when empty wait() conditions were specified, and re-use existing code paths for match handling as much as possible. This is achieved by the manual creation of a SKIP term with the appropriate count value. It's assumed that naive decoder implementations will run this kind of condition-less query for every individual sample, which means that efficiency is important. Make sample number 0 available to condition-less calls, too. Don't skip the first sample in the input stream.
2017-03-12decoder: terminate .wait() and .decode(), join threads for v3 instancesGerhard Sittig
Add support to terminate blocking .wait() and .decode() method calls of v3 decoder instances. This terminates the decoder thread's main routine and allows to release associated resources. Cope with requested as well as unexpected termination of decode() calls. Add debug messages to thread related code paths. Make sure to unblock the main thread which feeds the decoder thread. This unbreaks situations where decoders e.g. throw "need samplerate to decode" exceptions. Drain Python errors which might remain from the most recent .decode() execution, to not affect other code paths. This avoids an issue where the creation of a new decoder instance fails in the presence of errors from a previous run. This fixes bug #902.
2017-02-28Fix memory leak in get_current_pinvalues()Marcus Comstedt
The ownership of the tuple reference is transferred to the caller, so the refcount should not be increased.
2017-02-28More refcounting fixesMarcus Comstedt
PyList_SetItem steals a reference, so code calling that must either transfer ownership or increase the refcount.
2017-02-26Fix refcounting bug in set_new_condition_list()Marcus Comstedt
py_conditionlist is an owned reference (it gets passed to Py_DecRef() at the end), so we need to increment the refcount when assigning it from the borrowed reference py_conds.