diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/plugin.c | 10 | ||||
-rw-r--r-- | src/plugins/scripts/lua/weechat-lua-api.c | 4 | ||||
-rw-r--r-- | src/plugins/scripts/lua/weechat-lua.c | 32 | ||||
-rw-r--r-- | src/plugins/scripts/perl/weechat-perl-api.c | 4 | ||||
-rw-r--r-- | src/plugins/scripts/perl/weechat-perl.c | 51 | ||||
-rw-r--r-- | src/plugins/scripts/python/weechat-python-api.c | 4 | ||||
-rw-r--r-- | src/plugins/scripts/python/weechat-python.c | 46 | ||||
-rw-r--r-- | src/plugins/scripts/ruby/weechat-ruby-api.c | 4 | ||||
-rw-r--r-- | src/plugins/scripts/ruby/weechat-ruby.c | 37 | ||||
-rw-r--r-- | src/plugins/scripts/script.c | 57 | ||||
-rw-r--r-- | src/plugins/scripts/script.h | 6 |
11 files changed, 225 insertions, 30 deletions
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index b033c552a..913d06532 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -562,18 +562,22 @@ void plugin_remove (struct t_weechat_plugin *plugin) { struct t_weechat_plugin *new_weechat_plugins; - struct t_gui_buffer *ptr_buffer; + struct t_gui_buffer *ptr_buffer, *next_buffer; /* close buffers created by this plugin */ - for (ptr_buffer = gui_buffers; ptr_buffer; - ptr_buffer = ptr_buffer->next_buffer) + ptr_buffer = gui_buffers; + while (ptr_buffer) { + next_buffer = ptr_buffer->next_buffer; + if (ptr_buffer->plugin == plugin) { ptr_buffer->close_callback = NULL; ptr_buffer->close_callback_data = NULL; gui_buffer_close (ptr_buffer, 1); } + + ptr_buffer = next_buffer; } /* remove plugin from list */ diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c index 667f55eae..fe874cb46 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ b/src/plugins/scripts/lua/weechat-lua-api.c @@ -2657,7 +2657,7 @@ weechat_lua_api_hook_signal_cb (void *data, char *signal, char *type_data, { struct t_script_callback *script_callback; char *lua_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; @@ -2666,7 +2666,7 @@ weechat_lua_api_hook_signal_cb (void *data, char *signal, char *type_data, free_needed = 0; if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) { - lua_argv[1] = (char *)signal_data; + lua_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/lua/weechat-lua.c b/src/plugins/scripts/lua/weechat-lua.c index f5a799840..2aa388710 100644 --- a/src/plugins/scripts/lua/weechat-lua.c +++ b/src/plugins/scripts/lua/weechat-lua.c @@ -57,10 +57,13 @@ weechat_lua_exec (struct t_plugin_script *script, { void *ret_value; int argc, *ret_i; + struct t_plugin_script *old_lua_current_script; lua_current_interpreter = script->interpreter; lua_getglobal (lua_current_interpreter, function); + + old_lua_current_script = lua_current_script; lua_current_script = script; if (argv && argv[0]) @@ -98,6 +101,7 @@ weechat_lua_exec (struct t_plugin_script *script, weechat_gettext ("%s%s: error: %s"), weechat_prefix ("error"), "lua", lua_tostring (lua_current_interpreter, -1)); + lua_current_script = old_lua_current_script; return NULL; } @@ -113,9 +117,12 @@ weechat_lua_exec (struct t_plugin_script *script, else { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS(function); + lua_current_script = old_lua_current_script; return NULL; } + lua_current_script = old_lua_current_script; + return ret_value; } @@ -257,6 +264,7 @@ weechat_lua_unload (struct t_plugin_script *script) { int *r; char *lua_argv[1] = { NULL }; + void *interpreter; weechat_printf (NULL, weechat_gettext ("%s: unloading script \"%s\""), @@ -272,9 +280,11 @@ weechat_lua_unload (struct t_plugin_script *script) free (r); } - lua_close (script->interpreter); + interpreter = script->interpreter; script_remove (weechat_lua_plugin, &lua_scripts, script); + + lua_close (script->interpreter); } /* @@ -437,6 +447,25 @@ weechat_lua_debug_dump_cb (void *data, char *signal, char *type_data, } /* + * weechat_lua_buffer_closed_cb: callback called when a buffer is closed + */ + +int +weechat_lua_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 (lua_scripts, signal_data); + + return WEECHAT_RC_OK; +} + +/* * weechat_plugin_init: initialize Lua plugin */ @@ -450,6 +479,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin) &weechat_lua_command_cb, &weechat_lua_completion_cb, &weechat_lua_debug_dump_cb, + &weechat_lua_buffer_closed_cb, &weechat_lua_load_cb); /* init ok */ diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c index 51698344a..082363983 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -2192,7 +2192,7 @@ weechat_perl_api_hook_signal_cb (void *data, char *signal, char *type_data, { struct t_script_callback *script_callback; char *perl_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; @@ -2201,7 +2201,7 @@ weechat_perl_api_hook_signal_cb (void *data, char *signal, char *type_data, free_needed = 0; if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) { - perl_argv[1] = (char *)signal_data; + perl_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/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c index 6073d4821..638c8ef69 100644 --- a/src/plugins/scripts/perl/weechat-perl.c +++ b/src/plugins/scripts/perl/weechat-perl.c @@ -113,7 +113,8 @@ weechat_perl_exec (struct t_plugin_script *script, void *ret_value; int *ret_i, mem_err, length; SV *ret_s; - + struct t_plugin_script *old_perl_current_script; + /* this code is placed here to conform ISO C90 */ dSP; @@ -133,6 +134,8 @@ weechat_perl_exec (struct t_plugin_script *script, SAVETMPS; PUSHMARK(sp); + old_perl_current_script = perl_current_script; + /* are we loading the script file ? */ if (strcmp (function, "weechat_perl_load_eval_file") != 0) perl_current_script = script; @@ -203,6 +206,15 @@ weechat_perl_exec (struct t_plugin_script *script, weechat_prefix ("error"), "perl", function); return NULL; } + + if (strcmp (function, "weechat_perl_load_eval_file") != 0) + { + perl_current_script = old_perl_current_script; +#ifdef MULTIPLICITY + if (perl_current_script) + PERL_SET_CONTEXT (perl_current_script->interpreter); +#endif + } return ret_value; } @@ -381,6 +393,7 @@ weechat_perl_unload (struct t_plugin_script *script) { int *r; char *perl_argv[1] = { NULL }; + void *interpreter; weechat_printf (NULL, weechat_gettext ("%s: unloading script \"%s\""), @@ -391,7 +404,7 @@ weechat_perl_unload (struct t_plugin_script *script) #else eval_pv (script->interpreter, TRUE); #endif - + if (script->shutdown_func && script->shutdown_func[0]) { r = (int *) weechat_perl_exec (script, @@ -402,15 +415,17 @@ weechat_perl_unload (struct t_plugin_script *script) free (r); } + interpreter = script->interpreter; + + script_remove (weechat_perl_plugin, &perl_scripts, script); + #ifdef MULTIPLICITY - perl_destruct (script->interpreter); - perl_free (script->interpreter); + perl_destruct (interpreter); + perl_free (interpreter); #else - if (script->interpreter) - free (script->interpreter); + if (interpreter) + free (interpreter); #endif - - script_remove (weechat_perl_plugin, &perl_scripts, script); } /* @@ -573,6 +588,25 @@ weechat_perl_debug_dump_cb (void *data, char *signal, char *type_data, } /* + * weechat_perl_buffer_closed_cb: callback called when a buffer is closed + */ + +int +weechat_perl_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 (perl_scripts, signal_data); + + return WEECHAT_RC_OK; +} + +/* * weechat_plugin_init: initialize Perl plugin */ @@ -605,6 +639,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin) &weechat_perl_command_cb, &weechat_perl_completion_cb, &weechat_perl_debug_dump_cb, + &weechat_perl_buffer_closed_cb, &weechat_perl_load_cb); /* init ok */ diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index 87a7c53c4..9a7696c24 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -2341,7 +2341,7 @@ weechat_python_api_hook_signal_cb (void *data, char *signal, char *type_data, { struct t_script_callback *script_callback; char *python_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; @@ -2350,7 +2350,7 @@ weechat_python_api_hook_signal_cb (void *data, char *signal, char *type_data, free_needed = 0; if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) { - python_argv[1] = (char *)signal_data; + python_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/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c index f485a6f18..32b46f581 100644 --- a/src/plugins/scripts/python/weechat-python.c +++ b/src/plugins/scripts/python/weechat-python.c @@ -59,6 +59,7 @@ weechat_python_exec (struct t_plugin_script *script, PyObject *rc; void *ret_value; int *ret_i; + struct t_plugin_script *old_python_current_script; /* PyEval_AcquireLock (); */ PyThreadState_Swap (script->interpreter); @@ -75,7 +76,8 @@ weechat_python_exec (struct t_plugin_script *script, /* PyEval_ReleaseThread (python_current_script->interpreter); */ return NULL; } - + + old_python_current_script = python_current_script; python_current_script = script; if (argv && argv[0]) @@ -151,6 +153,9 @@ weechat_python_exec (struct t_plugin_script *script, "a valid value"), weechat_prefix ("error"), "python", function); /* PyEval_ReleaseThread (python_current_script->interpreter); */ + python_current_script = old_python_current_script; + if (python_current_script) + PyThreadState_Swap (python_current_script->interpreter); return NULL; } @@ -161,13 +166,21 @@ weechat_python_exec (struct t_plugin_script *script, "function \"%s\""), weechat_prefix ("error"), "python", function); /* PyEval_ReleaseThread (python_current_script->interpreter); */ + python_current_script = old_python_current_script; + if (python_current_script) + PyThreadState_Swap (python_current_script->interpreter); return NULL; } - if (PyErr_Occurred ()) PyErr_Print (); + if (PyErr_Occurred ()) + PyErr_Print (); /* PyEval_ReleaseThread (python_current_script->interpreter); */ + python_current_script = old_python_current_script; + if (python_current_script) + PyThreadState_Swap (python_current_script->interpreter); + return ret_value; } @@ -426,6 +439,7 @@ void weechat_python_unload (struct t_plugin_script *script) { int *r; + void *interpreter; weechat_printf (NULL, weechat_gettext ("%s: unloading script \"%s\""), @@ -438,11 +452,13 @@ weechat_python_unload (struct t_plugin_script *script) if (r) free (r); } - - PyThreadState_Swap (script->interpreter); - Py_EndInterpreter (script->interpreter); + + interpreter = script->interpreter; script_remove (weechat_python_plugin, &python_scripts, script); + + PyThreadState_Swap (interpreter); + Py_EndInterpreter (interpreter); } /* @@ -605,6 +621,25 @@ weechat_python_debug_dump_cb (void *data, char *signal, char *type_data, } /* + * weechat_python_buffer_closed_cb: callback called when a buffer is closed + */ + +int +weechat_python_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 (python_scripts, signal_data); + + return WEECHAT_RC_OK; +} + +/* * weechat_plugin_init: initialize Python plugin */ @@ -644,6 +679,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin) &weechat_python_command_cb, &weechat_python_completion_cb, &weechat_python_debug_dump_cb, + &weechat_python_buffer_closed_cb, &weechat_python_load_cb); /* init ok */ 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 */ diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c index 80e04609a..12dc1ec9d 100644 --- a/src/plugins/scripts/script.c +++ b/src/plugins/scripts/script.c @@ -90,6 +90,9 @@ script_init (struct t_weechat_plugin *weechat_plugin, int (*callback_signal_debug_dump)(void *data, char *signal, char *type_data, void *signal_data), + int (*callback_signal_buffer_closed)(void *data, char *signal, + char *type_data, + void *signal_data), int (*callback_load_file)(void *data, char *filename)) { char *string, *completion = "list|listfull|load|autoload|reload|unload %f"; @@ -155,6 +158,9 @@ script_init (struct t_weechat_plugin *weechat_plugin, /* add signal for "debug_dump" */ weechat_hook_signal ("debug_dump", callback_signal_debug_dump, NULL); + /* add signal for "buffer_closed" */ + weechat_hook_signal ("buffer_closed", callback_signal_buffer_closed, NULL); + /* autoload scripts */ script_auto_load (weechat_plugin, callback_load_file); } @@ -401,6 +407,34 @@ script_add (struct t_weechat_plugin *weechat_plugin, } /* + * script_remove_buffer_callbacks: remove callbacks for a buffer (called when a + * buffer is closed by user) + */ + +void +script_remove_buffer_callbacks (struct t_plugin_script *scripts, + struct t_gui_buffer *buffer) +{ + struct t_plugin_script *ptr_script; + struct t_script_callback *ptr_script_callback, *next_script_callback; + + for (ptr_script = scripts; ptr_script; + ptr_script = ptr_script->next_script) + { + ptr_script_callback = ptr_script->callbacks; + while (ptr_script_callback) + { + next_script_callback = ptr_script_callback->next_callback; + + if (ptr_script_callback->buffer == buffer) + script_callback_remove (ptr_script, ptr_script_callback); + + ptr_script_callback = next_script_callback; + } + } +} + +/* * script_remove: remove a script from list of scripts */ @@ -409,7 +443,7 @@ script_remove (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script **scripts, struct t_plugin_script *script) { - struct t_script_callback *ptr_script_callback; + struct t_script_callback *ptr_script_callback, *next_script_callback; for (ptr_script_callback = script->callbacks; ptr_script_callback; ptr_script_callback = ptr_script_callback->next_callback) @@ -419,6 +453,12 @@ script_remove (struct t_weechat_plugin *weechat_plugin, { weechat_unhook (ptr_script_callback->hook); } + } + + ptr_script_callback = script->callbacks; + while (ptr_script_callback) + { + next_script_callback = ptr_script_callback->next_callback; /* free config file */ if (ptr_script_callback->config_file @@ -433,6 +473,21 @@ script_remove (struct t_weechat_plugin *weechat_plugin, /* remove bar item */ if (ptr_script_callback->bar_item) weechat_bar_item_remove (ptr_script_callback->bar_item); + + /* remove buffer */ + if (ptr_script_callback->buffer) + { + for (next_script_callback = ptr_script_callback->next_callback; + next_script_callback; + next_script_callback = next_script_callback->next_callback) + { + if (next_script_callback->buffer != ptr_script_callback->buffer) + break; + } + weechat_buffer_close (ptr_script_callback->buffer, 1); + } + + ptr_script_callback = next_script_callback; } /* remove all callbacks created by this script */ diff --git a/src/plugins/scripts/script.h b/src/plugins/scripts/script.h index 7f4ac248f..e189929d1 100644 --- a/src/plugins/scripts/script.h +++ b/src/plugins/scripts/script.h @@ -68,6 +68,10 @@ extern void script_init (struct t_weechat_plugin *weechat_plugin, char *signal, char *type_data, void *signal_data), + int (*callback_signal_buffer_closed)(void *data, + char *signal, + char *type_data, + void *signal_data), int (*callback_load_file)(void *data, char *filename)); extern char *script_ptr2str (void *pointer); extern void *script_str2ptr (char *pointer_str); @@ -84,6 +88,8 @@ extern struct t_plugin_script *script_add (struct t_weechat_plugin *weechat_plug char *author, char *version, char *license, char *description, char *shutdown_func, char *charset); +extern void script_remove_buffer_callbacks (struct t_plugin_script *scripts, + struct t_gui_buffer *buffer); extern void script_remove (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script **scripts, struct t_plugin_script *script); |