gawk-diffs
[Top][All Lists]
Advanced

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

[gawk-diffs] [SCM] gawk branch, feature/fixtype, updated. gawk-4.1.0-189


From: Andrew J. Schorr
Subject: [gawk-diffs] [SCM] gawk branch, feature/fixtype, updated. gawk-4.1.0-1897-geb261da
Date: Thu, 7 Jul 2016 02:30:44 +0000 (UTC)

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/fixtype has been updated
       via  eb261daff5e9a96f294cd806d1fd3e68f06fdbaa (commit)
      from  ce342a04922797cb53557178c54d32c4efafda16 (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=eb261daff5e9a96f294cd806d1fd3e68f06fdbaa

commit eb261daff5e9a96f294cd806d1fd3e68f06fdbaa
Author: Andrew J. Schorr <address@hidden>
Date:   Wed Jul 6 22:29:58 2016 -0400

    Modify MAYBE_NUM usage and typeof function to return "strnum" only for 
actual numeric strings.

diff --git a/ChangeLog b/ChangeLog
index 3284747..7d11fd5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,23 @@
 2016-07-06         Andrew J. Schorr     <address@hidden>
 
+       * awk.h: Modify comments to indicate that MAYBE_NUM will now be
+       left enabled to indicate strnum values by the NUMBER|MAYBE_NUM
+       combination, whereas STRING|MAYBE_NUM indicates a potential strnum.
+       (fixtype): Modify MAYBE_NUM test to avoid calling force_number if
+       NUMCUR is already set.
+       * builtin.c (do_typeof): Call fixtype to resolve argument type.
+       This forces parsing of numeric strings, so there's a performance
+       penalty, but we must do this to give a correct result. The meaning
+       of "strnum" changes from "potential strnum" to "actual strnum".
+       * eval.c (set_TEXTDOMAIN): Remove some dead code left over from last
+       patch.
+       * int_array.c (is_integer): When a MAYBE_NUM is converted successfully
+       to a NUMBER, leave the MAYBE_NUM flag enabled.
+       * mpfr.c (mpg_force_number): Ditto.
+       * node.c (r_force_number): Ditto.
+
+2016-07-06         Andrew J. Schorr     <address@hidden>
+
        * awk.h: Modify stptr comment to indicate that all strings are now
        NUL-terminated.
        * builtin.c (do_mktime): Remove unnecessary logic to terminate
diff --git a/awk.h b/awk.h
index 09757b9..9e1fae1 100644
--- a/awk.h
+++ b/awk.h
@@ -406,14 +406,16 @@ typedef struct exp_node {
         *      b = a + 0       # Adds NUMCUR to a, since numeric value
         *                      # is now available. But the type hasn't changed!
         *
-        * MAYBE_NUM is the joker.  It means "this is string data, but
-        * the user may have really wanted it to be a number. If we have
-        * to guess, like in a comparison, turn it into a number if the string
-        * is indeed numeric."
+        * MAYBE_NUM is the joker.  When STRING|MAYBE_NUM is set, it means
+        * "this is string data, but the user may have really wanted it to be a
+        * number. If we have to guess, like in a comparison, turn it into a
+        * number if the string is indeed numeric."
         * For example,    gawk -v a=42 ....
         * Here, `a' gets STRING|STRCUR|MAYBE_NUM and then when used where
         * a number is needed, it gets turned into a NUMBER and STRING
-        * is cleared.
+        * is cleared. In that case, we leave the MAYBE_NUM in place, so
+        * the combination NUMBER|MAYBE_NUM means it is a strnum a.k.a. a
+        * "numeric string".
         *
         * WSTRCUR is for efficiency. If in a multibyte locale, and we
         * need to do something character based (substr, length, etc.)
@@ -1865,7 +1867,7 @@ fixtype(NODE *n)
 {
        assert(n->type == Node_val || n->type == Node_typedregex);
        if (n->type == Node_val) {
-               if ((n->flags & MAYBE_NUM) != 0)
+               if ((n->flags & (NUMCUR|MAYBE_NUM)) == MAYBE_NUM)
                        return force_number(n);
                if ((n->flags & INTIND) != 0)
                        return force_string(n);
diff --git a/builtin.c b/builtin.c
index a21df18..032f0ec 100644
--- a/builtin.c
+++ b/builtin.c
@@ -3951,14 +3951,14 @@ do_typeof(int nargs)
                break;
        case Node_val:
        case Node_var:
-               switch (arg->flags & (STRING|NUMBER|MAYBE_NUM)) {
+               switch (fixtype(arg)->flags & (STRING|NUMBER|MAYBE_NUM)) {
                case STRING:
                        res = "string";
                        break;
                case NUMBER:
                        res = "number";
                        break;
-               case STRING|MAYBE_NUM:
+               case NUMBER|MAYBE_NUM:
                        res = "strnum";
                        break;
                case NUMBER|STRING:
diff --git a/eval.c b/eval.c
index aaabdb3..cfb1d1e 100644
--- a/eval.c
+++ b/eval.c
@@ -955,12 +955,10 @@ set_LINT()
 void
 set_TEXTDOMAIN()
 {
-       int len;
        NODE *tmp;
 
        tmp = TEXTDOMAIN_node->var_value = 
force_string(TEXTDOMAIN_node->var_value);
        TEXTDOMAIN = tmp->stptr;
-       len = tmp->stlen;
        /*
         * Note: don't call textdomain(); this value is for
         * the awk program, not for gawk itself.
diff --git a/int_array.c b/int_array.c
index 93e96d1..937a91c 100644
--- a/int_array.c
+++ b/int_array.c
@@ -142,7 +142,8 @@ is_integer(NODE *symbol, NODE *subs)
        if (len == 1 && *cp != '-') {   /* single digit */
                subs->numbr = (long) (*cp - '0');
                if ((subs->flags & MAYBE_NUM) != 0) {
-                       subs->flags &= ~(MAYBE_NUM|STRING);
+                       /* leave MAYBE_NUM set */
+                       subs->flags &= ~STRING;
                        subs->flags |= NUMBER;
                }
                subs->flags |= (NUMCUR|NUMINT);
@@ -158,7 +159,8 @@ is_integer(NODE *symbol, NODE *subs)
 
        subs->numbr = l;
        if ((subs->flags & MAYBE_NUM) != 0) {
-               subs->flags &= ~(MAYBE_NUM|STRING);
+               /* leave MAYBE_NUM set */
+               subs->flags &= ~STRING;
                subs->flags |= NUMBER;
        }
        subs->flags |= NUMCUR;
diff --git a/mpfr.c b/mpfr.c
index cf7a7c2..b239e4b 100644
--- a/mpfr.c
+++ b/mpfr.c
@@ -342,7 +342,8 @@ mpg_force_number(NODE *n)
 
        if (force_mpnum(n, (do_non_decimal_data && ! do_traditional), true)) {
                if ((n->flags & MAYBE_NUM) != 0) {
-                       n->flags &= ~(MAYBE_NUM|STRING);
+                       /* leave MAYBE_NUM set to indicate a strnum */
+                       n->flags &= ~STRING;
                        n->flags |= NUMBER;
                }
        } else
diff --git a/node.c b/node.c
index 2cd8833..37aa946 100644
--- a/node.c
+++ b/node.c
@@ -66,9 +66,9 @@ r_force_number(NODE *n)
                return n;
 
        /*
-        * We should always set NUMCUR and clear MAYBE_NUM, and we may possibly
-        * change STRING to NUMBER if MAYBE_NUM was set and it's a good numeric
-        * string.
+        * We should always set NUMCUR. If MAYBE_NUM is set and it's a
+        * numeric string, we clear STRING and enable NUMBER, but if it's not
+        * numeric, we disable MAYBE_NUM.
         */
 
        /* All the conditionals are an attempt to avoid the expensive strtod */
@@ -166,7 +166,8 @@ badnum:
 
 goodnum:
        if ((n->flags & MAYBE_NUM) != 0) {
-               n->flags &= ~(MAYBE_NUM|STRING);
+               /* leave MAYBE_NUM enabled to indicate that this is a strnum */
+               n->flags &= ~STRING;
                n->flags |= NUMBER;
        }
        return n;
diff --git a/test/ChangeLog b/test/ChangeLog
index 5897906..6821488 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,11 @@
+2016-07-06         Andrew J. Schorr     <address@hidden>
+
+       * forcenum.awk: We no longer need to force the strnum conversion,
+       since typeof now does this automatically.
+       * forcenum.ok: Change "number" to "strnum" for the numeric strings.
+       * rebuild.in: Change input to include a strnum.
+       * rebuild.ok: Update results.
+
 2016-07-04         Andrew J. Schorr     <address@hidden>
 
        * Makefile.am (arrayind3): New test.
diff --git a/test/forcenum.awk b/test/forcenum.awk
index 54c536c..1a7ddce 100644
--- a/test/forcenum.awk
+++ b/test/forcenum.awk
@@ -1,8 +1,6 @@
 BEGIN {
-       # first, make some strnums
+       # make some strnums
        nf = split("|5apple|+NaN| 6|0x1az|011Q|027", f, "|")
-       for (i = 1; i <= nf; i++) {
-               x = f[i]+0      # trigger strnum conversion to number or string
+       for (i = 1; i <= nf; i++)
                printf "[%s] -> %g (type %s)\n", f[i], f[i], typeof(f[i])
-       }
 }
diff --git a/test/forcenum.ok b/test/forcenum.ok
index c74eefc..a379db6 100644
--- a/test/forcenum.ok
+++ b/test/forcenum.ok
@@ -1,7 +1,7 @@
 [] -> 0 (type string)
 [5apple] -> 5 (type string)
-[+NaN] -> nan (type number)
-[ 6] -> 6 (type number)
+[+NaN] -> nan (type strnum)
+[ 6] -> 6 (type strnum)
 [0x1az] -> 26 (type string)
 [011Q] -> 9 (type string)
-[027] -> 23 (type number)
+[027] -> 23 (type strnum)
diff --git a/test/rebuild.in b/test/rebuild.in
index b2901ea..2f16a82 100644
--- a/test/rebuild.in
+++ b/test/rebuild.in
@@ -1 +1 @@
-a b
+a 6.3
diff --git a/test/rebuild.ok b/test/rebuild.ok
index 2963527..0fe72e2 100644
--- a/test/rebuild.ok
+++ b/test/rebuild.ok
@@ -1,2 +1,2 @@
-test b
+test 6.3
 strnum

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

Summary of changes:
 ChangeLog         |   18 ++++++++++++++++++
 awk.h             |   14 ++++++++------
 builtin.c         |    4 ++--
 eval.c            |    2 --
 int_array.c       |    6 ++++--
 mpfr.c            |    3 ++-
 node.c            |    9 +++++----
 test/ChangeLog    |    8 ++++++++
 test/forcenum.awk |    6 ++----
 test/forcenum.ok  |    6 +++---
 test/rebuild.in   |    2 +-
 test/rebuild.ok   |    2 +-
 12 files changed, 54 insertions(+), 26 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

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