diff --git a/ChangeLog b/ChangeLog index e4ca94b7b..1e89842e5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -115,6 +115,8 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] * python: fix load of scripts with python >= 3.3 * relay: fix memory leak on unload of relay plugin * ruby: fix ruby init with ruby >= 2.0 (bug #41115) +* scripts: fix script interpreter used after register during load of script + in python/perl/ruby/lua/guile plugins (bug #41345) * xfer: add support of IPv6 for DCC chat/file (patch #7992) * xfer: use same infolist for hook and signals (patch #7974) * xfer: add option xfer.file.auto_check_crc32 (patch #7963) diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c index bdd47e92f..0f9e40be0 100644 --- a/src/plugins/guile/weechat-guile-api.c +++ b/src/plugins/guile/weechat-guile-api.c @@ -212,6 +212,7 @@ weechat_guile_api_register (SCM name, SCM author, SCM version, SCM license, API_SCM_TO_STRING(version), API_SCM_TO_STRING(description)); } + guile_current_script->interpreter = scm_current_module (); } else { diff --git a/src/plugins/guile/weechat-guile.c b/src/plugins/guile/weechat-guile.c index d0f094284..26d61df11 100644 --- a/src/plugins/guile/weechat-guile.c +++ b/src/plugins/guile/weechat-guile.c @@ -425,7 +425,6 @@ weechat_guile_load (const char *filename) weechat_guile_catch (scm_gc_protect_object, (void *)module); guile_current_script = guile_registered_script; - guile_current_script->interpreter = (void *)module; /* * set input/close callbacks for buffers created by this script diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c index d3e333de0..e54cbcbcf 100644 --- a/src/plugins/lua/weechat-lua-api.c +++ b/src/plugins/lua/weechat-lua-api.c @@ -156,6 +156,7 @@ weechat_lua_api_register (lua_State *L) "version %s (%s)"), LUA_PLUGIN_NAME, name, version, description); } + lua_current_script->interpreter = (lua_State *) lua_current_interpreter; } else { diff --git a/src/plugins/lua/weechat-lua.c b/src/plugins/lua/weechat-lua.c index 8a4160a21..4a3a73ea4 100644 --- a/src/plugins/lua/weechat-lua.c +++ b/src/plugins/lua/weechat-lua.c @@ -445,8 +445,6 @@ weechat_lua_load (const char *filename) } lua_current_script = lua_registered_script; - lua_current_script->interpreter = (lua_State *) lua_current_interpreter; - /* * set input/close callbacks for buffers created by this script * (to restore callbacks after upgrade) diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c index 632e17872..6fb73f759 100644 --- a/src/plugins/perl/weechat-perl-api.c +++ b/src/plugins/perl/weechat-perl-api.c @@ -156,9 +156,6 @@ XS (XS_weechat_api_register) description, shutdown_func, charset); if (perl_current_script) { -#ifndef MULTIPLICITY - perl_current_script->interpreter = SvPV_nolen (eval_pv ("__PACKAGE__", TRUE)); -#endif perl_registered_script = perl_current_script; if ((weechat_perl_plugin->debug >= 2) || !perl_quiet) { @@ -167,6 +164,11 @@ XS (XS_weechat_api_register) "version %s (%s)"), PERL_PLUGIN_NAME, name, version, description); } +#ifdef MULTIPLICITY + perl_current_script->interpreter = perl_current_interpreter; +#else + perl_current_script->interpreter = SvPV_nolen (eval_pv ("__PACKAGE__", TRUE)); +#endif } else { diff --git a/src/plugins/perl/weechat-perl.c b/src/plugins/perl/weechat-perl.c index d2b8f4a3c..e26d3de86 100644 --- a/src/plugins/perl/weechat-perl.c +++ b/src/plugins/perl/weechat-perl.c @@ -46,6 +46,9 @@ struct t_plugin_script *last_perl_script = NULL; struct t_plugin_script *perl_current_script = NULL; struct t_plugin_script *perl_registered_script = NULL; const char *perl_current_script_filename = NULL; +#ifdef MULTIPLICITY +PerlInterpreter *perl_current_interpreter = NULL; +#endif int perl_quit_or_upgrade = 0; /* @@ -345,10 +348,7 @@ weechat_perl_load (const char *filename) struct stat buf; char *perl_code; int length; - -#ifdef MULTIPLICITY - PerlInterpreter *perl_current_interpreter; -#else +#ifndef MULTIPLICITY char pkgname[64]; #endif @@ -454,9 +454,7 @@ weechat_perl_load (const char *filename) } perl_current_script = perl_registered_script; -#ifdef MULTIPLICITY - perl_current_script->interpreter = (PerlInterpreter *)perl_current_interpreter; -#else +#ifndef MULTIPLICITY perl_current_script->interpreter = strdup (pkgname); #endif diff --git a/src/plugins/perl/weechat-perl.h b/src/plugins/perl/weechat-perl.h index c57a75f47..09f320c98 100644 --- a/src/plugins/perl/weechat-perl.h +++ b/src/plugins/perl/weechat-perl.h @@ -33,6 +33,9 @@ extern struct t_plugin_script *last_perl_script; extern struct t_plugin_script *perl_current_script; extern struct t_plugin_script *perl_registered_script; extern const char *perl_current_script_filename; +#ifdef MULTIPLICITY +extern PerlInterpreter *perl_current_interpreter; +#endif extern HV *weechat_perl_hashtable_to_hash (struct t_hashtable *hashtable); extern struct t_hashtable *weechat_perl_hash_to_hashtable (SV *hash, int size, diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c index 3a3cc7b68..0a8df4c6e 100644 --- a/src/plugins/python/weechat-python-api.c +++ b/src/plugins/python/weechat-python-api.c @@ -143,6 +143,7 @@ weechat_python_api_register (PyObject *self, PyObject *args) "version %s (%s)"), PYTHON_PLUGIN_NAME, name, version, description); } + python_current_script->interpreter = (PyThreadState *)python_current_interpreter; } else { diff --git a/src/plugins/python/weechat-python.c b/src/plugins/python/weechat-python.c index cfd6117c8..b40f5d323 100644 --- a/src/plugins/python/weechat-python.c +++ b/src/plugins/python/weechat-python.c @@ -49,6 +49,7 @@ struct t_plugin_script *python_current_script = NULL; struct t_plugin_script *python_registered_script = NULL; const char *python_current_script_filename = NULL; PyThreadState *python_mainThreadState = NULL; +PyThreadState *python_current_interpreter = NULL; char *python2_bin = NULL; /* outputs subroutines */ @@ -590,7 +591,6 @@ weechat_python_load (const char *filename) wchar_t *wargv[] = { NULL, NULL }; #endif FILE *fp; - PyThreadState *python_current_interpreter; PyObject *weechat_outputs, *python_path, *path; const char *weechat_home; char *str_home; @@ -754,7 +754,6 @@ weechat_python_load (const char *filename) } python_current_script = python_registered_script; - python_current_script->interpreter = (PyThreadState *) python_current_interpreter; /* PyEval_ReleaseThread (python_current_script->interpreter); */ /* diff --git a/src/plugins/python/weechat-python.h b/src/plugins/python/weechat-python.h index 15c6f1e4d..b2b849629 100644 --- a/src/plugins/python/weechat-python.h +++ b/src/plugins/python/weechat-python.h @@ -42,6 +42,7 @@ extern struct t_plugin_script *last_python_script; extern struct t_plugin_script *python_current_script; extern struct t_plugin_script *python_registered_script; extern const char *python_current_script_filename; +extern PyThreadState *python_current_interpreter; extern PyObject *weechat_python_hashtable_to_dict (struct t_hashtable *hashtable); extern struct t_hashtable *weechat_python_dict_to_hashtable (PyObject *dict, diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c index 471f038a6..5408b8ffc 100644 --- a/src/plugins/ruby/weechat-ruby-api.c +++ b/src/plugins/ruby/weechat-ruby-api.c @@ -156,6 +156,7 @@ weechat_ruby_api_register (VALUE class, VALUE name, VALUE author, "version %s (%s)"), RUBY_PLUGIN_NAME, c_name, c_version, c_description); } + ruby_current_script->interpreter = (VALUE *)ruby_current_module; } else { diff --git a/src/plugins/ruby/weechat-ruby.c b/src/plugins/ruby/weechat-ruby.c index 0b4ccd2f5..259786942 100644 --- a/src/plugins/ruby/weechat-ruby.c +++ b/src/plugins/ruby/weechat-ruby.c @@ -71,6 +71,7 @@ struct t_plugin_script *last_ruby_script = NULL; struct t_plugin_script *ruby_current_script = NULL; struct t_plugin_script *ruby_registered_script = NULL; const char *ruby_current_script_filename = NULL; +VALUE ruby_current_module = NULL; /* * string used to execute action "install": @@ -502,7 +503,7 @@ int weechat_ruby_load (const char *filename) { char modname[64]; - VALUE curModule, ruby_retcode, err, argv[1]; + VALUE ruby_retcode, err, argv[1]; int ruby_error; struct stat buf; @@ -527,12 +528,13 @@ weechat_ruby_load (const char *filename) snprintf (modname, sizeof(modname), "%s%d", MOD_NAME_PREFIX, ruby_num); ruby_num++; - curModule = rb_define_module(modname); + ruby_current_module = rb_define_module (modname); ruby_current_script_filename = filename; argv[0] = rb_str_new2 (filename); - ruby_retcode = rb_protect_funcall (curModule, rb_intern("load_eval_file"), + ruby_retcode = rb_protect_funcall (ruby_current_module, + rb_intern ("load_eval_file"), &ruby_error, 1, argv); if (ruby_retcode == Qnil) @@ -572,13 +574,14 @@ weechat_ruby_load (const char *filename) if (NUM2INT(ruby_retcode) == 1 || NUM2INT(ruby_retcode) == 2) { - weechat_ruby_print_exception(rb_iv_get(curModule, "@load_eval_file_error")); + weechat_ruby_print_exception(rb_iv_get (ruby_current_module, + "@load_eval_file_error")); } return 0; } - (void) rb_protect_funcall (curModule, rb_intern("weechat_init"), + (void) rb_protect_funcall (ruby_current_module, rb_intern ("weechat_init"), &ruby_error, 0, NULL); if (ruby_error) @@ -611,7 +614,6 @@ weechat_ruby_load (const char *filename) } ruby_current_script = ruby_registered_script; - ruby_current_script->interpreter = (VALUE *) curModule; rb_gc_register_address (ruby_current_script->interpreter); /* diff --git a/src/plugins/ruby/weechat-ruby.h b/src/plugins/ruby/weechat-ruby.h index 00b7d63b8..847cf2756 100644 --- a/src/plugins/ruby/weechat-ruby.h +++ b/src/plugins/ruby/weechat-ruby.h @@ -34,6 +34,7 @@ extern struct t_plugin_script *last_ruby_script; extern struct t_plugin_script *ruby_current_script; extern struct t_plugin_script *ruby_registered_script; extern const char *ruby_current_script_filename; +extern VALUE ruby_current_module; extern VALUE weechat_ruby_hashtable_to_hash (struct t_hashtable *hashtable); extern struct t_hashtable *weechat_ruby_hash_to_hashtable (VALUE dict,