From f57f0699d7193571233735ba691ba19fc072b7dc Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 21 Jun 2015 22:03:01 +0300 Subject: Fix typeof to not change untyped param to scalar. --- builtin.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index 61a4398b..942a36dd 100644 --- a/builtin.c +++ b/builtin.c @@ -3872,7 +3872,6 @@ do_typeof(int nargs) { NODE *arg; char *res = "unknown"; - int null_str_flags = (STRCUR|STRING|NUMCUR|NUMBER); arg = POP(); switch (arg->type) { @@ -3884,7 +3883,7 @@ do_typeof(int nargs) break; case Node_val: case Node_var: - if ((arg->flags & null_str_flags) == null_str_flags) + if (arg == Nnull_string) res = "untyped"; else if ((arg->flags & STRING) != 0) res = "scalar_s"; -- cgit v1.2.3 From a3e0954544c7cc4f34b710ac863d56419b57915a Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Mon, 22 Jun 2015 22:56:06 +0300 Subject: Fix typeof to work correctly on subarrays. --- builtin.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index 942a36dd..e476ec99 100644 --- a/builtin.c +++ b/builtin.c @@ -3872,11 +3872,13 @@ do_typeof(int nargs) { NODE *arg; char *res = "unknown"; + bool deref = true; arg = POP(); switch (arg->type) { case Node_var_array: res = "array"; + deref = false; break; case Node_typedregex: res = "regexp"; @@ -3899,7 +3901,8 @@ do_typeof(int nargs) break; } - DEREF(arg); + if (deref) + DEREF(arg); return make_string(res, strlen(res)); } -- cgit v1.2.3 From 0302c2f241b0a4ab47a0e60213c132c4135fed93 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 25 Jun 2015 22:21:20 +0300 Subject: More work straightening out typeof, including tests. --- builtin.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index e476ec99..1dd7dcbe 100644 --- a/builtin.c +++ b/builtin.c @@ -2144,7 +2144,9 @@ do_print(int nargs, int redirtype) fatal(_("attempt to use array `%s' in a scalar context"), array_vname(tmp)); } - if ((tmp->flags & (NUMBER|STRING)) == NUMBER) { + if (tmp->type == Node_typedregex) + args_array[i] = force_string(tmp); + else if ((tmp->flags & (NUMBER|STRING)) == NUMBER) { if (OFMTidx == CONVFMTidx) args_array[i] = force_string(tmp); else @@ -3877,11 +3879,14 @@ do_typeof(int nargs) arg = POP(); switch (arg->type) { case Node_var_array: + /* Node_var_array is never UPREF'ed */ res = "array"; deref = false; break; case Node_typedregex: + /* Op_push_re does not UPREF */ res = "regexp"; + deref = false; break; case Node_val: case Node_var: @@ -3894,6 +3899,7 @@ do_typeof(int nargs) break; case Node_var_new: res = "untyped"; + deref = false; break; default: fatal(_("typeof: unknown argument type `%s'"), -- cgit v1.2.3