|
|
33e5ff |
From c1f670b26671cc8d60d967bbcb42cb8deb3baf2b Mon Sep 17 00:00:00 2001
|
|
|
33e5ff |
From: "Arnold D. Robbins" <arnold@skeeve.com>
|
|
|
33e5ff |
Date: Tue, 31 Jul 2018 21:40:49 +0300
|
|
|
33e5ff |
Subject: Fix assigning $0 from a number.
|
|
|
33e5ff |
|
|
|
33e5ff |
---
|
|
|
33e5ff |
ChangeLog | 6 ++++++
|
|
|
33e5ff |
interpret.h | 1 +
|
|
|
33e5ff |
test/ChangeLog | 5 +++++
|
|
|
33e5ff |
test/Makefile.am | 5 ++++-
|
|
|
33e5ff |
test/Makefile.in | 10 +++++++++-
|
|
|
33e5ff |
test/Maketests | 5 +++++
|
|
|
33e5ff |
test/assignnumfield.awk | 1 +
|
|
|
33e5ff |
test/assignnumfield.in | 5 +++++
|
|
|
33e5ff |
test/assignnumfield.ok | 5 +++++
|
|
|
33e5ff |
9 files changed, 41 insertions(+), 2 deletions(-)
|
|
|
33e5ff |
create mode 100644 test/assignnumfield.awk
|
|
|
33e5ff |
create mode 100644 test/assignnumfield.in
|
|
|
33e5ff |
create mode 100644 test/assignnumfield.ok
|
|
|
33e5ff |
|
|
|
33e5ff |
diff --git a/ChangeLog b/ChangeLog
|
|
|
33e5ff |
index 904e984c..68210057 100644
|
|
|
33e5ff |
--- a/ChangeLog
|
|
|
33e5ff |
+++ b/ChangeLog
|
|
|
33e5ff |
@@ -1,3 +1,9 @@
|
|
|
33e5ff |
+2018-07-31 Arnold D. Robbins <arnold@skeeve.com>
|
|
|
33e5ff |
+
|
|
|
33e5ff |
+ * interpret.h (unfield): Add a call to force_string() on
|
|
|
33e5ff |
+ new value. See test/assignnumfield.awk. Thanks to
|
|
|
33e5ff |
+ Ralph Corderoy <ralph@inputplus.co.uk> for the bug report.
|
|
|
33e5ff |
+
|
|
|
33e5ff |
2018-02-25 Arnold D. Robbins <arnold@skeeve.com>
|
|
|
33e5ff |
|
|
|
33e5ff |
* 4.2.1: Release tar ball made.
|
|
|
33e5ff |
diff --git a/interpret.h b/interpret.h
|
|
|
33e5ff |
index 8408a532..fed0078c 100644
|
|
|
33e5ff |
--- a/interpret.h
|
|
|
33e5ff |
+++ b/interpret.h
|
|
|
33e5ff |
@@ -46,16 +46,25 @@ unfield(NODE **l, NODE **r)
|
|
|
33e5ff |
* valref 1, that effectively means that this is an assignment like "$n = $n",
|
|
|
33e5ff |
* so a no-op, other than triggering $0 reconstitution.
|
|
|
33e5ff |
*/
|
|
|
33e5ff |
-#define UNFIELD(l, r) \
|
|
|
33e5ff |
-{ \
|
|
|
33e5ff |
- /* if was a field, turn it into a var */ \
|
|
|
33e5ff |
- if ((r->flags & MALLOC) != 0 || r->valref == 1) { \
|
|
|
33e5ff |
- l = r; \
|
|
|
33e5ff |
- } else { \
|
|
|
33e5ff |
- l = dupnode(r); \
|
|
|
33e5ff |
- DEREF(r); \
|
|
|
33e5ff |
- } \
|
|
|
33e5ff |
-}
|
|
|
33e5ff |
+// not a macro so we can step into it with a debugger
|
|
|
33e5ff |
+#ifndef UNFIELD_DEFINED
|
|
|
33e5ff |
+#define UNFIELD_DEFINED 1
|
|
|
33e5ff |
+static inline void
|
|
|
33e5ff |
+unfield(NODE **l, NODE **r)
|
|
|
33e5ff |
+{
|
|
|
33e5ff |
+ /* if was a field, turn it into a var */
|
|
|
33e5ff |
+ if (((*r)->flags & MALLOC) != 0 || (*r)->valref == 1) {
|
|
|
33e5ff |
+ (*l) = (*r);
|
|
|
33e5ff |
+ } else {
|
|
|
33e5ff |
+ (*l) = dupnode(*r);
|
|
|
33e5ff |
+ DEREF(*r);
|
|
|
33e5ff |
+ }
|
|
|
33e5ff |
+ force_string(*l);
|
|
|
33e5ff |
+}
|
|
|
33e5ff |
+
|
|
|
33e5ff |
+#define UNFIELD(l, r) unfield(& (l), & (r))
|
|
|
33e5ff |
+#endif
|
|
|
33e5ff |
+
|
|
|
33e5ff |
int
|
|
|
33e5ff |
r_interpret(INSTRUCTION *code)
|
|
|
33e5ff |
{
|
|
|
33e5ff |
diff --git a/test/ChangeLog b/test/ChangeLog
|
|
|
33e5ff |
index 392d593b..2af89e66 100644
|
|
|
33e5ff |
--- a/test/ChangeLog
|
|
|
33e5ff |
+++ b/test/ChangeLog
|
|
|
33e5ff |
@@ -1,3 +1,8 @@
|
|
|
33e5ff |
+2018-07-31 Arnold D. Robbins <arnold@skeeve.com>
|
|
|
33e5ff |
+
|
|
|
33e5ff |
+ * Makefile.am (EXTRA_DIST): Add assignnumfield files.
|
|
|
33e5ff |
+ * assignnumfield.awk, assignnumfield.in, assignnumfield.ok: New files.
|
|
|
33e5ff |
+
|
|
|
33e5ff |
2018-02-25 Arnold D. Robbins <arnold@skeeve.com>
|
|
|
33e5ff |
|
|
|
33e5ff |
* 4.2.1: Release tar ball made.
|
|
|
33e5ff |
diff --git a/test/Makefile.am b/test/Makefile.am
|
|
|
33e5ff |
index e6f1e223..774424f7 100644
|
|
|
33e5ff |
--- a/test/Makefile.am
|
|
|
33e5ff |
+++ b/test/Makefile.am
|
|
|
33e5ff |
@@ -121,6 +121,9 @@ EXTRA_DIST = \
|
|
|
33e5ff |
asort.ok \
|
|
|
33e5ff |
asorti.awk \
|
|
|
33e5ff |
asorti.ok \
|
|
|
33e5ff |
+ assignnumfield.awk \
|
|
|
33e5ff |
+ assignnumfield.in \
|
|
|
33e5ff |
+ assignnumfield.ok \
|
|
|
33e5ff |
awkpath.ok \
|
|
|
33e5ff |
back89.awk \
|
|
|
33e5ff |
back89.in \
|
|
|
33e5ff |
@@ -1235,7 +1238,7 @@ BASIC_TESTS = \
|
|
|
33e5ff |
addcomma anchgsub anchor argarray arrayind1 arrayind2 arrayind3 arrayparm \
|
|
|
33e5ff |
arrayprm2 arrayprm3 arrayref arrymem1 arryref2 arryref3 arryref4 arryref5 \
|
|
|
33e5ff |
arynasty arynocls aryprm1 aryprm2 aryprm3 aryprm4 aryprm5 aryprm6 aryprm7 \
|
|
|
33e5ff |
- aryprm8 aryprm9 arysubnm aryunasgn asgext awkpath \
|
|
|
33e5ff |
+ aryprm8 aryprm9 arysubnm aryunasgn asgext awkpath assignnumfield \
|
|
|
33e5ff |
back89 backgsub badassign1 badbuild \
|
|
|
33e5ff |
callparam childin clobber closebad clsflnam compare compare2 \
|
|
|
33e5ff |
concat1 concat2 concat3 concat4 concat5 convfmt \
|
|
|
33e5ff |
diff --git a/test/Makefile.in b/test/Makefile.in
|
|
|
33e5ff |
index 532aca07..69b86d07 100644
|
|
|
33e5ff |
--- a/test/Makefile.in
|
|
|
33e5ff |
+++ b/test/Makefile.in
|
|
|
33e5ff |
@@ -379,6 +379,9 @@ EXTRA_DIST = \
|
|
|
33e5ff |
asort.ok \
|
|
|
33e5ff |
asorti.awk \
|
|
|
33e5ff |
asorti.ok \
|
|
|
33e5ff |
+ assignnumfield.awk \
|
|
|
33e5ff |
+ assignnumfield.in \
|
|
|
33e5ff |
+ assignnumfield.ok \
|
|
|
33e5ff |
awkpath.ok \
|
|
|
33e5ff |
back89.awk \
|
|
|
33e5ff |
back89.in \
|
|
|
33e5ff |
@@ -1493,7 +1496,7 @@ BASIC_TESTS = \
|
|
|
33e5ff |
addcomma anchgsub anchor argarray arrayind1 arrayind2 arrayind3 arrayparm \
|
|
|
33e5ff |
arrayprm2 arrayprm3 arrayref arrymem1 arryref2 arryref3 arryref4 arryref5 \
|
|
|
33e5ff |
arynasty arynocls aryprm1 aryprm2 aryprm3 aryprm4 aryprm5 aryprm6 aryprm7 \
|
|
|
33e5ff |
- aryprm8 aryprm9 arysubnm aryunasgn asgext awkpath \
|
|
|
33e5ff |
+ aryprm8 aryprm9 arysubnm aryunasgn asgext awkpath assignnumfield \
|
|
|
33e5ff |
back89 backgsub badassign1 badbuild \
|
|
|
33e5ff |
callparam childin clobber closebad clsflnam compare compare2 \
|
|
|
33e5ff |
concat1 concat2 concat3 concat4 concat5 convfmt \
|
|
|
33e5ff |
@@ -2787,6 +2790,11 @@ asgext:
|
|
|
33e5ff |
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
|
|
|
33e5ff |
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
|
|
|
33e5ff |
|
|
|
33e5ff |
+assignnumfield:
|
|
|
33e5ff |
+ @echo $@
|
|
|
33e5ff |
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
|
|
|
33e5ff |
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
|
|
|
33e5ff |
+
|
|
|
33e5ff |
back89:
|
|
|
33e5ff |
@echo $@
|
|
|
33e5ff |
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
|
|
|
33e5ff |
diff --git a/test/Maketests b/test/Maketests
|
|
|
33e5ff |
index 8c604222..eb7c4651 100644
|
|
|
33e5ff |
--- a/test/Maketests
|
|
|
33e5ff |
+++ b/test/Maketests
|
|
|
33e5ff |
@@ -140,6 +140,11 @@ asgext:
|
|
|
33e5ff |
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
|
|
|
33e5ff |
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
|
|
|
33e5ff |
|
|
|
33e5ff |
+assignnumfield:
|
|
|
33e5ff |
+ @echo $@
|
|
|
33e5ff |
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
|
|
|
33e5ff |
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
|
|
|
33e5ff |
+
|
|
|
33e5ff |
back89:
|
|
|
33e5ff |
@echo $@
|
|
|
33e5ff |
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
|
|
|
33e5ff |
diff --git a/test/assignnumfield.awk b/test/assignnumfield.awk
|
|
|
33e5ff |
new file mode 100644
|
|
|
33e5ff |
index 00000000..3a056cb0
|
|
|
33e5ff |
--- /dev/null
|
|
|
33e5ff |
+++ b/test/assignnumfield.awk
|
|
|
33e5ff |
@@ -0,0 +1 @@
|
|
|
33e5ff |
+{$0 = ++i} 1
|
|
|
33e5ff |
diff --git a/test/assignnumfield.in b/test/assignnumfield.in
|
|
|
33e5ff |
new file mode 100644
|
|
|
33e5ff |
index 00000000..b82c4b2d
|
|
|
33e5ff |
--- /dev/null
|
|
|
33e5ff |
+++ b/test/assignnumfield.in
|
|
|
33e5ff |
@@ -0,0 +1,5 @@
|
|
|
33e5ff |
+a b c
|
|
|
33e5ff |
+a b c
|
|
|
33e5ff |
+a b c
|
|
|
33e5ff |
+a b c
|
|
|
33e5ff |
+a b c
|
|
|
33e5ff |
diff --git a/test/assignnumfield.ok b/test/assignnumfield.ok
|
|
|
33e5ff |
new file mode 100644
|
|
|
33e5ff |
index 00000000..8a1218a1
|
|
|
33e5ff |
--- /dev/null
|
|
|
33e5ff |
+++ b/test/assignnumfield.ok
|
|
|
33e5ff |
@@ -0,0 +1,5 @@
|
|
|
33e5ff |
+1
|
|
|
33e5ff |
+2
|
|
|
33e5ff |
+3
|
|
|
33e5ff |
+4
|
|
|
33e5ff |
+5
|
|
|
33e5ff |
--
|
|
|
33e5ff |
cgit v1.2.1
|
|
|
33e5ff |
|