gawk-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] gawk branch, feature/mdim-restart, updated. gawk-4.1.0-4683-g32cf6


From: Arnold Robbins
Subject: [SCM] gawk branch, feature/mdim-restart, updated. gawk-4.1.0-4683-g32cf648f
Date: Sat, 26 Mar 2022 15:13:52 -0400 (EDT)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".

The branch, feature/mdim-restart has been updated
       via  32cf648f9ee4f30e95e3a4503ed56f9b2ca9c8ab (commit)
       via  0368d0007ddeba8c0f6b32bef47c0b7d3b49784b (commit)
       via  b67edcd6079e5c600f9b36c00994555ed54edc00 (commit)
      from  0a5688347945717c3bce4993ac507f692a85ebe2 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=32cf648f9ee4f30e95e3a4503ed56f9b2ca9c8ab

commit 32cf648f9ee4f30e95e3a4503ed56f9b2ca9c8ab
Author: Arnold D. Robbins <arnold@skeeve.com>
Date:   Sat Mar 26 22:13:19 2022 +0300

    Continue fixing.

diff --git a/array.c b/array.c
index 748e2b7f..47999f55 100644
--- a/array.c
+++ b/array.c
@@ -1434,7 +1434,7 @@ assoc_list(NODE *symbol, const char *sort_str, 
sort_context_t sort_ctxt)
 
 /* new_array_element --- return a new empty element node */
 
-extern NODE *
+NODE *
 new_array_element(void)
 {
        NODE *n;
diff --git a/eval.c b/eval.c
index e5dd5735..47dcdf10 100644
--- a/eval.c
+++ b/eval.c
@@ -1526,6 +1526,8 @@ eval_condition(NODE *t)
 static bool cmp_doubles(const NODE *t1, const NODE *t2, scalar_cmp_t 
comparison_type);
 extern bool mpg_cmp_as_numbers(const NODE *t1, const NODE *t2, scalar_cmp_t 
comparison_type);
 
+static void elem_new_to_scalar(NODE *n);
+
 /* cmp_scalars -- compare two nodes on the stack */
 
 static bool
@@ -1537,6 +1539,10 @@ cmp_scalars(scalar_cmp_t comparison_type)
 
        t2 = POP_SCALAR();
        t1 = TOP();
+
+       elem_new_to_scalar(t1);
+       elem_new_to_scalar(t2);
+
        if (t1->type == Node_var_array) {
                DEREF(t2);
                fatal(_("attempt to use array `%s' in a scalar context"), 
array_vname(t1));
@@ -1875,3 +1881,22 @@ init_interpret()
                interpret = r_interpret;
 }
 
+/* elem_new_to_scalar --- convert Node_elem_new to untyped scalar */
+
+static void
+elem_new_to_scalar(NODE *n)
+{
+       NODE *s;
+
+       if (n->type != Node_elem_new)
+               return;
+
+       getnode(s);
+       *s = *Nnull_string;
+       // See the comment in awk.h:force_string_fmt as to why we
+       // increase the valref.
+       s->valref = n->valref + 1;
+       *n = *s;
+
+       freenode(s);
+}

http://git.sv.gnu.org/cgit/gawk.git/commit/?id=0368d0007ddeba8c0f6b32bef47c0b7d3b49784b

commit 0368d0007ddeba8c0f6b32bef47c0b7d3b49784b
Author: Arnold D. Robbins <arnold@skeeve.com>
Date:   Sat Mar 26 21:55:07 2022 +0300

    Next fix.

diff --git a/interpret.h b/interpret.h
index 30a4db4c..8227eccb 100644
--- a/interpret.h
+++ b/interpret.h
@@ -1490,7 +1490,8 @@ match_re:
 
                case Op_pop:
                        r = POP_SCALAR();
-                       DEREF(r);
+                       if (r->type != Node_elem_new)
+                               DEREF(r);
                        break;
 
                case Op_line_range:

http://git.sv.gnu.org/cgit/gawk.git/commit/?id=b67edcd6079e5c600f9b36c00994555ed54edc00

commit b67edcd6079e5c600f9b36c00994555ed54edc00
Author: Arnold D. Robbins <arnold@skeeve.com>
Date:   Sat Mar 26 21:19:06 2022 +0300

    Continue making progress.

diff --git a/awk.h b/awk.h
index 753d105b..dc0202a4 100644
--- a/awk.h
+++ b/awk.h
@@ -1945,9 +1945,18 @@ static inline NODE *
 force_string_fmt(NODE *s, const char *fmtstr, int fmtidx)
 {
        if (s->type == Node_elem_new) {
-               *s = *Nnull_string;
-               s->valref = 1;
-               s->flags &= ~(NUMCUR|NUMBER);
+               NODE *p = make_string("", 0);
+               *s = *p;
+               // This is interesting. A Node_elem_new gets converted to
+               // a string on number only by an operation working on it
+               // where it's on the stack. The Node_elem_new itself does
+               // get UPREF'ed when pushed on the stack. So converting it
+               // needs to make it look like a Node_val that _was_ UPREF'ed.
+               // Thus we increase the valref so that later on when it's
+               // unref'ed the valref doesn't go to zero too early.
+               // The same thing is done in the two versions of str2number.
+               s->valref++;
+               freenode(p);
                return s;
        }
 
diff --git a/mpfr.c b/mpfr.c
index a6022f9a..3fd21614 100644
--- a/mpfr.c
+++ b/mpfr.c
@@ -350,9 +350,13 @@ mpg_force_number(NODE *n)
        char *cp, *cpend;
 
        if (n->type == Node_elem_new) {
-               *n = *Nnull_string;
-               n->flags &= ~(STRING|STRCUR);
-               n->valref = 1;
+               NODE *r = make_number(0.0);
+
+               *n = *r;
+               // See the comment in awk.h:force_string_fmt for an explanation
+               // of why we increment valref.
+               n->valref++;
+               freenode(r);
                return n;
        }
 
diff --git a/node.c b/node.c
index 13d41aca..f6b54d2d 100644
--- a/node.c
+++ b/node.c
@@ -62,9 +62,12 @@ r_force_number(NODE *n)
        char *ptr;
 
        if (n->type == Node_elem_new) {
-               *n = *Nnull_string;
-               n->flags &= ~(STRING|STRCUR);
-               n->valref = 1;
+               NODE *p = make_number(0.0);
+               *n = *p;
+               // See the comment in awk.h:force_string_fmt for an explanation
+               // of why we increment valref.
+               n->valref++;
+               freenode(p);
                return n;
        }
 
diff --git a/test/typeof3.awk b/test/typeof3.awk
index d148f373..2f864f45 100644
--- a/test/typeof3.awk
+++ b/test/typeof3.awk
@@ -15,5 +15,5 @@ BEGIN {
 BEGIN {
        print typeof(x)
        print typeof(a[1])
-       a[1][2] # fatals on this
+       a[1][2] # this used to fatal, it no longer does
 }
diff --git a/test/typeof3.ok b/test/typeof3.ok
index a6cd6c4a..f9026b08 100644
--- a/test/typeof3.ok
+++ b/test/typeof3.ok
@@ -4,6 +4,4 @@ regexp
 number
 4
 number
-unassigned
-gawk: typeof3.awk:18: fatal: attempt to use scalar `a["1"]' as an array
-EXIT CODE: 2
+untyped

-----------------------------------------------------------------------

Summary of changes:
 array.c          |  2 +-
 awk.h            | 15 ++++++++++++---
 eval.c           | 25 +++++++++++++++++++++++++
 interpret.h      |  3 ++-
 mpfr.c           | 10 +++++++---
 node.c           |  9 ++++++---
 test/typeof3.awk |  2 +-
 test/typeof3.ok  |  4 +---
 8 files changed, 55 insertions(+), 15 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]