gawk-diffs
[Top][All Lists]
Advanced

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

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


From: Arnold Robbins
Subject: [gawk-diffs] [SCM] gawk branch, feature/namespaces, updated. gawk-4.1.0-2604-g02a77f8
Date: Wed, 28 Jun 2017 14:36:31 -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/namespaces has been updated
       via  02a77f869d2822a4826f7f07009a87f86cd4b79a (commit)
      from  fec1b324f39faa49f271a7981a3ea7d60d96893a (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=02a77f869d2822a4826f7f07009a87f86cd4b79a

commit 02a77f869d2822a4826f7f07009a87f86cd4b79a
Author: Arnold D. Robbins <address@hidden>
Date:   Wed Jun 28 21:36:07 2017 +0300

    Memory management bug fix for fully qualified names.

diff --git a/ChangeLog b/ChangeLog
index fd96196..fd12cb7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2017-06-28         Arnold D. Robbins     <address@hidden>
+
+       * awk.h [ns_name]: Add macro in preparation for use.
+       * debug.c (print_instruction): Add case for Op_K_namespace.
+       Not really used yet.
+       * symbol.c (fix_up_namespace): Bug fix to always allocate
+       memory for a full name. Add boolean parameter to indicate
+       if memory was malloc'ed or not.
+       (lookup): Adjust call to fix_up_namespace and use make_str_node
+       if the string was malloced.
+       (install): Ditto.
+
 2017-06-25         Andrew J. Schorr     <address@hidden>
 
        * gawkmisc.c (xmalloc): Remove function now in support/xalloc.h.
diff --git a/awk.h b/awk.h
index 09bb282..bc26936 100644
--- a/awk.h
+++ b/awk.h
@@ -929,6 +929,9 @@ typedef struct exp_instruction {
 #define condpair_left   d.di
 #define condpair_right  x.xi
 
+/* Op_K_namespace */
+#define ns_name                d.name
+
 /* Op_store_var */
 #define initval         x.xn
 
diff --git a/debug.c b/debug.c
index 0e5a453..cf049a9 100644
--- a/debug.c
+++ b/debug.c
@@ -3979,6 +3979,10 @@ print_instruction(INSTRUCTION *pc, Func_print 
print_func, FILE *fp, int in_dump)
                print_func(fp, "[expr_count = %ld]\n", pc->expr_count);
                break;
 
+       case Op_K_namespace:
+               print_func(fp, "[ns_name = %s]\n", pc->ns_name);
+               break;
+
        case Op_concat:
                /* NB: concat_flag CSVAR only used in grammar, don't display it 
*/
                print_func(fp, "[expr_count = %ld] [concat_flag = %s]\n",
diff --git a/symbol.c b/symbol.c
index 581200e..5aecf50 100644
--- a/symbol.c
+++ b/symbol.c
@@ -38,7 +38,7 @@ static void (*install_func)(NODE *) = NULL;
 static NODE *make_symbol(const char *name, NODETYPE type);
 static NODE *install(const char *name, NODE *parm, NODETYPE type);
 static void free_bcpool(INSTRUCTION_POOL *pl);
-static const char *fix_up_namespace(const char *name);
+static const char *fix_up_namespace(const char *name, bool *malloced);
 
 static AWK_CONTEXT *curr_ctxt = NULL;
 static int ctxt_level;
@@ -94,6 +94,7 @@ lookup(const char *name, bool do_qualify)
        NODE *tmp;
        NODE *tables[5];        /* manual init below, for z/OS */
        int i;
+       bool malloced;
 
        /* ``It's turtles, all the way down.'' */
        tables[0] = param_table;        /* parameters shadow everything */
@@ -103,9 +104,12 @@ lookup(const char *name, bool do_qualify)
        tables[4] = NULL;
 
        if (do_qualify)
-               name = fix_up_namespace(name);
+               name = fix_up_namespace(name, & malloced);
 
-       tmp = make_string(name, strlen(name));
+       if (malloced)
+               tmp = make_str_node(name, strlen(name), ALREADY_MALLOCED);
+       else
+               tmp = make_string(name, strlen(name));
 
        n = NULL;
        for (i = 0; tables[i] != NULL; i++) {
@@ -306,10 +310,15 @@ install(const char *name, NODE *parm, NODETYPE type)
        NODE *table;
        NODE *n_name;
        NODE *prev;
+       bool malloced;
 
-       name = fix_up_namespace(name);
+       name = fix_up_namespace(name, & malloced);
+
+       if (malloced)
+               n_name = make_str_node(name, strlen(name), ALREADY_MALLOCED);
+       else
+               n_name = make_string(name, strlen(name));
 
-       n_name = make_string(name, strlen(name));
        table = symbol_table;
 
        if (type == Node_param_list) {
@@ -974,14 +983,15 @@ is_all_upper(const char *name)
 /* fix_up_namespace --- qualify / dequalify a simple name */
 
 static const char *
-fix_up_namespace(const char *name)
+fix_up_namespace(const char *name, bool *malloced)
 {
        static char awk_ns[] = "awk::";
        const size_t awk_ns_len = sizeof(awk_ns) - 1;   // don't include 
trailing \0
-       static size_t len = 0;
-       static char *buf = NULL;
        char *cp;
 
+       assert(malloced != NULL);
+       *malloced = false;
+
        // first, check if it's qualified
        if ((cp = strchr(name, ':')) != NULL) {
                // does it start with awk:: ?
@@ -996,16 +1006,13 @@ fix_up_namespace(const char *name)
        if (current_namespace == awk_namespace || is_all_upper(name))
                return name;    // put it into awk namespace
 
-       size_t needed = strlen(current_namespace) + 2 + strlen(name) + 1;
-       if (len == 0) {
-               emalloc(buf, char *, needed, "fix_up_namespace");
-               len = needed;
-       } else if (len < needed) {
-               erealloc(buf, char *, needed, "fix_up_namespace");
-               len = needed;
-       } // else
-               // nothing to do, just sprintf into the buffer
+       // make it fully qualified
+       size_t len = strlen(current_namespace) + 2 + strlen(name) + 1;
+       char *buf = NULL;
 
+       emalloc(buf, char *, len, "fix_up_namespace");
        sprintf(buf, "%s::%s", current_namespace, name);
+       *malloced = true;
+
        return buf;
 }

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

Summary of changes:
 ChangeLog | 12 ++++++++++++
 awk.h     |  3 +++
 debug.c   |  4 ++++
 symbol.c  | 41 ++++++++++++++++++++++++-----------------
 4 files changed, 43 insertions(+), 17 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

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