diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-04-30 13:21:21 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-04-30 13:21:21 +0200 |
commit | 886b81498f2b0e738c16ec55d4675f3c8555117d (patch) | |
tree | 5faa27240b105ce0c0f67c4a40fc1ee17fc40cfe /src/plugins/scripts/ruby | |
parent | 760e216c5b3cc7945bfb17f94e39900d20c185e7 (diff) | |
download | weechat-886b81498f2b0e738c16ec55d4675f3c8555117d.zip |
Fixed crash with scripts when WeeChat calls functions of many scripts at same time with callbacks (bug #23109)
Diffstat (limited to 'src/plugins/scripts/ruby')
-rw-r--r-- | src/plugins/scripts/ruby/weechat-ruby-api.c | 4 | ||||
-rw-r--r-- | src/plugins/scripts/ruby/weechat-ruby.c | 37 |
2 files changed, 35 insertions, 6 deletions
diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c index 6b72b6ec4..70bba8fde 100644 --- a/src/plugins/scripts/ruby/weechat-ruby-api.c +++ b/src/plugins/scripts/ruby/weechat-ruby-api.c @@ -2708,7 +2708,7 @@ weechat_ruby_api_hook_signal_cb (void *data, char *signal, char *type_data, { struct t_script_callback *script_callback; char *ruby_argv[3]; - static char value_str[64]; + static char value_str[64], empty_value[1] = { '\0' }; int *rc, ret, free_needed; script_callback = (struct t_script_callback *)data; @@ -2717,7 +2717,7 @@ weechat_ruby_api_hook_signal_cb (void *data, char *signal, char *type_data, free_needed = 0; if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) { - ruby_argv[1] = (char *)signal_data; + ruby_argv[1] = (signal_data) ? (char *)signal_data : empty_value; } else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) { diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c index d34e8dd16..7e920c612 100644 --- a/src/plugins/scripts/ruby/weechat-ruby.c +++ b/src/plugins/scripts/ruby/weechat-ruby.c @@ -112,7 +112,9 @@ weechat_ruby_exec (struct t_plugin_script *script, VALUE rc, err; int ruby_error, *ret_i; void *ret_value; - + struct t_plugin_script *old_ruby_current_script; + + old_ruby_current_script = ruby_current_script; ruby_current_script = script; if (argv && argv[0]) @@ -209,6 +211,7 @@ weechat_ruby_exec (struct t_plugin_script *script, weechat_gettext ("%s%s: function \"%s\" must return a " "valid value"), weechat_prefix ("error"), "ruby", function); + ruby_current_script = old_ruby_current_script; return WEECHAT_RC_OK; } @@ -218,9 +221,12 @@ weechat_ruby_exec (struct t_plugin_script *script, weechat_gettext ("%s%s: not enough memory in function " "\"%s\""), weechat_prefix ("error"), "ruby", function); + ruby_current_script = old_ruby_current_script; return NULL; } + ruby_current_script = old_ruby_current_script; + return ret_value; } @@ -433,7 +439,8 @@ weechat_ruby_unload (struct t_plugin_script *script) { int *r; char *ruby_argv[1] = { NULL }; - + void *interpreter; + weechat_printf (NULL, weechat_gettext ("%s: unloading script \"%s\""), "ruby", script->name); @@ -448,10 +455,12 @@ weechat_ruby_unload (struct t_plugin_script *script) free (r); } - if (script->interpreter) - rb_gc_unregister_address (script->interpreter); + interpreter = script->interpreter; script_remove (weechat_ruby_plugin, &ruby_scripts, script); + + if (interpreter) + rb_gc_unregister_address (interpreter); } /* @@ -614,6 +623,25 @@ weechat_ruby_debug_dump_cb (void *data, char *signal, char *type_data, } /* + * weechat_ruby_buffer_closed_cb: callback called when a buffer is closed + */ + +int +weechat_ruby_buffer_closed_cb (void *data, char *signal, char *type_data, + void *signal_data) +{ + /* make C compiler happy */ + (void) data; + (void) signal; + (void) type_data; + + if (signal_data) + script_remove_buffer_callbacks (ruby_scripts, signal_data); + + return WEECHAT_RC_OK; +} + +/* * weechat_plugin_init: initialize Ruby plugin */ @@ -704,6 +732,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin) &weechat_ruby_command_cb, &weechat_ruby_completion_cb, &weechat_ruby_debug_dump_cb, + &weechat_ruby_buffer_closed_cb, &weechat_ruby_load_cb); /* init ok */ |