summaryrefslogtreecommitdiff
path: root/src/plugins/scripts
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2008-03-23 23:00:04 +0100
committerSebastien Helleu <flashcode@flashtux.org>2008-03-23 23:00:04 +0100
commit57323fa71effad75d78b36a45d5457b1bd782963 (patch)
tree50d7a5bacacebcdf59d5bf38dff84c83bf557d31 /src/plugins/scripts
parent14feea7ab84df3e367bc3732e8ba1470e1a3f5a7 (diff)
downloadweechat-57323fa71effad75d78b36a45d5457b1bd782963.zip
Removed sizeof(char) and useless type casts from void* to another pointer type (patch from Leonid Evdokimov)
Diffstat (limited to 'src/plugins/scripts')
-rw-r--r--src/plugins/scripts/lua/weechat-lua.c2
-rw-r--r--src/plugins/scripts/perl/weechat-perl.c58
-rw-r--r--src/plugins/scripts/python/weechat-python.c83
-rw-r--r--src/plugins/scripts/ruby/weechat-ruby.c2
-rw-r--r--src/plugins/scripts/script-api.c8
-rw-r--r--src/plugins/scripts/script-callback.c2
-rw-r--r--src/plugins/scripts/script.c22
7 files changed, 89 insertions, 88 deletions
diff --git a/src/plugins/scripts/lua/weechat-lua.c b/src/plugins/scripts/lua/weechat-lua.c
index 9a00906e4..50458c209 100644
--- a/src/plugins/scripts/lua/weechat-lua.c
+++ b/src/plugins/scripts/lua/weechat-lua.c
@@ -105,7 +105,7 @@ weechat_lua_exec (struct t_plugin_script *script,
ret_value = strdup ((char *) lua_tostring (lua_current_interpreter, -1));
else if (ret_type == WEECHAT_SCRIPT_EXEC_INT)
{
- ret_i = (int *)malloc (sizeof (int));
+ ret_i = malloc (sizeof (*ret_i));
if (ret_i)
*ret_i = lua_tonumber (lua_current_interpreter, -1);
ret_value = ret_i;
diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c
index 1b2876c03..2ab653233 100644
--- a/src/plugins/scripts/perl/weechat-perl.c
+++ b/src/plugins/scripts/perl/weechat-perl.c
@@ -119,9 +119,9 @@ weechat_perl_exec (struct t_plugin_script *script,
#ifndef MULTIPLICITY
length = strlen (script->interpreter) + strlen (function) + 3;
- func = (char *)malloc (length * sizeof (char));
+ func = malloc (length);
if (!func)
- return NULL;
+ return NULL;
snprintf (func, length, "%s::%s", (char *) script->interpreter, function);
#else
(void) length;
@@ -135,7 +135,7 @@ weechat_perl_exec (struct t_plugin_script *script,
/* are we loading the script file ? */
if (strcmp (function, "weechat_perl_load_eval_file") != 0)
- perl_current_script = script;
+ perl_current_script = script;
count = perl_call_argv (func, G_EVAL | G_SCALAR, argv);
ret_value = NULL;
@@ -149,42 +149,42 @@ weechat_perl_exec (struct t_plugin_script *script,
weechat_gettext ("%s%s: error: %s"),
weechat_prefix ("error"), "perl", SvPV_nolen (ERRSV));
(void) POPs; /* poping the 'undef' */
- mem_err = 0;
+ mem_err = 0;
}
else
{
if (count != 1)
- {
+ {
weechat_printf (NULL,
weechat_gettext ("%s%s: function \"%s\" must "
"return one valid value (%d)"),
weechat_prefix ("error"), "perl", function, count);
- mem_err = 0;
- }
+ mem_err = 0;
+ }
else
- {
- if (ret_type == WEECHAT_SCRIPT_EXEC_STRING)
- {
- ret_s = newSVsv(POPs);
- ret_value = strdup (SvPV_nolen (ret_s));
- SvREFCNT_dec (ret_s);
- }
- else if (ret_type == WEECHAT_SCRIPT_EXEC_INT)
- {
- ret_i = (int *)malloc (sizeof (int));
- if (ret_i)
- *ret_i = POPi;
- ret_value = ret_i;
- }
- else
- {
- weechat_printf (NULL,
+ {
+ if (ret_type == WEECHAT_SCRIPT_EXEC_STRING)
+ {
+ ret_s = newSVsv(POPs);
+ ret_value = strdup (SvPV_nolen (ret_s));
+ SvREFCNT_dec (ret_s);
+ }
+ else if (ret_type == WEECHAT_SCRIPT_EXEC_INT)
+ {
+ ret_i = malloc (sizeof (*ret_i));
+ if (ret_i)
+ *ret_i = POPi;
+ ret_value = ret_i;
+ }
+ else
+ {
+ weechat_printf (NULL,
weechat_gettext ("%s%s: function \"%s\" is "
"internally misused"),
weechat_prefix ("error"), "perl", function);
- mem_err = 0;
- }
- }
+ mem_err = 0;
+ }
+ }
}
PUTBACK;
@@ -197,11 +197,11 @@ weechat_perl_exec (struct t_plugin_script *script,
if (!ret_value && (mem_err == 1))
{
- weechat_printf (NULL,
+ weechat_printf (NULL,
weechat_gettext ("%s%s: not enough memory in function "
"\"%s\""),
weechat_prefix ("error"), "perl", function);
- return NULL;
+ return NULL;
}
return ret_value;
diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c
index 0b7dd6c4f..b259427be 100644
--- a/src/plugins/scripts/python/weechat-python.c
+++ b/src/plugins/scripts/python/weechat-python.c
@@ -137,7 +137,7 @@ weechat_python_exec (struct t_plugin_script *script,
else if (PyInt_Check (rc) && (ret_type == WEECHAT_SCRIPT_EXEC_INT))
{
- ret_i = (int *)malloc (sizeof (int));
+ ret_i = malloc (sizeof (*ret_i));
if (ret_i)
*ret_i = (int) PyInt_AsLong(rc);
ret_value = ret_i;
@@ -277,8 +277,8 @@ weechat_python_load (char *filename)
"sub-interpreter"),
weechat_prefix ("error"), "python");
fclose (fp);
- /* PyEval_ReleaseLock (); */
- return 0;
+ /* PyEval_ReleaseLock (); */
+ return 0;
}
/* PyThreadState_Swap (python_current_interpreter); */
@@ -293,10 +293,10 @@ weechat_python_load (char *filename)
weechat_prefix ("error"), "python");
fclose (fp);
- Py_EndInterpreter (python_current_interpreter);
+ Py_EndInterpreter (python_current_interpreter);
/* PyEval_ReleaseLock (); */
-
- return 0;
+
+ return 0;
}
/* adding $weechat_dir/python in $PYTHONPATH */
@@ -304,19 +304,19 @@ weechat_python_load (char *filename)
w_home = weechat_info_get ("weechat_dir");
if (w_home)
{
- len = strlen (w_home) + 1 + strlen("python") + 1;
- p_home = (char *)malloc (len * sizeof (char));
- if (p_home)
- {
- snprintf (p_home, len, "%s/python", w_home);
- path = PyString_FromString (p_home);
- if (path != NULL)
- {
- PyList_Insert (python_path, 0, path);
- Py_DECREF (path);
- }
- free (p_home);
- }
+ len = strlen (w_home) + 1 + strlen("python") + 1;
+ p_home = malloc (len);
+ if (p_home)
+ {
+ snprintf (p_home, len, "%s/python", w_home);
+ path = PyString_FromString (p_home);
+ if (path != NULL)
+ {
+ PyList_Insert (python_path, 0, path);
+ Py_DECREF (path);
+ }
+ free (p_home);
+ }
}
/* define some constants */
@@ -344,15 +344,15 @@ weechat_python_load (char *filename)
}
else
{
- if (PySys_SetObject("stdout", weechat_outputs) == -1)
+ if (PySys_SetObject("stdout", weechat_outputs) == -1)
{
- weechat_printf (NULL,
+ weechat_printf (NULL,
weechat_gettext ("%s%s: unable to redirect stdout"),
weechat_prefix ("error"), "python");
}
- if (PySys_SetObject("stderr", weechat_outputs) == -1)
+ if (PySys_SetObject("stderr", weechat_outputs) == -1)
{
- weechat_printf (NULL,
+ weechat_printf (NULL,
weechat_gettext ("%s%s: unable to redirect stderr"),
weechat_prefix ("error"), "python");
}
@@ -365,22 +365,22 @@ weechat_python_load (char *filename)
weechat_printf (NULL,
weechat_gettext ("%s%s: unable to parse file \"%s\""),
weechat_prefix ("error"), "python", filename);
- fclose (fp);
-
- if (PyErr_Occurred ()) PyErr_Print ();
- Py_EndInterpreter (python_current_interpreter);
- /* PyEval_ReleaseLock (); */
-
- /* if script was registered, removing from list */
- if (python_current_script != NULL)
- {
- script_remove (weechat_python_plugin, &python_scripts,
- python_current_script);
- }
+ fclose (fp);
+
+ if (PyErr_Occurred ())
+ PyErr_Print ();
+ Py_EndInterpreter (python_current_interpreter);
+ /* PyEval_ReleaseLock (); */
+
+ /* if script was registered, removing from list */
+ if (python_current_script != NULL)
+ script_remove (weechat_python_plugin, &python_scripts,
+ python_current_script);
return 0;
}
- if (PyErr_Occurred ()) PyErr_Print ();
+ if (PyErr_Occurred ())
+ PyErr_Print ();
fclose (fp);
@@ -391,11 +391,12 @@ weechat_python_load (char *filename)
"found (or failed) in file \"%s\""),
weechat_prefix ("error"), "python", filename);
- if (PyErr_Occurred ()) PyErr_Print ();
- Py_EndInterpreter (python_current_interpreter);
- /* PyEval_ReleaseLock (); */
-
- return 0;
+ if (PyErr_Occurred ())
+ PyErr_Print ();
+ Py_EndInterpreter (python_current_interpreter);
+ /* PyEval_ReleaseLock (); */
+
+ return 0;
}
python_current_script->interpreter = (PyThreadState *) python_current_interpreter;
diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c
index 1736ecda6..dc32998c6 100644
--- a/src/plugins/scripts/ruby/weechat-ruby.c
+++ b/src/plugins/scripts/ruby/weechat-ruby.c
@@ -198,7 +198,7 @@ weechat_ruby_exec (struct t_plugin_script *script,
}
else if ((TYPE(rc) == T_FIXNUM) && (ret_type == WEECHAT_SCRIPT_EXEC_INT))
{
- ret_i = (int *)malloc (sizeof (int));
+ ret_i = malloc (sizeof (*ret_i));
if (ret_i)
*ret_i = NUM2INT(rc);
ret_value = ret_i;
diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c
index 7f8f42219..52bb09df3 100644
--- a/src/plugins/scripts/script-api.c
+++ b/src/plugins/scripts/script-api.c
@@ -911,8 +911,8 @@ script_api_config_get_plugin (struct t_weechat_plugin *weechat_plugin,
{
char *option_fullname, *return_value;
- option_fullname = (char *)malloc ((strlen (script->name) +
- strlen (option) + 2) * sizeof (char));
+ option_fullname = malloc ((strlen (script->name) +
+ strlen (option) + 2));
if (!option_fullname)
return NULL;
@@ -939,8 +939,8 @@ script_api_config_set_plugin (struct t_weechat_plugin *weechat_plugin,
char *option_fullname;
int return_code;
- option_fullname = (char *)malloc ((strlen (script->name) +
- strlen (option) + 2) * sizeof (char));
+ option_fullname = malloc ((strlen (script->name) +
+ strlen (option) + 2));
if (!option_fullname)
return 0;
diff --git a/src/plugins/scripts/script-callback.c b/src/plugins/scripts/script-callback.c
index 537375820..fb9ae66ca 100644
--- a/src/plugins/scripts/script-callback.c
+++ b/src/plugins/scripts/script-callback.c
@@ -36,7 +36,7 @@ script_callback_alloc ()
{
struct t_script_callback *new_script_callback;
- new_script_callback = (struct t_script_callback *)malloc (sizeof (struct t_script_callback));
+ new_script_callback = malloc (sizeof (*new_script_callback));
if (new_script_callback)
{
new_script_callback->script = NULL;
diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c
index 53f9dc425..c7c5d507f 100644
--- a/src/plugins/scripts/script.c
+++ b/src/plugins/scripts/script.c
@@ -101,7 +101,7 @@ script_init (struct t_weechat_plugin *weechat_plugin,
/* add hook for config option */
length = strlen (weechat_plugin->name) + 32;
- string = (char *)malloc (length * sizeof (char));
+ string = malloc (length);
if (string)
{
snprintf (string, length, "%s.%s",
@@ -114,7 +114,7 @@ script_init (struct t_weechat_plugin *weechat_plugin,
/* create directories in WeeChat home */
weechat_mkdir_home (weechat_plugin->name, 0755);
length = strlen (weechat_plugin->name) + strlen ("/autoload") + 1;
- string = (char *)malloc (length * sizeof (char));
+ string = malloc (length);
if (string)
{
snprintf (string, length, "%s/autoload", weechat_plugin->name);
@@ -124,7 +124,7 @@ script_init (struct t_weechat_plugin *weechat_plugin,
/* add command */
length = strlen (completion) + strlen (weechat_plugin->name) + 16;
- string = (char *)malloc (length * sizeof (char));
+ string = malloc (length);
if (string)
{
snprintf (string, length, "%s|%%(%s_script)",
@@ -146,7 +146,7 @@ script_init (struct t_weechat_plugin *weechat_plugin,
/* add completion */
length = strlen (weechat_plugin->name) + 16;
- string = (char *)malloc (length * sizeof (char));
+ string = malloc (length);
if (string)
{
snprintf (string, length, "%s_script", weechat_plugin->name);
@@ -214,7 +214,7 @@ script_auto_load (struct t_weechat_plugin *weechat_plugin,
if (!dir_home)
return;
dir_length = strlen (dir_home) + strlen (weechat_plugin->name) + 16;
- dir_name = (char *)malloc (dir_length * sizeof (char));
+ dir_name = malloc (dir_length);
if (!dir_name)
return;
@@ -264,7 +264,7 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin,
if (!dir_home)
return NULL;
length = strlen (dir_home) + strlen (filename + 1) + 1;
- final_name = (char *)malloc (length * sizeof (char));
+ final_name = malloc (length);
if (final_name)
{
snprintf (final_name, length, "%s%s", dir_home, filename + 1);
@@ -279,7 +279,7 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin,
/* try WeeChat user's autoload dir */
length = strlen (dir_home) + strlen (weechat_plugin->name) + 8 +
strlen (filename) + 16;
- final_name = (char *)malloc (length * sizeof (char));
+ final_name = malloc (length);
if (final_name)
{
snprintf (final_name, length,
@@ -293,7 +293,7 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin,
/* try WeeChat language user's dir */
length = strlen (dir_home) + strlen (weechat_plugin->name) +
strlen (filename) + 16;
- final_name = (char *)malloc (length * sizeof (char));
+ final_name = malloc (length);
if (final_name)
{
snprintf (final_name, length,
@@ -305,7 +305,7 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin,
/* try WeeChat user's dir */
length = strlen (dir_home) + strlen (filename) + 16;
- final_name = (char *)malloc (length * sizeof (char));
+ final_name = malloc (length);
if (final_name)
{
snprintf (final_name, length,
@@ -322,7 +322,7 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin,
{
length = strlen (dir_system) + strlen (weechat_plugin->name) +
strlen (filename) + 16;
- final_name = (char *)malloc (length * sizeof (char));
+ final_name = malloc (length);
if (final_name)
{
snprintf (final_name,length,
@@ -369,7 +369,7 @@ script_add (struct t_weechat_plugin *weechat_plugin,
license, name, weechat_plugin->license);
}
- new_script = (struct t_plugin_script *)malloc (sizeof (struct t_plugin_script));
+ new_script = malloc (sizeof (*new_script));
if (new_script)
{
new_script->filename = strdup (filename);