Fix: bt2: correctly handle empty result of bt_field_enumeration_unsigned_get_mapping_...
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 21 Oct 2024 18:20:01 +0000 (14:20 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 4 Nov 2024 16:17:44 +0000 (11:17 -0500)
commit278239516fde3ce2af2214922917f08abd451880
tree0db9c502a9a3ccfd7da01acaef01b67e47dd31e0
parentea4e48f58e879701a7fe43dcd02f2663849d09d3
Fix: bt2: correctly handle empty result of bt_field_enumeration_unsigned_get_mapping_labels

When calling `_EnumerationFieldClassConst.mappings_for_value()` and the
result is empty (no matching mappings), we get:

      File "/home/smarchi/build/babeltrace/src/bindings/python/bt2/build/build_lib/bt2/field_class.py", line 240, in mappings_for_value
        return [self[label] for label in labels]
                                         ^^^^^^
    TypeError: 'NoneType' object is not iterable

Here's what happens:

 - When the input value matches no mappings, the library sets the array
   output parameter to `NULL`.
 - The SWIG argout typemap checks the array output parameter value to
   choose between returning a list or `None`.  So in this case, we return
   the tuple `(__BT_FUNC_STATUS_OK, None)`.
 - Back in the Python side, we try to iterate over `None`.

Fix this by checking the status in the typemap to see if the call
succeeded.

Add a corresponding test.

Change-Id: If1c7de435c27b9c37b67b66a7b8384480ac654e1
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13385
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/bindings/python/bt2/bt2/native_bt_field_class.i
tests/bindings/python/bt2/test_field_class.py
This page took 0.026353 seconds and 4 git commands to generate.