diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2017-02-17 08:18:51 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2017-02-17 08:18:51 +0200 |
commit | 4ce031ad3c3d157a425f721688a09a7dde018619 (patch) | |
tree | 340825da478a70246a71f441ba69b6188c85dd4a | |
parent | eb8d0c64228657bad4ef2e2fd732eeed937f3af1 (diff) | |
download | egawk-4ce031ad3c3d157a425f721688a09a7dde018619.tar.gz egawk-4ce031ad3c3d157a425f721688a09a7dde018619.tar.bz2 egawk-4ce031ad3c3d157a425f721688a09a7dde018619.zip |
Fix typeof on null fields.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | builtin.c | 15 | ||||
-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/typeof5.awk | 10 | ||||
-rw-r--r-- | test/typeof5.in | 1 | ||||
-rw-r--r-- | test/typeof5.ok | 4 |
9 files changed, 55 insertions, 8 deletions
@@ -1,3 +1,8 @@ +2017-02-17 Arnold D. Robbins <arnold@skeeve.com> + + * builtin.c (do_typeof): Handle arguments that have + the NULL_FIELD flag set. + 2017-02-03 Andrew J. Schorr <aschorr@telemetry-investments.com> * awkgram.y (set_profile_text): Improve code clarity by using emalloc @@ -3977,7 +3977,7 @@ NODE * do_typeof(int nargs) { NODE *arg; - char *res = "unknown"; + char *res = NULL; bool deref = true; arg = POP(); @@ -3989,9 +3989,6 @@ do_typeof(int nargs) break; case Node_val: switch (fixtype(arg)->flags & (STRING|NUMBER|USER_INPUT|REGEX)) { - case STRING: - res = "string"; - break; case NUMBER: res = "number"; break; @@ -4001,14 +3998,20 @@ do_typeof(int nargs) case REGEX: res = "regexp"; break; + case STRING: + res = "string"; + // fall through case NUMBER|STRING: - if (arg == Nnull_string) { + if (arg == Nnull_string || (arg->flags & NULL_FIELD) != 0) { res = "unassigned"; break; } /* fall through */ default: - warning(_("typeof detected invalid flags combination `%s'; please file a bug report."), flags2str(arg->flags)); + if (res == NULL) { + warning(_("typeof detected invalid flags combination `%s'; please file a bug report."), flags2str(arg->flags)); + res = "unknown"; + } break; } break; diff --git a/test/ChangeLog b/test/ChangeLog index 3566cce7..fc7358e1 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,9 @@ +2017-02-17 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (typeof5): New test. + * typeof5.awk, typeof5.in, typeof5.ok: New files. + Thanks to Andrew Schorr for part of the tests. + 2017-01-27 Andrew J. Schorr <aschorr@telemetry-investments.com> * Makefile.am (gensub3): New test. diff --git a/test/Makefile.am b/test/Makefile.am index 9f79df8f..7715c39d 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1110,6 +1110,9 @@ EXTRA_DIST = \ typeof3.ok \ typeof4.awk \ typeof4.ok \ + typeof5.awk \ + typeof5.in \ + typeof5.ok \ uninit2.awk \ uninit2.ok \ uninit3.awk \ @@ -1234,7 +1237,8 @@ GAWK_EXT_TESTS = \ splitarg4 strftime \ strtonum strtonum1 switch2 symtab1 symtab2 symtab3 symtab4 symtab5 symtab6 \ symtab7 symtab8 symtab9 symtab10 \ - typedregex1 typedregex2 typedregex3 typeof1 typeof2 typeof3 typeof4 \ + typedregex1 typedregex2 typedregex3 \ + typeof1 typeof2 typeof3 typeof4 typeof5 \ timeout \ watchpoint1 diff --git a/test/Makefile.in b/test/Makefile.in index 1cd8bf15..88b731b2 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -1368,6 +1368,9 @@ EXTRA_DIST = \ typeof3.ok \ typeof4.awk \ typeof4.ok \ + typeof5.awk \ + typeof5.in \ + typeof5.ok \ uninit2.awk \ uninit2.ok \ uninit3.awk \ @@ -1491,7 +1494,8 @@ GAWK_EXT_TESTS = \ splitarg4 strftime \ strtonum strtonum1 switch2 symtab1 symtab2 symtab3 symtab4 symtab5 symtab6 \ symtab7 symtab8 symtab9 symtab10 \ - typedregex1 typedregex2 typedregex3 typeof1 typeof2 typeof3 typeof4 \ + typedregex1 typedregex2 typedregex3 \ + typeof1 typeof2 typeof3 typeof4 typeof5 \ timeout \ watchpoint1 @@ -4331,6 +4335,11 @@ typeof4: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +typeof5: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + timeout: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/Maketests b/test/Maketests index 30211d66..8ae71525 100644 --- a/test/Maketests +++ b/test/Maketests @@ -1527,6 +1527,11 @@ typeof4: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +typeof5: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + timeout: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/typeof5.awk b/test/typeof5.awk new file mode 100644 index 00000000..30cd6aca --- /dev/null +++ b/test/typeof5.awk @@ -0,0 +1,10 @@ +BEGIN { + print typeof($0) + print typeof($1) +} + +{ + $3 = $1 + print typeof($2) + print typeof($3) +} diff --git a/test/typeof5.in b/test/typeof5.in new file mode 100644 index 00000000..9daeafb9 --- /dev/null +++ b/test/typeof5.in @@ -0,0 +1 @@ +test diff --git a/test/typeof5.ok b/test/typeof5.ok new file mode 100644 index 00000000..80f8cf51 --- /dev/null +++ b/test/typeof5.ok @@ -0,0 +1,4 @@ +unassigned +unassigned +unassigned +string |