Cleanup g_strfreev() to auto_gcharv

Include some additional minor cleanups
This commit is contained in:
John Hernandez
2023-07-13 16:31:31 +02:00
parent 029f1caa52
commit 865a056315
16 changed files with 165 additions and 234 deletions

View File

@@ -273,7 +273,7 @@ callbacks_get_window_handler(const char* tag)
gboolean
plugins_run_command(const char* const input)
{
gchar** split = g_strsplit(input, " ", -1);
auto_gcharv gchar** split = g_strsplit(input, " ", -1);
GList* command_hashes = g_hash_table_get_values(p_commands);
GList* curr_hash = command_hashes;
@@ -283,26 +283,20 @@ plugins_run_command(const char* const input)
PluginCommand* command = g_hash_table_lookup(command_hash, split[0]);
if (command) {
gboolean result;
gchar** args = parse_args_with_freetext(input, command->min_args, command->max_args, &result);
auto_gcharv gchar** args = parse_args_with_freetext(input, command->min_args, command->max_args, &result);
if (result == FALSE) {
ui_invalid_command_usage(command->command_name, NULL);
g_strfreev(split);
g_list_free(command_hashes);
return TRUE;
} else {
command->callback_exec(command, args);
g_strfreev(split);
g_strfreev(args);
g_list_free(command_hashes);
return TRUE;
}
g_list_free(command_hashes);
return TRUE;
}
curr_hash = g_list_next(curr_hash);
}
g_list_free(command_hashes);
g_strfreev(split);
return FALSE;
}

View File

@@ -82,50 +82,47 @@ plugins_init(void)
#endif
// load plugins
gchar** plugins_pref = prefs_get_plugins();
if (plugins_pref) {
for (int i = 0; i < g_strv_length(plugins_pref); i++) {
gboolean loaded = FALSE;
gchar* filename = plugins_pref[i];
auto_gcharv gchar** plugins_pref = prefs_get_plugins();
if (!plugins_pref) {
return;
}
for (int i = 0; i < g_strv_length(plugins_pref); i++) {
gboolean loaded = FALSE;
gchar* filename = plugins_pref[i];
#ifdef HAVE_PYTHON
if (g_str_has_suffix(filename, ".py")) {
ProfPlugin* plugin = python_plugin_create(filename);
if (plugin) {
g_hash_table_insert(plugins, strdup(filename), plugin);
loaded = TRUE;
}
if (g_str_has_suffix(filename, ".py")) {
ProfPlugin* plugin = python_plugin_create(filename);
if (plugin) {
g_hash_table_insert(plugins, strdup(filename), plugin);
loaded = TRUE;
}
}
#endif
#ifdef HAVE_C
if (g_str_has_suffix(filename, ".so")) {
ProfPlugin* plugin = c_plugin_create(filename);
if (plugin) {
g_hash_table_insert(plugins, strdup(filename), plugin);
loaded = TRUE;
}
if (g_str_has_suffix(filename, ".so")) {
ProfPlugin* plugin = c_plugin_create(filename);
if (plugin) {
g_hash_table_insert(plugins, strdup(filename), plugin);
loaded = TRUE;
}
}
#endif
if (loaded) {
log_info("Loaded plugin: %s", filename);
} else {
log_info("Failed to load plugin: %s", filename);
}
if (loaded) {
log_info("Loaded plugin: %s", filename);
} else {
log_info("Failed to load plugin: %s", filename);
}
// initialise plugins
GList* values = g_hash_table_get_values(plugins);
GList* curr = values;
while (curr) {
ProfPlugin* plugin = curr->data;
plugin->init_func(plugin, PACKAGE_VERSION, PACKAGE_STATUS, NULL, NULL);
curr = g_list_next(curr);
}
g_list_free(values);
}
prefs_free_plugins(plugins_pref);
return;
// initialise plugins
GList* values = g_hash_table_get_values(plugins);
GList* curr = values;
while (curr) {
ProfPlugin* plugin = curr->data;
plugin->init_func(plugin, PACKAGE_VERSION, PACKAGE_STATUS, NULL, NULL);
curr = g_list_next(curr);
}
g_list_free(values);
}
void