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-185


From: Arnold Robbins
Subject: [gawk-diffs] [SCM] gawk branch, feature/fixtype, updated. gawk-4.1.0-1859-ge18ebe1
Date: Sun, 26 Jun 2016 15:27:22 +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  e18ebe10166e2c63f3385666978b678fe6ce67a2 (commit)
       via  278767f062a9c6f8ae9ff777b1a41e094813fa09 (commit)
       via  f5974cd7969e6e53d90d2d3d0023c958e83a3dd1 (commit)
       via  b2ebebda055fb7e9cd02c03e394decdbcf63afd3 (commit)
      from  9d9f63e5f27ea49493fc885e4e29e3196e72f601 (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=e18ebe10166e2c63f3385666978b678fe6ce67a2

commit e18ebe10166e2c63f3385666978b678fe6ce67a2
Author: Arnold D. Robbins <address@hidden>
Date:   Sun Jun 26 18:26:39 2016 +0300

    Minor improvements after Andy's reworking of stuff.

diff --git a/ChangeLog b/ChangeLog
index 1c5b763..3ce9292 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2016-06-26         Arnold D. Robbins     <address@hidden>
 
+       * awk.h: Edit some comments. Add others. Minor coding style changes.
+       * builtin.c (format_tree): Restore a comment.
+       (do_mktime): Restore saving/restoring of byte after format string.
+       (do_sub): Coding style. Use %.*s in warning message.
+       (nondec2awknum): Restore saving/restoring of byte after string value
+       being converted.
+       * eval.c: Minor coding style edits.
+       * int_array.c (is_integer): Fix order of checks for not
+       updating string value: check length == 0 before testing values.
+       Coding style edits.
+       * mpfr.c (do_mpfr_strtonum): Coding style edits.
+       * node.c (r_force_number): Restore saving/restoring of byte after
+       string value being converted. Edit comments some.
+
+2016-06-26         Arnold D. Robbins     <address@hidden>
+
        Repair change of 2015-08-25 to handling of MAYBE_NUM.
        * mpfr.c (mpg_force_number): Just clear MAYBE_NUM.
        * node.c (r_force_number): Clear STRING separately after
diff --git a/awk.h b/awk.h
index 8b899b8..1d1e4fb 100644
--- a/awk.h
+++ b/awk.h
@@ -1825,22 +1825,25 @@ force_number(NODE *n)
 #endif /* GAWKDEBUG */
 
 
+/* fixtype --- make a node decide if it's a number or a string */
+
 /*
  * In certain contexts, the true type of a scalar value matters, and we
- * must ascertain whether it is a a NUMBER or a STRING. In such situations,
+ * must ascertain whether it is a NUMBER or a STRING. In such situations,
  * please use this function to resolve the type.
  *
  * It is safe to assume that the return value will be the same NODE,
- * since force_number on a MAYBE_NUM should always returns the same NODE,
+ * since force_number on a MAYBE_NUM should always return the same NODE,
  * and force_string on an INTIND should as well.
  *
  * There is no way to handle a Node_typedregex correctly, so we ignore
  * that case.
  */
+
 static inline NODE *
 fixtype(NODE *n)
 {
-       assert((n->type == Node_val) || (n->type == Node_typedregex));
+       assert(n->type == Node_val || n->type == Node_typedregex);
        if (n->type == Node_val) {
                if ((n->flags & MAYBE_NUM) != 0)
                        return force_number(n);
@@ -1850,10 +1853,13 @@ fixtype(NODE *n)
        return n;
 }
 
+/* boolval --- return true/false based on awk's criteria */
+
 /*
- * In `awk', a value is considered to be true if it is nonzero _or_
+ * In awk, a value is considered to be true if it is nonzero _or_
  * non-null. Otherwise, the value is false.
  */
+
 static inline int
 boolval(NODE *t)
 {
diff --git a/builtin.c b/builtin.c
index 67b963e..08ce327 100644
--- a/builtin.c
+++ b/builtin.c
@@ -1048,6 +1048,7 @@ check_pos:
                case 'c':
                        need_format = false;
                        parse_next_arg();
+                       /* user input that looks numeric is numeric */
                        fixtype(arg);
                        if ((arg->flags & NUMBER) != 0) {
                                uval = get_number_uj(arg);
@@ -2034,12 +2035,16 @@ do_mktime(int nargs)
        int month, day, hour, minute, second, count;
        int dst = -1; /* default is unknown */
        time_t then_stamp;
+       char save;
 
        t1 = POP_SCALAR();
        if (do_lint && (fixtype(t1)->flags & STRING) == 0)
                lintwarn(_("mktime: received non-string argument"));
        t1 = force_string(t1);
 
+       save = t1->stptr[t1->stlen];
+       t1->stptr[t1->stlen] = '\0';
+
        count = sscanf(t1->stptr, "%ld %d %d %d %d %d %d",
                        & year, & month, & day,
                        & hour, & minute, & second,
@@ -2053,6 +2058,7 @@ do_mktime(int nargs)
                || (month < 1 || month > 12) ))
                        lintwarn(_("mktime: at least one of the values is out 
of the default range"));
 
+       t1->stptr[t1->stlen] = save;
        DEREF(t1);
 
        if (count < 6
@@ -2859,10 +2865,9 @@ do_sub(int nargs, unsigned int flags)
                target = POP_STRING();  /* original string */
 
                glob_flag = POP_SCALAR();       /* value of global flag */
-               if (((glob_flag->flags & STRING) != 0)
-                       && (glob_flag->stlen > 0
-                               && (glob_flag->stptr[0] == 'g'
-                                       || glob_flag->stptr[0] == 'G')))
+               if (   (glob_flag->flags & STRING) != 0
+                   && glob_flag->stlen > 0
+                   && (glob_flag->stptr[0] == 'g' || glob_flag->stptr[0] == 
'G'))
                        how_many = -1;
                else {
                        (void) force_number(glob_flag);
@@ -2875,7 +2880,9 @@ do_sub(int nargs, unsigned int flags)
                                how_many = LONG_MAX;
                        if (d <= 0) {
                                (void) force_string(glob_flag);
-                               warning(_("gensub: third argument `%s' treated 
as 1"), glob_flag->stptr);
+                               warning(_("gensub: third argument `%.*s' 
treated as 1"),
+                                               (int) glob_flag->stlen,
+                                               glob_flag->stptr);
                        }
                }
                DEREF(glob_flag);
@@ -3561,6 +3568,7 @@ AWKNUM
 nondec2awknum(char *str, size_t len, char **endptr)
 {
        AWKNUM retval = 0.0;
+       char save;
        short val;
        char *start = str;
 
@@ -3632,7 +3640,10 @@ nondec2awknum(char *str, size_t len, char **endptr)
                        *endptr = str;
        } else {
 decimal:
+               save = str[len];
+               str[len] = '\0';
                retval = strtod(str, endptr);
+               str[len] = save;
        }
 done:
        return retval;
diff --git a/eval.c b/eval.c
index d773520..5b4418b 100644
--- a/eval.c
+++ b/eval.c
@@ -942,18 +942,16 @@ set_LINT()
                        if (lintlen == 5 && strncmp(lintval, "fatal", 5) == 0)
                                lintfunc = r_fatal;
                        else if (lintlen == 7 && strncmp(lintval, "invalid", 7) 
== 0) {
-                               do_flags &= ~ DO_LINT_ALL;
+                               do_flags &= ~DO_LINT_ALL;
                                do_flags |= DO_LINT_INVALID;
                        }
                } else {
                        do_flags &= ~(DO_LINT_ALL|DO_LINT_INVALID);
                }
-       } else {
-               if (! iszero(n))
-                       do_flags |= DO_LINT_ALL;
-               else
-                       do_flags &= ~(DO_LINT_ALL|DO_LINT_INVALID);
-       }
+       } else if (! iszero(n))
+               do_flags |= DO_LINT_ALL;
+       else
+               do_flags &= ~(DO_LINT_ALL|DO_LINT_INVALID);
 
        /* explicitly use warning() here, in case lintfunc == r_fatal */
        if (old_lint != do_lint && old_lint && ! do_lint)
diff --git a/int_array.c b/int_array.c
index 4ba7c98..f17bdde 100644
--- a/int_array.c
+++ b/int_array.c
@@ -96,11 +96,13 @@ is_integer(NODE *symbol, NODE *subs)
        if ((subs->flags & STRCUR) != 0) {
                char *cp = subs->stptr;
 
-               if ((cp[0] == '0') || isspace((unsigned char) cp[0])
-                       || (subs->stlen < 1)
+               if (       subs->stlen == 0
+                       || cp[0] == '0'
+                       || isspace((unsigned char) cp[0])
                        || isspace((unsigned char) cp[subs->stlen - 1])
-                       || ((subs->stlen >= 2) && (cp[0] == '-')
-                               && (cp[1] == '0')))
+                       || (       subs->stlen >= 2
+                               && (cp[0] == '-' || cp[0] == '+')
+                               && cp[1] == '0'))
                        return NULL;
        }
 
@@ -122,50 +124,51 @@ is_integer(NODE *symbol, NODE *subs)
         * a[-3]=1; print "-3" in a  -- true
         */
 
-       {
-               /* must be a STRING */
-               char *cp = subs->stptr, *cpend, *ptr;
-               char save;
-               size_t len = subs->stlen;
+       /* must be a STRING */
+       char *cp = subs->stptr, *cpend, *ptr;
+       char save;
+       size_t len = subs->stlen;
 
-               if (len == 0 || (! isdigit((unsigned char) *cp) && *cp != '-'))
-                       return NULL;
-               if (len > 1 && 
-                       ((*cp == '0')           /* "00", "011" .. */
-                               || (*cp == '-' && *(cp + 1) == '0')     /* 
"-0", "-011" .. */
-                       )
-               )
-                       return NULL;
-               if (len == 1 && *cp != '-') {   /* single digit */
-                       subs->numbr = (long) (*cp - '0');
-                       if ((subs->flags & MAYBE_NUM) != 0) {
-                               subs->flags &= ~(MAYBE_NUM|STRING);
-                               subs->flags |= NUMBER;
-                       }
-                       subs->flags |= (NUMCUR|NUMINT);
-                       return & success_node;
-               }
-
-               cpend = cp + len;
-               save = *cpend;
-               *cpend = '\0';
+       if (len == 0 || (! isdigit((unsigned char) *cp) && *cp != '-'))
+               return NULL;
 
-               errno = 0;
-               l = strtol(cp, & ptr, 10);
-               *cpend = save;
-               if (errno != 0 || ptr != cpend)
-                       return NULL;
-               subs->numbr = l;
+       if (len > 1 && 
+               ((*cp == '0')           /* "00", "011" .. */
+                       || (*cp == '-' && *(cp + 1) == '0')     /* "-0", "-011" 
.. */
+               )
+       )
+               return NULL;
+       if (len == 1 && *cp != '-') {   /* single digit */
+               subs->numbr = (long) (*cp - '0');
                if ((subs->flags & MAYBE_NUM) != 0) {
                        subs->flags &= ~(MAYBE_NUM|STRING);
                        subs->flags |= NUMBER;
                }
-               subs->flags |= NUMCUR;
-               if (l <= INT32_MAX && l >= INT32_MIN) {
-                       subs->flags |= NUMINT;
-                       return & success_node;
-               }
+               subs->flags |= (NUMCUR|NUMINT);
+               return & success_node;
        }
+
+       cpend = cp + len;
+       save = *cpend;
+       *cpend = '\0';
+
+       errno = 0;
+       l = strtol(cp, & ptr, 10);
+       *cpend = save;
+       if (errno != 0 || ptr != cpend)
+               return NULL;
+
+       subs->numbr = l;
+       if ((subs->flags & MAYBE_NUM) != 0) {
+               subs->flags &= ~(MAYBE_NUM|STRING);
+               subs->flags |= NUMBER;
+       }
+       subs->flags |= NUMCUR;
+       if (l <= INT32_MAX && l >= INT32_MIN) {
+               subs->flags |= NUMINT;
+               return & success_node;
+       }
+
        return NULL;
 }
 
diff --git a/mpfr.c b/mpfr.c
index 9d270e6..b15c9b0 100644
--- a/mpfr.c
+++ b/mpfr.c
@@ -1079,16 +1079,14 @@ do_mpfr_strtonum(int nargs)
                force_mpnum(r, true, use_lc_numeric);
                r->stptr = NULL;
                r->stlen = 0;
+       } else if (is_mpg_float(tmp)) {
+               int tval;
+               r = mpg_float();
+               tval = mpfr_set(r->mpg_numbr, tmp->mpg_numbr, ROUND_MODE);
+               IEEE_FMT(r->mpg_numbr, tval);
        } else {
-               if (is_mpg_float(tmp)) {
-                       int tval;
-                       r = mpg_float();
-                       tval = mpfr_set(r->mpg_numbr, tmp->mpg_numbr, 
ROUND_MODE);
-                       IEEE_FMT(r->mpg_numbr, tval);
-               } else {
-                       r = mpg_integer();
-                       mpz_set(r->mpg_i, tmp->mpg_i);
-               }
+               r = mpg_integer();
+               mpz_set(r->mpg_i, tmp->mpg_i);
        }
 
        DEREF(tmp);
diff --git a/node.c b/node.c
index bfa9a35..39c25df 100644
--- a/node.c
+++ b/node.c
@@ -59,6 +59,7 @@ r_force_number(NODE *n)
 {
        char *cp;
        char *cpend;
+       char save;
        char *ptr;
        extern double strtod();
 
@@ -66,12 +67,12 @@ r_force_number(NODE *n)
                return n;
 
        /*
-        * we should always set NUMCUR and clear MAYBE_NUM, and we may possibly
+        * 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.
         */
 
-       /* all the conditionals are an attempt to avoid the expensive strtod */
+       /* All the conditionals are an attempt to avoid the expensive strtod */
 
        n->flags |= NUMCUR;
        n->numbr = 0.0;
@@ -122,23 +123,27 @@ r_force_number(NODE *n)
                goto badnum;
        }
 
+       errno = 0;
        if (do_non_decimal_data         /* main.c assures false if do_posix */
                && ! do_traditional && get_numbase(cp, true) != 10) {
-               errno = 0;
+               /* nondec2awknum() saves and restores the byte after the string 
itself */
                n->numbr = nondec2awknum(cp, cpend - cp, &ptr);
        } else {
-               errno = 0;
+               save = *cpend;
+               *cpend = '\0';
                n->numbr = (AWKNUM) strtod((const char *) cp, &ptr);
+               *cpend = save;
        }
 
        /* POSIX says trailing space is OK for NUMBER */
        while (isspace((unsigned char) *ptr))
                ptr++;
+
        if (errno == 0) {
                if (ptr == cpend)
                        goto goodnum;
                /* else keep the leading numeric value without updating flags */
-               /* fall through to badnum*/
+               /* fall through to badnum */
        } else {
                errno = 0;
                /*
@@ -151,7 +156,7 @@ r_force_number(NODE *n)
                 * Or should we accept it as a NUMBER even though strtod
                 * threw an error?
                 */
-               /* fall through to badnum*/
+               /* fall through to badnum */
        }
 badnum:
        n->flags &= ~MAYBE_NUM;

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

commit 278767f062a9c6f8ae9ff777b1a41e094813fa09
Merge: 9d9f63e f5974cd
Author: Arnold D. Robbins <address@hidden>
Date:   Sun Jun 26 18:15:59 2016 +0300

    Merge branch 'master' into feature/fixtype

diff --cc ChangeLog
index 2d0ca88,1450e47..1c5b763
--- a/ChangeLog
+++ b/ChangeLog
@@@ -1,17 -1,13 +1,29 @@@
+ 2016-06-26         Arnold D. Robbins     <address@hidden>
+ 
+       Repair change of 2015-08-25 to handling of MAYBE_NUM.
+       * mpfr.c (mpg_force_number): Just clear MAYBE_NUM.
+       * node.c (r_force_number): Clear STRING separately after
+       setting NUMBER.
+ 
+       Thanks to Andrew Schorr for reporting the problem.
+       A test case will eventually be merged into master.
+ 
++      Only in stable and master.
++
 +2016-06-20         Andrew J. Schorr     <address@hidden>
 +
 +      * builtin.c (do_strftime): Call fixtype before checking flags for
 +      STRING type.
 +      (do_print): Call fixtype before checking whether argument is a NUMBER.
 +      * eval.c (set_BINMODE): Call fixtype before checking value type.
 +      No need to call force_number if the flags say it's a number.
 +      (r_get_field): Fix lint check for non-numeric argument.
 +      * io.c (redirect): Call fixtype before checking whether it's a string.
 +
 +2016-06-18         Andrew J. Schorr     <address@hidden>
 +
 +      * node.c (r_force_number): Fix typo in comment.
 +
  2016-06-16         Arnold D. Robbins     <address@hidden>
  
        * awk.h: Add comment headers for several functions.

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

Summary of changes:
 ChangeLog   |   28 ++++++++++++++++++++
 awk.h       |   14 +++++++---
 builtin.c   |   21 +++++++++++----
 eval.c      |   12 ++++-----
 int_array.c |   85 +++++++++++++++++++++++++++++++----------------------------
 mpfr.c      |   16 +++++------
 node.c      |   17 +++++++-----
 7 files changed, 121 insertions(+), 72 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

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