mirror of
https://github.com/irssi/irssi.git
synced 2024-11-03 04:27:19 -05:00
Settings registered with Irssi::settings_add_xx() are now correctly removed
after script is unloaded. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1883 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
388d2e1f44
commit
ebd0334cb6
@ -8,10 +8,12 @@ void
|
||||
init()
|
||||
CODE:
|
||||
perl_api_version_check("Irssi");
|
||||
perl_settings_init();
|
||||
|
||||
void
|
||||
deinit()
|
||||
CODE:
|
||||
perl_settings_deinit();
|
||||
|
||||
BOOT:
|
||||
irssi_boot(Channel);
|
||||
|
@ -1,4 +1,69 @@
|
||||
#include "module.h"
|
||||
#include "misc.h"
|
||||
|
||||
static GHashTable *perl_settings;
|
||||
|
||||
static void perl_settings_add(const char *key)
|
||||
{
|
||||
PERL_SCRIPT_REC *script;
|
||||
GSList *list;
|
||||
|
||||
script = perl_script_find_package(perl_get_package());
|
||||
g_return_if_fail(script != NULL);
|
||||
|
||||
list = g_hash_table_lookup(perl_settings, script);
|
||||
list = g_slist_append(list, g_strdup(key));
|
||||
g_hash_table_insert(perl_settings, script, list);
|
||||
}
|
||||
|
||||
static void perl_settings_remove(const char *key)
|
||||
{
|
||||
PERL_SCRIPT_REC *script;
|
||||
GSList *list, *pos;
|
||||
|
||||
script = perl_script_find_package(perl_get_package());
|
||||
g_return_if_fail(script != NULL);
|
||||
|
||||
list = g_hash_table_lookup(perl_settings, script);
|
||||
pos = gslist_find_icase_string(list, key);
|
||||
if (pos != NULL) {
|
||||
list = g_slist_remove(list, pos->data);
|
||||
g_hash_table_insert(perl_settings, script, list);
|
||||
}
|
||||
}
|
||||
|
||||
static void perl_settings_free(PERL_SCRIPT_REC *script, GSList *list)
|
||||
{
|
||||
g_slist_foreach(list, (GFunc) g_free, NULL);
|
||||
g_slist_free(list);
|
||||
}
|
||||
|
||||
static void sig_script_destroyed(PERL_SCRIPT_REC *script)
|
||||
{
|
||||
GSList *list;
|
||||
|
||||
list = g_hash_table_lookup(perl_settings, script);
|
||||
if (list != NULL) {
|
||||
g_slist_foreach(list, (GFunc) settings_remove, NULL);
|
||||
perl_settings_free(script, list);
|
||||
g_hash_table_remove(perl_settings, script);
|
||||
}
|
||||
}
|
||||
|
||||
void perl_settings_init(void)
|
||||
{
|
||||
perl_settings = g_hash_table_new((GHashFunc) g_direct_hash,
|
||||
(GCompareFunc) g_direct_equal);
|
||||
signal_add("script destroyed", (SIGNAL_FUNC) sig_script_destroyed);
|
||||
}
|
||||
|
||||
void perl_settings_deinit(void)
|
||||
{
|
||||
signal_remove("script destroyed", (SIGNAL_FUNC) sig_script_destroyed);
|
||||
|
||||
g_hash_table_foreach(perl_settings, (GHFunc) perl_settings_free, NULL);
|
||||
g_hash_table_destroy(perl_settings);
|
||||
}
|
||||
|
||||
MODULE = Irssi::Settings PACKAGE = Irssi
|
||||
PROTOTYPES: ENABLE
|
||||
@ -24,19 +89,31 @@ settings_add_str(section, key, def)
|
||||
char *section
|
||||
char *key
|
||||
char *def
|
||||
CODE:
|
||||
perl_settings_add(key);
|
||||
settings_add_str(section, key, def);
|
||||
|
||||
void
|
||||
settings_add_int(section, key, def)
|
||||
char *section
|
||||
char *key
|
||||
int def
|
||||
CODE:
|
||||
perl_settings_add(key);
|
||||
settings_add_int(section, key, def);
|
||||
|
||||
void
|
||||
settings_add_bool(section, key, def)
|
||||
char *section
|
||||
char *key
|
||||
int def
|
||||
CODE:
|
||||
perl_settings_add(key);
|
||||
settings_add_bool(section, key, def);
|
||||
|
||||
void
|
||||
settings_remove(key)
|
||||
char *key
|
||||
CODE:
|
||||
perl_settings_remove(key);
|
||||
settings_remove(key);
|
||||
|
Loading…
Reference in New Issue
Block a user