diff options
| author | Masaki Muranaka <[email protected]> | 2012-07-18 15:47:57 +0900 |
|---|---|---|
| committer | Masaki Muranaka <[email protected]> | 2012-07-18 15:47:57 +0900 |
| commit | f146fd039706c426c738fc1186a86fa1fca89a4a (patch) | |
| tree | d907a2584ffca628597d6d166fc0ea35aac8fb5e /src | |
| parent | 7bb71a7d5826accc50a521e770b5b7afe283ad90 (diff) | |
| download | mruby-f146fd039706c426c738fc1186a86fa1fca89a4a.tar.gz mruby-f146fd039706c426c738fc1186a86fa1fca89a4a.zip | |
MRB_FUNCALL_ARGC_MAX support. (refs comments in #324).
Diffstat (limited to 'src')
| -rw-r--r-- | src/class.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/class.c b/src/class.c index bf63198dd..762fa1591 100644 --- a/src/class.c +++ b/src/class.c @@ -7,7 +7,6 @@ #include "mruby.h" #include <stdarg.h> #include <stdio.h> -#include <assert.h> #include "mruby/class.h" #include "mruby/proc.h" #include "mruby/string.h" @@ -866,27 +865,38 @@ 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_value *args; +#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); - assert(args != 0); +#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++) { args[i] = va_arg(ap, mrb_value); } va_end(ap); - } else { - args = NULL; } + 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; } |
