lib: save and restore current thread error when calling destruction listeners and...
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 13 Nov 2019 20:36:42 +0000 (15:36 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Fri, 15 Nov 2019 17:42:27 +0000 (12:42 -0500)
commit42a6316598eda35c8f23f8afbf579e385dc6de40
treea3ea34cb6c11fbf77210bf87a527c349d37097ab
parent36e94ad605ae7ee5d31a3acb1d20d65de95f9e11
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>
src/lib/graph/component.c
src/lib/graph/iterator.c
src/lib/trace-ir/trace-class.c
src/lib/trace-ir/trace.c
This page took 0.025835 seconds and 4 git commands to generate.