summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro Matsumoto <[email protected]>2012-07-19 17:45:13 +0900
committerYukihiro Matsumoto <[email protected]>2012-07-19 17:45:13 +0900
commit4b9ef5dabee09115edc15ecad05b335ecfaf598d (patch)
tree4e4cd8efd8f8bbecfd1dfc1bc7763b48cfb312d0
parent8ae67d10b33aef56eab8ccd13b2a7471968df1ee (diff)
downloadmruby-4b9ef5dabee09115edc15ecad05b335ecfaf598d.tar.gz
mruby-4b9ef5dabee09115edc15ecad05b335ecfaf598d.zip
use no malloc in mrb_funcall; close #386
-rw-r--r--include/mrbconf.h5
-rw-r--r--src/class.c24
2 files changed, 7 insertions, 22 deletions
diff --git a/include/mrbconf.h b/include/mrbconf.h
index 757192d89..cf8217b23 100644
--- a/include/mrbconf.h
+++ b/include/mrbconf.h
@@ -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
diff --git a/src/class.c b/src/class.c
index 762fa1591..38eb5ea1f 100644
--- a/src/class.c
+++ b/src/class.c
@@ -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);
}