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. --- ChangeLog | 13 +++++++++++++ awk.h | 1 + awkgram.c | 6 +++++- awkgram.y | 6 +++++- builtin.c | 3 +-- eval.c | 1 + interpret.h | 9 ++++++--- test/ChangeLog | 5 +++++ test/Makefile.am | 4 +++- test/Makefile.in | 9 ++++++++- test/Maketests | 5 +++++ test/typeof2.awk | 20 ++++++++++++++++++++ test/typeof2.ok | 6 ++++++ 13 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 test/typeof2.awk create mode 100644 test/typeof2.ok diff --git a/ChangeLog b/ChangeLog index 586ea3ee..b00a5c22 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2015-06-21 Arnold D. Robbins + + Fixes for typeof - Don't let typeof change an untyped variable + into a scalar. + + * awk.h (opcodeval): Add Op_push_arg_untyped. + * awkgram.y (snode): Separate out case for do_typeof, use + Op_push_arg_untyped. + * builtin.c (do_typeof): Arg will be equal to Nnull_string + if it's untyped. + * eval.c (optypes): Add Op_push_arg_untyped. + * interpret.h (r_interpret): Add Op_push_arg_untyped handling. + 2015-06-19 Arnold D. Robbins * builtin.c (do_isarray): Minor edit to lint warning. diff --git a/awk.h b/awk.h index 5acd33d8..0c42f2e7 100644 --- a/awk.h +++ b/awk.h @@ -643,6 +643,7 @@ typedef enum opcodeval { Op_push, /* scalar variable */ Op_push_arg, /* variable type (scalar or array) argument to built-in */ + Op_push_arg_untyped, /* like Op_push_arg, but for typeof */ Op_push_i, /* number, string */ Op_push_re, /* regex */ Op_push_array, diff --git a/awkgram.c b/awkgram.c index 12f648ed..ade5ed6a 100644 --- a/awkgram.c +++ b/awkgram.c @@ -6697,10 +6697,14 @@ snode(INSTRUCTION *subn, INSTRUCTION *r) if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push) arg->nexti->opcode = Op_push_arg; /* argument may be array */ } - } else if (r->builtin == do_isarray || r->builtin == do_typeof) { + } else if (r->builtin == do_isarray) { arg = subn->nexti; if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push) arg->nexti->opcode = Op_push_arg; /* argument may be array */ + } else if (r->builtin == do_typeof) { + arg = subn->nexti; + if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push) + arg->nexti->opcode = Op_push_arg_untyped; /* argument may be untyped */ } else if (r->builtin == do_intdiv #ifdef HAVE_MPFR || r->builtin == MPF(intdiv) diff --git a/awkgram.y b/awkgram.y index 28541f86..d2503697 100644 --- a/awkgram.y +++ b/awkgram.y @@ -4277,10 +4277,14 @@ snode(INSTRUCTION *subn, INSTRUCTION *r) if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push) arg->nexti->opcode = Op_push_arg; /* argument may be array */ } - } else if (r->builtin == do_isarray || r->builtin == do_typeof) { + } else if (r->builtin == do_isarray) { arg = subn->nexti; if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push) arg->nexti->opcode = Op_push_arg; /* argument may be array */ + } else if (r->builtin == do_typeof) { + arg = subn->nexti; + if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push) + arg->nexti->opcode = Op_push_arg_untyped; /* argument may be untyped */ } else if (r->builtin == do_intdiv #ifdef HAVE_MPFR || r->builtin == MPF(intdiv) 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"; diff --git a/eval.c b/eval.c index 73bd56cb..c6008580 100644 --- a/eval.c +++ b/eval.c @@ -338,6 +338,7 @@ static struct optypetab { { "Op_indirect_func_call", NULL }, { "Op_push", NULL }, { "Op_push_arg", NULL }, + { "Op_push_arg_untyped", NULL }, { "Op_push_i", NULL }, { "Op_push_re", NULL }, { "Op_push_array", NULL }, diff --git a/interpret.h b/interpret.h index 03532f43..554a7663 100644 --- a/interpret.h +++ b/interpret.h @@ -144,6 +144,7 @@ top: case Op_push: case Op_push_arg: + case Op_push_arg_untyped: { NODE *save_symbol; bool isparam = false; @@ -175,8 +176,10 @@ top: case Node_var_new: uninitialized_scalar: - m->type = Node_var; - m->var_value = dupnode(Nnull_string); + if (op != Op_push_arg_untyped) { + m->type = Node_var; + m->var_value = dupnode(Nnull_string); + } if (do_lint) lintwarn(isparam ? _("reference to uninitialized argument `%s'") : @@ -187,7 +190,7 @@ uninitialized_scalar: break; case Node_var_array: - if (op == Op_push_arg) + if (op == Op_push_arg || op == Op_push_arg_untyped) PUSH(m); else fatal(_("attempt to use array `%s' in a scalar context"), diff --git a/test/ChangeLog b/test/ChangeLog index b57a756f..393f38e8 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2015-06-21 Arnold D. Robbins + + * Makefile.am (typeof2): New test. + * typeof2.awk, typeof2.ok: New files. + 2015-06-19 Arnold D. Robbins * Makefile.am (gsubind, typedregex1, typeof1): New tests. diff --git a/test/Makefile.am b/test/Makefile.am index 537a5655..25b8b708 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -985,6 +985,8 @@ EXTRA_DIST = \ typedregex1.ok \ typeof1.awk \ typeof1.ok \ + typeof2.awk \ + typeof2.ok \ uninit2.awk \ uninit2.ok \ uninit3.awk \ @@ -1099,7 +1101,7 @@ GAWK_EXT_TESTS = \ splitarg4 strftime \ strtonum switch2 symtab1 symtab2 symtab3 symtab4 symtab5 symtab6 \ symtab7 symtab8 symtab9 \ - typedregex1 typeof1 + typedregex1 typeof1 typeof2 timeout EXTRA_TESTS = inftest regtest diff --git a/test/Makefile.in b/test/Makefile.in index a8895ed7..1ab60181 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -1242,6 +1242,8 @@ EXTRA_DIST = \ typedregex1.ok \ typeof1.awk \ typeof1.ok \ + typeof2.awk \ + typeof2.ok \ uninit2.awk \ uninit2.ok \ uninit3.awk \ @@ -1355,7 +1357,7 @@ GAWK_EXT_TESTS = \ splitarg4 strftime \ strtonum switch2 symtab1 symtab2 symtab3 symtab4 symtab5 symtab6 \ symtab7 symtab8 symtab9 \ - typedregex1 typeof1 + typedregex1 typeof1 typeof2 EXTRA_TESTS = inftest regtest INET_TESTS = inetdayu inetdayt inetechu inetecht @@ -3905,6 +3907,11 @@ typeof1: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +typeof2: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + double1: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/Maketests b/test/Maketests index a674d5d0..baf973ec 100644 --- a/test/Maketests +++ b/test/Maketests @@ -1342,6 +1342,11 @@ typeof1: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +typeof2: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + double1: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/typeof2.awk b/test/typeof2.awk new file mode 100644 index 00000000..25da02e4 --- /dev/null +++ b/test/typeof2.awk @@ -0,0 +1,20 @@ +BEGIN { + print typeof(x) + x[1] = 3 + print typeof(x) +} + +function test1() { +} + +function test2(p) { + p[1] = 1 +} + +BEGIN { + print typeof(a) + test1(a) + print typeof(a) + test2(a) + print typeof(a) +} diff --git a/test/typeof2.ok b/test/typeof2.ok new file mode 100644 index 00000000..cc032a83 --- /dev/null +++ b/test/typeof2.ok @@ -0,0 +1,6 @@ +untyped +array +untyped +gawk: typeof2.awk:16: warning: function `test1' called with more arguments than declared +untyped +array -- cgit v1.2.3 From 9bf2c3a7bac4abe6c97af4efb2614575279e7b63 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Mon, 22 Jun 2015 22:08:22 +0300 Subject: Make isarray also not scalarize untyped parameters. --- ChangeLog | 6 ++++++ awkgram.c | 6 +----- awkgram.y | 6 +----- profile.c | 1 + 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index b00a5c22..5f27a324 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2015-06-22 Arnold D. Robbins + + * awkgram.y (snode): Make isarray not scalarize untyped parameters + also. + * profile.c (pprint): Add Op_push_arg_untyped. + 2015-06-21 Arnold D. Robbins Fixes for typeof - Don't let typeof change an untyped variable diff --git a/awkgram.c b/awkgram.c index ade5ed6a..6dc4b334 100644 --- a/awkgram.c +++ b/awkgram.c @@ -6697,11 +6697,7 @@ snode(INSTRUCTION *subn, INSTRUCTION *r) if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push) arg->nexti->opcode = Op_push_arg; /* argument may be array */ } - } else if (r->builtin == do_isarray) { - arg = subn->nexti; - if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push) - arg->nexti->opcode = Op_push_arg; /* argument may be array */ - } else if (r->builtin == do_typeof) { + } else if (r->builtin == do_isarray || r->builtin == do_typeof) { arg = subn->nexti; if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push) arg->nexti->opcode = Op_push_arg_untyped; /* argument may be untyped */ diff --git a/awkgram.y b/awkgram.y index d2503697..e9b66ba6 100644 --- a/awkgram.y +++ b/awkgram.y @@ -4277,11 +4277,7 @@ snode(INSTRUCTION *subn, INSTRUCTION *r) if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push) arg->nexti->opcode = Op_push_arg; /* argument may be array */ } - } else if (r->builtin == do_isarray) { - arg = subn->nexti; - if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push) - arg->nexti->opcode = Op_push_arg; /* argument may be array */ - } else if (r->builtin == do_typeof) { + } else if (r->builtin == do_isarray || r->builtin == do_typeof) { arg = subn->nexti; if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push) arg->nexti->opcode = Op_push_arg_untyped; /* argument may be untyped */ diff --git a/profile.c b/profile.c index 0f686768..90f01c07 100644 --- a/profile.c +++ b/profile.c @@ -317,6 +317,7 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool in_for_header) case Op_push_array: case Op_push: case Op_push_arg: + case Op_push_arg_untyped: m = pc->memory; switch (m->type) { case Node_param_list: -- cgit v1.2.3 From d43f951d4e8be461fd8be7182a4ff1b219fa8edd Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Mon, 22 Jun 2015 22:53:02 +0300 Subject: Improve debugger support for typed regexps. --- ChangeLog | 8 ++++++++ awkgram.c | 2 ++ awkgram.y | 2 ++ debug.c | 8 ++++++++ 4 files changed, 20 insertions(+) diff --git a/ChangeLog b/ChangeLog index 5f27a324..84792446 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,14 @@ also. * profile.c (pprint): Add Op_push_arg_untyped. + Improve debugger support for typed regexps. + Thanks to Hermann Peifer for the bug report. + + * awkgram.y (valinfo): Add support for Node_typedregex. + * debug.c (watchpoint_triggerred): Handle Node_typedregex. + (initialize_watch_item): Ditto. + (print_memory): Ditto. + 2015-06-21 Arnold D. Robbins Fixes for typeof - Don't let typeof change an untyped variable diff --git a/awkgram.c b/awkgram.c index 6dc4b334..a1a055b6 100644 --- a/awkgram.c +++ b/awkgram.c @@ -6895,6 +6895,8 @@ valinfo(NODE *n, Func_print print_func, FILE *fp) { if (n == Nnull_string) print_func(fp, "uninitialized scalar\n"); + else if (n->type == Node_typedregex) + print_func(fp, "@/%.*s/\n", n->re_exp->stlen, n->re_exp->stptr); else if ((n->flags & STRING) != 0) { pp_string_fp(print_func, fp, n->stptr, n->stlen, '"', false); print_func(fp, "\n"); diff --git a/awkgram.y b/awkgram.y index e9b66ba6..50fd90a0 100644 --- a/awkgram.y +++ b/awkgram.y @@ -4475,6 +4475,8 @@ valinfo(NODE *n, Func_print print_func, FILE *fp) { if (n == Nnull_string) print_func(fp, "uninitialized scalar\n"); + else if (n->type == Node_typedregex) + print_func(fp, "@/%.*s/\n", n->re_exp->stlen, n->re_exp->stptr); else if ((n->flags & STRING) != 0) { pp_string_fp(print_func, fp, n->stptr, n->stlen, '"', false); print_func(fp, "\n"); diff --git a/debug.c b/debug.c index 6aaba099..99106e55 100644 --- a/debug.c +++ b/debug.c @@ -1736,6 +1736,8 @@ watchpoint_triggered(struct list_item *w) /* new != NULL */ if (t2->type == Node_val) w->cur_value = dupnode(t2); + else if (t2->type == Node_typedregex) + w->cur_value = dupnode(t2); else { w->flags |= CUR_IS_ARRAY; w->cur_size = (t2->type == Node_var_array) ? assoc_length(t2) : 0; @@ -1748,6 +1750,7 @@ watchpoint_triggered(struct list_item *w) w->flags |= CUR_IS_ARRAY; w->cur_size = assoc_length(t2); } else + /* works for Node_typedregex too */ w->cur_value = dupnode(t2); } @@ -1790,6 +1793,8 @@ initialize_watch_item(struct list_item *w) } else if (symbol->type == Node_var_array) { w->flags |= CUR_IS_ARRAY; w->cur_size = assoc_length(symbol); + } else if (symbol->type == Node_typedregex) { + w->cur_value = dupnode(r); } /* else can't happen */ } @@ -3703,6 +3708,9 @@ print_memory(NODE *m, NODE *func, Func_print print_func, FILE *fp) print_func(fp, " [%s]", flags2str(m->flags)); break; + case Node_typedregex: + print_func(fp, "@"); + /* fall through */ case Node_regex: pp_string_fp(print_func, fp, m->re_exp->stptr, m->re_exp->stlen, '/', false); break; -- 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. --- ChangeLog | 5 +++++ builtin.c | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 84792446..9e412428 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,11 @@ (initialize_watch_item): Ditto. (print_memory): Ditto. + Fix typeof to work on subarrays. Thanks, yet again, to + Hermann Peifer for the bug report. + + * builtin.c (do_typeof): Don't deref Node_var_array. + 2015-06-21 Arnold D. Robbins Fixes for typeof - Don't let typeof change an untyped variable 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. --- ChangeLog | 15 +++++++++++++++ awk.h | 1 + builtin.c | 8 +++++++- debug.c | 1 + interpret.h | 4 +++- test/ChangeLog | 5 +++++ test/Makefile.am | 4 ++++ test/Makefile.in | 4 ++++ test/typeof3.awk | 19 +++++++++++++++++++ test/typeof3.ok | 8 ++++++++ test/typeof4.awk | 13 +++++++++++++ test/typeof4.ok | 1 + 12 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 test/typeof3.awk create mode 100644 test/typeof3.ok create mode 100644 test/typeof4.awk create mode 100644 test/typeof4.ok diff --git a/ChangeLog b/ChangeLog index 9e412428..49c557de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2015-06-25 Arnold D. Robbins + + Further work straightening out memory management for typeof. + + * awk.h (DEREF): Add an assert. + * builtin.c (do_typeof): Add comments, cases where not to deref. + * debug.c (print_instruction): Add Op_push_arg_untyped. + * interpret.h (r_interpret): Additional comments / tweaks for + Op_push_arg_untyped. + + Unrelated. Make `x = @/foo/ ; print x' print something. + + * builtin.c (do_print): Check for Node_typedregex and handle it. + Needed for adding test code. + 2015-06-22 Arnold D. Robbins * awkgram.y (snode): Make isarray not scalarize untyped parameters diff --git a/awk.h b/awk.h index 0c42f2e7..220dba95 100644 --- a/awk.h +++ b/awk.h @@ -1182,6 +1182,7 @@ extern void r_unref(NODE *tmp); static inline void DEREF(NODE *r) { + assert(r->valref > 0); if (--r->valref == 0) r_unref(r); } 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'"), diff --git a/debug.c b/debug.c index 99106e55..d0e47f4a 100644 --- a/debug.c +++ b/debug.c @@ -3990,6 +3990,7 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump) case Op_push_i: case Op_push: case Op_push_arg: + case Op_push_arg_untyped: case Op_push_param: case Op_push_array: case Op_push_re: diff --git a/interpret.h b/interpret.h index 554a7663..1005174a 100644 --- a/interpret.h +++ b/interpret.h @@ -177,6 +177,7 @@ top: case Node_var_new: uninitialized_scalar: if (op != Op_push_arg_untyped) { + /* convert untyped to scalar */ m->type = Node_var; m->var_value = dupnode(Nnull_string); } @@ -185,7 +186,8 @@ uninitialized_scalar: _("reference to uninitialized argument `%s'") : _("reference to uninitialized variable `%s'"), save_symbol->vname); - m = dupnode(Nnull_string); + if (op != Op_push_arg_untyped) + m = dupnode(Nnull_string); PUSH(m); break; diff --git a/test/ChangeLog b/test/ChangeLog index 393f38e8..8d74c4ef 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2015-06-25 Arnold D. Robbins + + * Makefile.am (typeof3, typeof4): New tests. + * typeof2.awk, typeof2.ok, typeof3.awk, typeof3.ok: New files. + 2015-06-21 Arnold D. Robbins * Makefile.am (typeof2): New test. diff --git a/test/Makefile.am b/test/Makefile.am index 25b8b708..0c32fa6c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -987,6 +987,10 @@ EXTRA_DIST = \ typeof1.ok \ typeof2.awk \ typeof2.ok \ + typeof3.awk \ + typeof3.ok \ + typeof4.awk \ + typeof4.ok \ uninit2.awk \ uninit2.ok \ uninit3.awk \ diff --git a/test/Makefile.in b/test/Makefile.in index 1ab60181..81562779 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -1244,6 +1244,10 @@ EXTRA_DIST = \ typeof1.ok \ typeof2.awk \ typeof2.ok \ + typeof3.awk \ + typeof3.ok \ + typeof4.awk \ + typeof4.ok \ uninit2.awk \ uninit2.ok \ uninit3.awk \ diff --git a/test/typeof3.awk b/test/typeof3.awk new file mode 100644 index 00000000..d148f373 --- /dev/null +++ b/test/typeof3.awk @@ -0,0 +1,19 @@ +BEGIN { + x = @/xx/ + print typeof(x) + print x +} + +# this set may not really be needed for the test +BEGIN { + x = 4 + print typeof(@/xxx/) + print typeof(3) + print x +} + +BEGIN { + print typeof(x) + print typeof(a[1]) + a[1][2] # fatals on this +} diff --git a/test/typeof3.ok b/test/typeof3.ok new file mode 100644 index 00000000..c8f458a1 --- /dev/null +++ b/test/typeof3.ok @@ -0,0 +1,8 @@ +regexp +xx +regexp +scalar_n +4 +scalar_n +untyped +gawk: test/typeof3.awk:18: fatal: attempt to use scalar `a["1"]' as an array diff --git a/test/typeof4.awk b/test/typeof4.awk new file mode 100644 index 00000000..62c2905c --- /dev/null +++ b/test/typeof4.awk @@ -0,0 +1,13 @@ +BEGIN{ a["x"]["y"]["z"]="scalar" ; walk_array(a, "a")} +function walk_array(arr, name, i, r) +{ + for (i in arr) { + r = typeof(arr[i]) +# printf("typeof(%s[%s]) = %s\n", name, i, r) > "/dev/stderr" + if (r == "array") { + walk_array(arr[i], name "[" i "]") + } else { + printf "%s[%s] = %s\n", name, i, arr[i] + } + } +} diff --git a/test/typeof4.ok b/test/typeof4.ok new file mode 100644 index 00000000..fca0263d --- /dev/null +++ b/test/typeof4.ok @@ -0,0 +1 @@ +a[x][y][z] = scalar -- cgit v1.2.3 From dc578b50b37e6f025971375a3ce52f23830049b2 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 25 Jun 2015 22:44:21 +0300 Subject: Make typeof3 and typeof4 tests actually work. --- test/Makefile.am | 2 +- test/Makefile.in | 12 +++++++++++- test/Maketests | 10 ++++++++++ test/typeof3.ok | 3 ++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/test/Makefile.am b/test/Makefile.am index 0c32fa6c..842f9bdb 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1105,7 +1105,7 @@ GAWK_EXT_TESTS = \ splitarg4 strftime \ strtonum switch2 symtab1 symtab2 symtab3 symtab4 symtab5 symtab6 \ symtab7 symtab8 symtab9 \ - typedregex1 typeof1 typeof2 + typedregex1 typeof1 typeof2 typeof3 typeof4 timeout EXTRA_TESTS = inftest regtest diff --git a/test/Makefile.in b/test/Makefile.in index 81562779..efb0badc 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -1361,7 +1361,7 @@ GAWK_EXT_TESTS = \ splitarg4 strftime \ strtonum switch2 symtab1 symtab2 symtab3 symtab4 symtab5 symtab6 \ symtab7 symtab8 symtab9 \ - typedregex1 typeof1 typeof2 + typedregex1 typeof1 typeof2 typeof3 typeof4 EXTRA_TESTS = inftest regtest INET_TESTS = inetdayu inetdayt inetechu inetecht @@ -3916,6 +3916,16 @@ typeof2: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +typeof3: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + +typeof4: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + double1: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/Maketests b/test/Maketests index baf973ec..e4cea0de 100644 --- a/test/Maketests +++ b/test/Maketests @@ -1347,6 +1347,16 @@ typeof2: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +typeof3: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + +typeof4: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + double1: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/typeof3.ok b/test/typeof3.ok index c8f458a1..8186ad9e 100644 --- a/test/typeof3.ok +++ b/test/typeof3.ok @@ -5,4 +5,5 @@ scalar_n 4 scalar_n untyped -gawk: test/typeof3.awk:18: fatal: attempt to use scalar `a["1"]' as an array +gawk: typeof3.awk:18: fatal: attempt to use scalar `a["1"]' as an array +EXIT CODE: 2 -- cgit v1.2.3 From 248f1f7ae2244e407218d3decd66423e89c21d05 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 25 Jun 2015 22:59:11 +0300 Subject: New test for debugger and typed regexps. --- test/ChangeLog | 5 +++++ test/Makefile.am | 10 +++++++++- test/Makefile.in | 10 +++++++++- test/dbugtypedre.awk | 1 + test/dbugtypedre.in | 4 ++++ test/dbugtypedre.ok | 17 +++++++++++++++++ 6 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 test/dbugtypedre.awk create mode 100644 test/dbugtypedre.in create mode 100644 test/dbugtypedre.ok diff --git a/test/ChangeLog b/test/ChangeLog index 8d74c4ef..08661b3a 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -3,6 +3,11 @@ * Makefile.am (typeof3, typeof4): New tests. * typeof2.awk, typeof2.ok, typeof3.awk, typeof3.ok: New files. + Unrelated: + + * Makefile.am (dbugtypedre): New tests. + * dbugtypedre.awk, dbugtypedre.in, dbugtypedre.ok: New files. + 2015-06-21 Arnold D. Robbins * Makefile.am (typeof2): New test. diff --git a/test/Makefile.am b/test/Makefile.am index 842f9bdb..cbec8a98 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -177,6 +177,9 @@ EXTRA_DIST = \ datanonl.ok \ dbugeval.in \ dbugeval.ok \ + dbugtypedre.awk \ + dbugtypedre.in \ + dbugtypedre.ok \ defref.awk \ defref.ok \ delargv.awk \ @@ -1085,7 +1088,7 @@ UNIX_TESTS = \ GAWK_EXT_TESTS = \ aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort \ backw badargs beginfile1 beginfile2 binmode1 charasbytes \ - colonwarn clos1way crlf dbugeval delsub devfd devfd1 devfd2 dumpvars errno exit \ + colonwarn clos1way crlf dbugeval dbugtypedre delsub devfd devfd1 devfd2 dumpvars errno exit \ fieldwdth fpat1 fpat2 fpat3 fpat4 fpatnull fsfwfs funlen \ functab1 functab2 functab3 fwtest fwtest2 fwtest3 \ genpot gensub gensub2 getlndir gnuops2 gnuops3 gnureops gsubind \ @@ -2132,6 +2135,11 @@ negtime:: @TZ=GMT AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @AWKPATH="$(srcdir)" $(AWK) -f checknegtime.awk $@.ok _$@ && rm -f _$@ +dbugtypedre: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -D -f $@.awk < $@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + # Targets generated for other tests: include Maketests diff --git a/test/Makefile.in b/test/Makefile.in index efb0badc..196590d6 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -434,6 +434,9 @@ EXTRA_DIST = \ datanonl.ok \ dbugeval.in \ dbugeval.ok \ + dbugtypedre.awk \ + dbugtypedre.in \ + dbugtypedre.ok \ defref.awk \ defref.ok \ delargv.awk \ @@ -1341,7 +1344,7 @@ UNIX_TESTS = \ GAWK_EXT_TESTS = \ aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort \ backw badargs beginfile1 beginfile2 binmode1 charasbytes \ - colonwarn clos1way crlf dbugeval delsub devfd devfd1 devfd2 dumpvars errno exit \ + colonwarn clos1way crlf dbugeval dbugtypedre delsub devfd devfd1 devfd2 dumpvars errno exit \ fieldwdth fpat1 fpat2 fpat3 fpat4 fpatnull fsfwfs funlen \ functab1 functab2 functab3 fwtest fwtest2 fwtest3 \ genpot gensub gensub2 getlndir gnuops2 gnuops3 gnureops gsubind \ @@ -2567,6 +2570,11 @@ negtime:: @echo $@ @TZ=GMT AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @AWKPATH="$(srcdir)" $(AWK) -f checknegtime.awk $@.ok _$@ && rm -f _$@ + +dbugtypedre: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -D -f $@.awk < $@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ Gt-dummy: # file Maketests, generated from Makefile.am by the Gentests program addcomma: diff --git a/test/dbugtypedre.awk b/test/dbugtypedre.awk new file mode 100644 index 00000000..b8c0b6d7 --- /dev/null +++ b/test/dbugtypedre.awk @@ -0,0 +1 @@ +@include "typeof1.awk" diff --git a/test/dbugtypedre.in b/test/dbugtypedre.in new file mode 100644 index 00000000..00158c65 --- /dev/null +++ b/test/dbugtypedre.in @@ -0,0 +1,4 @@ +watch e +run +next +p e diff --git a/test/dbugtypedre.ok b/test/dbugtypedre.ok new file mode 100644 index 00000000..de3c8bcd --- /dev/null +++ b/test/dbugtypedre.ok @@ -0,0 +1,17 @@ +Watchpoint 1: e +Starting program: +scalar_n +untyped +regexp +scalar_s +array scalar_n +Stopping in BEGIN ... +Watchpoint 1: e + Old value: untyped variable + New value: @/foo/ +main() at `typeof1.awk':7 +7 e = @/foo/ ; print typeof(e) +regexp +8 print typeof(@/bar/) +e = @/foo/ +EXIT CODE: 2 -- cgit v1.2.3 From 397423c7a0709fce5abd1c7a5d55411b9a170267 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 25 Jun 2015 23:04:57 +0300 Subject: Fix negtime test to run out-of-tree. --- test/ChangeLog | 4 ++++ test/Makefile.am | 2 +- test/Makefile.in | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/ChangeLog b/test/ChangeLog index a9d130cc..cc7576ef 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,7 @@ +2015-06-25 Arnold D. Robbins + + * Makefile.am (negtime): Fix out-of-tree test run. + 2015-06-17 Andrew J. Schorr * inplace1.ok, inplace2.ok, inplace3.ok: Update line number in error diff --git a/test/Makefile.am b/test/Makefile.am index 02c0aaa8..5e72014b 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -2074,7 +2074,7 @@ paramasfunc2:: negtime:: @echo $@ @TZ=GMT AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ - @AWKPATH="$(srcdir)" $(AWK) -f checknegtime.awk $@.ok _$@ && rm -f _$@ + @AWKPATH="$(srcdir)" $(AWK) -f checknegtime.awk "$(srcdir)"/$@.ok _$@ && rm -f _$@ # Targets generated for other tests: include Maketests diff --git a/test/Makefile.in b/test/Makefile.in index 9d51a3d8..0116f3a4 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -2511,7 +2511,7 @@ paramasfunc2:: negtime:: @echo $@ @TZ=GMT AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ - @AWKPATH="$(srcdir)" $(AWK) -f checknegtime.awk $@.ok _$@ && rm -f _$@ + @AWKPATH="$(srcdir)" $(AWK) -f checknegtime.awk "$(srcdir)"/$@.ok _$@ && rm -f _$@ Gt-dummy: # file Maketests, generated from Makefile.am by the Gentests program addcomma: -- cgit v1.2.3 From 3712ad29b6cddcf49bf1507f5677a49ccfcff83d Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 25 Jun 2015 23:11:40 +0300 Subject: Typo fix in debug.c. --- ChangeLog | 4 ++++ debug.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 49c557de..3b872bdd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,10 @@ * builtin.c (do_print): Check for Node_typedregex and handle it. Needed for adding test code. + Unrelated. Typo fix. + + * debug.c (initialize_watch_item): Dupnode the right thing. + 2015-06-22 Arnold D. Robbins * awkgram.y (snode): Make isarray not scalarize untyped parameters diff --git a/debug.c b/debug.c index d0e47f4a..2bb6e53a 100644 --- a/debug.c +++ b/debug.c @@ -1794,7 +1794,7 @@ initialize_watch_item(struct list_item *w) w->flags |= CUR_IS_ARRAY; w->cur_size = assoc_length(symbol); } else if (symbol->type == Node_typedregex) { - w->cur_value = dupnode(r); + w->cur_value = dupnode(symbol); } /* else can't happen */ } -- cgit v1.2.3