gawk-diffs
[Top][All Lists]
Advanced

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

[gawk-diffs] [SCM] gawk branch, extgawk, updated. 1a69f3ec43ba9748ad6344


From: Andrew J. Schorr
Subject: [gawk-diffs] [SCM] gawk branch, extgawk, updated. 1a69f3ec43ba9748ad63443f88b2e26b014c11d2
Date: Thu, 26 Jul 2012 15:08:27 +0000

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, extgawk has been updated
       via  1a69f3ec43ba9748ad63443f88b2e26b014c11d2 (commit)
      from  7e5b2a94ce3c089c50c5862168d1d917e5febcf4 (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=1a69f3ec43ba9748ad63443f88b2e26b014c11d2

commit 1a69f3ec43ba9748ad63443f88b2e26b014c11d2
Author: Andrew J. Schorr <address@hidden>
Date:   Thu Jul 26 11:08:02 2012 -0400

    Fix api_sym_update_scalar.

diff --git a/ChangeLog b/ChangeLog
index a80439a..5af81f5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2012-07-26         Andrew J. Schorr     <address@hidden>
+
+       * gawkapi.c (api_sym_update_scalar): Fix some minor bugs.  Was
+       not updating AWK_NUMBER when valref != 1.  And strings were not
+       freeing MPFR values.
+
 2012-07-25         Arnold D. Robbins     <address@hidden>
 
        Start refactoring of IOBUF handling and turn "open hooks"
diff --git a/gawkapi.c b/gawkapi.c
index b72a62a..a1241df 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -574,53 +574,69 @@ api_sym_update_scalar(awk_ext_id_t id,
            || node->type != Node_var)
                return false;
 
+       /*
+        * Optimization: if valref is 1, and the new value is a string or
+        * a number, we can avoid calling unref and then making a new node
+        * by simply installing the new value.  First, we follow the same
+        * recipe used by node.c:r_unref to wipe the current values, and then
+        * we copy the logic from r_make_number or r_make_str_node to install
+        * the new value.
+        */
        switch (value->val_type) {
        case AWK_NUMBER:
+               if (node->var_value->valref == 1 && ! do_mpfr) {
+                       NODE *r = node->var_value;
+
+                       /* r_unref: */
+                       if ((r->flags & (MALLOC|STRCUR)) == (MALLOC|STRCUR))
+                               efree(r->stptr);
+                       free_wstr(r);
+
+                       /* r_make_number: */
+                       r->numbr = value->num_value;
+                       r->flags = MALLOC|NUMBER|NUMCUR;
+                       r->stptr = NULL;
+                       r->stlen = 0;
+                       return true;
+               }
+               break;
        case AWK_STRING:
-               /* try for optimization */
                if (node->var_value->valref == 1) {
                        NODE *r = node->var_value;
 
-                       if (value->val_type == AWK_NUMBER && do_mpfr)
-                               break;  /* break switch, do it the hard way */
-
-                       /* release the old string value if any */
-                       if (r->flags & STRCUR) {
-                               if (r->flags & MALLOC)
-                                       efree(r->stptr);
-                               r->stptr = NULL;
-                               r->stlen = 0;
-                       }
+                       /* r_unref: */
+                       if ((r->flags & (MALLOC|STRCUR)) == (MALLOC|STRCUR))
+                               efree(r->stptr);
+#ifdef HAVE_MPFR
+                       if (is_mpg_float(r))
+                               mpfr_clear(r->mpg_numbr);
+                       else if (is_mpg_integer(r))
+                               mpz_clear(r->mpg_i);
+#endif
                        free_wstr(r);
 
-                       if (value->val_type == AWK_NUMBER) {
-                               r->flags = MALLOC|NUMBER|NUMCUR;
-                               r->numbr = value->num_value;
-                       } else {
-                               r->flags &= ~(NUMBER|NUMCUR);
-                               r->flags |= (STRING|STRCUR|MALLOC);
-                               r->stfmt = -1;
-                               r->stptr = value->str_value.str;
-                               r->stlen = value->str_value.len;
-                       }
-
+                       /* r_make_str_node(ALREADY_MALLOCED): */
+                       r->numbr = 0;
+                       r->flags = (MALLOC|STRING|STRCUR);
+                       r->stfmt = -1;
+                       r->stptr = value->str_value.str;
+                       r->stlen = value->str_value.len;
                        return true;
                }
-               /* else
-                       fall through */
+               break;
        case AWK_UNDEFINED:
        case AWK_SCALAR:
        case AWK_VALUE_COOKIE:
-               unref(node->var_value);
-               node->var_value = awk_value_to_node(value);
-
-               return true;
-
-       case AWK_ARRAY:
                break;
+
+       default:        /* AWK_ARRAY or invalid type */
+               return false;
        }
 
-       return false;
+       /* do it the hard (slow) way */
+       unref(node->var_value);
+       node->var_value = awk_value_to_node(value);
+       return true;
 }
 
 /*

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

Summary of changes:
 ChangeLog |    6 ++++
 gawkapi.c |   78 ++++++++++++++++++++++++++++++++++++------------------------
 2 files changed, 53 insertions(+), 31 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

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