From: Jérémie Galarneau Date: Tue, 9 Feb 2016 22:54:21 +0000 (-0500) Subject: Plugin symbol resolving fix X-Git-Tag: v2.0.0-pre1~840 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=2e339de1f00bbca92186d5dada36075d497808c8 Plugin symbol resolving fix Signed-off-by: Jérémie Galarneau --- diff --git a/converter/babeltrace.c b/converter/babeltrace.c index 748cd6b8..568d5b8f 100644 --- a/converter/babeltrace.c +++ b/converter/babeltrace.c @@ -40,6 +40,8 @@ #include #include +#include +#include #include #include #include @@ -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 diff --git a/include/babeltrace/plugin/component-factory.h b/include/babeltrace/plugin/component-factory.h index 4513035c..3612d541 100644 --- a/include/babeltrace/plugin/component-factory.h +++ b/include/babeltrace/plugin/component-factory.h @@ -30,6 +30,7 @@ #include #include #include +#include #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); /** diff --git a/include/babeltrace/plugin/plugin.h b/include/babeltrace/plugin/plugin.h index 1642b7a0..3bb7c044 100644 --- a/include/babeltrace/plugin/plugin.h +++ b/include/babeltrace/plugin/plugin.h @@ -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) diff --git a/plugins/component-factory.c b/plugins/component-factory.c index a7fdab38..1be827c4 100644 --- a/plugins/component-factory.c +++ b/plugins/component-factory.c @@ -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); diff --git a/plugins/ctf/text/text.c b/plugins/ctf/text/text.c index 8e95c8b4..9732678c 100644 --- a/plugins/ctf/text/text.c +++ b/plugins/ctf/text/text.c @@ -3,7 +3,7 @@ * * Babeltrace CTF Text Output Plugin * - * Copyright 2015 Jérémie Galarneau + * Copyright 2016 Jérémie Galarneau * * Author: Jérémie Galarneau * @@ -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 { diff --git a/plugins/plugin.c b/plugins/plugin.c index 9218868d..48ca2134 100644 --- a/plugins/plugin.c +++ b/plugins/plugin.c @@ -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: