lib: save and restore current thread error when calling destruction listeners and finalize methods
Consider the following chain of events:
- User creates and runs a graph
- An error happens when running the graph, _ERROR is returned and the
current thread has an error
- The user does put_ref on the graph to clean up, deliberately leaving
the error on the current thread so it's processed above on the stack.
- When calling put_ref, a trace destruction listener is called.
- After calling the trace destruction listener, the lib asserts that no
error is set (BT_ASSERT_POST_NO_ERROR), which is not true, so the
assert fails.
In this case, the user of the graph would have to take the error, do the
put_ref and restore the error, if it wants to leave it for a function
higher in the stack. However, it is such a common scenario to hit an
error, do some put_ref to clean up and return the error, that it would
be very heavy (and error-prone) to have to do this all the time.
This patch makes it safe to call put_ref with an error set by wrapping
all the user code that can be called as a consequence of a put_ref
(destruction listeners and finalize methods) with an error take/move.
Before calling the user destruction listener or finalize method, the lib
saves the error on the stack. The user callback is therefore called
with no error set and the lib can still validate with
BT_ASSERT_POST_NO_ERROR that it leaves no error on the current thread
after returning. The error is then moved back.
We could say that put_ref now become "error-neutral", in that they can
be called with an error set on the current thread, and they won't modify
it.
Change-Id: I8c7a5429d53073483b9e03f0ec654c826466ee4e
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2385
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
This page took 0.028059 seconds and 4 git commands to generate.