Plugin symbol resolving fix
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 9 Feb 2016 22:54:21 +0000 (17:54 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 16:57:26 +0000 (12:57 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
converter/babeltrace.c
include/babeltrace/plugin/component-factory.h
include/babeltrace/plugin/plugin.h
plugins/component-factory.c
plugins/ctf/text/text.c
plugins/plugin.c

index 748cd6b80040977d51afde9357fef108f2009e90..568d5b8f98d9102282c40a08904bddb35b057a37 100644 (file)
@@ -40,6 +40,8 @@
 
 #include <babeltrace/iterator.h>
 #include <babeltrace/plugin/component-factory.h>
+#include <babeltrace/ref.h>
+#include <babeltrace/values.h>
 #include <popt.h>
 #include <errno.h>
 #include <stdlib.h>
@@ -733,6 +735,7 @@ int main(int argc, char **argv)
        struct bt_trace_descriptor *td_write;
        struct bt_context *ctx;
        struct bt_component_factory *component_factory;
+       struct bt_value *components = NULL;
        int i;
 
        call_plugins_hooks();
@@ -772,6 +775,13 @@ int main(int argc, char **argv)
                goto end;
        }
 
+       components = bt_component_factory_get_components(component_factory);
+       if (!components || bt_value_array_is_empty(components)) {
+               printf_error("No plugins found, exiting.");
+               ret = -1;
+               goto end;
+       }
+
        if (opt_input_paths->len == 0) {
                ret = -1;
                goto end;
@@ -907,6 +917,8 @@ end:
        free(opt_debug_info_dir);
        free(opt_debug_info_target_prefix);
        g_ptr_array_free(opt_input_paths, TRUE);
+       BT_PUT(components);
+       BT_PUT(component_factory);
        if (partial_error)
                exit(EXIT_FAILURE);
        else
index 4513035ce727d44558e4481d7cdc8942a6272176..3612d54158c4ecbe7e146afb00c650af343e215f 100644 (file)
@@ -30,6 +30,7 @@
 #include <babeltrace/plugin/sink.h>
 #include <babeltrace/plugin/filter.h>
 #include <babeltrace/plugin/plugin-system.h>
+#include <babeltrace/values.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -76,7 +77,7 @@ extern struct bt_component_factory *bt_component_factory_create(void);
 /**
  * Get the list of components registered to this factory.
  */
-extern struct bt_object *bt_component_factory_get_components(
+extern struct bt_value *bt_component_factory_get_components(
                struct bt_component_factory *factory);
 
 /**
index 1642b7a0cf4956dd454fe925e792555e243e820f..3bb7c0440e45dcdc39f25c759211670cc55e42fa 100644 (file)
@@ -36,9 +36,9 @@ typedef enum bt_component_status (*bt_plugin_init_func)(
 typedef void (*bt_plugin_exit_func)(void);
 
 /* A plugin must define the __bt_plugin_init symbol */
-#define BT_PLUGIN_NAME(_x)     const char *__bt_plugin_name = (_x)
-#define BT_PLUGIN_AUTHOR(_x)   const char *__bt_plugin_author = (_x)
-#define BT_PLUGIN_LICENSE(_x)  const char *__bt_plugin_license = (_x)
+#define BT_PLUGIN_NAME(_x)     const char __bt_plugin_name[] = (_x)
+#define BT_PLUGIN_AUTHOR(_x)   const char __bt_plugin_author[] = (_x)
+#define BT_PLUGIN_LICENSE(_x)  const char __bt_plugin_license[] = (_x)
 #define BT_PLUGIN_INIT(_x)      bt_plugin_init_func __bt_plugin_init = (_x)
 #define BT_PLUGIN_EXIT(_x)      bt_plugin_exit_func __bt_plugin_exit = (_x)
 
index a7fdab3890e801587c3d635225a6d67e2c03b0be..1be827c4ae500ef05811a016be2ad0fcd0e88cd8 100644 (file)
@@ -278,7 +278,7 @@ error:
        return factory;
 }
 
-struct bt_object *bt_component_factory_get_components(
+struct bt_value *bt_component_factory_get_components(
                struct bt_component_factory *factory)
 {
        assert(0);
index 8e95c8b44884fe96d88423c348c325dfb7ae1f72..9732678cd9a1a7fd25c0f0eeed9f01a668774f59 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Babeltrace CTF Text Output Plugin
  *
- * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
@@ -47,7 +47,7 @@ BT_PLUGIN_EXIT(ctf_text_plugin_exit);
 
 /* Defines BT_PLUGIN_INIT. */
 BT_PLUGIN_COMPONENT_CLASSES_BEGIN
-BT_PLUGIN_SINK_COMPONENT_CLASS_ENTRY(plugin_name, ctf_text_init)
+BT_PLUGIN_SINK_COMPONENT_CLASS_ENTRY(__bt_plugin_name, ctf_text_init)
 BT_PLUGIN_COMPONENT_CLASSES_END
 
 enum loglevel {
index 9218868d3438fd8d8c51a0397909337035c76364..48ca2134f22b211b53ff7ef9d5ea763e3bfa7f63 100644 (file)
@@ -47,8 +47,8 @@ void bt_plugin_destroy(struct bt_object *obj)
 
        if (plugin->module) {
                if (!g_module_close(plugin->module)) {
-                       printf_error("Module close error: %s",
-                               g_module_error());
+                               printf_error("Module close error: %s",
+                                       g_module_error());
 
                }
        }
@@ -59,6 +59,7 @@ BT_HIDDEN
 struct bt_plugin *bt_plugin_create(GModule *module)
 {
        struct bt_plugin *plugin = NULL;
+       gpointer symbol = NULL;
 
        if (!module) {
                goto error;
@@ -71,30 +72,38 @@ struct bt_plugin *bt_plugin_create(GModule *module)
 
        bt_object_init(plugin, bt_plugin_destroy);
        if (!g_module_symbol(module, PLUGIN_SYMBOL_NAME,
-               (gpointer *) &plugin->name)) {
+                       (gpointer *) &plugin->name)) {
                printf_error("Unable to resolve plugin symbol %s from %s",
-                       PLUGIN_SYMBOL_NAME, g_module_name(module));
+                               PLUGIN_SYMBOL_NAME, g_module_name(module));
                goto error;
        }
 
-       printf("Loaded plugin with name %s\n", plugin->name);
        if (!g_module_symbol(module, PLUGIN_SYMBOL_LICENSE,
-               (gpointer *) &plugin->license)) {
+                       (gpointer *) &plugin->license)) {
                printf_error("Unable to resolve plugin symbol %s from %s",
-                       PLUGIN_SYMBOL_LICENSE, g_module_name(module));
+                               PLUGIN_SYMBOL_LICENSE, g_module_name(module));
                goto error;
        }
-       if (!g_module_symbol(module, PLUGIN_SYMBOL_INIT,
-               (gpointer *) &plugin->init)) {
+       if (!g_module_symbol(module, PLUGIN_SYMBOL_INIT, &symbol)) {
                printf_error("Unable to resolve plugin symbol %s from %s",
-                       PLUGIN_SYMBOL_INIT, g_module_name(module));
+                               PLUGIN_SYMBOL_INIT, g_module_name(module));
                goto error;
+       } else {
+               plugin->init = *((bt_plugin_init_func *) symbol);
+               if (!plugin->init) {
+                       printf_error("NULL %s symbol target",
+                                       PLUGIN_SYMBOL_INIT);
+                       goto error;
+               }
        }
 
-       /* Optional symbols */
-       g_module_symbol(module, PLUGIN_SYMBOL_EXIT, (gpointer *) &plugin->exit);
+       /* Optional */
+       if (g_module_symbol(module, PLUGIN_SYMBOL_EXIT,
+                       (gpointer *) &symbol)) {
+               plugin->exit = *((bt_plugin_exit_func *) symbol);
+       }
        g_module_symbol(module, PLUGIN_SYMBOL_AUTHOR,
-               (gpointer *) &plugin->author);
+                       (gpointer *) &plugin->author);
 
        return plugin;
 error:
This page took 0.043921 seconds and 4 git commands to generate.