lib: make bt_value_map_foreach_entry_{const_}func() return a status code
This patch makes the bt_value_map_foreach_entry_func() and
bt_value_map_foreach_entry_const_func() types return status codes
instead of `bt_bool`.
The available status codes are `OK` (continue the loop, like returning
`BT_TRUE` before this patch), `ERROR`, `MEMORY_ERROR`, and `INTERRUPT`
(break the loop, like returning `BT_FALSE` before this patch).
When the user function returns
`BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_ERROR`,
bt_value_map_foreach_entry() returns
`BT_VALUE_MAP_FOREACH_ENTRY_STATUS_USER_ERROR` (set to the new global
status code `__BT_FUNC_STATUS_USER_ERROR`). This makes it possible to
distinguish between an internal library error and a user function error.
The purpose of this patch is to make it possible for a user function to
append an error cause to the current thread's error the same way other
user functions do: append the cause and return an error status.
For example, consider this scenario:
1. User calls bt_value_map_foreach_entry() with a user function and user
data which contains a status member.
2. User function calls a library function which fails. The library
function appends a cause to the current thread's error.
3. User function appends a cause to the current thread's error.
4. User function sets the user data's status member to the failing
library function's status and returns `BT_FALSE` to interrupt the
loop.
5. bt_value_map_foreach_entry() returns
`BT_VALUE_MAP_FOREACH_ENTRY_STATUS_INTERRUPTED` (not an error
status).
6. The caller of bt_value_map_foreach_entry() interprets
`BT_VALUE_MAP_FOREACH_ENTRY_STATUS_INTERRUPTED` as an error because
the user data's status member has an error value.
With this patch, it becomes:
1. User calls bt_value_map_foreach_entry() with a user function.
2. User function calls a library function which fails. The library
function appends a cause to the current thread's error.
3. User function appends a cause to the current thread's error.
4. User function returns `BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_ERROR`
or `BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_MEMORY_ERROR`, depending
on the failing library function's status, which breaks the loop.
5. bt_value_map_foreach_entry() appends a cause to the current thread's
error and returns `BT_VALUE_MAP_FOREACH_ENTRY_STATUS_USER_ERROR` or
`BT_VALUE_MAP_FOREACH_ENTRY_STATUS_MEMORY_ERROR`.
The latter seems more natural to me.
In Python, nothing wraps bt_value_map_foreach_entry() directly, so I
just converted bt_value_map_get_keys_cb() to return the appropriate
status instead of `BT_TRUE` or `BT_FALSE`. In other words,
bt2.utils._handle_func_status() does not need any change because it will
never receive `native_bt.__BT_FUNC_STATUS_USER_ERROR`.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I235d7957003b51630f4a2f72c1ccdef89d6173e8
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2365
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
12 files changed:
This page took 0.028887 seconds and 4 git commands to generate.