diff options
| author | Yukihiro Matsumoto <[email protected]> | 2012-07-19 08:24:10 +0900 |
|---|---|---|
| committer | Yukihiro Matsumoto <[email protected]> | 2012-07-19 08:24:10 +0900 |
| commit | c697e111c8a302ce13da8d25330fca07a73767fa (patch) | |
| tree | 2355622dbe9b95d028158f0924c0b794335b790a | |
| parent | b60baedae5e1f00646987c89791d4577ae961410 (diff) | |
| parent | a7e0f9f6408f3c1a081ca221615f2e675deb2976 (diff) | |
| download | mruby-c697e111c8a302ce13da8d25330fca07a73767fa.tar.gz mruby-c697e111c8a302ce13da8d25330fca07a73767fa.zip | |
Merge branch 'master' of github.com:mruby/mruby
| -rw-r--r-- | include/mrbconf.h | 4 | ||||
| -rw-r--r-- | src/class.c | 38 |
2 files changed, 31 insertions, 11 deletions
diff --git a/include/mrbconf.h b/include/mrbconf.h index 5d307e66f..757192d89 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -23,6 +23,10 @@ #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 diff --git a/src/class.c b/src/class.c index 7f53b7a2b..762fa1591 100644 --- a/src/class.c +++ b/src/class.c @@ -863,26 +863,42 @@ mrb_method_search(mrb_state *mrb, struct RClass* c, mrb_sym mid) } 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, ...) { - mrb_value args[16]; +#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) { - for (i=0; i<5; i++) { - args[i] = mrb_nil_value(); - } - } - else { + 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); - // assert(argc < 16); - for (i=0; i<argc; i++) { + for (i = 0; i < argc; i++) { args[i] = va_arg(ap, mrb_value); } 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; } |
