From b930d79a316d08c899787c0d2e39865913863a52 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 13 Apr 2023 21:28:02 +0300 Subject: Bug fix for asort(SYMTAB, arr). --- ChangeLog | 6 +++++ array.c | 22 +++++++++++----- pc/ChangeLog | 1 + pc/Makefile.tst | 6 +++++ test/ChangeLog | 5 ++++ test/Makefile.am | 7 +++-- test/Makefile.in | 12 +++++++-- test/Maketests | 5 ++++ test/asortsymtab.awk | 10 ++++++++ test/asortsymtab.ok | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 136 insertions(+), 10 deletions(-) create mode 100644 test/asortsymtab.awk create mode 100644 test/asortsymtab.ok diff --git a/ChangeLog b/ChangeLog index 8555a0b3..9ffcaa5d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2023-04-13 Arnold D. Robbins + + * array.c (asort_actual): Handle Node_var_new. Can happen + if you sort SYMTAB. Thanks to zhou shuiqing + for the report. + 2023-04-07 Arnold D. Robbins * array.c (assoc_info): Update to handle additional cases so diff --git a/array.c b/array.c index 09151169..62fd0597 100644 --- a/array.c +++ b/array.c @@ -935,17 +935,24 @@ asort_actual(int nargs, sort_context_t ctxt) NODE *value; - if (r->type == Node_val) + switch (r->type) { + case Node_val: value = dupnode(r); - else if (r->type == Node_var) + break; + case Node_var: /* SYMTAB ... */ value = dupnode(r->var_value); - else if (r->type == Node_builtin_func - || r->type == Node_func - || r->type == Node_ext_func) { + break; + case Node_var_new: + value = dupnode(Nnull_string); + break; + case Node_builtin_func: + case Node_func: + case Node_ext_func: /* FUNCTAB ... */ value = make_string(r->vname, strlen(r->vname)); - } else { + break; + case Node_var_array: NODE *arr; arr = make_array(); subs = force_string(subs); @@ -956,6 +963,9 @@ asort_actual(int nargs, sort_context_t ctxt) arr->parent_array = array; /* actual parent, not the temporary one. */ value = assoc_copy(r, arr); + break; + default: + cant_happen("asort_actual: got unexpected type %s", nodetype2str(r->type)); } assoc_set(result, subs, value); } diff --git a/pc/ChangeLog b/pc/ChangeLog index 9df38d9d..0da31a42 100644 --- a/pc/ChangeLog +++ b/pc/ChangeLog @@ -1,6 +1,7 @@ 2023-04-13 Arnold D. Robbins * config.h: Regenerated. + * Makefile.tst: Regenerated. 2023-03-12 Eli Zaretskii diff --git a/pc/Makefile.tst b/pc/Makefile.tst index f9e9681b..d012f626 100644 --- a/pc/Makefile.tst +++ b/pc/Makefile.tst @@ -189,6 +189,7 @@ UNIX_TESTS = \ GAWK_EXT_TESTS = \ aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort \ arraysort2 arraytype asortbool backw badargs beginfile1 beginfile2 \ + asortsymtab \ binmode1 charasbytes clos1way clos1way2 clos1way3 clos1way4 \ clos1way5 clos1way6 colonwarn commas crlf dbugeval dbugeval2 \ dbugeval3 dbugeval4 dbugtypedre1 dbugtypedre2 delsub \ @@ -2676,6 +2677,11 @@ backw: @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +asortsymtab: + @echo $@ + @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + clos1way: @echo $@ @-[ -z "$$GAWKLOCALE" ] && GAWKLOCALE=C; export GAWKLOCALE; \ diff --git a/test/ChangeLog b/test/ChangeLog index 19d7ead9..651fdb98 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2023-04-13 Arnold D. Robbins + + * Makefile.am (EXTRA_DIST): New test: asortsymtab. + * asortsymtab.awk, asortsymtab.ok: New files. + 2023-04-13 Arnold D. Robbins * badargs.ok: Update after code changes. diff --git a/test/Makefile.am b/test/Makefile.am index b30d3d7a..cc99dfa9 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -127,15 +127,17 @@ EXTRA_DIST = \ asgext.ok \ asort.awk \ asort.ok \ + asortbool.awk \ + asortbool.ok \ asorti.awk \ asorti.ok \ + asortsymtab.awk \ + asortsymtab.ok \ assignnumfield.awk \ assignnumfield.in \ assignnumfield.ok \ assignnumfield2.awk \ assignnumfield2.ok \ - asortbool.awk \ - asortbool.ok \ awkpath.ok \ back89.awk \ back89.in \ @@ -1502,6 +1504,7 @@ UNIX_TESTS = \ GAWK_EXT_TESTS = \ aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort \ arraysort2 arraytype asortbool backw badargs beginfile1 beginfile2 \ + asortsymtab \ binmode1 charasbytes clos1way clos1way2 clos1way3 clos1way4 \ clos1way5 clos1way6 colonwarn commas crlf dbugeval dbugeval2 \ dbugeval3 dbugeval4 dbugtypedre1 dbugtypedre2 delsub \ diff --git a/test/Makefile.in b/test/Makefile.in index ed835ab6..3ed140cc 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -395,15 +395,17 @@ EXTRA_DIST = \ asgext.ok \ asort.awk \ asort.ok \ + asortbool.awk \ + asortbool.ok \ asorti.awk \ asorti.ok \ + asortsymtab.awk \ + asortsymtab.ok \ assignnumfield.awk \ assignnumfield.in \ assignnumfield.ok \ assignnumfield2.awk \ assignnumfield2.ok \ - asortbool.awk \ - asortbool.ok \ awkpath.ok \ back89.awk \ back89.in \ @@ -1770,6 +1772,7 @@ UNIX_TESTS = \ GAWK_EXT_TESTS = \ aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort \ arraysort2 arraytype asortbool backw badargs beginfile1 beginfile2 \ + asortsymtab \ binmode1 charasbytes clos1way clos1way2 clos1way3 clos1way4 \ clos1way5 clos1way6 colonwarn commas crlf dbugeval dbugeval2 \ dbugeval3 dbugeval4 dbugtypedre1 dbugtypedre2 delsub \ @@ -4441,6 +4444,11 @@ backw: @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +asortsymtab: + @echo $@ + @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + clos1way: @echo $@ @-[ -z "$$GAWKLOCALE" ] && GAWKLOCALE=C; export GAWKLOCALE; \ diff --git a/test/Maketests b/test/Maketests index a4b215c6..f532fc92 100644 --- a/test/Maketests +++ b/test/Maketests @@ -1370,6 +1370,11 @@ backw: @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +asortsymtab: + @echo $@ + @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + clos1way: @echo $@ @-[ -z "$$GAWKLOCALE" ] && GAWKLOCALE=C; export GAWKLOCALE; \ diff --git a/test/asortsymtab.awk b/test/asortsymtab.awk new file mode 100644 index 00000000..7cb65a69 --- /dev/null +++ b/test/asortsymtab.awk @@ -0,0 +1,10 @@ +BEGIN { + asort(SYMTAB, arr) + for (idx in arr) { + print idx + } + asort(FUNCTAB, arr) + for (idx in arr) { + print idx + } +} diff --git a/test/asortsymtab.ok b/test/asortsymtab.ok new file mode 100644 index 00000000..9b4799bf --- /dev/null +++ b/test/asortsymtab.ok @@ -0,0 +1,72 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 -- cgit v1.2.1