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>
This page took 0.026353 seconds and 4 git commands to generate.