aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
authorJoão Valverde <joao.valverde@tecnico.ulisboa.pt>2017-09-26 19:17:52 +0100
committerJoão Valverde <j@v6e.pt>2017-09-26 19:52:30 +0000
commita1969dd6f608685e53c9e28992bc928f09a18849 (patch)
tree2de38eae370d962ec71848b716b1b3483c58d38f /wsutil
parenta269ae1b6a0a65d3e28a4c59487f7fd9b8a5685c (diff)
plugins: No need to allocate a new struct
Change-Id: Ic39cf1c7f199dc5e4879d954a649d21453dcc5e5 Reviewed-on: https://code.wireshark.org/review/23753 Petri-Dish: João Valverde <j@v6e.pt> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: João Valverde <j@v6e.pt>
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/plugins.c56
1 files changed, 26 insertions, 30 deletions
diff --git a/wsutil/plugins.c b/wsutil/plugins.c
index 6d1bd0aa60..5a6d735df0 100644
--- a/wsutil/plugins.c
+++ b/wsutil/plugins.c
@@ -321,52 +321,48 @@ scan_plugins(plugin_load_failure_mode mode)
}
}
-struct plugin_description {
- const char *name;
- const char *version;
- const char *types;
- const char *filename;
-};
-
static void
-add_plugin_type_description(gpointer key _U_, gpointer value, gpointer user_data)
+add_plugin_to_descriptions(gpointer key _U_, gpointer value, gpointer user_data)
{
- GPtrArray *descriptions = (GPtrArray *)user_data;
- struct plugin_description *plug_desc;
- plugin *plug = (plugin *)value;
-
- plug_desc = g_new(struct plugin_description, 1);
- plug_desc->name = plug->name;
- plug_desc->version = plug->version;
- plug_desc->types = plug->types->str;
- plug_desc->filename = g_module_name(plug->handle);
-
- g_ptr_array_add(descriptions, plug_desc);
+ g_ptr_array_add((GPtrArray *)user_data, value);
}
static int
-compare_descriptions(gconstpointer _a, gconstpointer _b)
+compare_plugins(gconstpointer _a, gconstpointer _b)
{
- const struct plugin_description *a = *(const struct plugin_description **)_a;
- const struct plugin_description *b = *(const struct plugin_description **)_b;
+ const plugin *a = *(const plugin **)_a;
+ const plugin *b = *(const plugin **)_b;
return strcmp(a->name, b->name);
}
+struct description_callback {
+ plugin_description_callback callback;
+ gpointer callback_data;
+};
+
+static void
+call_description_callback(gpointer data, gpointer user_data)
+{
+ plugin *plug = (plugin *)data;
+ struct description_callback *desc = (struct description_callback *)user_data;
+
+ desc->callback(plug->name, plug->version, plug->types->str, g_module_name(plug->handle), desc->callback_data);
+}
+
WS_DLL_PUBLIC void
plugins_get_descriptions(plugin_description_callback callback, void *user_data)
{
GPtrArray *descriptions;
- struct plugin_description *desc;
+ struct description_callback cb;
descriptions = g_ptr_array_sized_new(g_hash_table_size(plugins_table));
- g_hash_table_foreach(plugins_table, add_plugin_type_description, descriptions);
- g_ptr_array_sort(descriptions, compare_descriptions);
- for (guint i = 0; i < descriptions->len; i++) {
- desc = (struct plugin_description *)descriptions->pdata[i];
- callback(desc->name, desc->version, desc->types, desc->filename, user_data);
- }
- g_ptr_array_free(descriptions, TRUE);
+ g_hash_table_foreach(plugins_table, add_plugin_to_descriptions, descriptions);
+ g_ptr_array_sort(descriptions, compare_plugins);
+ cb.callback = callback;
+ cb.callback_data = user_data;
+ g_ptr_array_foreach(descriptions, call_description_callback, &cb);
+ g_ptr_array_free(descriptions, FALSE);
}
static void