1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-26 12:56:37 +02:00

api: return allocated string in hook_info callback and function info_get

This commit is contained in:
Sébastien Helleu
2019-04-12 21:29:39 +02:00
parent c80dc2a5ca
commit 3d95217745
54 changed files with 724 additions and 526 deletions
+9 -12
View File
@@ -67,8 +67,6 @@
plugin_script_str2ptr (weechat_lua_plugin, \
LUA_CURRENT_SCRIPT_NAME, \
lua_function_name, __string)
#define API_STATIC_STRING(__string) \
plugin_script_get_static_string(&lua_data, __string);
#define API_RETURN_OK \
{ \
lua_pushinteger (L, 1); \
@@ -3082,14 +3080,14 @@ API_FUNC(hook_modifier_exec)
API_RETURN_STRING_FREE(result);
}
const char *
char *
weechat_lua_api_hook_info_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' }, *result;
char empty_arg[1] = { '\0' };
const char *ptr_function, *ptr_data;
script = (struct t_plugin_script *)pointer;
@@ -3101,12 +3099,10 @@ weechat_lua_api_hook_info_cb (const void *pointer, void *data,
func_argv[1] = (info_name) ? (char *)info_name : empty_arg;
func_argv[2] = (arguments) ? (char *)arguments : empty_arg;
result = (char *)weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
ptr_function,
"sss", func_argv);
return API_STATIC_STRING(result);
return (char *)weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
ptr_function,
"sss", func_argv);
}
return NULL;
@@ -4343,7 +4339,8 @@ API_FUNC(command_options)
API_FUNC(info_get)
{
const char *info_name, *arguments, *result;
const char *info_name, *arguments;
char *result;
API_INIT_FUNC(1, "info_get", API_RETURN_EMPTY);
if (lua_gettop (L) < 2)
@@ -4354,7 +4351,7 @@ API_FUNC(info_get)
result = weechat_info_get (info_name, arguments);
API_RETURN_STRING(result);
API_RETURN_STRING_FREE(result);
}
API_FUNC(info_get_hashtable)
+5 -8
View File
@@ -57,7 +57,6 @@ int lua_eval_mode = 0;
int lua_eval_send_input = 0;
int lua_eval_exec_commands = 0;
struct t_gui_buffer *lua_eval_buffer = NULL;
char *lua_eval_output = NULL;
#if LUA_VERSION_NUM >= 502
#define LUA_LOAD "load"
#else
@@ -1071,23 +1070,23 @@ weechat_lua_hdata_cb (const void *pointer, void *data,
* Returns lua info "lua_eval".
*/
const char *
char *
weechat_lua_info_eval_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
char *output;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
weechat_lua_eval (NULL, 0, 0, (arguments) ? arguments : "");
if (lua_eval_output)
free (lua_eval_output);
lua_eval_output = strdup (*lua_buffer_output);
output = strdup (*lua_buffer_output);
weechat_string_dyn_copy (lua_buffer_output, NULL);
return lua_eval_output;
return output;
}
/*
@@ -1303,8 +1302,6 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
if (lua_action_autoload_list)
free (lua_action_autoload_list);
weechat_string_dyn_free (lua_buffer_output, 1);
if (lua_eval_output)
free (lua_eval_output);
return WEECHAT_RC_OK;
}