use no malloc in mrb_funcall; close #386

This commit is contained in:
Yukihiro Matsumoto
2012-07-19 17:45:13 +09:00
parent 8ae67d10b3
commit 4b9ef5dabe
2 changed files with 7 additions and 22 deletions
+2 -3
View File
@@ -21,12 +21,11 @@
//#define DISABLE_STRUCT /* Struct class */
//#define DISABLE_STDIO /* use of stdio */
//#define MRB_FUNCALL_ARGC_MAX 16 /* argv size in mrb_funcall */
#undef HAVE_UNISTD_H /* WINDOWS */
#define HAVE_UNISTD_H /* LINUX */
#define MRB_FUNCALL_ARGC_MAX 16U /* Allocate arrays using auto variable. */
//#undef MRB_FUNCALL_ARGC_MAX /* Allocate arrays using mrb_malloc if undefned. */
/* end of configuration */
#ifdef MRB_USE_FLOAT
+5 -19
View File
@@ -862,26 +862,21 @@ mrb_method_search(mrb_state *mrb, struct RClass* c, mrb_sym mid)
return m;
}
#ifndef MRB_FUNCALL_ARGC_MAX
#define MRB_FUNCALL_ARGC_MAX 16
#endif
mrb_value
mrb_funcall(mrb_state *mrb, mrb_value self, const char *name, int argc, ...)
{
#if defined(MRB_FUNCALL_ARGC_MAX)
mrb_value args[MRB_FUNCALL_ARGC_MAX];
#else
mrb_value *args = NULL;
#endif
mrb_value result;
va_list ap;
int i;
if (argc != 0) {
#if !defined(MRB_FUNCALL_ARGC_MAX)
args = mrb_malloc(mrb, sizeof(mrb_value) * argc);
#else
if (argc > MRB_FUNCALL_ARGC_MAX) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "Too long arguments. (limit=%d)\n", MRB_FUNCALL_ARGC_MAX);
}
#endif
va_start(ap, argc);
for (i = 0; i < argc; i++) {
@@ -889,16 +884,7 @@ mrb_funcall(mrb_state *mrb, mrb_value self, const char *name, int argc, ...)
}
va_end(ap);
}
result = mrb_funcall_argv(mrb, self, name, argc, args);
#if !defined(MRB_FUNCALL_ARGC_MAX)
if (args != NULL) {
mrb_free(mrb, args);
}
#endif
return result;
return mrb_funcall_argv(mrb, self, name, argc, args);
}