Commit 4b9ef5da authored by Yukihiro Matsumoto's avatar Yukihiro Matsumoto

use no malloc in mrb_funcall; close #386

parent 8ae67d10
...@@ -21,12 +21,11 @@ ...@@ -21,12 +21,11 @@
//#define DISABLE_STRUCT /* Struct class */ //#define DISABLE_STRUCT /* Struct class */
//#define DISABLE_STDIO /* use of stdio */ //#define DISABLE_STDIO /* use of stdio */
//#define MRB_FUNCALL_ARGC_MAX 16 /* argv size in mrb_funcall */
#undef HAVE_UNISTD_H /* WINDOWS */ #undef HAVE_UNISTD_H /* WINDOWS */
#define HAVE_UNISTD_H /* LINUX */ #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 */ /* end of configuration */
#ifdef MRB_USE_FLOAT #ifdef MRB_USE_FLOAT
......
...@@ -862,26 +862,21 @@ mrb_method_search(mrb_state *mrb, struct RClass* c, mrb_sym mid) ...@@ -862,26 +862,21 @@ mrb_method_search(mrb_state *mrb, struct RClass* c, mrb_sym mid)
return m; return m;
} }
#ifndef MRB_FUNCALL_ARGC_MAX
#define MRB_FUNCALL_ARGC_MAX 16
#endif
mrb_value mrb_value
mrb_funcall(mrb_state *mrb, mrb_value self, const char *name, int argc, ...) 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]; mrb_value args[MRB_FUNCALL_ARGC_MAX];
#else
mrb_value *args = NULL;
#endif
mrb_value result;
va_list ap; va_list ap;
int i; int i;
if (argc != 0) { if (argc != 0) {
#if !defined(MRB_FUNCALL_ARGC_MAX)
args = mrb_malloc(mrb, sizeof(mrb_value) * argc);
#else
if (argc > MRB_FUNCALL_ARGC_MAX) { if (argc > MRB_FUNCALL_ARGC_MAX) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "Too long arguments. (limit=%d)\n", 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); va_start(ap, argc);
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
...@@ -889,16 +884,7 @@ mrb_funcall(mrb_state *mrb, mrb_value self, const char *name, int argc, ...) ...@@ -889,16 +884,7 @@ mrb_funcall(mrb_state *mrb, mrb_value self, const char *name, int argc, ...)
} }
va_end(ap); va_end(ap);
} }
return mrb_funcall_argv(mrb, self, name, argc, args);
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;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment