Add bt_plugin_set object
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 26 Apr 2017 12:44:15 +0000 (08:44 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:41 +0000 (12:57 -0400)
It is unusual in the Babeltrace API to return a NULL-terminated array of
objects which must be individually put by the user in addition to
calling free() on the returned array. This is what was returned by
bt_plugin_create_all_from_file(), bt_plugin_create_all_from_dir(),
and bt_plugin_create_all_from_static().

Instead, create a bt_plugin_set object of which the only purpose is to
contain plugins. A plugin set has a reference count and is not more
awkward to use than any other standard Babeltrace object.

Tests and the CLI are updated accordingly.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
cli/babeltrace.c
include/babeltrace/plugin/plugin-internal.h
include/babeltrace/plugin/plugin-so-internal.h
include/babeltrace/plugin/plugin.h
include/babeltrace/plugin/python-plugin-provider-internal.h
lib/plugin/plugin-so.c
lib/plugin/plugin.c
python-plugin-provider/python-plugin-provider.c
tests/lib/test_plugin.c

index cb8492f2acfd9630f1b5d1feb8c8d5653ac2f075..821772e191b048a2b444da3018e94444eb8b885d 100644 (file)
@@ -40,6 +40,7 @@
 #include <babeltrace/graph/notification-iterator.h>
 #include <babeltrace/ref.h>
 #include <babeltrace/values.h>
+#include <unistd.h>
 #include <stdlib.h>
 #include <popt.h>
 #include <string.h>
@@ -626,25 +627,33 @@ end:
 }
 
 static
-void add_to_loaded_plugins(struct bt_plugin **plugins)
+void add_to_loaded_plugins(struct bt_plugin_set *plugin_set)
 {
-       while (*plugins) {
-               struct bt_plugin *plugin = *plugins;
-               /* Check if it's already loaded (from another path). */
+       int i;
+       int count;
+
+       count = bt_plugin_set_get_plugin_count(plugin_set);
+       assert(count >= 0);
+
+       for (i = 0; i < count; i++) {
+               struct bt_plugin *plugin =
+                       bt_plugin_set_get_plugin(plugin_set, i);
                struct bt_plugin *loaded_plugin =
                                find_plugin(bt_plugin_get_name(plugin));
 
+               assert(plugin);
+
                if (loaded_plugin) {
                        printf_verbose("Not loading plugin `%s`: already loaded from `%s`\n",
                                        bt_plugin_get_path(plugin),
                                        bt_plugin_get_path(loaded_plugin));
-                       BT_PUT(loaded_plugin);
-                       BT_PUT(plugin);
+                       bt_put(loaded_plugin);
                } else {
-                       /* Transfer ownership to global array. */
-                       g_ptr_array_add(loaded_plugins, plugin);
+                       /* Add to global array. */
+                       g_ptr_array_add(loaded_plugins, bt_get(plugin));
                }
-               *(plugins++) = NULL;
+
+               bt_put(plugin);
        }
 }
 
@@ -662,7 +671,7 @@ int load_dynamic_plugins(struct bt_value *plugin_paths)
        for (i = 0; i < nr_paths; i++) {
                struct bt_value *plugin_path_value = NULL;
                const char *plugin_path;
-               struct bt_plugin **plugins;
+               struct bt_plugin_set *plugin_set;
 
                plugin_path_value = bt_value_array_get(plugin_paths, i);
                if (bt_value_string_get(plugin_path_value,
@@ -671,17 +680,16 @@ int load_dynamic_plugins(struct bt_value *plugin_paths)
                        continue;
                }
 
-               plugins = bt_plugin_create_all_from_dir(plugin_path, false);
-               if (!plugins) {
+               plugin_set = bt_plugin_create_all_from_dir(plugin_path, false);
+               if (!plugin_set) {
                        printf_debug("Unable to dynamically load plugins from path %s.\n",
                                plugin_path);
                        BT_PUT(plugin_path_value);
                        continue;
                }
 
-               add_to_loaded_plugins(plugins);
-               free(plugins);
-
+               add_to_loaded_plugins(plugin_set);
+               bt_put(plugin_set);
                BT_PUT(plugin_path_value);
        }
 end:
@@ -692,17 +700,17 @@ static
 int load_static_plugins(void)
 {
        int ret = 0;
-       struct bt_plugin **plugins;
+       struct bt_plugin_set *plugin_set;
 
-       plugins = bt_plugin_create_all_from_static();
-       if (!plugins) {
+       plugin_set = bt_plugin_create_all_from_static();
+       if (!plugin_set) {
                printf_debug("Unable to load static plugins.\n");
                ret = -1;
                goto end;
        }
 
-       add_to_loaded_plugins(plugins);
-       free(plugins);
+       add_to_loaded_plugins(plugin_set);
+       bt_put(plugin_set);
 end:
        return ret;
 }
index 9b66836f4889445b851932b5da6af1503a13710e..7b38a2d3d219ffcceed302fe7dd0e3a7b06d506f 100644 (file)
@@ -72,6 +72,13 @@ struct bt_plugin {
        void (*destroy_spec_data)(struct bt_plugin *);
 };
 
+struct bt_plugin_set {
+       struct bt_object base;
+
+       /* Array of struct bt_plugin * */
+       GPtrArray *plugins;
+};
+
 static inline
 void bt_plugin_destroy(struct bt_object *obj)
 {
@@ -244,4 +251,52 @@ void bt_plugin_freeze(struct bt_plugin *plugin)
        plugin->frozen = true;
 }
 
+static
+void bt_plugin_set_destroy(struct bt_object *obj)
+{
+       struct bt_plugin_set *plugin_set =
+               container_of(obj, struct bt_plugin_set, base);
+
+       if (!plugin_set) {
+               return;
+       }
+
+       if (plugin_set->plugins) {
+               g_ptr_array_free(plugin_set->plugins, TRUE);
+       }
+
+       g_free(plugin_set);
+}
+
+static inline
+struct bt_plugin_set *bt_plugin_set_create(void)
+{
+       struct bt_plugin_set *plugin_set = g_new0(struct bt_plugin_set, 1);
+
+       if (!plugin_set) {
+               goto end;
+       }
+
+       bt_object_init(plugin_set, bt_plugin_set_destroy);
+
+       plugin_set->plugins = g_ptr_array_new_with_free_func(
+               (GDestroyNotify) bt_put);
+       if (!plugin_set->plugins) {
+               BT_PUT(plugin_set);
+               goto end;
+       }
+
+end:
+       return plugin_set;
+}
+
+static inline
+void bt_plugin_set_add_plugin(struct bt_plugin_set *plugin_set,
+               struct bt_plugin *plugin)
+{
+       assert(plugin_set);
+       assert(plugin);
+       g_ptr_array_add(plugin_set->plugins, bt_get(plugin));
+}
+
 #endif /* BABELTRACE_PLUGIN_PLUGIN_INTERNAL_H */
index c9d59f5f80420b6123de36e4b6e1d46fb03af5af..9c511769220656c6bb3796af58b0370357f7170b 100644 (file)
@@ -55,10 +55,10 @@ struct bt_plugin_so_spec_data {
 };
 
 BT_HIDDEN
-struct bt_plugin **bt_plugin_so_create_all_from_file(const char *path);
+struct bt_plugin_set *bt_plugin_so_create_all_from_file(const char *path);
 
 BT_HIDDEN
-struct bt_plugin **bt_plugin_so_create_all_from_static(void);
+struct bt_plugin_set *bt_plugin_so_create_all_from_static(void);
 
 BT_HIDDEN
 void bt_plugin_so_on_add_component_class(struct bt_plugin *plugin,
index 31baf57665d08fbda0cf5b916e46426f322f36fc..0e0bc8da54068df2fba76327ed2826e3a2b8b8f2 100644 (file)
@@ -37,6 +37,7 @@ extern "C" {
 #endif
 
 struct bt_plugin;
+struct bt_plugin_set;
 struct bt_component_class;
 
 /**
@@ -57,12 +58,12 @@ extern struct bt_component_class *bt_plugin_find_component_class(
                const char *plugin_name, const char *component_class_name,
                enum bt_component_class_type component_class_type);
 
-extern struct bt_plugin **bt_plugin_create_all_from_file(const char *path);
+extern struct bt_plugin_set *bt_plugin_create_all_from_file(const char *path);
 
-extern struct bt_plugin **bt_plugin_create_all_from_dir(const char *path,
+extern struct bt_plugin_set *bt_plugin_create_all_from_dir(const char *path,
                bool recurse);
 
-extern struct bt_plugin **bt_plugin_create_all_from_static(void);
+extern struct bt_plugin_set *bt_plugin_create_all_from_static(void);
 
 /**
  * Get the name of a plug-in.
@@ -118,6 +119,13 @@ struct bt_component_class *bt_plugin_get_component_class_by_name_and_type(
                struct bt_plugin *plugin, const char *name,
                enum bt_component_class_type type);
 
+extern
+int bt_plugin_set_get_plugin_count(struct bt_plugin_set *plugin_set);
+
+extern
+struct bt_plugin *bt_plugin_set_get_plugin(struct bt_plugin_set *plugin_set,
+               unsigned int index);
+
 #ifdef __cplusplus
 }
 #endif
index acf913ff3a57d05f27d042f03bdb02fd5796aaab..2f81e5793210b6cc8c47675b30e599d62d1885b3 100644 (file)
@@ -26,6 +26,6 @@
 #include <babeltrace/plugin/plugin.h>
 
 extern
-struct bt_plugin **bt_plugin_python_create_all_from_file(const char *path);
+struct bt_plugin_set *bt_plugin_python_create_all_from_file(const char *path);
 
 #endif /* BABELTRACE_PLUGIN_PYTHON_PLUGIN_PROVIDER_INTERNAL_H */
index 771937ed8782a57d4c07a9dddd5103c176da4c38..7b152e2ce606568bcd4fa08eb82956b2d40a7c90 100644 (file)
@@ -688,7 +688,7 @@ end:
 }
 
 static
-struct bt_plugin **bt_plugin_so_create_all_from_sections(
+struct bt_plugin_set *bt_plugin_so_create_all_from_sections(
                struct bt_plugin_so_shared_lib_handle *shared_lib_handle,
                struct __bt_plugin_descriptor const * const *descriptors_begin,
                struct __bt_plugin_descriptor const * const *descriptors_end,
@@ -704,7 +704,7 @@ struct bt_plugin **bt_plugin_so_create_all_from_sections(
        size_t cc_descriptors_count;
        size_t cc_descr_attrs_count;
        size_t i;
-       struct bt_plugin **plugins = NULL;
+       struct bt_plugin_set *plugin_set = NULL;
 
        descriptor_count = descriptors_end - descriptors_begin;
        attrs_count = attrs_end - attrs_begin;
@@ -718,8 +718,8 @@ struct bt_plugin **bt_plugin_so_create_all_from_sections(
                cc_descriptors_begin, cc_descriptors_end, cc_descriptors_count);
        printf_verbose("Section: Plugin component class descriptor attributes: [%p - %p], (%zu elements)\n",
                cc_descr_attrs_begin, cc_descr_attrs_end, cc_descr_attrs_count);
-       plugins = calloc(descriptor_count + 1, sizeof(*plugins));
-       if (!plugins) {
+       plugin_set = bt_plugin_set_create();
+       if (!plugin_set) {
                goto error;
        }
 
@@ -759,24 +759,24 @@ struct bt_plugin **bt_plugin_so_create_all_from_sections(
                        goto error;
                }
 
-               /* Transfer ownership to the array */
-               plugins[i] = plugin;
+               /* Add to plugin set */
+               bt_plugin_set_add_plugin(plugin_set, plugin);
+               bt_put(plugin);
        }
 
        goto end;
 
 error:
-       g_free(plugins);
-       plugins = NULL;
+       BT_PUT(plugin_set);
 
 end:
-       return plugins;
+       return plugin_set;
 }
 
 BT_HIDDEN
-struct bt_plugin **bt_plugin_so_create_all_from_static(void)
+struct bt_plugin_set *bt_plugin_so_create_all_from_static(void)
 {
-       struct bt_plugin **plugins = NULL;
+       struct bt_plugin_set *plugin_set = NULL;
        struct bt_plugin_so_shared_lib_handle *shared_lib_handle =
                bt_plugin_so_shared_lib_handle_create(NULL);
 
@@ -784,7 +784,7 @@ struct bt_plugin **bt_plugin_so_create_all_from_static(void)
                goto end;
        }
 
-       plugins = bt_plugin_so_create_all_from_sections(shared_lib_handle,
+       plugin_set = bt_plugin_so_create_all_from_sections(shared_lib_handle,
                SECTION_BEGIN(__bt_plugin_descriptors),
                SECTION_END(__bt_plugin_descriptors),
                SECTION_BEGIN(__bt_plugin_descriptor_attributes),
@@ -797,14 +797,14 @@ struct bt_plugin **bt_plugin_so_create_all_from_static(void)
 end:
        BT_PUT(shared_lib_handle);
 
-       return plugins;
+       return plugin_set;
 }
 
 BT_HIDDEN
-struct bt_plugin **bt_plugin_so_create_all_from_file(const char *path)
+struct bt_plugin_set *bt_plugin_so_create_all_from_file(const char *path)
 {
        size_t path_len;
-       struct bt_plugin **plugins = NULL;
+       struct bt_plugin_set *plugin_set = NULL;
        struct __bt_plugin_descriptor const * const *descriptors_begin = NULL;
        struct __bt_plugin_descriptor const * const *descriptors_end = NULL;
        struct __bt_plugin_descriptor_attribute const * const *attrs_begin = NULL;
@@ -923,14 +923,14 @@ struct bt_plugin **bt_plugin_so_create_all_from_file(const char *path)
        }
 
        /* Initialize plugin */
-       plugins = bt_plugin_so_create_all_from_sections(shared_lib_handle,
+       plugin_set = bt_plugin_so_create_all_from_sections(shared_lib_handle,
                descriptors_begin, descriptors_end, attrs_begin, attrs_end,
                cc_descriptors_begin, cc_descriptors_end,
                cc_descr_attrs_begin, cc_descr_attrs_end);
 
 end:
        BT_PUT(shared_lib_handle);
-       return plugins;
+       return plugin_set;
 }
 
 static
index d85604afbd89a2e15ad15a5b402dbc19bcca72b0..5f251030fd20b84c304b0aa52e9fd6fe602dba69 100644 (file)
 #ifdef BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT
 #include <babeltrace/plugin/python-plugin-provider-internal.h>
 static
-struct bt_plugin **(*bt_plugin_python_create_all_from_file_sym)(const char *path) =
+struct bt_plugin_set *(*bt_plugin_python_create_all_from_file_sym)(const char *path) =
        bt_plugin_python_create_all_from_file;
 #else /* BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT */
 static GModule *python_plugin_provider_module;
 static
-struct bt_plugin **(*bt_plugin_python_create_all_from_file_sym)(const char *path);
+struct bt_plugin_set *(*bt_plugin_python_create_all_from_file_sym)(const char *path);
 
 __attribute__((constructor)) static
 void init_python_plugin_provider(void) {
@@ -80,14 +80,45 @@ void fini_python_plugin_provider(void) {
 }
 #endif
 
-struct bt_plugin **bt_plugin_create_all_from_static(void)
+extern
+int bt_plugin_set_get_plugin_count(struct bt_plugin_set *plugin_set)
+{
+       int count = -1;
+
+       if (!plugin_set) {
+               goto end;
+       }
+
+       count = plugin_set->plugins->len;
+
+end:
+       return count;
+}
+
+extern
+struct bt_plugin *bt_plugin_set_get_plugin(struct bt_plugin_set *plugin_set,
+               unsigned int index)
+{
+       struct bt_plugin *plugin = NULL;
+
+       if (!plugin_set || index >= plugin_set->plugins->len) {
+               goto end;
+       }
+
+       plugin = bt_get(g_ptr_array_index(plugin_set->plugins, index));
+
+end:
+       return plugin;
+}
+
+struct bt_plugin_set *bt_plugin_create_all_from_static(void)
 {
        return bt_plugin_so_create_all_from_static();
 }
 
-struct bt_plugin **bt_plugin_create_all_from_file(const char *path)
+struct bt_plugin_set *bt_plugin_create_all_from_file(const char *path)
 {
-       struct bt_plugin **plugins = NULL;
+       struct bt_plugin_set *plugin_set = NULL;
 
        if (!path) {
                goto end;
@@ -96,21 +127,21 @@ struct bt_plugin **bt_plugin_create_all_from_file(const char *path)
        printf_verbose("Trying to load plugins from `%s`\n", path);
 
        /* Try shared object plugins */
-       plugins = bt_plugin_so_create_all_from_file(path);
-       if (plugins) {
+       plugin_set = bt_plugin_so_create_all_from_file(path);
+       if (plugin_set) {
                goto end;
        }
 
        /* Try Python plugins if support is available */
        if (bt_plugin_python_create_all_from_file_sym) {
-               plugins = bt_plugin_python_create_all_from_file_sym(path);
-               if (plugins) {
+               plugin_set = bt_plugin_python_create_all_from_file_sym(path);
+               if (plugin_set) {
                        goto end;
                }
        }
 
 end:
-       return plugins;
+       return plugin_set;
 }
 
 static void destroy_gstring(void *data)
@@ -118,30 +149,16 @@ static void destroy_gstring(void *data)
        g_string_free(data, TRUE);
 }
 
-void free_plugins(struct bt_plugin **plugins) {
-       if (plugins) {
-               struct bt_plugin **cur_plugin = plugins;
-
-               while (*cur_plugin) {
-                       bt_put(*cur_plugin);
-                       cur_plugin++;
-               }
-
-               free(plugins);
-       }
-}
-
 struct bt_plugin *bt_plugin_find(const char *plugin_name)
 {
        const char *system_plugin_dir;
        char *home_plugin_dir = NULL;
        const char *envvar;
        struct bt_plugin *plugin = NULL;
-       struct bt_plugin **plugins = NULL;
-       struct bt_plugin **cur_plugin;
+       struct bt_plugin_set *plugin_set = NULL;
        GPtrArray *dirs = NULL;
        int ret;
-       size_t i;
+       size_t i, j;
 
        if (!plugin_name) {
                goto end;
@@ -203,41 +220,41 @@ struct bt_plugin *bt_plugin_find(const char *plugin_name)
 
                printf_verbose("Trying to load plugins from directory `%s`\n",
                        dir->str);
-               free_plugins(plugins);
-               plugins = bt_plugin_create_all_from_dir(dir->str, false);
-               if (!plugins) {
+               BT_PUT(plugin_set);
+               plugin_set = bt_plugin_create_all_from_dir(dir->str, false);
+               if (!plugin_set) {
                        continue;
                }
 
-               cur_plugin = plugins;
+               for (j = 0; j < plugin_set->plugins->len; j++) {
+                       struct bt_plugin *candidate_plugin =
+                               g_ptr_array_index(plugin_set->plugins, j);
 
-               while (*cur_plugin) {
-                       if (strcmp(bt_plugin_get_name(*cur_plugin), plugin_name)
-                                       == 0) {
-                               plugin = bt_get(*cur_plugin);
+                       if (strcmp(bt_plugin_get_name(candidate_plugin),
+                                       plugin_name) == 0) {
+                               plugin = bt_get(candidate_plugin);
                                goto end;
                        }
-
-                       cur_plugin++;
                }
        }
 
-       free_plugins(plugins);
-       plugins = bt_plugin_create_all_from_static();
-       cur_plugin = plugins;
+       bt_put(plugin_set);
+       plugin_set = bt_plugin_create_all_from_static();
+
+       for (j = 0; j < plugin_set->plugins->len; j++) {
+               struct bt_plugin *candidate_plugin =
+                       g_ptr_array_index(plugin_set->plugins, j);
 
-       while (*cur_plugin) {
-               if (strcmp(bt_plugin_get_name(*cur_plugin), plugin_name) == 0) {
-                       plugin = bt_get(*cur_plugin);
+               if (strcmp(bt_plugin_get_name(candidate_plugin),
+                               plugin_name) == 0) {
+                       plugin = bt_get(candidate_plugin);
                        goto end;
                }
-
-               cur_plugin++;
        }
 
 end:
        free(home_plugin_dir);
-       free_plugins(plugins);
+       bt_put(plugin_set);
 
        if (dirs) {
                g_ptr_array_free(dirs, TRUE);
@@ -289,7 +306,8 @@ struct dirent *alloc_dirent(const char *path)
 
 static
 enum bt_plugin_status bt_plugin_create_append_all_from_dir(
-               GPtrArray *plugins, const char *path, bool recurse)
+               struct bt_plugin_set *plugin_set, const char *path,
+               bool recurse)
 {
        DIR *directory = NULL;
        struct dirent *entry = NULL, *result = NULL;
@@ -362,24 +380,27 @@ enum bt_plugin_status bt_plugin_create_append_all_from_dir(
                }
 
                if (S_ISDIR(st.st_mode) && recurse) {
-                       ret = bt_plugin_create_append_all_from_dir(plugins,
+                       ret = bt_plugin_create_append_all_from_dir(plugin_set,
                                file_path, true);
                        if (ret < 0) {
                                goto end;
                        }
                } else if (S_ISREG(st.st_mode)) {
-                       struct bt_plugin **plugins_from_file =
+                       struct bt_plugin_set *plugins_from_file =
                                bt_plugin_create_all_from_file(file_path);
 
                        if (plugins_from_file) {
-                               struct bt_plugin **plugin;
+                               size_t j;
+
+                               for (j = 0; j < plugins_from_file->plugins->len; j++) {
+                                       struct bt_plugin *plugin =
+                                               g_ptr_array_index(plugins_from_file->plugins, j);
 
-                               for (plugin = plugins_from_file; *plugin; plugin++) {
-                                       /* Transfer ownership to array */
-                                       g_ptr_array_add(plugins, *plugin);
+                                       bt_plugin_set_add_plugin(plugin_set,
+                                               plugin);
                                }
 
-                               free(plugins_from_file);
+                               bt_put(plugins_from_file);
                        }
                }
        }
@@ -398,37 +419,31 @@ end:
        return ret;
 }
 
-struct bt_plugin **bt_plugin_create_all_from_dir(const char *path,
+struct bt_plugin_set *bt_plugin_create_all_from_dir(const char *path,
                bool recurse)
 {
-       GPtrArray *plugins_array = g_ptr_array_new();
-       struct bt_plugin **plugins = NULL;
+       struct bt_plugin_set *plugin_set;
        enum bt_plugin_status status;
 
+       plugin_set = bt_plugin_set_create();
+       if (!plugin_set) {
+               goto error;
+       }
+
        /* Append found plugins to array */
-       status = bt_plugin_create_append_all_from_dir(plugins_array, path,
+       status = bt_plugin_create_append_all_from_dir(plugin_set, path,
                recurse);
        if (status < 0) {
                goto error;
        }
 
-       /* Add sentinel to array */
-       g_ptr_array_add(plugins_array, NULL);
-       plugins = (struct bt_plugin **) plugins_array->pdata;
        goto end;
 
 error:
-       if (plugins_array) {
-               g_ptr_array_free(plugins_array, TRUE);
-               plugins_array = NULL;
-       }
+       BT_PUT(plugin_set);
 
 end:
-       if (plugins_array) {
-               g_ptr_array_free(plugins_array, FALSE);
-       }
-
-       return plugins;
+       return plugin_set;
 }
 
 const char *bt_plugin_get_name(struct bt_plugin *plugin)
index c7727f21020cbfddc4977b4c93e9872ee0f78ad6..2b566adaa4273de540a706f6366674f3b017a5b7 100644 (file)
@@ -345,9 +345,10 @@ end:
 }
 
 G_MODULE_EXPORT
-struct bt_plugin **bt_plugin_python_create_all_from_file(const char *path)
+struct bt_plugin_set *bt_plugin_python_create_all_from_file(const char *path)
 {
-       struct bt_plugin **plugins = NULL;
+       struct bt_plugin_set *plugin_set = NULL;
+       struct bt_plugin *plugin = NULL;
        PyObject *py_plugin_info = NULL;
        gchar *basename = NULL;
        size_t path_len;
@@ -422,33 +423,27 @@ struct bt_plugin **bt_plugin_python_create_all_from_file(const char *path)
 
        /*
         * Get bt_plugin from plugin info object.
-        *
-        * calloc(2, ...) because a single Python plugin file always
-        * provides a single Babeltrace plugin (second item is the
-        * sentinel).
         */
-       plugins = calloc(2, sizeof(*plugins));
-       if (!plugins) {
+       plugin = bt_plugin_from_python_plugin_info(py_plugin_info);
+       if (!plugin) {
                goto error;
        }
 
-       plugins[0] = bt_plugin_from_python_plugin_info(py_plugin_info);
-       if (!plugins[0]) {
+       bt_plugin_set_path(plugin, path);
+       plugin_set = bt_plugin_set_create();
+       if (!plugin_set) {
                goto error;
        }
 
-       bt_plugin_set_path(plugins[0], path);
+       bt_plugin_set_add_plugin(plugin_set, plugin);
        goto end;
 
 error:
-       if (plugins) {
-               BT_PUT(plugins[0]);
-               free(plugins);
-               plugins = NULL;
-       }
+       BT_PUT(plugin_set);
 
 end:
+       bt_put(plugin);
        Py_XDECREF(py_plugin_info);
        g_free(basename);
-       return plugins;
+       return plugin_set;
 }
index fdc16c5bbdb3b623141f2b853f37c0d5fb3a66de..b66cb827ae1fdf6cc9f7b83189fcc85d564ba23c 100644 (file)
@@ -60,13 +60,13 @@ static char *get_test_plugin_path(const char *plugin_dir,
 
 static void test_invalid(const char *plugin_dir)
 {
-       struct bt_plugin **plugins;
+       struct bt_plugin_set *plugin_set;
 
-       plugins = bt_plugin_create_all_from_file(NON_EXISTING_PATH);
-       ok(!plugins, "bt_plugin_create_all_from_file() fails with a non-existing file");
+       plugin_set = bt_plugin_create_all_from_file(NON_EXISTING_PATH);
+       ok(!plugin_set, "bt_plugin_create_all_from_file() fails with a non-existing file");
 
-       plugins = bt_plugin_create_all_from_file(plugin_dir);
-       ok(!plugins, "bt_plugin_create_all_from_file() fails with a directory");
+       plugin_set = bt_plugin_create_all_from_file(plugin_dir);
+       ok(!plugin_set, "bt_plugin_create_all_from_file() fails with a directory");
 
        ok(!bt_plugin_create_all_from_file(NULL),
                "bt_plugin_create_all_from_file() handles NULL correctly");
@@ -95,7 +95,7 @@ static void test_invalid(const char *plugin_dir)
 
 static void test_minimal(const char *plugin_dir)
 {
-       struct bt_plugin **plugins;
+       struct bt_plugin_set *plugin_set;
        struct bt_plugin *plugin;
        char *minimal_path = get_test_plugin_path(plugin_dir, "minimal");
 
@@ -103,12 +103,13 @@ static void test_minimal(const char *plugin_dir)
        diag("minimal plugin test below");
 
        reset_test_plugin_symbols();
-       plugins = bt_plugin_create_all_from_file(minimal_path);
-       ok(plugins && plugins[0], "bt_plugin_create_all_from_file() succeeds with a valid file");
+       plugin_set = bt_plugin_create_all_from_file(minimal_path);
+       ok(plugin_set && bt_plugin_set_get_plugin_count(plugin_set) == 1,
+               "bt_plugin_create_all_from_file() succeeds with a valid file");
        ok(test_plugin_init_called, "plugin's initialization function is called during bt_plugin_create_all_from_file()");
-       ok(plugins && plugins[0] && !plugins[1],
+       ok(bt_plugin_set_get_plugin_count(plugin_set) == 1,
                "bt_plugin_create_all_from_file() returns the expected number of plugins");
-       plugin = plugins[0];
+       plugin = bt_plugin_set_get_plugin(plugin_set, 0);
        ok(strcmp(bt_plugin_get_name(plugin), "test_minimal") == 0,
                "bt_plugin_get_name() returns the expected name");
        ok(strcmp(bt_plugin_get_description(plugin),
@@ -125,16 +126,16 @@ static void test_minimal(const char *plugin_dir)
                "bt_plugin_get_path() returns the expected path");
        ok(bt_plugin_get_component_class_count(plugin) == 0,
                "bt_plugin_get_component_class_count() returns the expected value");
-       BT_PUT(plugin);
+       bt_put(plugin);
+       bt_put(plugin_set);
        ok(test_plugin_exit_called, "plugin's exit function is called when the plugin is destroyed");
 
        free(minimal_path);
-       free(plugins);
 }
 
 static void test_sfs(const char *plugin_dir)
 {
-       struct bt_plugin **plugins;
+       struct bt_plugin_set *plugin_set;
        struct bt_plugin *plugin;
        struct bt_component_class *sink_comp_class;
        struct bt_component_class *source_comp_class;
@@ -153,9 +154,9 @@ static void test_sfs(const char *plugin_dir)
        assert(sfs_path);
        diag("sfs plugin test below");
 
-       plugins = bt_plugin_create_all_from_file(sfs_path);
-       assert(plugins && plugins[0]);
-       plugin = plugins[0];
+       plugin_set = bt_plugin_create_all_from_file(sfs_path);
+       assert(plugin_set && bt_plugin_set_get_plugin_count(plugin_set) == 1);
+       plugin = bt_plugin_set_get_plugin(plugin_set, 0);
        ok(bt_plugin_get_version(plugin, &major, &minor, &patch, &extra) ==
                BT_PLUGIN_STATUS_OK,
                "bt_plugin_get_version() succeeds when there's a version");
@@ -231,7 +232,7 @@ static void test_sfs(const char *plugin_dir)
        BT_PUT(sink_component);
 
        free(sfs_path);
-       free(plugins);
+       bt_put(plugin_set);
        bt_put(object);
        bt_put(res_params);
        bt_put(results);
@@ -240,29 +241,23 @@ static void test_sfs(const char *plugin_dir)
 
 static void test_create_all_from_dir(const char *plugin_dir)
 {
-       struct bt_plugin **plugins;
-       struct bt_plugin *plugin;
-       int i;
+       struct bt_plugin_set *plugin_set;
 
        diag("create from all test below");
 
-       plugins = bt_plugin_create_all_from_dir(NON_EXISTING_PATH, false);
-       ok(!plugins,
+       plugin_set = bt_plugin_create_all_from_dir(NON_EXISTING_PATH, false);
+       ok(!plugin_set,
                "bt_plugin_create_all_from_dir() fails with an invalid path");
 
-       plugins = bt_plugin_create_all_from_dir(plugin_dir, false);
-       ok(plugins, "bt_plugin_create_all_from_dir() succeeds with a valid path");
-
-       i = 0;
-       while ((plugin = plugins[i])) {
-               BT_PUT(plugin);
-               i++;
-       }
+       plugin_set = bt_plugin_create_all_from_dir(plugin_dir, false);
+       ok(plugin_set, "bt_plugin_create_all_from_dir() succeeds with a valid path");
 
        /* 2 or 4, if `.la` files are considered or not */
-       ok(i == 2 || i == 4, "bt_plugin_create_all_from_dir() returns the expected number of plugin objects");
+       ok(bt_plugin_set_get_plugin_count(plugin_set) == 2 ||
+               bt_plugin_set_get_plugin_count(plugin_set) == 4,
+               "bt_plugin_create_all_from_dir() returns the expected number of plugin objects");
 
-       free(plugins);
+       bt_put(plugin_set);
 }
 
 static void test_find(const char *plugin_dir)
This page took 0.037634 seconds and 4 git commands to generate.