Fix `mrb_get_argv()` to return array pointer every time; fix #4832

parent fb9e92e8
...@@ -542,15 +542,12 @@ MRB_API mrb_value* ...@@ -542,15 +542,12 @@ MRB_API mrb_value*
mrb_get_argv(mrb_state *mrb) mrb_get_argv(mrb_state *mrb)
{ {
mrb_int argc = mrb->c->ci->argc; mrb_int argc = mrb->c->ci->argc;
mrb_value *array_argv; mrb_value *array_argv = mrb->c->stack + 1;
if (argc < 0) { if (argc < 0) {
struct RArray *a = mrb_ary_ptr(mrb->c->stack[1]); struct RArray *a = mrb_ary_ptr(*array_argv);
array_argv = ARY_PTR(a); array_argv = ARY_PTR(a);
} }
else {
array_argv = NULL;
}
return array_argv; return array_argv;
} }
...@@ -594,9 +591,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -594,9 +591,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
char c; char c;
mrb_int i = 0; mrb_int i = 0;
va_list ap; va_list ap;
mrb_int argc = mrb_get_argc(mrb);
mrb_int arg_i = 0; mrb_int arg_i = 0;
mrb_value *array_argv = mrb_get_argv(mrb); mrb_int argc = mrb->c->ci->argc;
mrb_value *array_argv = mrb->c->stack+1;
mrb_bool argv_on_stack = argc >= 0;
mrb_bool opt = FALSE; mrb_bool opt = FALSE;
mrb_bool opt_skip = TRUE; mrb_bool opt_skip = TRUE;
mrb_bool given = TRUE; mrb_bool given = TRUE;
...@@ -604,10 +602,14 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -604,10 +602,14 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
mrb_bool reqkarg = FALSE; mrb_bool reqkarg = FALSE;
mrb_int needargc = 0; mrb_int needargc = 0;
if (!argv_on_stack) {
struct RArray *a = mrb_ary_ptr(*array_argv);
array_argv = ARY_PTR(a);
argc = ARY_LEN(a);
}
va_start(ap, format); va_start(ap, format);
#define ARGV \ #define ARGV array_argv
(array_argv ? array_argv : (mrb->c->stack + 1))
while ((c = *fmt++)) { while ((c = *fmt++)) {
switch (c) { switch (c) {
...@@ -931,7 +933,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ...@@ -931,7 +933,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
{ {
mrb_value **var; mrb_value **var;
mrb_int *pl; mrb_int *pl;
mrb_bool nocopy = altmode || array_argv ? TRUE : FALSE; mrb_bool nocopy = altmode || argv_on_stack ? TRUE : FALSE;
var = va_arg(ap, mrb_value**); var = va_arg(ap, mrb_value**);
pl = va_arg(ap, mrb_int*); pl = va_arg(ap, mrb_int*);
......
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