refactor: partly move plugins to glib

That's not very nice yet but we have to start somewhere.
This commit is contained in:
Michael Vetter
2026-02-27 00:20:27 +01:00
parent 20154048e7
commit de5949e8eb
10 changed files with 99 additions and 99 deletions

View File

@@ -112,7 +112,7 @@ api_register_command(const char* const plugin_name, const char* command_name, in
void* callback, void (*callback_exec)(PluginCommand* command, gchar** args), void (*callback_destroy)(void* callback))
{
PluginCommand* command = g_new0(PluginCommand, 1);
command->command_name = strdup(command_name);
command->command_name = g_strdup(command_name);
command->min_args = min_args;
command->max_args = max_args;
command->callback = callback;
@@ -123,17 +123,17 @@ api_register_command(const char* const plugin_name, const char* command_name, in
int i;
for (i = 0; synopsis[i] != NULL; i++) {
help->synopsis[i] = strdup(synopsis[i]);
help->synopsis[i] = g_strdup(synopsis[i]);
}
help->desc = strdup(description);
help->desc = g_strdup(description);
for (i = 0; arguments[i][0] != NULL; i++) {
help->args[i][0] = strdup(arguments[i][0]);
help->args[i][1] = strdup(arguments[i][1]);
help->args[i][0] = g_strdup(arguments[i][0]);
help->args[i][1] = g_strdup(arguments[i][1]);
}
for (i = 0; examples[i] != NULL; i++) {
help->examples[i] = strdup(examples[i]);
help->examples[i] = g_strdup(examples[i]);
}
command->help = help;
@@ -145,7 +145,7 @@ void
api_register_timed(const char* const plugin_name, void* callback, int interval_seconds,
void (*callback_exec)(PluginTimedFunction* timed_function), void (*callback_destroy)(void* callback))
{
PluginTimedFunction* timed_function = malloc(sizeof(PluginTimedFunction));
PluginTimedFunction* timed_function = g_new0(PluginTimedFunction, 1);
timed_function->callback = callback;
timed_function->callback_exec = callback_exec;
timed_function->callback_destroy = callback_destroy;
@@ -226,7 +226,7 @@ api_get_current_nick(void)
ProfMucWin* mucwin = (ProfMucWin*)current;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
const char* const nick = muc_nick(mucwin->roomjid);
return nick ? strdup(nick) : NULL;
return nick ? g_strdup(nick) : NULL;
} else {
return NULL;
}
@@ -235,7 +235,7 @@ api_get_current_nick(void)
char*
api_get_name_from_roster(const char* barejid)
{
return strdup(roster_get_display_name(barejid));
return g_strdup(roster_get_display_name(barejid));
}
char*
@@ -257,7 +257,7 @@ api_get_current_occupants(void)
int i = 0;
while (curr) {
Occupant* occupant = curr->data;
result[i++] = strdup(occupant->nick);
result[i++] = g_strdup(occupant->nick);
curr = g_list_next(curr);
}
result[i] = NULL;
@@ -283,7 +283,7 @@ api_get_room_nick(const char* barejid)
{
const char* const nick = muc_nick(barejid);
return nick ? strdup(nick) : NULL;
return nick ? g_strdup(nick) : NULL;
}
void
@@ -331,7 +331,7 @@ api_win_create(
return;
}
PluginWindowCallback* window = malloc(sizeof(PluginWindowCallback));
PluginWindowCallback* window = g_new0(PluginWindowCallback, 1);
window->callback = callback;
window->callback_exec = callback_exec;
window->callback_destroy = callback_destroy;
@@ -485,7 +485,7 @@ api_incoming_message(const char* const barejid, const char* const resource, cons
{
ProfMessage* message = message_init();
message->from_jid = jid_create_from_bare_and_resource(barejid, resource);
message->plain = strdup(plain);
message->plain = g_strdup(plain);
sv_ev_incoming_message(message);

View File

@@ -75,14 +75,14 @@ autocompleters_add(const char* const plugin_name, const char* key, char** items)
} else {
Autocomplete new_ac = autocomplete_new();
autocomplete_add_all(new_ac, items);
g_hash_table_insert(key_to_ac, strdup(key), new_ac);
g_hash_table_insert(key_to_ac, g_strdup(key), new_ac);
}
} else {
key_to_ac = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)autocomplete_free);
Autocomplete new_ac = autocomplete_new();
autocomplete_add_all(new_ac, items);
g_hash_table_insert(key_to_ac, strdup(key), new_ac);
g_hash_table_insert(plugin_to_acs, strdup(plugin_name), key_to_ac);
g_hash_table_insert(key_to_ac, g_strdup(key), new_ac);
g_hash_table_insert(plugin_to_acs, g_strdup(plugin_name), key_to_ac);
}
}
@@ -123,11 +123,11 @@ autocompleters_filepath_add(const char* const plugin_name, const char* prefix)
{
GHashTable* prefixes = g_hash_table_lookup(plugin_to_filepath_acs, plugin_name);
if (prefixes) {
g_hash_table_add(prefixes, strdup(prefix));
g_hash_table_add(prefixes, g_strdup(prefix));
} else {
prefixes = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
g_hash_table_add(prefixes, strdup(prefix));
g_hash_table_insert(plugin_to_filepath_acs, strdup(plugin_name), prefixes);
g_hash_table_add(prefixes, g_strdup(prefix));
g_hash_table_insert(plugin_to_filepath_acs, g_strdup(plugin_name), prefixes);
}
}

View File

@@ -94,7 +94,7 @@ c_api_register_command(const char* filename, const char* command_name, int min_a
auto_char char* plugin_name = _c_plugin_name(filename);
log_debug("Register command %s for %s", command_name, plugin_name);
CommandWrapper* wrapper = malloc(sizeof(CommandWrapper));
CommandWrapper* wrapper = g_new0(CommandWrapper, 1);
wrapper->func = callback;
api_register_command(plugin_name, command_name, min_args, max_args, synopsis,
description, arguments, examples, wrapper, c_command_callback, free);
@@ -106,7 +106,7 @@ c_api_register_timed(const char* filename, void (*callback)(void), int interval_
auto_char char* plugin_name = _c_plugin_name(filename);
log_debug("Register timed for %s", plugin_name);
TimedWrapper* wrapper = malloc(sizeof(TimedWrapper));
TimedWrapper* wrapper = g_new0(TimedWrapper, 1);
wrapper->func = callback;
api_register_timed(plugin_name, wrapper, interval_seconds, c_timed_callback, free);
}
@@ -242,7 +242,7 @@ c_api_win_create(const char* filename, char* tag, void (*callback)(char* tag, ch
{
auto_char char* plugin_name = _c_plugin_name(filename);
WindowWrapper* wrapper = malloc(sizeof(WindowWrapper));
WindowWrapper* wrapper = g_new0(WindowWrapper, 1);
wrapper->func = callback;
api_win_create(plugin_name, tag, wrapper, c_window_callback, free);
}

View File

@@ -78,8 +78,8 @@ c_plugin_create(const char* const filename)
return NULL;
}
plugin = malloc(sizeof(ProfPlugin));
plugin->name = strdup(filename);
plugin = g_new0(ProfPlugin, 1);
plugin->name = g_strdup(filename);
plugin->lang = LANG_C;
plugin->module = handle;
plugin->init_func = c_init_hook;

View File

@@ -139,9 +139,9 @@ _free_timed_function_list(GList* timed_functions)
void
callbacks_init(void)
{
p_commands = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_command_hash);
p_timed_functions = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_timed_function_list);
p_window_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_window_callbacks);
p_commands = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_free_command_hash);
p_timed_functions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_free_timed_function_list);
p_window_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_free_window_callbacks);
}
void
@@ -193,11 +193,11 @@ callbacks_add_command(const char* const plugin_name, PluginCommand* command)
{
GHashTable* command_hash = g_hash_table_lookup(p_commands, plugin_name);
if (command_hash) {
g_hash_table_insert(command_hash, strdup(command->command_name), command);
g_hash_table_insert(command_hash, g_strdup(command->command_name), command);
} else {
command_hash = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_command);
g_hash_table_insert(command_hash, strdup(command->command_name), command);
g_hash_table_insert(p_commands, strdup(plugin_name), command_hash);
command_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_free_command);
g_hash_table_insert(command_hash, g_strdup(command->command_name), command);
g_hash_table_insert(p_commands, g_strdup(plugin_name), command_hash);
}
cmd_ac_add(command->command_name);
cmd_ac_add_help(&command->command_name[1]);
@@ -212,7 +212,7 @@ callbacks_add_timed(const char* const plugin_name, PluginTimedFunction* timed_fu
timed_function_list = g_list_append(timed_function_list, timed_function);
} else {
timed_function_list = g_list_append(timed_function_list, timed_function);
g_hash_table_insert(p_timed_functions, strdup(plugin_name), timed_function_list);
g_hash_table_insert(p_timed_functions, g_strdup(plugin_name), timed_function_list);
}
}
@@ -244,11 +244,11 @@ callbacks_add_window_handler(const char* const plugin_name, const char* tag, Plu
{
GHashTable* window_callbacks = g_hash_table_lookup(p_window_callbacks, plugin_name);
if (window_callbacks) {
g_hash_table_insert(window_callbacks, strdup(tag), window_callback);
g_hash_table_insert(window_callbacks, g_strdup(tag), window_callback);
} else {
window_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_window_callback);
g_hash_table_insert(window_callbacks, strdup(tag), window_callback);
g_hash_table_insert(p_window_callbacks, strdup(plugin_name), window_callbacks);
window_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_free_window_callback);
g_hash_table_insert(window_callbacks, g_strdup(tag), window_callback);
g_hash_table_insert(p_window_callbacks, g_strdup(plugin_name), window_callbacks);
}
}

View File

@@ -60,21 +60,21 @@ disco_add_feature(const char* plugin_name, char* feature)
}
if (!features) {
features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
features = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
}
if (!plugin_to_features) {
plugin_to_features = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_features);
plugin_to_features = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_free_features);
}
GHashTable* plugin_features = g_hash_table_lookup(plugin_to_features, plugin_name);
gboolean added = FALSE;
if (plugin_features == NULL) {
plugin_features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
g_hash_table_add(plugin_features, strdup(feature));
g_hash_table_insert(plugin_to_features, strdup(plugin_name), plugin_features);
plugin_features = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
g_hash_table_add(plugin_features, g_strdup(feature));
g_hash_table_insert(plugin_to_features, g_strdup(plugin_name), plugin_features);
added = TRUE;
} else if (!g_hash_table_contains(plugin_features, feature)) {
g_hash_table_add(plugin_features, strdup(feature));
g_hash_table_add(plugin_features, g_strdup(feature));
added = TRUE;
}
@@ -83,12 +83,12 @@ disco_add_feature(const char* plugin_name, char* feature)
}
if (!g_hash_table_contains(features, feature)) {
g_hash_table_insert(features, strdup(feature), GINT_TO_POINTER(1));
g_hash_table_insert(features, g_strdup(feature), GINT_TO_POINTER(1));
} else {
void* refcountp = g_hash_table_lookup(features, feature);
int refcount = GPOINTER_TO_INT(refcountp);
refcount++;
g_hash_table_replace(features, strdup(feature), GINT_TO_POINTER(refcount));
g_hash_table_replace(features, g_strdup(feature), GINT_TO_POINTER(refcount));
}
}
@@ -118,7 +118,7 @@ disco_remove_features(const char* plugin_name)
g_hash_table_remove(features, feature);
} else {
refcount--;
g_hash_table_replace(features, strdup(feature), GINT_TO_POINTER(refcount));
g_hash_table_replace(features, g_strdup(feature), GINT_TO_POINTER(refcount));
}
}

View File

@@ -108,7 +108,7 @@ void
plugins_init(void)
{
prof_add_shutdown_routine(_plugins_shutdown);
plugins = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
plugins = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
callbacks_init();
autocompleters_init();
plugin_themes_init();
@@ -133,7 +133,7 @@ plugins_init(void)
if (g_str_has_suffix(filename, ".py")) {
ProfPlugin* plugin = python_plugin_create(filename);
if (plugin) {
g_hash_table_insert(plugins, strdup(filename), plugin);
g_hash_table_insert(plugins, g_strdup(filename), plugin);
loaded = TRUE;
}
}
@@ -142,7 +142,7 @@ plugins_init(void)
if (g_str_has_suffix(filename, ".so")) {
ProfPlugin* plugin = c_plugin_create(filename);
if (plugin) {
g_hash_table_insert(plugins, strdup(filename), plugin);
g_hash_table_insert(plugins, g_strdup(filename), plugin);
loaded = TRUE;
}
}
@@ -171,14 +171,14 @@ plugins_free_install_result(PluginsInstallResult* result)
if (!result) {
return;
}
g_slist_free_full(result->installed, free);
g_slist_free_full(result->failed, free);
g_slist_free_full(result->installed, g_free);
g_slist_free_full(result->failed, g_free);
}
PluginsInstallResult*
plugins_install_all(const char* const path)
{
PluginsInstallResult* result = malloc(sizeof(PluginsInstallResult));
PluginsInstallResult* result = g_new0(PluginsInstallResult, 1);
result->installed = NULL;
result->failed = NULL;
GSList* contents = NULL;
@@ -191,9 +191,9 @@ plugins_install_all(const char* const path)
if (g_str_has_suffix(curr->data, ".py") || g_str_has_suffix(curr->data, ".so")) {
gchar* plugin_name = g_path_get_basename(curr->data);
if (plugins_install(plugin_name, curr->data, error_message)) {
result->installed = g_slist_append(result->installed, strdup(curr->data));
result->installed = g_slist_append(result->installed, g_strdup(curr->data));
} else {
result->failed = g_slist_append(result->failed, strdup(curr->data));
result->failed = g_slist_append(result->failed, g_strdup(curr->data));
}
}
curr = g_slist_next(curr);
@@ -253,7 +253,7 @@ plugins_load_all(void)
while (curr) {
error_message = g_string_new(NULL);
if (plugins_load(curr->data, error_message)) {
loaded = g_slist_append(loaded, strdup(curr->data));
loaded = g_slist_append(loaded, g_strdup(curr->data));
}
curr = g_slist_next(curr);
g_string_free(error_message, TRUE);
@@ -288,7 +288,7 @@ plugins_load(const char* const name, GString* error_message)
#endif
}
if (plugin) {
g_hash_table_insert(plugins, strdup(name), plugin);
g_hash_table_insert(plugins, g_strdup(name), plugin);
if (connection_get_status() == JABBER_CONNECTED) {
plugin->init_func(plugin, PACKAGE_VERSION, PACKAGE_STATUS, session_get_account_name(), connection_get_fulljid());
} else {
@@ -311,7 +311,7 @@ plugins_unload_all(void)
GList* plugin_names_dup = NULL;
GList* curr = plugin_names;
while (curr) {
plugin_names_dup = g_list_append(plugin_names_dup, strdup(curr->data));
plugin_names_dup = g_list_append(plugin_names_dup, g_strdup(curr->data));
curr = g_list_next(curr);
}
g_list_free(plugin_names);
@@ -324,7 +324,7 @@ plugins_unload_all(void)
curr = g_list_next(curr);
}
g_list_free_full(plugin_names_dup, free);
g_list_free_full(plugin_names_dup, g_free);
return result;
}
@@ -366,7 +366,7 @@ plugins_reload_all(void)
GList* plugin_names_dup = NULL;
GList* curr = plugin_names;
while (curr) {
plugin_names_dup = g_list_append(plugin_names_dup, strdup(curr->data));
plugin_names_dup = g_list_append(plugin_names_dup, g_strdup(curr->data));
curr = g_list_next(curr);
}
g_list_free(plugin_names);
@@ -380,7 +380,7 @@ plugins_reload_all(void)
curr = g_list_next(curr);
}
g_list_free_full(plugin_names_dup, free);
g_list_free_full(plugin_names_dup, g_free);
}
gboolean
@@ -409,7 +409,7 @@ _plugins_unloaded_list_dir(const gchar* const dir, GSList** result)
while (plugin) {
ProfPlugin* found = g_hash_table_lookup(plugins, plugin);
if ((g_str_has_suffix(plugin, ".so") || g_str_has_suffix(plugin, ".py")) && !found) {
*result = g_slist_append(*result, strdup(plugin));
*result = g_slist_append(*result, g_strdup(plugin));
}
plugin = g_dir_read_name(plugins_dir);
}
@@ -520,15 +520,15 @@ plugins_pre_chat_message_display(const char* const barejid, const char* const re
return NULL;
}
char* new_message = NULL;
char* curr_message = strdup(message);
gchar* new_message = NULL;
gchar* curr_message = g_strdup(message);
GList* curr = values;
while (curr) {
ProfPlugin* plugin = curr->data;
new_message = plugin->pre_chat_message_display(plugin, barejid, resource, curr_message);
if (new_message) {
free(curr_message);
g_free(curr_message);
curr_message = new_message;
}
curr = g_list_next(curr);
@@ -559,15 +559,15 @@ plugins_pre_chat_message_send(const char* const barejid, const char* message)
return NULL;
}
char* new_message = NULL;
char* curr_message = strdup(message);
gchar* new_message = NULL;
gchar* curr_message = g_strdup(message);
GList* curr = values;
while (curr) {
ProfPlugin* plugin = curr->data;
if (plugin->contains_hook(plugin, "prof_pre_chat_message_send")) {
new_message = plugin->pre_chat_message_send(plugin, barejid, curr_message);
free(curr_message);
g_free(curr_message);
if (new_message) {
curr_message = new_message;
} else {
@@ -604,15 +604,15 @@ plugins_pre_room_message_display(const char* const barejid, const char* const ni
return NULL;
}
char* new_message = NULL;
char* curr_message = strdup(message);
gchar* new_message = NULL;
gchar* curr_message = g_strdup(message);
GList* curr = values;
while (curr) {
ProfPlugin* plugin = curr->data;
new_message = plugin->pre_room_message_display(plugin, barejid, nick, curr_message);
if (new_message) {
free(curr_message);
g_free(curr_message);
curr_message = new_message;
}
curr = g_list_next(curr);
@@ -643,15 +643,15 @@ plugins_pre_room_message_send(const char* const barejid, const char* message)
return NULL;
}
char* new_message = NULL;
char* curr_message = strdup(message);
gchar* new_message = NULL;
gchar* curr_message = g_strdup(message);
GList* curr = values;
while (curr) {
ProfPlugin* plugin = curr->data;
if (plugin->contains_hook(plugin, "prof_pre_room_message_send")) {
new_message = plugin->pre_room_message_send(plugin, barejid, curr_message);
free(curr_message);
g_free(curr_message);
if (new_message) {
curr_message = new_message;
} else {
@@ -700,7 +700,7 @@ plugins_on_room_history_message(const char* const barejid, const char* const nic
}
g_list_free(values);
free(timestamp_str);
g_free(timestamp_str);
}
char*
@@ -712,15 +712,15 @@ plugins_pre_priv_message_display(const char* const fulljid, const char* message)
}
auto_jid Jid* jidp = jid_create(fulljid);
char* new_message = NULL;
char* curr_message = strdup(message);
gchar* new_message = NULL;
gchar* curr_message = g_strdup(message);
GList* curr = values;
while (curr) {
ProfPlugin* plugin = curr->data;
new_message = plugin->pre_priv_message_display(plugin, jidp->barejid, jidp->resourcepart, curr_message);
if (new_message) {
free(curr_message);
g_free(curr_message);
curr_message = new_message;
}
curr = g_list_next(curr);
@@ -753,15 +753,15 @@ plugins_pre_priv_message_send(const char* const fulljid, const char* const messa
}
auto_jid Jid* jidp = jid_create(fulljid);
char* new_message = NULL;
char* curr_message = strdup(message);
gchar* new_message = NULL;
gchar* curr_message = g_strdup(message);
GList* curr = values;
while (curr) {
ProfPlugin* plugin = curr->data;
if (plugin->contains_hook(plugin, "prof_pre_priv_message_send")) {
new_message = plugin->pre_priv_message_send(plugin, jidp->barejid, jidp->resourcepart, curr_message);
free(curr_message);
g_free(curr_message);
if (new_message) {
curr_message = new_message;
} else {
@@ -801,15 +801,15 @@ plugins_on_message_stanza_send(const char* const text)
return NULL;
}
char* new_stanza = NULL;
char* curr_stanza = strdup(text);
gchar* new_stanza = NULL;
gchar* curr_stanza = g_strdup(text);
GList* curr = values;
while (curr) {
ProfPlugin* plugin = curr->data;
new_stanza = plugin->on_message_stanza_send(plugin, curr_stanza);
if (new_stanza) {
free(curr_stanza);
g_free(curr_stanza);
curr_stanza = new_stanza;
}
curr = g_list_next(curr);
@@ -847,15 +847,15 @@ plugins_on_presence_stanza_send(const char* const text)
return NULL;
}
char* new_stanza = NULL;
char* curr_stanza = strdup(text);
gchar* new_stanza = NULL;
gchar* curr_stanza = g_strdup(text);
GList* curr = values;
while (curr) {
ProfPlugin* plugin = curr->data;
new_stanza = plugin->on_presence_stanza_send(plugin, curr_stanza);
if (new_stanza) {
free(curr_stanza);
g_free(curr_stanza);
curr_stanza = new_stanza;
}
curr = g_list_next(curr);
@@ -894,14 +894,14 @@ plugins_on_iq_stanza_send(const char* const text)
}
char* new_stanza = NULL;
char* curr_stanza = strdup(text);
char* curr_stanza = g_strdup(text);
GList* curr = values;
while (curr) {
ProfPlugin* plugin = curr->data;
new_stanza = plugin->on_iq_stanza_send(plugin, curr_stanza);
if (new_stanza) {
free(curr_stanza);
g_free(curr_stanza);
curr_stanza = new_stanza;
}
curr = g_list_next(curr);

View File

@@ -451,10 +451,10 @@ python_api_get_name_from_roster(PyObject* self, PyObject* args)
Py_RETURN_NONE;
}
char* barejid_str = python_str_or_unicode_to_string(barejid);
gchar* barejid_str = python_str_or_unicode_to_string(barejid);
allow_python_threads();
char* name = strdup(roster_get_display_name(barejid_str));
gchar* name = g_strdup(roster_get_display_name(barejid_str));
free(barejid_str);
disable_python_threads();
if (name) {
@@ -1630,16 +1630,16 @@ _python_plugin_name(void)
#if PY_VERSION_HEX >= 0x030B0000
PyFrameObject* frame = PyThreadState_GetFrame(ts);
PyCodeObject* code = PyFrame_GetCode(frame);
char* filename = python_str_or_unicode_to_string(code->co_filename);
gchar* filename = python_str_or_unicode_to_string(code->co_filename);
Py_DECREF(code);
Py_DECREF(frame);
#else
PyFrameObject* frame = ts->frame;
char* filename = python_str_or_unicode_to_string(frame->f_code->co_filename);
gchar* filename = python_str_or_unicode_to_string(frame->f_code->co_filename);
#endif
gchar** split = g_strsplit(filename, "/", 0);
free(filename);
char* plugin_name = strdup(split[g_strv_length(split) - 1]);
gchar* plugin_name = g_strdup(split[g_strv_length(split) - 1]);
g_strfreev(split);
return plugin_name;
@@ -1659,20 +1659,20 @@ python_str_or_unicode_to_string(void* obj)
#ifdef PY_IS_PYTHON3
if (PyUnicode_Check(pyobj)) {
PyObject* utf8_str = PyUnicode_AsUTF8String(pyobj);
char* result = strdup(PyBytes_AS_STRING(utf8_str));
gchar* result = g_strdup(PyBytes_AS_STRING(utf8_str));
Py_XDECREF(utf8_str);
return result;
} else {
return strdup(PyBytes_AS_STRING(pyobj));
return g_strdup(PyBytes_AS_STRING(pyobj));
}
#else
if (PyUnicode_Check(pyobj)) {
PyObject* utf8_str = PyUnicode_AsUTF8String(pyobj);
char* result = strdup(PyString_AsString(utf8_str));
gchar* result = g_strdup(PyString_AsString(utf8_str));
Py_XDECREF(utf8_str);
return result;
} else {
return strdup(PyString_AsString(pyobj));
return g_strdup(PyString_AsString(pyobj));
}
#endif
}

View File

@@ -130,8 +130,8 @@ python_plugin_create(const char* const filename)
python_check_error();
if (p_module) {
ProfPlugin* plugin = malloc(sizeof(ProfPlugin));
plugin->name = strdup(filename);
ProfPlugin* plugin = g_new0(ProfPlugin, 1);
plugin->name = g_strdup(filename);
plugin->lang = LANG_PYTHON;
plugin->module = p_module;
plugin->init_func = python_init_hook;

View File

@@ -88,7 +88,7 @@ plugin_settings_string_get(const char* const group, const char* const key, const
if (group && key && g_key_file_has_key(settings, group, key, NULL)) {
return g_key_file_get_string(settings, group, key, NULL);
} else if (def) {
return strdup(def);
return g_strdup(def);
} else {
return NULL;
}