+ /* Used to access and restore the current exception. */
+ PyObject *py_exc_type;
+ PyObject *py_exc_value;
+ PyObject *py_exc_tb;
+
+ /* Fetch and normalize the Python exception. */
+ PyErr_Fetch(&py_exc_type, &py_exc_value, &py_exc_tb);
+ PyErr_NormalizeException(&py_exc_type, &py_exc_value, &py_exc_tb);
+ BT_ASSERT(py_exc_type);
+ BT_ASSERT(py_exc_value);
+ BT_ASSERT(py_exc_tb);
+
+ /*
+ * Set the exception's traceback so it's possible to get it using
+ * PyException_GetTraceback in
+ * restore_current_thread_error_and_append_exception_chain_recursive.
+ */
+ PyException_SetTraceback(py_exc_value, py_exc_tb);
+
+ restore_current_thread_error_and_append_exception_chain_recursive(
+ active_log_level, py_exc_value, self_component_class,
+ self_component, self_message_iterator, module_name);
+
+ PyErr_Restore(py_exc_type, py_exc_value, py_exc_tb);
+}
+
+static inline
+void log_exception_and_maybe_append_error(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,
+ const char *module_name)
+{
+ GString *gstr;
+
+ BT_ASSERT(PyErr_Occurred());
+ gstr = bt_py_common_format_current_exception(active_log_level);
+ if (!gstr) {
+ /* bt_py_common_format_current_exception() logs errors */