From 84e438afc1b27f23047613c413e2caec283af065 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 18 Oct 2019 15:18:27 -0400 Subject: [PATCH] bt2: rename exception handling functions It's currently not very clear if the Python exception handling functions append a Babeltrace error cause or clear the Python error indicator. It's therefore easy to mis-use them. Rename them to better indicate what they do. Change-Id: I7dc31264196c6410e715c620cf9e4cd48a2711f6 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/2222 Tested-by: jenkins Reviewed-by: Francis Deslauriers --- .../bt2/bt2/native_bt_component_class.i.h | 41 ++++++++++--------- .../python/bt2/bt2/native_bt_graph.i.h | 6 ++- .../bt2/bt2/native_bt_log_and_append_error.h | 12 +++--- .../python/bt2/bt2/native_bt_trace.i.h | 3 +- .../python/bt2/bt2/native_bt_trace_class.i.h | 3 +- 5 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/bindings/python/bt2/bt2/native_bt_component_class.i.h b/src/bindings/python/bt2/bt2/native_bt_component_class.i.h index b29f3fa9..92f20891 100644 --- a/src/bindings/python/bt2/bt2/native_bt_component_class.i.h +++ b/src/bindings/python/bt2/bt2/native_bt_component_class.i.h @@ -104,7 +104,8 @@ void native_comp_class_dtor(void) { } static inline -int py_exc_to_status(bt_self_component_class *self_component_class, +int py_exc_to_status_clear( + bt_self_component_class *self_component_class, bt_self_component *self_component, bt_self_message_iterator *self_message_iterator, const char *module_name, int active_log_level) @@ -144,7 +145,7 @@ int py_exc_to_status(bt_self_component_class *self_component_class, } BT_ASSERT(active_log_level != -1); - log_exception_and_maybe_append_error(BT_LOG_WARNING, + log_exception_and_maybe_append_cause(BT_LOG_WARNING, active_log_level, true, self_component_class, self_component, self_message_iterator, module_name); @@ -163,25 +164,25 @@ end: } static -int py_exc_to_status_component_class( +int py_exc_to_status_component_class_clear( bt_self_component_class *self_component_class, int active_log_level) { - return py_exc_to_status(self_component_class, NULL, NULL, NULL, + return py_exc_to_status_clear(self_component_class, NULL, NULL, NULL, active_log_level); } static -int py_exc_to_status_component(bt_self_component *self_component) +int py_exc_to_status_component_clear(bt_self_component *self_component) { - return py_exc_to_status(NULL, self_component, NULL, NULL, -1); + return py_exc_to_status_clear(NULL, self_component, NULL, NULL, -1); } static -int py_exc_to_status_message_iterator( +int py_exc_to_status_message_iterator_clear( bt_self_message_iterator *self_message_iterator) { - return py_exc_to_status(NULL, NULL, self_message_iterator, NULL, -1); + return py_exc_to_status_clear(NULL, NULL, self_message_iterator, NULL, -1); } static @@ -266,7 +267,7 @@ bt_component_class_initialize_method_status component_class_init( BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING, log_level, self_component, "Failed to call Python class's _bt_init_from_native() method: " "py-cls-addr=%p", py_cls); - status = py_exc_to_status_component(self_component); + status = py_exc_to_status_component_clear(self_component); goto end; } @@ -345,7 +346,7 @@ component_class_get_supported_mip_versions( BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING, log_level, BT_LOG_TAG, "Failed to call Python class's _bt_get_supported_mip_versions_from_native() method: " "py-cls-addr=%p", py_cls); - status = py_exc_to_status_component_class(self_component_class, + status = py_exc_to_status_component_class_clear(self_component_class, log_level); goto end; } @@ -560,7 +561,7 @@ component_class_can_seek_beginning( *can_seek = PyObject_IsTrue(py_result); status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_BEGINNING_METHOD_STATUS_OK; } else { - status = py_exc_to_status_message_iterator(self_message_iterator); + status = py_exc_to_status_message_iterator_clear(self_message_iterator); BT_ASSERT(status != __BT_FUNC_STATUS_OK); } @@ -582,7 +583,7 @@ component_class_seek_beginning(bt_self_message_iterator *self_message_iterator) py_result = PyObject_CallMethod(py_iter, "_bt_seek_beginning_from_native", NULL); BT_ASSERT(!py_result || py_result == Py_None); - status = py_exc_to_status_message_iterator(self_message_iterator); + status = py_exc_to_status_message_iterator_clear(self_message_iterator); Py_XDECREF(py_result); return status; } @@ -608,7 +609,7 @@ component_class_can_seek_ns_from_origin( *can_seek = PyObject_IsTrue(py_result); status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK; } else { - status = py_exc_to_status_message_iterator(self_message_iterator); + status = py_exc_to_status_message_iterator_clear(self_message_iterator); BT_ASSERT(status != BT_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK); } @@ -632,7 +633,7 @@ component_class_seek_ns_from_origin( py_result = PyObject_CallMethod(py_iter, "_bt_seek_ns_from_origin_from_native", "L", ns_from_origin); BT_ASSERT(!py_result || py_result == Py_None); - status = py_exc_to_status_message_iterator(self_message_iterator); + status = py_exc_to_status_message_iterator_clear(self_message_iterator); Py_XDECREF(py_result); return status; } @@ -677,7 +678,7 @@ bt_component_class_port_connected_method_status component_class_port_connected( "_bt_port_connected_from_native", "(OiO)", py_self_port_ptr, self_component_port_type, py_other_port_ptr); BT_ASSERT(!py_method_result || py_method_result == Py_None); - status = py_exc_to_status_component(self_component); + status = py_exc_to_status_component_clear(self_component); end: Py_XDECREF(py_self_port_ptr); @@ -772,7 +773,7 @@ component_class_sink_graph_is_configured( py_method_result = PyObject_CallMethod(py_comp, "_bt_graph_is_configured_from_native", NULL); BT_ASSERT(!py_method_result || py_method_result == Py_None); - status = py_exc_to_status_component(self_component); + status = py_exc_to_status_component_clear(self_component); Py_XDECREF(py_method_result); return status; } @@ -850,7 +851,7 @@ bt_component_class_query_method_status component_class_query( py_object, py_params_ptr, method_data ? method_data : Py_None); if (!py_results_addr) { - status = py_exc_to_status_component_class(self_component_class, + status = py_exc_to_status_component_class_clear(self_component_class, log_level); if (status < 0) { static const char *fmt = @@ -1065,7 +1066,7 @@ component_class_message_iterator_init( python_error: /* Handling of errors that cause a Python exception to be set. */ - status = py_exc_to_status_message_iterator(self_message_iterator); + status = py_exc_to_status_message_iterator_clear(self_message_iterator); BT_ASSERT(status != __BT_FUNC_STATUS_OK); goto end; @@ -1169,7 +1170,7 @@ component_class_message_iterator_next( py_method_result = PyObject_CallMethod(py_message_iter, "_bt_next_from_native", NULL); if (!py_method_result) { - status = py_exc_to_status_message_iterator(message_iterator); + status = py_exc_to_status_message_iterator_clear(message_iterator); BT_ASSERT(status != __BT_FUNC_STATUS_OK); goto end; } @@ -1203,7 +1204,7 @@ component_class_sink_consume(bt_self_component_sink *self_component_sink) BT_ASSERT(py_comp); py_method_result = PyObject_CallMethod(py_comp, "_user_consume", NULL); - status = py_exc_to_status_component(self_component); + status = py_exc_to_status_component_clear(self_component); BT_ASSERT(py_method_result || status != __BT_FUNC_STATUS_OK); Py_XDECREF(py_method_result); return status; diff --git a/src/bindings/python/bt2/bt2/native_bt_graph.i.h b/src/bindings/python/bt2/bt2/native_bt_graph.i.h index 0bd8a0b2..44941e19 100644 --- a/src/bindings/python/bt2/bt2/native_bt_graph.i.h +++ b/src/bindings/python/bt2/bt2/native_bt_graph.i.h @@ -60,7 +60,8 @@ static bt_graph_listener_func_status port_added_listener( py_res = PyObject_CallFunction(py_callable, "(OiOi)", py_component_ptr, component_class_type, py_port_ptr, port_type); if (!py_res) { - loge_exception("Graph's port added listener (Python)", + loge_exception_append_cause( + "Graph's port added listener (Python)", BT_LOG_OUTPUT_LEVEL); PyErr_Clear(); status = __BT_FUNC_STATUS_ERROR; @@ -306,7 +307,8 @@ bt_graph_listener_func_status ports_connected_listener( py_downstream_component_ptr, downstream_component_class_type, py_downstream_port_ptr); if (!py_res) { - loge_exception("Graph's port connected listener (Python)", + loge_exception_append_cause( + "Graph's port connected listener (Python)", BT_LOG_OUTPUT_LEVEL); PyErr_Clear(); status = __BT_FUNC_STATUS_ERROR; diff --git a/src/bindings/python/bt2/bt2/native_bt_log_and_append_error.h b/src/bindings/python/bt2/bt2/native_bt_log_and_append_error.h index 37cc2e78..11b6e414 100644 --- a/src/bindings/python/bt2/bt2/native_bt_log_and_append_error.h +++ b/src/bindings/python/bt2/bt2/native_bt_log_and_append_error.h @@ -176,8 +176,10 @@ void restore_bt_error_and_append_current_exception_chain( } static inline -void log_exception_and_maybe_append_error(int func_log_level, - int active_log_level, bool append_error, +void log_exception_and_maybe_append_cause( + int func_log_level, + int active_log_level, + bool append_error, bt_self_component_class *self_component_class, bt_self_component *self_component, bt_self_message_iterator *self_message_iterator, @@ -226,15 +228,15 @@ bt_logging_level get_self_message_iterator_log_level( } static inline -void loge_exception(const char *module_name, int active_log_level) +void loge_exception_append_cause(const char *module_name, int active_log_level) { - log_exception_and_maybe_append_error(BT_LOG_ERROR, active_log_level, + log_exception_and_maybe_append_cause(BT_LOG_ERROR, active_log_level, true, NULL, NULL, NULL, module_name); } static inline void logw_exception(int active_log_level) { - log_exception_and_maybe_append_error(BT_LOG_WARNING, active_log_level, + log_exception_and_maybe_append_cause(BT_LOG_WARNING, active_log_level, false, NULL, NULL, NULL, NULL); } diff --git a/src/bindings/python/bt2/bt2/native_bt_trace.i.h b/src/bindings/python/bt2/bt2/native_bt_trace.i.h index 708142e6..03e6380a 100644 --- a/src/bindings/python/bt2/bt2/native_bt_trace.i.h +++ b/src/bindings/python/bt2/bt2/native_bt_trace.i.h @@ -39,7 +39,8 @@ trace_destroyed_listener(const bt_trace *trace, void *py_callable) if (py_res) { BT_ASSERT(py_res == Py_None); } else { - loge_exception("Trace's destruction listener (Python)", + loge_exception_append_cause( + "Trace's destruction listener (Python)", BT_LOG_OUTPUT_LEVEL); } diff --git a/src/bindings/python/bt2/bt2/native_bt_trace_class.i.h b/src/bindings/python/bt2/bt2/native_bt_trace_class.i.h index 5e91a6c2..f508ffb0 100644 --- a/src/bindings/python/bt2/bt2/native_bt_trace_class.i.h +++ b/src/bindings/python/bt2/bt2/native_bt_trace_class.i.h @@ -39,7 +39,8 @@ trace_class_destroyed_listener(const bt_trace_class *trace_class, void *py_calla if (py_res) { BT_ASSERT(py_res == Py_None); } else { - loge_exception("Trace class's destruction listener (Python)", + loge_exception_append_cause( + "Trace class's destruction listener (Python)", BT_LOG_OUTPUT_LEVEL); } -- 2.34.1