From 2ce06c9e12da671dd1098ed4174a070af95cb406 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 19 Jun 2019 17:08:09 -0400 Subject: [PATCH] lib: keep plugin name, if any, in component class structure This is to make the plugin name available when having a component class object in an upcoming error reporting API. We don't keep the `bt_plugin` object itself because it's a component class's owner, and a component class can outlive its containing plugin: only the shared object data is kept alive in that case. Signed-off-by: Philippe Proulx Change-Id: I9cfbac32d88a6e7edac238b5a63b232695613b8c Reviewed-on: https://review.lttng.org/c/babeltrace/+/1523 Tested-by: jenkins Reviewed-by: Simon Marchi Reviewed-by: Francis Deslauriers --- src/lib/graph/component-class.c | 11 +++++++++++ src/lib/graph/component-class.h | 1 + src/lib/plugin/plugin.h | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/src/lib/graph/component-class.c b/src/lib/graph/component-class.c index 9d7e17b5..d17dbd4c 100644 --- a/src/lib/graph/component-class.c +++ b/src/lib/graph/component-class.c @@ -83,6 +83,11 @@ void destroy_component_class(struct bt_object *obj) class->help = NULL; } + if (class->plugin_name) { + g_string_free(class->plugin_name, TRUE); + class->plugin_name = NULL; + } + if (class->destroy_listeners) { g_array_free(class->destroy_listeners, TRUE); class->destroy_listeners = NULL; @@ -117,6 +122,12 @@ int bt_component_class_init(struct bt_component_class *class, goto error; } + class->plugin_name = g_string_new(NULL); + if (!class->plugin_name) { + BT_LOGE_STR("Failed to allocate a GString."); + goto error; + } + class->destroy_listeners = g_array_new(FALSE, TRUE, sizeof(struct bt_component_class_destroy_listener)); if (!class->destroy_listeners) { diff --git a/src/lib/graph/component-class.h b/src/lib/graph/component-class.h index bded3328..c6757ed3 100644 --- a/src/lib/graph/component-class.h +++ b/src/lib/graph/component-class.h @@ -54,6 +54,7 @@ struct bt_component_class { GString *name; GString *description; GString *help; + GString *plugin_name; /* Array of struct bt_component_class_destroy_listener */ GArray *destroy_listeners; diff --git a/src/lib/plugin/plugin.h b/src/lib/plugin/plugin.h index 202c69be..417d116c 100644 --- a/src/lib/plugin/plugin.h +++ b/src/lib/plugin/plugin.h @@ -351,6 +351,11 @@ int bt_plugin_add_component_class( abort(); } + /* Set component class's original plugin name */ + BT_ASSERT(comp_class->plugin_name); + BT_ASSERT(plugin->info.name); + g_string_assign(comp_class->plugin_name, plugin->info.name->str); + /* Add new component class */ bt_object_get_ref(comp_class); g_ptr_array_add(comp_classes, comp_class); -- 2.34.1