From 4fdbb83a079f24a742633fd4d02084911580c19c Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Fri, 22 Mar 2013 19:54:44 +0100 Subject: [PATCH] ruby: fix crash with Ruby 2.0: use one array for the last 6 arguments of function config_new_option (bug #31050) --- ChangeLog | 2 ++ doc/de/weechat_scripting.de.txt | 10 ++++++++ doc/en/weechat_plugin_api.en.txt | 5 ++++ doc/en/weechat_scripting.en.txt | 9 +++++++ doc/fr/weechat_plugin_api.fr.txt | 6 +++++ doc/fr/weechat_scripting.fr.txt | 10 ++++++++ doc/fr/weechat_user.fr.txt | 2 +- doc/it/weechat_plugin_api.it.txt | 6 +++++ doc/it/weechat_scripting.it.txt | 10 ++++++++ doc/ja/weechat_scripting.ja.txt | 10 ++++++++ doc/pl/weechat_scripting.pl.txt | 10 ++++++++ src/plugins/ruby/weechat-ruby-api.c | 38 +++++++++++++++-------------- 12 files changed, 99 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index ea855ff41..f54a7f23f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -79,6 +79,8 @@ Version 0.4.1 (under dev!) * rmodifier: rename default rmodifier "nickserv" to "command_auth" (with new modifier "irc_command_auth"), add default rmodifier "message_auth" (modifier "irc_message_auth") +* ruby: fix crash with Ruby 2.0: use one array for the last 6 arguments of + function config_new_option (bug #31050) * script: create "script" directory on each action, just in case it has been removed (bug #38472) * script: add option script.scripts.autoload, add options "autoload", diff --git a/doc/de/weechat_scripting.de.txt b/doc/de/weechat_scripting.de.txt index b61af0d95..155c7793a 100644 --- a/doc/de/weechat_scripting.de.txt +++ b/doc/de/weechat_scripting.de.txt @@ -56,6 +56,16 @@ Ruby * Es muss 'weechat_init' definiert und darin die Funktion 'register' ausgeführt werden * Funktionen werden im Format `Weechat.xxx(arg1, arg2, ...)` ausgeführt +// TRANSLATION MISSING +* Due to a limitation of Ruby (15 arguments max by function), the function + `Weechat.config_new_option` receives the callbacks in an array of 6 strings + (3 callbacks + 3 data strings), so a call to this function looks like: + +[source,ruby] +---------------------------------------- +Weechat.config_new_option(config, section, "name", "string", "description of option", "", 0, 0, + "value", "value", 0, ["check_cb", "", "change_cb", "", "delete_cb", ""]) +---------------------------------------- Lua ^^^ diff --git a/doc/en/weechat_plugin_api.en.txt b/doc/en/weechat_plugin_api.en.txt index f51d4cd10..03a5a13a0 100644 --- a/doc/en/weechat_plugin_api.en.txt +++ b/doc/en/weechat_plugin_api.en.txt @@ -4352,6 +4352,11 @@ option5 = weechat.config_new_option(config_file, section, "option5", "color", "", "") ---------------------------------------- +[NOTE] +In Ruby, the 3 callbacks + data (6 strings) must be given in an array of 6 +strings (due to a Ruby limitation of 15 arguments by function), see the +'WeeChat Scripting Guide' for more info (_fixed in version 0.4.1_). + weechat_config_search_option ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/en/weechat_scripting.en.txt b/doc/en/weechat_scripting.en.txt index e7d4dc04f..32e3859a3 100644 --- a/doc/en/weechat_scripting.en.txt +++ b/doc/en/weechat_scripting.en.txt @@ -56,6 +56,15 @@ Ruby * You have to define 'weechat_init' and call 'register' inside * Functions are called with `Weechat.xxx(arg1, arg2, ...)` +* Due to a limitation of Ruby (15 arguments max by function), the function + `Weechat.config_new_option` receives the callbacks in an array of 6 strings + (3 callbacks + 3 data strings), so a call to this function looks like: + +[source,ruby] +---------------------------------------- +Weechat.config_new_option(config, section, "name", "string", "description of option", "", 0, 0, + "value", "value", 0, ["check_cb", "", "change_cb", "", "delete_cb", ""]) +---------------------------------------- Lua ^^^ diff --git a/doc/fr/weechat_plugin_api.fr.txt b/doc/fr/weechat_plugin_api.fr.txt index cb8c9c0a5..f6389f49e 100644 --- a/doc/fr/weechat_plugin_api.fr.txt +++ b/doc/fr/weechat_plugin_api.fr.txt @@ -4405,6 +4405,12 @@ option5 = weechat.config_new_option(config_file, section, "option5", "color", "", "") ---------------------------------------- +[NOTE] +En Ruby, les 3 "callbacks" + "data" (6 chaînes) doivent être données dans un +tableau de 6 chaînes de caractères (en raison d'une limitation de Ruby à 15 +paramètres par fonction), voir le 'Guide pour Scripts WeeChat' pour plus d'infos +(_corrigé dans la version 0.4.1_). + weechat_config_search_option ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/fr/weechat_scripting.fr.txt b/doc/fr/weechat_scripting.fr.txt index 80da13f3f..22b505b30 100644 --- a/doc/fr/weechat_scripting.fr.txt +++ b/doc/fr/weechat_scripting.fr.txt @@ -57,6 +57,16 @@ Ruby * Vous devez définir 'weechat_init' et appeler 'register' dedans * Les fonctions sont appelées par `Weechat.xxx(arg1, arg2, ...)` +* En raison d'une limitation de Ruby (15 paramètres maximum par fonction), la + fonction `Weechat.config_new_option` reçoit les "callbacks" dans un tableau de + 6 chaînes de caractères (3 callbacks + 3 chaînes de données), donc un appel à + cette fonction ressemble à ceci : + +[source,ruby] +---------------------------------------- +Weechat.config_new_option(config, section, "name", "string", "description of option", "", 0, 0, + "value", "value", 0, ["check_cb", "", "change_cb", "", "delete_cb", ""]) +---------------------------------------- Lua ^^^ diff --git a/doc/fr/weechat_user.fr.txt b/doc/fr/weechat_user.fr.txt index 218bafe63..bd1d8279a 100644 --- a/doc/fr/weechat_user.fr.txt +++ b/doc/fr/weechat_user.fr.txt @@ -1436,7 +1436,7 @@ Extensions ---------- Pour en apprendre plus sur le développement d'extension ou de script (via -l'API), merci de consulter la 'Référence API Extension WeeChat' ou 'Le Guide +l'API), merci de consulter la 'Référence API Extension WeeChat' ou le 'Guide pour Scripts WeeChat'. [[plugins_in_weechat]] diff --git a/doc/it/weechat_plugin_api.it.txt b/doc/it/weechat_plugin_api.it.txt index 14061d5c5..f08fe03e2 100644 --- a/doc/it/weechat_plugin_api.it.txt +++ b/doc/it/weechat_plugin_api.it.txt @@ -4354,6 +4354,12 @@ option5 = weechat.config_new_option(config_file, section, "option5", "color", "", "") ---------------------------------------- +// TRANSLATION MISSING +[NOTE] +In Ruby, the 3 callbacks + data (6 strings) must be given in an array of 6 +strings (due to a Ruby limitation of 15 arguments by function), see the +'WeeChat Scripting Guide' for more info (_fixed in version 0.4.1_). + weechat_config_search_option ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/it/weechat_scripting.it.txt b/doc/it/weechat_scripting.it.txt index 3001170b1..03c6950ea 100644 --- a/doc/it/weechat_scripting.it.txt +++ b/doc/it/weechat_scripting.it.txt @@ -57,6 +57,16 @@ Ruby * E necessario definire 'weechat_init' e chiamare 'register' all'interno * Le funzioni sono chiamate con `Weechat.xxx(arg1, arg2, ...)` +// TRANSLATION MISSING +* Due to a limitation of Ruby (15 arguments max by function), the function + `Weechat.config_new_option` receives the callbacks in an array of 6 strings + (3 callbacks + 3 data strings), so a call to this function looks like: + +[source,ruby] +---------------------------------------- +Weechat.config_new_option(config, section, "name", "string", "description of option", "", 0, 0, + "value", "value", 0, ["check_cb", "", "change_cb", "", "delete_cb", ""]) +---------------------------------------- Lua ^^^ diff --git a/doc/ja/weechat_scripting.ja.txt b/doc/ja/weechat_scripting.ja.txt index f5c7eda75..70ab66b2c 100644 --- a/doc/ja/weechat_scripting.ja.txt +++ b/doc/ja/weechat_scripting.ja.txt @@ -49,6 +49,16 @@ WeeChat (Wee Enhanced Environment for Chat) はフリー、高速、軽量な * 'weechat_init' を定義して、内部で 'register' を呼び出してください。 * 関数は `Weechat.xxx(arg1, arg2, ...)` のように呼び出してください。 +// TRANSLATION MISSING +* Due to a limitation of Ruby (15 arguments max by function), the function + `Weechat.config_new_option` receives the callbacks in an array of 6 strings + (3 callbacks + 3 data strings), so a call to this function looks like: + +[source,ruby] +---------------------------------------- +Weechat.config_new_option(config, section, "name", "string", "description of option", "", 0, 0, + "value", "value", 0, ["check_cb", "", "change_cb", "", "delete_cb", ""]) +---------------------------------------- ==== Lua ==== diff --git a/doc/pl/weechat_scripting.pl.txt b/doc/pl/weechat_scripting.pl.txt index 0d4c36958..03a0dcf50 100644 --- a/doc/pl/weechat_scripting.pl.txt +++ b/doc/pl/weechat_scripting.pl.txt @@ -56,6 +56,16 @@ Ruby * Trzeba zdefiniować 'weechat_init' i wywołać 'register' wewnątrz * Funkcje są wywoływane za pomocą `Weechat.xxx(arg1, arg2, ...)` +// TRANSLATION MISSING +* Due to a limitation of Ruby (15 arguments max by function), the function + `Weechat.config_new_option` receives the callbacks in an array of 6 strings + (3 callbacks + 3 data strings), so a call to this function looks like: + +[source,ruby] +---------------------------------------- +Weechat.config_new_option(config, section, "name", "string", "description of option", "", 0, 0, + "value", "value", 0, ["check_cb", "", "change_cb", "", "delete_cb", ""]) +---------------------------------------- Lua ^^^ diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c index bbc2fbcbe..101caec96 100644 --- a/src/plugins/ruby/weechat-ruby-api.c +++ b/src/plugins/ruby/weechat-ruby-api.c @@ -1333,28 +1333,21 @@ weechat_ruby_api_config_new_option (VALUE class, VALUE config_file, VALUE description, VALUE string_values, VALUE min, VALUE max, VALUE default_value, VALUE value, VALUE null_value_allowed, - VALUE function_check_value, - VALUE data_check_value, - VALUE function_change, - VALUE data_change, - VALUE function_delete, - VALUE data_delete) + VALUE callbacks) { char *c_config_file, *c_section, *c_name, *c_type, *c_description; char *c_string_values, *c_default_value, *c_value; char *c_function_check_value, *c_data_check_value, *c_function_change; char *c_data_change, *c_function_delete, *c_data_delete, *result; int c_min, c_max, c_null_value_allowed; - VALUE return_value; + VALUE function_check_value, data_check_value, function_change, data_change; + VALUE function_delete, data_delete, return_value; API_FUNC(1, "config_new_option", API_RETURN_EMPTY); if (NIL_P (config_file) || NIL_P (section) || NIL_P (name) || NIL_P (type) || NIL_P (description) || NIL_P (string_values) || NIL_P (min) || NIL_P (max) || NIL_P (default_value) || NIL_P (value) - || NIL_P (null_value_allowed) || NIL_P (function_check_value) - || NIL_P (data_check_value) || NIL_P (function_change) - || NIL_P (data_change) || NIL_P (function_delete) - || NIL_P (data_delete)) + || NIL_P (null_value_allowed) || NIL_P (callbacks)) API_WRONG_ARGS(API_RETURN_EMPTY); Check_Type (config_file, T_STRING); @@ -1368,12 +1361,21 @@ weechat_ruby_api_config_new_option (VALUE class, VALUE config_file, Check_Type (default_value, T_STRING); Check_Type (value, T_STRING); Check_Type (null_value_allowed, T_FIXNUM); - Check_Type (function_check_value, T_STRING); - Check_Type (data_check_value, T_STRING); - Check_Type (function_change, T_STRING); - Check_Type (data_change, T_STRING); - Check_Type (function_delete, T_STRING); - Check_Type (data_delete, T_STRING); + Check_Type (callbacks, T_ARRAY); + + /* + * due to a Ruby limitation (15 arguments max by function), we receive the + * the callbacks in an array of 6 strings (3 callbacks + 3 data) + */ + if (RARRAY_LEN(callbacks) != 6) + API_WRONG_ARGS(API_RETURN_EMPTY); + + function_check_value = rb_ary_entry (callbacks, 0); + data_check_value = rb_ary_entry (callbacks, 1); + function_change = rb_ary_entry (callbacks, 2); + data_change = rb_ary_entry (callbacks, 3); + function_delete = rb_ary_entry (callbacks, 4); + data_delete = rb_ary_entry (callbacks, 5); c_config_file = StringValuePtr (config_file); c_section = StringValuePtr (section); @@ -5915,7 +5917,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) API_DEF_FUNC(config_new, 3); API_DEF_FUNC(config_new_section, 14); API_DEF_FUNC(config_search_section, 2); - API_DEF_FUNC(config_new_option, 17); + API_DEF_FUNC(config_new_option, 12); API_DEF_FUNC(config_search_option, 3); API_DEF_FUNC(config_string_to_boolean, 1); API_DEF_FUNC(config_option_reset, 2);