From ebc63d1b8303a479c9ed347c1152448984fffa67 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Sat, 22 Oct 2022 15:27:06 +0200 Subject: [PATCH] scripts: Send null values to config section callbacks The callback_read and callback_create_option functions in the scripting APIs always get the value as a string, never as null. This means that if the value is null, there is no way for the script to distinguish this from an empty string for string options. This makes it impossible to properly make options with fallback values, like the irc server and server_default options, as far as I can see. All the scripting languages except Tcl use that language's equivalent for null. For JavaScript which has both null and undefined, null is used. For Tcl, the magic null string defined in commit 197a7a01e is used and the documentation is updated to describe that. I tested this with these scripts: https://gist.github.com/trygveaa/2d49c609addf9773d2ed16e15d1e3447 You can load all of those scripts and see the result with this command (assuming you have the scripts in the current directory): weechat -t -r "/filter add script * * script; /script load $(echo script_config.*)" --- doc/de/weechat_scripting.de.adoc | 21 ++++++++++++++++----- doc/en/weechat_plugin_api.en.adoc | 4 ++-- doc/en/weechat_scripting.en.adoc | 12 +++++++++++- doc/fr/weechat_plugin_api.fr.adoc | 4 ++-- doc/fr/weechat_scripting.fr.adoc | 22 ++++++++++++++++------ doc/it/weechat_plugin_api.it.adoc | 4 ++-- doc/it/weechat_scripting.it.adoc | 13 ++++++++++++- doc/ja/weechat_plugin_api.ja.adoc | 4 ++-- doc/ja/weechat_scripting.ja.adoc | 12 +++++++++++- doc/pl/weechat_scripting.pl.adoc | 12 +++++++++++- doc/sr/weechat_plugin_api.sr.adoc | 4 ++-- doc/sr/weechat_scripting.sr.adoc | 21 ++++++++++++++++----- src/plugins/guile/weechat-guile-api.c | 4 ++-- src/plugins/guile/weechat-guile.c | 7 +++++-- src/plugins/javascript/weechat-js-api.cpp | 4 ++-- src/plugins/javascript/weechat-js.cpp | 7 +++++-- src/plugins/lua/weechat-lua-api.c | 4 ++-- src/plugins/lua/weechat-lua.c | 7 +++++-- src/plugins/perl/weechat-perl-api.c | 4 ++-- src/plugins/perl/weechat-perl.c | 7 +++++-- src/plugins/php/weechat-php-api.c | 4 ++-- src/plugins/php/weechat-php.c | 7 +++++-- src/plugins/python/weechat-python-api.c | 4 ++-- src/plugins/python/weechat-python.c | 2 +- src/plugins/python/weechat.pyi | 4 ++-- src/plugins/ruby/weechat-ruby-api.c | 4 ++-- src/plugins/ruby/weechat-ruby.c | 7 +++++-- src/plugins/tcl/weechat-tcl-api.c | 4 ++-- 28 files changed, 152 insertions(+), 61 deletions(-) diff --git a/doc/de/weechat_scripting.de.adoc b/doc/de/weechat_scripting.de.adoc index 6a256391b..172723148 100644 --- a/doc/de/weechat_scripting.de.adoc +++ b/doc/de/weechat_scripting.de.adoc @@ -201,11 +201,22 @@ Funktionen werden aufgerufen mittels `+weechat.xxx(arg1, arg2, ...)+`. Funktionen werden aufgerufen mittels `+weechat::xxx arg1 arg2 ...+`. -Da Tcl nur String-Typen hat, gibt es keinen Null-Typ, der als Argument übergeben werden kann -wenn eine Funktion Nullwerte akzeptiert. Um dies zu überwinden, können Sie die Konstante -`$::weechat::WEECHAT_NULL` verwenden, das als Nullwert fungiert. Diese Konstante ist definiert -als `\uFFFF\uFFFF\uFFFFWEECHAT_NULL\uFFFF\uFFFF\uFFFF`, es ist somit sehr unwahrscheinlich -das es ungewollt verwendet wird. +// TRANSLATION MISSING +[[tcl_null]] +===== Null values + +Since Tcl only has string types, there's no null type to pass as an argument +when a function accepts null values or to get as an argument in a callback +function. To overcome this the WeeChat API defines the constant +`$::weechat::WEECHAT_NULL` which acts as a null value. This constant is defined +as `\uFFFF\uFFFF\uFFFFWEECHAT_NULL\uFFFF\uFFFF\uFFFF`, so it's very unlikely to +appear unintentionally. + +You can pass this constant when a function accepts null as an argument and you +will get it as the value of an argument in a callback function if the argument +value is null. To see which functions accept null values and passes null values +to callbacks, look at the Python prototypes in the +link:weechat_plugin_api.en.html[WeeChat plugin API reference ^↗^,window=_blank]. [[language_guile]] ==== Guile (Scheme) diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index a26241688..5475efa8b 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -6451,7 +6451,7 @@ def config_new_section(config_file: str, name: str, callback_delete_option: str, callback_delete_option_data: str) -> str: ... # example -def my_section_read_cb(data: str, config_file: str, section: str, option_name: str, value: str) -> int: +def my_section_read_cb(data: str, config_file: str, section: str, option_name: str, value: str | None) -> int: # ... return weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED # return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE @@ -6466,7 +6466,7 @@ def my_section_write_default_cb(data: str, config_file: str, section_name: str) # ... return weechat.WEECHAT_CONFIG_WRITE_OK -def my_section_create_option_cb(data: str, config_file: str, section: str, option_name: str, value: str) -> int: +def my_section_create_option_cb(data: str, config_file: str, section: str, option_name: str, value: str | None) -> int: # ... return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE diff --git a/doc/en/weechat_scripting.en.adoc b/doc/en/weechat_scripting.en.adoc index f54d53796..ed5f0c84a 100644 --- a/doc/en/weechat_scripting.en.adoc +++ b/doc/en/weechat_scripting.en.adoc @@ -191,12 +191,22 @@ Functions are called with `+weechat.xxx(arg1, arg2, ...)+`. Functions are called with `+weechat::xxx arg1 arg2 ...+`. +[[tcl_null]] +===== Null values + Since Tcl only has string types, there's no null type to pass as an argument -when a function accepts null values. To overcome this you can use the constant +when a function accepts null values or to get as an argument in a callback +function. To overcome this the WeeChat API defines the constant `$::weechat::WEECHAT_NULL` which acts as a null value. This constant is defined as `\uFFFF\uFFFF\uFFFFWEECHAT_NULL\uFFFF\uFFFF\uFFFF`, so it's very unlikely to appear unintentionally. +You can pass this constant when a function accepts null as an argument and you +will get it as the value of an argument in a callback function if the argument +value is null. To see which functions accept null values and passes null values +to callbacks, look at the Python prototypes in the +link:weechat_plugin_api.en.html[WeeChat plugin API reference ^↗^,window=_blank]. + [[language_guile]] ==== Guile (Scheme) diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index 41f6fdac4..0f8a4c7de 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -6554,7 +6554,7 @@ def config_new_section(config_file: str, name: str, callback_delete_option: str, callback_delete_option_data: str) -> str: ... # exemple -def my_section_read_cb(data: str, config_file: str, section: str, option_name: str, value: str) -> int: +def my_section_read_cb(data: str, config_file: str, section: str, option_name: str, value: str | None) -> int: # ... return weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED # return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE @@ -6569,7 +6569,7 @@ def my_section_write_default_cb(data: str, config_file: str, section_name: str) # ... return weechat.WEECHAT_CONFIG_WRITE_OK -def my_section_create_option_cb(data: str, config_file: str, section: str, option_name: str, value: str) -> int: +def my_section_create_option_cb(data: str, config_file: str, section: str, option_name: str, value: str | None) -> int: # ... return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE diff --git a/doc/fr/weechat_scripting.fr.adoc b/doc/fr/weechat_scripting.fr.adoc index f481640f7..de87cb8e4 100644 --- a/doc/fr/weechat_scripting.fr.adoc +++ b/doc/fr/weechat_scripting.fr.adoc @@ -201,12 +201,22 @@ Les fonctions sont appelées par `+weechat.xxx(arg1, arg2, ...)+`. Les fonctions sont appelées par `+weechat::xxx arg1 arg2 ...+`. -Étant donné que Tcl n'a que des types "string", il n'y a pas de type null à -donner comme paramètre quand une fonctionne accepte des valeurs nulles. -Pour surmonter cela vous pouvez utiliser la constante `$::weechat::WEECHAT_NULL` -qui agit comme la valeur nulle. Cette constante est définie avec la valeur -`\uFFFF\uFFFF\uFFFFWEECHAT_NULL\uFFFF\uFFFF\uFFFF`, il est donc très peu probable -qu'elle apparaisse de manière non intentionnelle. +// TRANSLATION MISSING +[[tcl_null]] +===== Null values + +Since Tcl only has string types, there's no null type to pass as an argument +when a function accepts null values or to get as an argument in a callback +function. To overcome this the WeeChat API defines the constant +`$::weechat::WEECHAT_NULL` which acts as a null value. This constant is defined +as `\uFFFF\uFFFF\uFFFFWEECHAT_NULL\uFFFF\uFFFF\uFFFF`, so it's very unlikely to +appear unintentionally. + +You can pass this constant when a function accepts null as an argument and you +will get it as the value of an argument in a callback function if the argument +value is null. To see which functions accept null values and passes null values +to callbacks, look at the Python prototypes in the +link:weechat_plugin_api.en.html[WeeChat plugin API reference ^↗^,window=_blank]. [[language_guile]] ==== Guile (Scheme) diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index 29cfe044f..52bc4cc66 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -6691,7 +6691,7 @@ def config_new_section(config_file: str, name: str, callback_delete_option: str, callback_delete_option_data: str) -> str: ... # esempio -def my_section_read_cb(data: str, config_file: str, section: str, option_name: str, value: str) -> int: +def my_section_read_cb(data: str, config_file: str, section: str, option_name: str, value: str | None) -> int: # ... return weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED # return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE @@ -6706,7 +6706,7 @@ def my_section_write_default_cb(data: str, config_file: str, section_name: str) # ... return weechat.WEECHAT_CONFIG_WRITE_OK -def my_section_create_option_cb(data: str, config_file: str, section: str, option_name: str, value: str) -> int: +def my_section_create_option_cb(data: str, config_file: str, section: str, option_name: str, value: str | None) -> int: # ... return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE diff --git a/doc/it/weechat_scripting.it.adoc b/doc/it/weechat_scripting.it.adoc index c31bffdf6..95e703e9d 100644 --- a/doc/it/weechat_scripting.it.adoc +++ b/doc/it/weechat_scripting.it.adoc @@ -210,12 +210,23 @@ Functions are called with `+weechat.xxx(arg1, arg2, ...)+`. Functions are called with `+weechat::xxx arg1 arg2 ...+`. +// TRANSLATION MISSING +[[tcl_null]] +===== Null values + Since Tcl only has string types, there's no null type to pass as an argument -when a function accepts null values. To overcome this you can use the constant +when a function accepts null values or to get as an argument in a callback +function. To overcome this the WeeChat API defines the constant `$::weechat::WEECHAT_NULL` which acts as a null value. This constant is defined as `\uFFFF\uFFFF\uFFFFWEECHAT_NULL\uFFFF\uFFFF\uFFFF`, so it's very unlikely to appear unintentionally. +You can pass this constant when a function accepts null as an argument and you +will get it as the value of an argument in a callback function if the argument +value is null. To see which functions accept null values and passes null values +to callbacks, look at the Python prototypes in the +link:weechat_plugin_api.en.html[WeeChat plugin API reference ^↗^,window=_blank]. + [[language_guile]] ==== Guile (Scheme) diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index 3370a9827..045f58639 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -6494,7 +6494,7 @@ def config_new_section(config_file: str, name: str, callback_delete_option: str, callback_delete_option_data: str) -> str: ... # 例 -def my_section_read_cb(data: str, config_file: str, section: str, option_name: str, value: str) -> int: +def my_section_read_cb(data: str, config_file: str, section: str, option_name: str, value: str | None) -> int: # ... return weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED # return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE @@ -6509,7 +6509,7 @@ def my_section_write_default_cb(data: str, config_file: str, section_name: str) # ... return weechat.WEECHAT_CONFIG_WRITE_OK -def my_section_create_option_cb(data: str, config_file: str, section: str, option_name: str, value: str) -> int: +def my_section_create_option_cb(data: str, config_file: str, section: str, option_name: str, value: str | None) -> int: # ... return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE diff --git a/doc/ja/weechat_scripting.ja.adoc b/doc/ja/weechat_scripting.ja.adoc index c9dbc32bb..b853379e9 100644 --- a/doc/ja/weechat_scripting.ja.adoc +++ b/doc/ja/weechat_scripting.ja.adoc @@ -208,12 +208,22 @@ Functions are called with `+weechat.xxx(arg1, arg2, ...)+`. Functions are called with `+weechat::xxx arg1 arg2 ...+`. // TRANSLATION MISSING +[[tcl_null]] +===== Null values + Since Tcl only has string types, there's no null type to pass as an argument -when a function accepts null values. To overcome this you can use the constant +when a function accepts null values or to get as an argument in a callback +function. To overcome this the WeeChat API defines the constant `$::weechat::WEECHAT_NULL` which acts as a null value. This constant is defined as `\uFFFF\uFFFF\uFFFFWEECHAT_NULL\uFFFF\uFFFF\uFFFF`, so it's very unlikely to appear unintentionally. +You can pass this constant when a function accepts null as an argument and you +will get it as the value of an argument in a callback function if the argument +value is null. To see which functions accept null values and passes null values +to callbacks, look at the Python prototypes in the +link:weechat_plugin_api.en.html[WeeChat plugin API reference ^↗^,window=_blank]. + [[language_guile]] ==== Guile (Scheme) diff --git a/doc/pl/weechat_scripting.pl.adoc b/doc/pl/weechat_scripting.pl.adoc index ac97343e1..3b7abf280 100644 --- a/doc/pl/weechat_scripting.pl.adoc +++ b/doc/pl/weechat_scripting.pl.adoc @@ -202,12 +202,22 @@ Funkcje są wywoływane za pomocą `+weechat.xxx(arg1, arg2, ...)+`. Funkcje są wywoływane za pomocą `+weechat::xxx arg1 arg2 ...+`. // TRANSLATION MISSING +[[tcl_null]] +===== Null values + Since Tcl only has string types, there's no null type to pass as an argument -when a function accepts null values. To overcome this you can use the constant +when a function accepts null values or to get as an argument in a callback +function. To overcome this the WeeChat API defines the constant `$::weechat::WEECHAT_NULL` which acts as a null value. This constant is defined as `\uFFFF\uFFFF\uFFFFWEECHAT_NULL\uFFFF\uFFFF\uFFFF`, so it's very unlikely to appear unintentionally. +You can pass this constant when a function accepts null as an argument and you +will get it as the value of an argument in a callback function if the argument +value is null. To see which functions accept null values and passes null values +to callbacks, look at the Python prototypes in the +link:weechat_plugin_api.en.html[WeeChat plugin API reference ^↗^,window=_blank]. + [[language_guile]] ==== Guile (Scheme) diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc index bf0d6a98d..d4e15f088 100644 --- a/doc/sr/weechat_plugin_api.sr.adoc +++ b/doc/sr/weechat_plugin_api.sr.adoc @@ -6264,7 +6264,7 @@ def config_new_section(config_file: str, name: str, callback_delete_option: str, callback_delete_option_data: str) -> str: ... # пример -def my_section_read_cb(data: str, config_file: str, section: str, option_name: str, value: str) -> int: +def my_section_read_cb(data: str, config_file: str, section: str, option_name: str, value: str | None) -> int: # ... return weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED # return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE @@ -6279,7 +6279,7 @@ def my_section_write_default_cb(data: str, config_file: str, section_name: str) # ... return weechat.WEECHAT_CONFIG_WRITE_OK -def my_section_create_option_cb(data: str, config_file: str, section: str, option_name: str, value: str) -> int: +def my_section_create_option_cb(data: str, config_file: str, section: str, option_name: str, value: str | None) -> int: # ... return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE diff --git a/doc/sr/weechat_scripting.sr.adoc b/doc/sr/weechat_scripting.sr.adoc index 55808a3c5..991e044c1 100644 --- a/doc/sr/weechat_scripting.sr.adoc +++ b/doc/sr/weechat_scripting.sr.adoc @@ -176,11 +176,22 @@ Weechat.bar_new("name", "off", "0", "window", "", "left", "vertical", "vertical" Функције се позивају са `+weechat::xxx арг1 арг2 ...+`. -Пошто Tcl има само стринг типове, не постоји null тип који се прослеђује као -аргумент када функција прихвата null вредности. Ако то желите да заобиђете, -употребите константу `$::weechat::WEECHAT_NULL` која се има улогу null вредности. -Ова константа је дефинисана као `\uFFFF\uFFFF\uFFFFWEECHAT_NULL\uFFFF\uFFFF\uFFFF`, -тако да је скоро немогуће да се појави без намере. +// TRANSLATION MISSING +[[tcl_null]] +===== Null values + +Since Tcl only has string types, there's no null type to pass as an argument +when a function accepts null values or to get as an argument in a callback +function. To overcome this the WeeChat API defines the constant +`$::weechat::WEECHAT_NULL` which acts as a null value. This constant is defined +as `\uFFFF\uFFFF\uFFFFWEECHAT_NULL\uFFFF\uFFFF\uFFFF`, so it's very unlikely to +appear unintentionally. + +You can pass this constant when a function accepts null as an argument and you +will get it as the value of an argument in a callback function if the argument +value is null. To see which functions accept null values and passes null values +to callbacks, look at the Python prototypes in the +link:weechat_plugin_api.en.html[WeeChat plugin API reference ^↗^,window=_blank]. [[language_guile]] ==== Guile (Scheme) diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c index a70860fcd..5efc6b3c8 100644 --- a/src/plugins/guile/weechat-guile-api.c +++ b/src/plugins/guile/weechat-guile-api.c @@ -924,7 +924,7 @@ weechat_guile_api_config_read_cb (const void *pointer, void *data, func_argv[1] = (char *)API_PTR2STR(config_file); func_argv[2] = (char *)API_PTR2STR(section); func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; + func_argv[4] = (value) ? (char *)value : NULL; rc = (int *) weechat_guile_exec (script, WEECHAT_SCRIPT_EXEC_INT, @@ -1045,7 +1045,7 @@ weechat_guile_api_config_section_create_option_cb (const void *pointer, void *da func_argv[1] = (char *)API_PTR2STR(config_file); func_argv[2] = (char *)API_PTR2STR(section); func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; + func_argv[4] = (value) ? (char *)value : NULL; rc = (int *) weechat_guile_exec (script, WEECHAT_SCRIPT_EXEC_INT, diff --git a/src/plugins/guile/weechat-guile.c b/src/plugins/guile/weechat-guile.c index a3108aa74..a0f584a9a 100644 --- a/src/plugins/guile/weechat-guile.c +++ b/src/plugins/guile/weechat-guile.c @@ -365,8 +365,11 @@ weechat_guile_exec (struct t_plugin_script *script, { switch (format[i]) { - case 's': /* string */ - argv2[i] = scm_from_locale_string ((char *)argv[i]); + case 's': /* string or null */ + if (argv[i]) + argv2[i] = scm_from_locale_string ((char *)argv[i]); + else + argv2[i] = SCM_ELISP_NIL; break; case 'i': /* integer */ argv2[i] = scm_from_int (*((int *)argv[i])); diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp index 03036e9b8..5e4de1ebf 100644 --- a/src/plugins/javascript/weechat-js-api.cpp +++ b/src/plugins/javascript/weechat-js-api.cpp @@ -856,7 +856,7 @@ weechat_js_api_config_read_cb (const void *pointer, void *data, func_argv[1] = (char *)API_PTR2STR(config_file); func_argv[2] = (char *)API_PTR2STR(section); func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; + func_argv[4] = (value) ? (char *)value : NULL; rc = (int *)weechat_js_exec (script, WEECHAT_SCRIPT_EXEC_INT, @@ -977,7 +977,7 @@ weechat_js_api_config_section_create_option_cb (const void *pointer, void *data, func_argv[1] = (char *)API_PTR2STR(config_file); func_argv[2] = (char *)API_PTR2STR(section); func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; + func_argv[4] = (value) ? (char *)value : NULL; rc = (int *)weechat_js_exec (script, WEECHAT_SCRIPT_EXEC_INT, diff --git a/src/plugins/javascript/weechat-js.cpp b/src/plugins/javascript/weechat-js.cpp index f87988fa6..b76d1d89e 100644 --- a/src/plugins/javascript/weechat-js.cpp +++ b/src/plugins/javascript/weechat-js.cpp @@ -205,8 +205,11 @@ weechat_js_exec (struct t_plugin_script *script, { switch (format[i]) { - case 's': /* string */ - argv2[i] = v8::String::New((const char *)argv[i]); + case 's': /* string or null */ + if (argv[i]) + argv2[i] = v8::String::New((const char *)argv[i]); + else + argv2[i] = v8::Null(); break; case 'i': /* integer */ argv2[i] = v8::Integer::New(*((int *)argv[i])); diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c index 95c129d98..95dc99adf 100644 --- a/src/plugins/lua/weechat-lua-api.c +++ b/src/plugins/lua/weechat-lua-api.c @@ -961,7 +961,7 @@ weechat_lua_api_config_read_cb (const void *pointer, void *data, func_argv[1] = (char *)API_PTR2STR(config_file); func_argv[2] = (char *)API_PTR2STR(section); func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; + func_argv[4] = (value) ? (char *)value : NULL; rc = (int *) weechat_lua_exec (script, WEECHAT_SCRIPT_EXEC_INT, @@ -1082,7 +1082,7 @@ weechat_lua_api_config_section_create_option_cb (const void *pointer, void *data func_argv[1] = (char *)API_PTR2STR(config_file); func_argv[2] = (char *)API_PTR2STR(section); func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; + func_argv[4] = (value) ? (char *)value : NULL; rc = (int *) weechat_lua_exec (script, WEECHAT_SCRIPT_EXEC_INT, diff --git a/src/plugins/lua/weechat-lua.c b/src/plugins/lua/weechat-lua.c index 898e438c0..36ff14f3a 100644 --- a/src/plugins/lua/weechat-lua.c +++ b/src/plugins/lua/weechat-lua.c @@ -307,8 +307,11 @@ weechat_lua_exec (struct t_plugin_script *script, int ret_type, { switch (format[i]) { - case 's': /* string */ - lua_pushstring (lua_current_interpreter, (char *)argv[i]); + case 's': /* string or null */ + if (argv[i]) + lua_pushstring (lua_current_interpreter, (char *)argv[i]); + else + lua_pushnil (lua_current_interpreter); break; case 'i': /* integer */ #if LUA_VERSION_NUM >= 503 diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c index 9e6a78cb4..5b44470b9 100644 --- a/src/plugins/perl/weechat-perl-api.c +++ b/src/plugins/perl/weechat-perl-api.c @@ -903,7 +903,7 @@ weechat_perl_api_config_section_read_cb (const void *pointer, void *data, func_argv[1] = (char *)API_PTR2STR(config_file); func_argv[2] = (char *)API_PTR2STR(section); func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; + func_argv[4] = (value) ? (char *)value : NULL; rc = (int *) weechat_perl_exec (script, WEECHAT_SCRIPT_EXEC_INT, @@ -1024,7 +1024,7 @@ weechat_perl_api_config_section_create_option_cb (const void *pointer, void *dat func_argv[1] = (char *)API_PTR2STR(config_file); func_argv[2] = (char *)API_PTR2STR(section); func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; + func_argv[4] = (value) ? (char *)value : NULL; rc = (int *) weechat_perl_exec (script, WEECHAT_SCRIPT_EXEC_INT, diff --git a/src/plugins/perl/weechat-perl.c b/src/plugins/perl/weechat-perl.c index 9967b01a5..ad4a659f0 100644 --- a/src/plugins/perl/weechat-perl.c +++ b/src/plugins/perl/weechat-perl.c @@ -363,8 +363,11 @@ weechat_perl_exec (struct t_plugin_script *script, { switch (format[i]) { - case 's': /* string */ - XPUSHs (sv_2mortal(newSVpv((char *)argv[i], 0))); + case 's': /* string or null */ + if (argv[i]) + XPUSHs (sv_2mortal(newSVpv((char *)argv[i], 0))); + else + XPUSHs (sv_2mortal(&PL_sv_undef)); break; case 'i': /* integer */ XPUSHs (sv_2mortal(newSViv(*((int *)argv[i])))); diff --git a/src/plugins/php/weechat-php-api.c b/src/plugins/php/weechat-php-api.c index 1728d147c..3d0054642 100644 --- a/src/plugins/php/weechat-php-api.c +++ b/src/plugins/php/weechat-php-api.c @@ -1085,7 +1085,7 @@ weechat_php_api_config_section_read_cb (const void *pointer, void *data, func_argv[1] = (char *)API_PTR2STR(config_file); func_argv[2] = (char *)API_PTR2STR(section); func_argv[3] = option_name ? (char *)option_name : weechat_php_empty_arg; - func_argv[4] = value ? (char *)value : weechat_php_empty_arg; + func_argv[4] = value ? (char *)value : NULL; weechat_php_cb (pointer, data, func_argv, "sssss", WEECHAT_SCRIPT_EXEC_INT, &rc); @@ -1142,7 +1142,7 @@ weechat_php_api_config_section_create_option_cb (const void *pointer, func_argv[1] = (char *)API_PTR2STR(config_file); func_argv[2] = (char *)API_PTR2STR(section); func_argv[3] = option_name ? (char *)option_name : weechat_php_empty_arg; - func_argv[4] = value ? (char *)value : weechat_php_empty_arg; + func_argv[4] = value ? (char *)value : NULL; weechat_php_cb (pointer, data, func_argv, "sssss", WEECHAT_SCRIPT_EXEC_INT, &rc); diff --git a/src/plugins/php/weechat-php.c b/src/plugins/php/weechat-php.c index f7bed5d51..a3b3dd554 100644 --- a/src/plugins/php/weechat-php.c +++ b/src/plugins/php/weechat-php.c @@ -570,8 +570,11 @@ weechat_php_exec (struct t_plugin_script *script, int ret_type, { switch (format[i]) { - case 's': /* string */ - ZVAL_STRING(¶ms[i], (char *)argv[i]); + case 's': /* string or null */ + if (argv[i]) + ZVAL_STRING(¶ms[i], (char *)argv[i]); + else + ZVAL_NULL(¶ms[i]); break; case 'i': /* integer */ ZVAL_LONG(¶ms[i], *((int *)argv[i])); diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c index 5e8399959..7afddd909 100644 --- a/src/plugins/python/weechat-python-api.c +++ b/src/plugins/python/weechat-python-api.c @@ -890,7 +890,7 @@ weechat_python_api_config_read_cb (const void *pointer, void *data, func_argv[1] = (char *)API_PTR2STR(config_file); func_argv[2] = (char *)API_PTR2STR(section); func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; + func_argv[4] = (value) ? (char *)value : NULL; rc = (int *) weechat_python_exec (script, WEECHAT_SCRIPT_EXEC_INT, @@ -1011,7 +1011,7 @@ weechat_python_api_config_section_create_option_cb (const void *pointer, void *d func_argv[1] = (char *)API_PTR2STR(config_file); func_argv[2] = (char *)API_PTR2STR(section); func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; + func_argv[4] = (value) ? (char *)value : NULL; rc = (int *) weechat_python_exec (script, WEECHAT_SCRIPT_EXEC_INT, diff --git a/src/plugins/python/weechat-python.c b/src/plugins/python/weechat-python.c index bda86d2e3..49ba73610 100644 --- a/src/plugins/python/weechat-python.c +++ b/src/plugins/python/weechat-python.c @@ -446,7 +446,7 @@ weechat_python_exec (struct t_plugin_script *script, { switch (format[i]) { - case 's': /* string */ + case 's': /* string or null */ argv2[i] = argv[i]; if (weechat_utf8_is_valid (argv2[i], -1, NULL)) format2[i] = 's'; /* str */ diff --git a/src/plugins/python/weechat.pyi b/src/plugins/python/weechat.pyi index ce72b2ad4..bf4d6bc2f 100644 --- a/src/plugins/python/weechat.pyi +++ b/src/plugins/python/weechat.pyi @@ -492,7 +492,7 @@ def config_new_section(config_file: str, name: str, :: # example - def my_section_read_cb(data: str, config_file: str, section: str, option_name: str, value: str) -> int: + def my_section_read_cb(data: str, config_file: str, section: str, option_name: str, value: str | None) -> int: # ... return weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED # return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE @@ -507,7 +507,7 @@ def config_new_section(config_file: str, name: str, # ... return weechat.WEECHAT_CONFIG_WRITE_OK - def my_section_create_option_cb(data: str, config_file: str, section: str, option_name: str, value: str) -> int: + def my_section_create_option_cb(data: str, config_file: str, section: str, option_name: str, value: str | None) -> int: # ... return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c index ae491f76f..f887774d3 100644 --- a/src/plugins/ruby/weechat-ruby-api.c +++ b/src/plugins/ruby/weechat-ruby-api.c @@ -1098,7 +1098,7 @@ weechat_ruby_api_config_read_cb (const void *pointer, void *data, func_argv[1] = (char *)API_PTR2STR(config_file); func_argv[2] = (char *)API_PTR2STR(section); func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; + func_argv[4] = (value) ? (char *)value : NULL; rc = (int *) weechat_ruby_exec (script, WEECHAT_SCRIPT_EXEC_INT, @@ -1219,7 +1219,7 @@ weechat_ruby_api_config_section_create_option_cb (const void *pointer, void *dat func_argv[1] = (char *)API_PTR2STR(config_file); func_argv[2] = (char *)API_PTR2STR(section); func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; + func_argv[4] = (value) ? (char *)value : NULL; rc = (int *) weechat_ruby_exec (script, WEECHAT_SCRIPT_EXEC_INT, diff --git a/src/plugins/ruby/weechat-ruby.c b/src/plugins/ruby/weechat-ruby.c index d493ba524..52e1c5ffc 100644 --- a/src/plugins/ruby/weechat-ruby.c +++ b/src/plugins/ruby/weechat-ruby.c @@ -480,8 +480,11 @@ weechat_ruby_exec (struct t_plugin_script *script, { switch (format[i]) { - case 's': /* string */ - argv2[i] = rb_str_new2 ((char *)argv[i]); + case 's': /* string or null */ + if (argv[i]) + argv2[i] = rb_str_new2 ((char *)argv[i]); + else + argv2[i] = Qnil; break; case 'i': /* integer */ argv2[i] = INT2FIX (*((int *)argv[i])); diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c index b7e1cf24c..b5bfecbb1 100644 --- a/src/plugins/tcl/weechat-tcl-api.c +++ b/src/plugins/tcl/weechat-tcl-api.c @@ -1101,7 +1101,7 @@ weechat_tcl_api_config_section_read_cb (const void *pointer, void *data, func_argv[1] = (char *)API_PTR2STR(config_file); func_argv[2] = (char *)API_PTR2STR(section); func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; + func_argv[4] = (value) ? (char *)value : WEECHAT_NULL_STRING; rc = (int *) weechat_tcl_exec (script, WEECHAT_SCRIPT_EXEC_INT, @@ -1222,7 +1222,7 @@ weechat_tcl_api_config_section_create_option_cb (const void *pointer, void *data func_argv[1] = (char *)API_PTR2STR(config_file); func_argv[2] = (char *)API_PTR2STR(section); func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; + func_argv[4] = (value) ? (char *)value : WEECHAT_NULL_STRING; rc = (int *) weechat_tcl_exec (script, WEECHAT_SCRIPT_EXEC_INT,