summaryrefslogtreecommitdiff
path: root/src/plugins/python
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/python')
-rw-r--r--src/plugins/python/weechat-python-api.c22
-rw-r--r--src/plugins/python/weechat-python.c26
2 files changed, 22 insertions, 26 deletions
diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c
index 572ce70aa..74ca1b33f 100644
--- a/src/plugins/python/weechat-python-api.c
+++ b/src/plugins/python/weechat-python-api.c
@@ -59,8 +59,6 @@
plugin_script_str2ptr (weechat_python_plugin, \
PYTHON_CURRENT_SCRIPT_NAME, \
python_function_name, __string)
-#define API_STATIC_STRING(__string) \
- plugin_script_get_static_string(&python_data, __string);
#define API_RETURN_OK return PyLong_FromLong((long)1)
#define API_RETURN_ERROR return PyLong_FromLong ((long)0)
#define API_RETURN_EMPTY \
@@ -3024,14 +3022,14 @@ API_FUNC(hook_modifier_exec)
API_RETURN_STRING_FREE(result);
}
-const char *
+char *
weechat_python_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;
@@ -3043,12 +3041,10 @@ weechat_python_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_python_exec (script,
- WEECHAT_SCRIPT_EXEC_STRING,
- ptr_function,
- "sss", func_argv);
-
- return API_STATIC_STRING(result);
+ return (char *)weechat_python_exec (script,
+ WEECHAT_SCRIPT_EXEC_STRING,
+ ptr_function,
+ "sss", func_argv);
}
return NULL;
@@ -4278,8 +4274,8 @@ API_FUNC(command_options)
API_FUNC(info_get)
{
- char *info_name, *arguments;
- const char *result;
+ char *info_name, *arguments, *result;
+ PyObject *return_value;
API_INIT_FUNC(1, "info_get", API_RETURN_EMPTY);
info_name = NULL;
@@ -4289,7 +4285,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)
diff --git a/src/plugins/python/weechat-python.c b/src/plugins/python/weechat-python.c
index 8aeacec0c..f36899dce 100644
--- a/src/plugins/python/weechat-python.c
+++ b/src/plugins/python/weechat-python.c
@@ -57,7 +57,6 @@ int python_eval_mode = 0;
int python_eval_send_input = 0;
int python_eval_exec_commands = 0;
struct t_gui_buffer *python_eval_buffer = NULL;
-char *python_eval_output = NULL;
#define PYTHON_EVAL_SCRIPT \
"import weechat\n" \
"\n" \
@@ -144,8 +143,7 @@ char *python_action_autoload_list = NULL;
char *
weechat_python_get_python2_bin ()
{
- const char *dir_separator;
- char *py2_bin, *path, **paths, bin[4096];
+ char *dir_separator, *py2_bin, *path, **paths, bin[4096];
char *versions[] = { "2.7", "2.6", "2.5", "2.4", "2.3", "2.2", "2", NULL };
int num_paths, i, j, rc;
struct stat stat_buf;
@@ -185,6 +183,9 @@ weechat_python_get_python2_bin ()
}
}
+ if (dir_separator)
+ free (dir_separator);
+
if (!py2_bin)
py2_bin = strdup ("python");
@@ -753,7 +754,7 @@ weechat_python_load (const char *filename, const char *code)
#endif /* PY_MAJOR_VERSION >= 3 */
FILE *fp;
PyObject *python_path, *path, *module_main, *globals, *rc;
- const char *weechat_home;
+ char *weechat_home;
char *str_home;
int len;
@@ -842,6 +843,7 @@ weechat_python_load (const char *filename, const char *code)
}
free (str_home);
}
+ free (weechat_home);
}
weechat_python_set_output ();
@@ -1332,7 +1334,7 @@ weechat_python_hdata_cb (const void *pointer, void *data,
* Returns python info "python2_bin".
*/
-const char *
+char *
weechat_python_info_python2_bin_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@@ -1355,30 +1357,30 @@ weechat_python_info_python2_bin_cb (const void *pointer, void *data,
python2_bin = weechat_python_get_python2_bin ();
}
}
- return python2_bin;
+ return (python2_bin) ? strdup (python2_bin) : NULL;
}
/*
* Returns python info "python_eval".
*/
-const char *
+char *
weechat_python_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_python_eval (NULL, 0, 0, (arguments) ? arguments : "");
- if (python_eval_output)
- free (python_eval_output);
- python_eval_output = strdup (*python_buffer_output);
+ output = strdup (*python_buffer_output);
weechat_string_dyn_copy (python_buffer_output, NULL);
- return python_eval_output;
+ return output;
}
/*
@@ -1658,8 +1660,6 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
if (python_action_autoload_list)
free (python_action_autoload_list);
weechat_string_dyn_free (python_buffer_output, 1);
- if (python_eval_output)
- free (python_eval_output);
return WEECHAT_RC_OK;
}