diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2020-01-19 20:52:46 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2020-01-19 20:52:46 +0200 |
commit | 15db23b88c2866ed900177cbf11ce37e373e5e20 (patch) | |
tree | 4adfc1f12e9877e5c567e46c4702400054bc8d2a | |
parent | a2a6e548bc3afcbf4c7401ebdfa8213dbe4e8dea (diff) | |
download | egawk-15db23b88c2866ed900177cbf11ce37e373e5e20.tar.gz egawk-15db23b88c2866ed900177cbf11ce37e373e5e20.tar.bz2 egawk-15db23b88c2866ed900177cbf11ce37e373e5e20.zip |
Fix a pretty-printer error with print[f].
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | profile.c | 21 | ||||
-rw-r--r-- | test/ChangeLog | 6 | ||||
-rw-r--r-- | test/Makefile.am | 6 | ||||
-rw-r--r-- | test/Makefile.in | 11 | ||||
-rw-r--r-- | test/Maketests | 5 | ||||
-rw-r--r-- | test/profile13.awk | 4 | ||||
-rw-r--r-- | test/profile13.ok | 5 | ||||
-rw-r--r-- | test/profile5.ok | 12 |
9 files changed, 64 insertions, 14 deletions
@@ -1,3 +1,9 @@ +2020-01-19 Arnold D. Robbins <arnold@skeeve.com> + + * profile.c (pp_top): New macro. + (pprint): Be smarter for print[f] with redirection that was + parenthesized, to not print `printf(("hello\n")) > "..."'. + 2020-01-08 Arnold D. Robbins <arnold@skeeve.com> Fix a number of subtle memory leaks. Thanks to the @@ -18,7 +24,7 @@ * interpret.h (Op_subscript): When retrieving from SYMTAB, check for Node_var_new; variables can exist but have not been assigned - a value. + a value. Thanks to Denis Shirokov <cosmogen@gmail.com> for the report. Unrelated: @@ -196,6 +196,10 @@ pp_pop() return n; } +/* pp_top --- look at what's on the top of the stack */ + +#define pp_top() pp_stack + /* pp_free --- release a pretty printed node */ static void @@ -665,9 +669,20 @@ cleanup: if (pc->opcode == Op_K_print_rec) // instead of `print $0', just `print' tmp = strdup(""); - else if (pc->redir_type != 0) - tmp = pp_list(pc->expr_count, "()", ", "); - else { + else if (pc->redir_type != 0) { + // Avoid turning printf("hello\n") into printf(("hello\n")) + NODE *n = pp_top(); + + if (pc->expr_count == 1 + && n->pp_str[0] == '(' + && n->pp_str[n->pp_len - 1] == ')') { + n = pp_pop(); + + tmp = strdup(n->pp_str); + pp_free(n); + } else + tmp = pp_list(pc->expr_count, "()", ", "); + } else { tmp = pp_list(pc->expr_count, " ", ", "); tmp[strlen(tmp) - 1] = '\0'; /* remove trailing space */ } diff --git a/test/ChangeLog b/test/ChangeLog index 30470034..c188931b 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,9 @@ +2020-01-19 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (EXTRA_DIST): New test, profile13. + * profile13.awk, profile13.ok: New files. + * profile5.ok: Updated after code changes. + 2020-01-08 Arnold D. Robbins <arnold@skeeve.com> * indirectbuiltin.awk, numrange.awk, numrange.ok: Changes diff --git a/test/Makefile.am b/test/Makefile.am index aa64110c..bf77ea34 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -961,6 +961,8 @@ EXTRA_DIST = \ profile12.awk \ profile12.in \ profile12.ok \ + profile13.awk \ + profile13.ok \ prt1eval.awk \ prt1eval.ok \ prtoeval.awk \ @@ -1393,7 +1395,7 @@ GAWK_EXT_TESTS = \ nsbad nsbad_cmd nsforloop nsfuncrecurse nsindirect1 nsindirect2 nsprof1 nsprof2 \ patsplit posix printfbad1 printfbad2 printfbad3 printfbad4 printhuge \ procinfs profile0 profile1 profile2 profile3 profile4 profile5 profile6 \ - profile7 profile8 profile9 profile10 profile11 profile12 pty1 pty2 \ + profile7 profile8 profile9 profile10 profile11 profile12 profile13 pty1 pty2 \ rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin \ rsstart1 rsstart2 rsstart3 rstest6 \ sandbox1 shadow shadowbuiltin sortfor sortfor2 sortu \ @@ -1455,7 +1457,7 @@ NEED_POSIX = escapebrace printf0 posix2008sub paramasfunc1 paramasfunc2 muldimpo # List of tests that need --pretty-print NEED_PRETTY = nsprof1 nsprof2 \ - profile4 profile5 profile8 profile9 profile10 profile11 + profile4 profile5 profile8 profile9 profile10 profile11 profile13 # List of tests that need --re-interval NEED_RE_INTERVAL = gsubtst3 reint reint2 diff --git a/test/Makefile.in b/test/Makefile.in index 9557b1e4..0794b3b8 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -1220,6 +1220,8 @@ EXTRA_DIST = \ profile12.awk \ profile12.in \ profile12.ok \ + profile13.awk \ + profile13.ok \ prt1eval.awk \ prt1eval.ok \ prtoeval.awk \ @@ -1652,7 +1654,7 @@ GAWK_EXT_TESTS = \ nsbad nsbad_cmd nsforloop nsfuncrecurse nsindirect1 nsindirect2 nsprof1 nsprof2 \ patsplit posix printfbad1 printfbad2 printfbad3 printfbad4 printhuge \ procinfs profile0 profile1 profile2 profile3 profile4 profile5 profile6 \ - profile7 profile8 profile9 profile10 profile11 profile12 pty1 pty2 \ + profile7 profile8 profile9 profile10 profile11 profile12 profile13 pty1 pty2 \ rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin \ rsstart1 rsstart2 rsstart3 rstest6 \ sandbox1 shadow shadowbuiltin sortfor sortfor2 sortu \ @@ -1713,7 +1715,7 @@ NEED_POSIX = escapebrace printf0 posix2008sub paramasfunc1 paramasfunc2 muldimpo # List of tests that need --pretty-print NEED_PRETTY = nsprof1 nsprof2 \ - profile4 profile5 profile8 profile9 profile10 profile11 + profile4 profile5 profile8 profile9 profile10 profile11 profile13 # List of tests that need --re-interval @@ -4657,6 +4659,11 @@ profile11: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +profile13: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + regnul1: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/Maketests b/test/Maketests index e339b2b9..d8c3299a 100644 --- a/test/Maketests +++ b/test/Maketests @@ -1810,6 +1810,11 @@ profile11: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +profile13: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + regnul1: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/profile13.awk b/test/profile13.awk new file mode 100644 index 00000000..dc090ae9 --- /dev/null +++ b/test/profile13.awk @@ -0,0 +1,4 @@ +BEGIN { + printf "hello\n" > "/dev/stderr" + printf("hello\n") > "/dev/stderr" +} diff --git a/test/profile13.ok b/test/profile13.ok new file mode 100644 index 00000000..258238a9 --- /dev/null +++ b/test/profile13.ok @@ -0,0 +1,5 @@ +BEGIN { + printf("hello\n") > "/dev/stderr" + printf("hello\n") > "/dev/stderr" +} + diff --git a/test/profile5.ok b/test/profile5.ok index 1b32ceda..309ec1e4 100644 --- a/test/profile5.ok +++ b/test/profile5.ok @@ -1680,14 +1680,14 @@ function _con(t, ts, a, b, c, d, i, r, A, B) if ((i = length(t = _tabtospc(A[1], ts, _conlastrln))) < _constatstrln) { t = t _getchrln(" ", _constatstrln - i) } - print((t B[1])) > _SYS_STDCON + print(t B[1]) > _SYS_STDCON for (i = 2; i < c; i++) { - print((_tabtospc(A[i], ts) B[i])) > _SYS_STDCON + print(_tabtospc(A[i], ts) B[i]) > _SYS_STDCON } - print((_conlastr = _tabtospc(A[c], ts))) > _SYS_STDCON + print(_conlastr = _tabtospc(A[c], ts)) > _SYS_STDCON fflush(_SYS_STDCON) } else { - print((t = _tabtospc(t, ts, _conlastrln))) > _SYS_STDCON + print(t = _tabtospc(t, ts, _conlastrln)) > _SYS_STDCON fflush(_SYS_STDCON) _conlastr = _conlastr t } @@ -1696,7 +1696,7 @@ function _con(t, ts, a, b, c, d, i, r, A, B) } _conlastrln = length(_conlastr) if (_constatstr) { - print(((t = _constatgtstr(_constatstr, _CON_WIDTH - 1 - _conlastrln)) _CHR["CR"] _conlastr)) > _SYS_STDCON + print((t = _constatgtstr(_constatstr, _CON_WIDTH - 1 - _conlastrln)) _CHR["CR"] _conlastr) > _SYS_STDCON fflush(_SYS_STDCON) _constatstrln = length(t) } @@ -1763,7 +1763,7 @@ function _constat(t, ts, ln, a) a = BINMODE BINMODE = "rw" ORS = "" - print((t _CHR["CR"] _conlastr)) > _SYS_STDCON + print(t _CHR["CR"] _conlastr) > _SYS_STDCON fflush(_SYS_STDCON) ORS = ln BINMODE = a |