Fix: lib: handle BT_FUNC_STATUS_NOT_FOUND in bt_plugin_so_create_all_from_sections
[babeltrace.git] / src / lib / plugin / plugin-so.c
index 6025bdec19ae829ab2922301467d4518fa1d35b9..698d03d0a0acb61ab667bcddcc6fb8b0a6d83697 100644 (file)
@@ -9,7 +9,6 @@
 #include "lib/logging.h"
 
 #include "common/assert.h"
-#include "lib/assert-pre.h"
 #include "compat/compiler.h"
 #include <babeltrace2/plugin/plugin-dev.h>
 #include "lib/graph/component-class.h"
@@ -460,7 +459,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                /* Find the corresponding component class descriptor entry */
                for (i = 0; i < comp_class_full_descriptors->len; i++) {
                        struct comp_class_full_descriptor *cc_full_descr =
-                               &g_array_index(comp_class_full_descriptors,
+                               &bt_g_array_index(comp_class_full_descriptors,
                                        struct comp_class_full_descriptor, i);
 
                        if (cur_cc_descr_attr->comp_class_descriptor !=
@@ -686,7 +685,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                                        NULL,
                                                descriptor->name,
                                                cur_cc_descr_attr->comp_class_descriptor->name,
-                                               bt_component_class_type_string(
+                                               bt_common_component_class_type_string(
                                                        cur_cc_descr_attr->comp_class_descriptor->type),
                                                cur_cc_descr_attr->type_name,
                                                cur_cc_descr_attr->type);
@@ -706,7 +705,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                                        NULL,
                                                descriptor->name,
                                                cur_cc_descr_attr->comp_class_descriptor->name,
-                                               bt_component_class_type_string(
+                                               bt_common_component_class_type_string(
                                                        cur_cc_descr_attr->comp_class_descriptor->type),
                                                cur_cc_descr_attr->type_name,
                                                cur_cc_descr_attr->type);
@@ -735,6 +734,12 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                status = init_status;
                                goto end;
                        } else {
+                               /*
+                                * Since we don't return an error,
+                                * there's no way to communicate this
+                                * error to the caller.
+                                */
+                               bt_current_thread_clear_error();
                                BT_LIB_LOGW(
                                        "User's plugin initialization function failed: "
                                        "status=%s",
@@ -751,7 +756,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
        /* Add described component classes to plugin */
        for (i = 0; i < comp_class_full_descriptors->len; i++) {
                struct comp_class_full_descriptor *cc_full_descr =
-                       &g_array_index(comp_class_full_descriptors,
+                       &bt_g_array_index(comp_class_full_descriptors,
                                struct comp_class_full_descriptor, i);
                struct bt_component_class *comp_class = NULL;
                struct bt_component_class_source *src_comp_class = NULL;
@@ -766,7 +771,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                NULL,
                        descriptor->name,
                        cc_full_descr->descriptor->name,
-                       bt_component_class_type_string(
+                       bt_common_component_class_type_string(
                                cc_full_descr->descriptor->type));
 
                if (cc_full_descr->descriptor->type == BT_COMPONENT_CLASS_TYPE_SOURCE ||
@@ -1336,6 +1341,12 @@ int bt_plugin_so_create_all_from_sections(
                        /* Add to plugin set */
                        bt_plugin_set_add_plugin(*plugin_set_out, plugin);
                        BT_OBJECT_PUT_REF_AND_RESET(plugin);
+               } else if (status == BT_FUNC_STATUS_NOT_FOUND) {
+                       /*
+                        * There was an error initializing the plugin,
+                        * but `fail_on_load_error` is false.
+                        */
+                       BT_OBJECT_PUT_REF_AND_RESET(plugin);
                } else if (status < 0) {
                        /*
                         * bt_plugin_so_init() handles
@@ -1368,7 +1379,6 @@ end:
        return status;
 }
 
-BT_HIDDEN
 int bt_plugin_so_create_all_from_static(bool fail_on_load_error,
                struct bt_plugin_set **plugin_set_out)
 {
@@ -1405,7 +1415,6 @@ end:
        return status;
 }
 
-BT_HIDDEN
 int bt_plugin_so_create_all_from_file(const char *path,
                bool fail_on_load_error, struct bt_plugin_set **plugin_set_out)
 {
@@ -1664,7 +1673,7 @@ end:
 
 static
 void plugin_comp_class_destroy_listener(struct bt_component_class *comp_class,
-               void *data)
+               void *data __attribute__((unused)))
 {
        bt_list_del(&comp_class->node);
        BT_OBJECT_PUT_REF_AND_RESET(comp_class->so_handle);
@@ -1672,6 +1681,13 @@ void plugin_comp_class_destroy_listener(struct bt_component_class *comp_class,
                "comp-cls-addr=%p", comp_class);
 }
 
+/*
+ * This function would normally not be BT_EXPORTed, but it is used by the
+ * Python plugin provider, which is conceptually part of libbabeltrace2, but
+ * implemented as a separate shared object, for modularity.  It is therefore
+ * exposed, but not part of the public ABI.
+ */
+BT_EXPORT
 void bt_plugin_so_on_add_component_class(struct bt_plugin *plugin,
                struct bt_component_class *comp_class)
 {
This page took 0.027884 seconds and 4 git commands to generate.