mirror of
https://github.com/weechat/weechat.git
synced 2026-07-01 15:26:37 +02:00
scripts: do not allocate memory when converting pointers to strings
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+156
-221
File diff suppressed because it is too large
Load Diff
+202
-222
File diff suppressed because it is too large
Load Diff
+838
-846
File diff suppressed because it is too large
Load Diff
@@ -487,11 +487,11 @@ weechat_php_func_map_get (const char* func_name)
|
||||
return weechat_hashtable_get (weechat_php_func_map, func_name);
|
||||
}
|
||||
|
||||
char *
|
||||
const char *
|
||||
weechat_php_func_map_add (zval *ofunc)
|
||||
{
|
||||
zval *func;
|
||||
char *func_name;
|
||||
const char *func_name;
|
||||
|
||||
if (!weechat_php_func_map)
|
||||
{
|
||||
|
||||
@@ -67,7 +67,7 @@ extern struct t_hashtable *weechat_php_array_to_hashtable (zval* arr,
|
||||
const char *type_keys,
|
||||
const char *type_values);
|
||||
extern zval *weechat_php_func_map_get (const char *func_name);
|
||||
extern char *weechat_php_func_map_add (zval *ofunc);
|
||||
extern const char *weechat_php_func_map_add (zval *ofunc);
|
||||
extern void *weechat_php_exec (struct t_plugin_script *script,
|
||||
int ret_type,
|
||||
const char *function,
|
||||
|
||||
@@ -324,22 +324,24 @@ plugin_script_valid (struct t_plugin_script *scripts,
|
||||
* Converts a pointer to a string for usage in a script.
|
||||
*
|
||||
* Returns string with format "0x12345678".
|
||||
*
|
||||
* Note: result must be freed after use.
|
||||
*/
|
||||
|
||||
char *
|
||||
const char *
|
||||
plugin_script_ptr2str (void *pointer)
|
||||
{
|
||||
char pointer_str[128];
|
||||
static char str_pointer[32][32];
|
||||
static int index_pointer = 0;
|
||||
|
||||
index_pointer = (index_pointer + 1) % 32;
|
||||
str_pointer[index_pointer][0] = '\0';
|
||||
|
||||
if (!pointer)
|
||||
return strdup ("");
|
||||
return str_pointer[index_pointer];
|
||||
|
||||
snprintf (pointer_str, sizeof (pointer_str),
|
||||
snprintf (str_pointer[index_pointer], sizeof (str_pointer[index_pointer]),
|
||||
"0x%lx", (long unsigned int)pointer);
|
||||
|
||||
return strdup (pointer_str);
|
||||
return str_pointer[index_pointer];
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -119,7 +119,7 @@ extern void plugin_script_init (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script_data *plugin_data);
|
||||
extern int plugin_script_valid (struct t_plugin_script *scripts,
|
||||
struct t_plugin_script *script);
|
||||
extern char *plugin_script_ptr2str (void *pointer);
|
||||
extern const char *plugin_script_ptr2str (void *pointer);
|
||||
extern void *plugin_script_str2ptr (struct t_weechat_plugin *weechat_plugin,
|
||||
const char *script_name,
|
||||
const char *function_name,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+213
-284
File diff suppressed because it is too large
Load Diff
+200
-222
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user