bt2: rename exception handling functions
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 18 Oct 2019 19:18:27 +0000 (15:18 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 21 Oct 2019 21:05:36 +0000 (17:05 -0400)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2222
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
src/bindings/python/bt2/bt2/native_bt_component_class.i.h
src/bindings/python/bt2/bt2/native_bt_graph.i.h
src/bindings/python/bt2/bt2/native_bt_log_and_append_error.h
src/bindings/python/bt2/bt2/native_bt_trace.i.h
src/bindings/python/bt2/bt2/native_bt_trace_class.i.h

index b29f3fa9d491b438647b80fb69a2eadba8658f50..92f20891b989f27478927713f46efc0329682cf1 100644 (file)
@@ -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;
index 0bd8a0b22ae82b40e6eec3a8aa8cc3e5d7e2e06f..44941e19d732898028a673c20c61dbce18f59a0e 100644 (file)
@@ -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;
index 37cc2e78ac6484bb93880d51a8916d88139bb017..11b6e414e1ec435e99a7575c912e84eabc2cb090 100644 (file)
@@ -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);
 }
index 708142e648ea670a3482502c623d36ffabc1063e..03e6380acf2627e77197862c71a9217b7bb6bb46 100644 (file)
@@ -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);
        }
 
index 5e91a6c21553f067473a5fc4ce98dc94ce60c2d8..f508ffb0cb7d0759c4b288719a9994b1b36c704f 100644 (file)
@@ -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);
        }
 
This page took 0.029189 seconds and 4 git commands to generate.