summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--src/plugins/scripts/lua/weechat-lua.c15
-rw-r--r--src/plugins/scripts/perl/weechat-perl.c17
-rw-r--r--src/plugins/scripts/python/weechat-python.c15
-rw-r--r--src/plugins/scripts/ruby/weechat-ruby.c15
-rw-r--r--src/plugins/scripts/script.c217
-rw-r--r--src/plugins/scripts/script.h16
-rw-r--r--src/plugins/scripts/tcl/weechat-tcl.c15
8 files changed, 167 insertions, 147 deletions
diff --git a/ChangeLog b/ChangeLog
index 5e34762c4..10628a57a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,7 @@
WeeChat ChangeLog
=================
Sébastien Helleu <flashcode@flashtux.org>
-v0.3.6-dev, 2011-08-16
+v0.3.6-dev, 2011-08-17
Version 0.3.6 (under dev!)
@@ -58,6 +58,8 @@ Version 0.3.6 (under dev!)
hdata_string, hdata_pointer, hdata_time, hdata_get_string
* api: fix bug with function config_set_desc_plugin (use immediately
description for option when function is called)
+* scripts: fix crash with scripts not auto-loaded having a buffer opened after
+ /upgrade (input/close callbacks for buffer not set properly)
* irc: send WHO command to check away nicks only if channel was not parted
* irc: fix crash when malformed IRC message 352 (WHO) is received (bug #33790)
* irc: fix crash when command "/buffer close" is used in a server command to
diff --git a/src/plugins/scripts/lua/weechat-lua.c b/src/plugins/scripts/lua/weechat-lua.c
index 32db149df..b555818fe 100644
--- a/src/plugins/scripts/lua/weechat-lua.c
+++ b/src/plugins/scripts/lua/weechat-lua.c
@@ -347,6 +347,16 @@ weechat_lua_load (const char *filename)
lua_current_script->interpreter = (lua_State *) lua_current_interpreter;
+ /*
+ * set input/close callbacks for buffers created by this script
+ * (to restore callbacks after upgrade)
+ */
+ script_set_buffer_callbacks (weechat_lua_plugin,
+ lua_scripts,
+ lua_current_script,
+ &weechat_lua_api_buffer_input_data_cb,
+ &weechat_lua_api_buffer_close_cb);
+
return 1;
}
@@ -724,16 +734,13 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
script_init (weechat_lua_plugin,
argc,
argv,
- &lua_scripts,
&weechat_lua_command_cb,
&weechat_lua_completion_cb,
&weechat_lua_infolist_cb,
&weechat_lua_signal_debug_dump_cb,
&weechat_lua_signal_buffer_closed_cb,
&weechat_lua_signal_script_action_cb,
- &weechat_lua_load_cb,
- &weechat_lua_api_buffer_input_data_cb,
- &weechat_lua_api_buffer_close_cb);
+ &weechat_lua_load_cb);
lua_quiet = 0;
script_display_short_list (weechat_lua_plugin,
diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c
index 353cdfd3f..3ab70faa0 100644
--- a/src/plugins/scripts/perl/weechat-perl.c
+++ b/src/plugins/scripts/perl/weechat-perl.c
@@ -521,7 +521,17 @@ weechat_perl_load (const char *filename)
#else
perl_current_script->interpreter = strdup (pkgname);
#endif
-
+
+ /*
+ * set input/close callbacks for buffers created by this script
+ * (to restore callbacks after upgrade)
+ */
+ script_set_buffer_callbacks (weechat_perl_plugin,
+ perl_scripts,
+ perl_current_script,
+ &weechat_perl_api_buffer_input_data_cb,
+ &weechat_perl_api_buffer_close_cb);
+
return 1;
}
@@ -966,16 +976,13 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
script_init (weechat_perl_plugin,
argc,
argv,
- &perl_scripts,
&weechat_perl_command_cb,
&weechat_perl_completion_cb,
&weechat_perl_infolist_cb,
&weechat_perl_signal_debug_dump_cb,
&weechat_perl_signal_buffer_closed_cb,
&weechat_perl_signal_script_action_cb,
- &weechat_perl_load_cb,
- &weechat_perl_api_buffer_input_data_cb,
- &weechat_perl_api_buffer_close_cb);
+ &weechat_perl_load_cb);
perl_quiet = 0;
script_display_short_list (weechat_perl_plugin,
diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c
index 591bf71e9..30866b60d 100644
--- a/src/plugins/scripts/python/weechat-python.c
+++ b/src/plugins/scripts/python/weechat-python.c
@@ -609,6 +609,16 @@ weechat_python_load (const char *filename)
python_current_script->interpreter = (PyThreadState *) python_current_interpreter;
/* PyEval_ReleaseThread (python_current_script->interpreter); */
+ /*
+ * set input/close callbacks for buffers created by this script
+ * (to restore callbacks after upgrade)
+ */
+ script_set_buffer_callbacks (weechat_python_plugin,
+ python_scripts,
+ python_current_script,
+ &weechat_python_api_buffer_input_data_cb,
+ &weechat_python_api_buffer_close_cb);
+
return 1;
}
@@ -1052,16 +1062,13 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
script_init (weechat_python_plugin,
argc,
argv,
- &python_scripts,
&weechat_python_command_cb,
&weechat_python_completion_cb,
&weechat_python_infolist_cb,
&weechat_python_signal_debug_dump_cb,
&weechat_python_signal_buffer_closed_cb,
&weechat_python_signal_script_action_cb,
- &weechat_python_load_cb,
- &weechat_python_api_buffer_input_data_cb,
- &weechat_python_api_buffer_close_cb);
+ &weechat_python_load_cb);
python_quiet = 0;
script_display_short_list (weechat_python_plugin,
diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c
index 278f270fb..a9c8681e9 100644
--- a/src/plugins/scripts/ruby/weechat-ruby.c
+++ b/src/plugins/scripts/ruby/weechat-ruby.c
@@ -582,6 +582,16 @@ weechat_ruby_load (const char *filename)
ruby_current_script->interpreter = (VALUE *) curModule;
rb_gc_register_address (ruby_current_script->interpreter);
+ /*
+ * set input/close callbacks for buffers created by this script
+ * (to restore callbacks after upgrade)
+ */
+ script_set_buffer_callbacks (weechat_ruby_plugin,
+ ruby_scripts,
+ ruby_current_script,
+ &weechat_ruby_api_buffer_input_data_cb,
+ &weechat_ruby_api_buffer_close_cb);
+
return 1;
}
@@ -1059,16 +1069,13 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
script_init (weechat_ruby_plugin,
argc,
argv,
- &ruby_scripts,
&weechat_ruby_command_cb,
&weechat_ruby_completion_cb,
&weechat_ruby_infolist_cb,
&weechat_ruby_signal_debug_dump_cb,
&weechat_ruby_signal_buffer_closed_cb,
&weechat_ruby_signal_script_action_cb,
- &weechat_ruby_load_cb,
- &weechat_ruby_api_buffer_input_data_cb,
- &weechat_ruby_api_buffer_close_cb);
+ &weechat_ruby_load_cb);
ruby_quiet = 0;
script_display_short_list (weechat_ruby_plugin,
diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c
index 32076959e..4e1b746d6 100644
--- a/src/plugins/scripts/script.c
+++ b/src/plugins/scripts/script.c
@@ -80,101 +80,6 @@ script_config_cb (void *data, const char *option, const char *value)
}
/*
- * script_upgrade_set_buffer_callbacks: restore buffers callbacks (input and
- * close) for buffers created by script
- * plugin
- */
-
-void
-script_upgrade_set_buffer_callbacks (struct t_weechat_plugin *weechat_plugin,
- struct t_plugin_script **scripts,
- int (*callback_buffer_input) (void *data,
- struct t_gui_buffer *buffer,
- const char *input_data),
- int (*callback_buffer_close) (void *data,
- struct t_gui_buffer *buffer))
-{
- struct t_infolist *infolist;
- struct t_gui_buffer *ptr_buffer;
- const char *script_name, *script_input_cb, *script_input_cb_data;
- const char *script_close_cb, *script_close_cb_data;
- struct t_plugin_script *ptr_script;
- struct t_script_callback *new_script_callback_input;
- struct t_script_callback *new_script_callback_close;
-
- infolist = weechat_infolist_get ("buffer", NULL, NULL);
- if (infolist)
- {
- while (weechat_infolist_next (infolist))
- {
- if (weechat_infolist_pointer (infolist, "plugin") == weechat_plugin)
- {
- ptr_buffer = weechat_infolist_pointer (infolist, "pointer");
- script_name = weechat_buffer_get_string (ptr_buffer, "localvar_script_name");
- if (script_name && script_name[0])
- {
- ptr_script = script_search (weechat_plugin, *scripts,
- script_name);
- if (ptr_script)
- {
- script_input_cb = weechat_buffer_get_string (ptr_buffer,
- "localvar_script_input_cb");
- script_input_cb_data = weechat_buffer_get_string (ptr_buffer,
- "localvar_script_input_cb_data");
- script_close_cb = weechat_buffer_get_string (ptr_buffer,
- "localvar_script_close_cb");
- script_close_cb_data = weechat_buffer_get_string (ptr_buffer,
- "localvar_script_close_cb_data");
-
- if (script_input_cb && script_input_cb[0])
- {
- new_script_callback_input = script_callback_alloc ();
- if (new_script_callback_input)
- {
- script_callback_init (new_script_callback_input,
- ptr_script,
- script_input_cb,
- script_input_cb_data);
- new_script_callback_input->buffer = ptr_buffer;
- script_callback_add (ptr_script,
- new_script_callback_input);
- weechat_buffer_set_pointer (ptr_buffer,
- "input_callback",
- callback_buffer_input);
- weechat_buffer_set_pointer (ptr_buffer,
- "input_callback_data",
- new_script_callback_input);
- }
- }
- if (script_close_cb && script_close_cb[0])
- {
- new_script_callback_close = script_callback_alloc ();
- if (new_script_callback_close)
- {
- script_callback_init (new_script_callback_close,
- ptr_script,
- script_close_cb,
- script_close_cb_data);
- new_script_callback_close->buffer = ptr_buffer;
- script_callback_add (ptr_script,
- new_script_callback_close);
- weechat_buffer_set_pointer (ptr_buffer,
- "close_callback",
- callback_buffer_close);
- weechat_buffer_set_pointer (ptr_buffer,
- "close_callback_data",
- new_script_callback_close);
- }
- }
- }
- }
- }
- }
- weechat_infolist_free (infolist);
- }
-}
-
-/*
* script_init: initialize script plugin
*/
@@ -182,7 +87,6 @@ void
script_init (struct t_weechat_plugin *weechat_plugin,
int argc,
char *argv[],
- struct t_plugin_script **scripts,
int (*callback_command)(void *data,
struct t_gui_buffer *buffer,
int argc, char **argv,
@@ -203,16 +107,11 @@ script_init (struct t_weechat_plugin *weechat_plugin,
int (*callback_signal_script_action)(void *data, const char *signal,
const char *type_data,
void *signal_data),
- void (*callback_load_file)(void *data, const char *filename),
- int (*callback_buffer_input) (void *data,
- struct t_gui_buffer *buffer,
- const char *input_data),
- int (*callback_buffer_close) (void *data,
- struct t_gui_buffer *buffer))
+ void (*callback_load_file)(void *data, const char *filename))
{
char *string, *completion;
char signal_name[128];
- int length, i, upgrading, auto_load_scripts;
+ int length, i, auto_load_scripts;
/* read script configuration */
script_config_read (weechat_plugin);
@@ -314,15 +213,10 @@ script_init (struct t_weechat_plugin *weechat_plugin,
weechat_hook_signal (signal_name, callback_signal_script_action, NULL);
/* parse arguments */
- upgrading = 0;
auto_load_scripts = 1;
for (i = 0; i < argc; i++)
{
- if (strcmp (argv[i], "--upgrade") == 0)
- {
- upgrading = 1;
- }
- else if ((strcmp (argv[i], "-s") == 0)
+ if ((strcmp (argv[i], "-s") == 0)
|| (strcmp (argv[i], "--no-script") == 0))
{
auto_load_scripts = 0;
@@ -334,15 +228,6 @@ script_init (struct t_weechat_plugin *weechat_plugin,
{
script_auto_load (weechat_plugin, callback_load_file);
}
-
- /* set buffer callbacks after upgrade */
- if (upgrading)
- {
- script_upgrade_set_buffer_callbacks (weechat_plugin,
- scripts,
- callback_buffer_input,
- callback_buffer_close);
- }
}
/*
@@ -690,6 +575,102 @@ script_add (struct t_weechat_plugin *weechat_plugin,
}
/*
+ * script_set_buffer_callbacks: restore buffers callbacks (input and
+ * close) for buffers created by script
+ * plugin
+ */
+
+void
+script_set_buffer_callbacks (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *scripts,
+ struct t_plugin_script *script,
+ int (*callback_buffer_input) (void *data,
+ struct t_gui_buffer *buffer,
+ const char *input_data),
+ int (*callback_buffer_close) (void *data,
+ struct t_gui_buffer *buffer))
+{
+ struct t_infolist *infolist;
+ struct t_gui_buffer *ptr_buffer;
+ const char *script_name, *script_input_cb, *script_input_cb_data;
+ const char *script_close_cb, *script_close_cb_data;
+ struct t_plugin_script *ptr_script;
+ struct t_script_callback *new_script_callback_input;
+ struct t_script_callback *new_script_callback_close;
+
+ infolist = weechat_infolist_get ("buffer", NULL, NULL);
+ if (infolist)
+ {
+ while (weechat_infolist_next (infolist))
+ {
+ if (weechat_infolist_pointer (infolist, "plugin") == weechat_plugin)
+ {
+ ptr_buffer = weechat_infolist_pointer (infolist, "pointer");
+ script_name = weechat_buffer_get_string (ptr_buffer, "localvar_script_name");
+ if (script_name && script_name[0])
+ {
+ ptr_script = script_search (weechat_plugin, scripts,
+ script_name);
+ if (ptr_script && (ptr_script == script))
+ {
+ script_input_cb = weechat_buffer_get_string (ptr_buffer,
+ "localvar_script_input_cb");
+ script_input_cb_data = weechat_buffer_get_string (ptr_buffer,
+ "localvar_script_input_cb_data");
+ script_close_cb = weechat_buffer_get_string (ptr_buffer,
+ "localvar_script_close_cb");
+ script_close_cb_data = weechat_buffer_get_string (ptr_buffer,
+ "localvar_script_close_cb_data");
+
+ if (script_input_cb && script_input_cb[0])
+ {
+ new_script_callback_input = script_callback_alloc ();
+ if (new_script_callback_input)
+ {
+ script_callback_init (new_script_callback_input,
+ ptr_script,
+ script_input_cb,
+ script_input_cb_data);
+ new_script_callback_input->buffer = ptr_buffer;
+ script_callback_add (ptr_script,
+ new_script_callback_input);
+ weechat_buffer_set_pointer (ptr_buffer,
+ "input_callback",
+ callback_buffer_input);
+ weechat_buffer_set_pointer (ptr_buffer,
+ "input_callback_data",
+ new_script_callback_input);
+ }
+ }
+ if (script_close_cb && script_close_cb[0])
+ {
+ new_script_callback_close = script_callback_alloc ();
+ if (new_script_callback_close)
+ {
+ script_callback_init (new_script_callback_close,
+ ptr_script,
+ script_close_cb,
+ script_close_cb_data);
+ new_script_callback_close->buffer = ptr_buffer;
+ script_callback_add (ptr_script,
+ new_script_callback_close);
+ weechat_buffer_set_pointer (ptr_buffer,
+ "close_callback",
+ callback_buffer_close);
+ weechat_buffer_set_pointer (ptr_buffer,
+ "close_callback_data",
+ new_script_callback_close);
+ }
+ }
+ }
+ }
+ }
+ }
+ weechat_infolist_free (infolist);
+ }
+}
+
+/*
* script_remove_buffer_callbacks: remove callbacks for a buffer (called when a
* buffer is closed by user)
*/
diff --git a/src/plugins/scripts/script.h b/src/plugins/scripts/script.h
index f79afb2dd..49b4f9520 100644
--- a/src/plugins/scripts/script.h
+++ b/src/plugins/scripts/script.h
@@ -71,7 +71,6 @@ struct t_plugin_script
extern void script_init (struct t_weechat_plugin *weechat_plugin,
int argc,
char *argv[],
- struct t_plugin_script **scripts,
int (*callback_command)(void *data,
struct t_gui_buffer *buffer,
int argc, char **argv,
@@ -96,12 +95,7 @@ extern void script_init (struct t_weechat_plugin *weechat_plugin,
const char *signal,
const char *type_data,
void *signal_data),
- void (*callback_load_file)(void *data, const char *filename),
- int (*callback_buffer_input) (void *data,
- struct t_gui_buffer *buffer,
- const char *input_data),
- int (*callback_buffer_close) (void *data,
- struct t_gui_buffer *buffer));
+ void (*callback_load_file)(void *data, const char *filename));
extern int script_valid (struct t_plugin_script *scripts,
struct t_plugin_script *script);
extern char *script_ptr2str (void *pointer);
@@ -120,6 +114,14 @@ extern struct t_plugin_script *script_add (struct t_weechat_plugin *weechat_plug
const char *author, const char *version,
const char *license, const char *description,
const char *shutdown_func, const char *charset);
+extern void script_set_buffer_callbacks (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *scripts,
+ struct t_plugin_script *script,
+ int (*callback_buffer_input) (void *data,
+ struct t_gui_buffer *buffer,
+ const char *input_data),
+ int (*callback_buffer_close) (void *data,
+ struct t_gui_buffer *buffer));
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,
diff --git a/src/plugins/scripts/tcl/weechat-tcl.c b/src/plugins/scripts/tcl/weechat-tcl.c
index 3e18edad8..bfeba401b 100644
--- a/src/plugins/scripts/tcl/weechat-tcl.c
+++ b/src/plugins/scripts/tcl/weechat-tcl.c
@@ -333,6 +333,16 @@ weechat_tcl_load (const char *filename)
}
tcl_current_script = tcl_registered_script;
+ /*
+ * set input/close callbacks for buffers created by this script
+ * (to restore callbacks after upgrade)
+ */
+ script_set_buffer_callbacks (weechat_tcl_plugin,
+ tcl_scripts,
+ tcl_current_script,
+ &weechat_tcl_api_buffer_input_data_cb,
+ &weechat_tcl_api_buffer_close_cb);
+
return 1;
}
@@ -710,16 +720,13 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
script_init (weechat_tcl_plugin,
argc,
argv,
- &tcl_scripts,
&weechat_tcl_command_cb,
&weechat_tcl_completion_cb,
&weechat_tcl_infolist_cb,
&weechat_tcl_signal_debug_dump_cb,
&weechat_tcl_signal_buffer_closed_cb,
&weechat_tcl_signal_script_action_cb,
- &weechat_tcl_load_cb,
- &weechat_tcl_api_buffer_input_data_cb,
- &weechat_tcl_api_buffer_close_cb);
+ &weechat_tcl_load_cb);
tcl_quiet = 0;
script_display_short_list (weechat_tcl_plugin,