If the calls to bt_trace_class_add_destruction_listener and
bt_trace_add_destruction_listener in the Python bindings fail (due to an
hypothetical memory error that can't happen today), abort is called.
Strangely, back on the Python side, there is a "listener_id is None"
check that is a bit useless, since we would have aborted had there been
a failure.
Regularize the situation by making the
bt_bt2_trace_class_add_destruction_listener and
bt_bt2_trace_add_destruction_listener wrappers return a status, like any
other API function. We can then use utils._handle_func_status like
everywhere else.
Change-Id: I17901a0278f1615b45e6adc3b7223f1b3b3ff35e
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1744
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
-uint64_t bt_bt2_trace_add_destruction_listener(bt_trace *trace, PyObject *py_callable)
+int bt_bt2_trace_add_destruction_listener(bt_trace *trace,
+ PyObject *py_callable, uint64_t *id)
- uint64_t id = UINT64_C(-1);
bt_trace_add_listener_status status;
BT_ASSERT(trace);
BT_ASSERT(py_callable);
status = bt_trace_add_destruction_listener(
bt_trace_add_listener_status status;
BT_ASSERT(trace);
BT_ASSERT(py_callable);
status = bt_trace_add_destruction_listener(
- trace, trace_destroyed_listener, py_callable, &id);
- if (status != __BT_FUNC_STATUS_OK) {
- BT_LOGF_STR("Failed to add trace destruction listener.");
- abort();
+ trace, trace_destroyed_listener, py_callable, id);
+ if (status == __BT_FUNC_STATUS_OK) {
+ Py_INCREF(py_callable);
- Py_INCREF(py_callable);
- return id;
-uint64_t bt_bt2_trace_add_destruction_listener(bt_trace *trace,
- PyObject *py_callable);
+int bt_bt2_trace_add_destruction_listener(bt_trace *trace,
+ PyObject *py_callable, uint64_t *id);
-uint64_t bt_bt2_trace_class_add_destruction_listener(bt_trace_class *trace_class,
- PyObject *py_callable)
+int bt_bt2_trace_class_add_destruction_listener(
+ bt_trace_class *trace_class, PyObject *py_callable,
+ uint64_t *id)
- uint64_t id = UINT64_C(-1);
bt_trace_class_add_listener_status status;
BT_ASSERT(trace_class);
BT_ASSERT(py_callable);
status = bt_trace_class_add_destruction_listener(
bt_trace_class_add_listener_status status;
BT_ASSERT(trace_class);
BT_ASSERT(py_callable);
status = bt_trace_class_add_destruction_listener(
- trace_class, trace_class_destroyed_listener, py_callable, &id);
- if (status != __BT_FUNC_STATUS_OK) {
- BT_LOGF_STR("Failed to add trace class destruction listener.");
- abort();
+ trace_class, trace_class_destroyed_listener, py_callable, id);
+ if (status == __BT_FUNC_STATUS_OK) {
+ Py_INCREF(py_callable);
- Py_INCREF(py_callable);
- return id;
-uint64_t bt_bt2_trace_class_add_destruction_listener(bt_trace_class *trace_class,
- PyObject *py_callable);
+int bt_bt2_trace_class_add_destruction_listener(
+ bt_trace_class *trace_class, PyObject *py_callable,
+ uint64_t *id);
_trace_destruction_listener_from_native, listener
)
_trace_destruction_listener_from_native, listener
)
- listener_id = fn(self._ptr, listener_from_native)
- if listener_id is None:
- utils._raise_bt2_error('cannot add destruction listener to trace object')
+ status, listener_id = fn(self._ptr, listener_from_native)
+ utils._handle_func_status(
+ status, 'cannot add destruction listener to trace object'
+ )
return bt2._ListenerHandle(listener_id, self)
return bt2._ListenerHandle(listener_id, self)
_trace_class_destruction_listener_from_native, listener
)
_trace_class_destruction_listener_from_native, listener
)
- listener_id = fn(self._ptr, listener_from_native)
- if listener_id is None:
- utils._raise_bt2_error(
- 'cannot add destruction listener to trace class object'
- )
+ status, listener_id = fn(self._ptr, listener_from_native)
+ utils._handle_func_status(
+ status, 'cannot add destruction listener to trace class object'
+ )
return bt2._ListenerHandle(listener_id, self)
return bt2._ListenerHandle(listener_id, self)