gawk-diffs
[Top][All Lists]
Advanced

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

[gawk-diffs] [SCM] gawk branch, array-iface, updated. c3033f11415c6323ad


From: John Haque
Subject: [gawk-diffs] [SCM] gawk branch, array-iface, updated. c3033f11415c6323ad6b4503c220d20d68c841a3
Date: Wed, 18 Apr 2012 10:15:12 +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, array-iface has been updated
       via  c3033f11415c6323ad6b4503c220d20d68c841a3 (commit)
      from  07e08a881ae177d3e3b7cfd2c5199443c6db3dd0 (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=c3033f11415c6323ad6b4503c220d20d68c841a3

commit c3033f11415c6323ad6b4503c220d20d68c841a3
Author: john haque <address@hidden>
Date:   Wed Apr 18 04:53:17 2012 -0500

    Polish array handling code.

diff --git a/ChangeLog b/ChangeLog
index 848ab3b..aaba8b4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2012-04-18         John Haque      <address@hidden>
+
+       * awk.h (atypeof, AFUNC): New macros.
+       (afunc_t): Renamed typedef from array_ptr.
+       * array.c (register_array_func, null_lookup): Use AFUNC macro
+       instead of hard-coded index for array functions.
+       (asort_actual): Unref null array elements before overwriting.
+       (force_array): Renamed from get_array.
+       (null_array): Renamed from init_array. Also initialize flags to 0.
+       (array_types): Renamed from atypes.
+       (num_array_types): Renamed from num_atypes.
+       * interpret.h (r_interpret): In case Op_sub_array, unref null array 
element.
+       * str_array.c (str_array_init): Reworked for (re)initialization of 
array.
+       * int_array.c (int_array_init): Ditto.
+       * cint_array.c (cint_array_init): Ditto.
+
 2012-04-16  Eli Zaretskii  <address@hidden>
 
        * io.c (read_with_timeout) [__MINGW32__]: Just call the blocking
diff --git a/array.c b/array.c
index a0c74e9..67712b9 100644
--- a/array.c
+++ b/array.c
@@ -27,20 +27,16 @@
 
 extern FILE *output_fp;
 extern NODE **fmt_list;          /* declared in eval.c */
-extern array_ptr str_array_func[];
-extern array_ptr cint_array_func[];
-extern array_ptr int_array_func[];
 
 static size_t SUBSEPlen;
 static char *SUBSEP;
 static char indent_char[] = "    ";
 
 static NODE **null_lookup(NODE *symbol, NODE *subs);
-static NODE **null_afunc(NODE *symbol, NODE *subs);
 static NODE **null_dump(NODE *symbol, NODE *subs);
-static array_ptr null_array_func[] = {
-       (array_ptr) 0,
-       (array_ptr) 0,
+static afunc_t null_array_func[] = {
+       (afunc_t) 0,
+       (afunc_t) 0,
        null_lookup,
        null_afunc,
        null_afunc,
@@ -52,27 +48,20 @@ static array_ptr null_array_func[] = {
 
 #define MAX_ATYPE 10
 
-static array_ptr *atypes[MAX_ATYPE];
-static int num_atypes = 0;
+static afunc_t *array_types[MAX_ATYPE];
+static int num_array_types = 0;
 
-/*
- * register_array_func --- add routines to handle arrays.
- *
- *     index 0 : initialization.
- *     index 1 : check if index is compatible.
- *     index 8 : array dump, memory and other statistics (do_adump).
- */
- 
+/* register_array_func --- add routines to handle arrays */
 
 int
-register_array_func(array_ptr *afunc)
+register_array_func(afunc_t *afunc)
 {
-       if (afunc && num_atypes < MAX_ATYPE) {
-               if (afunc != str_array_func && ! afunc[1])
+       if (afunc && num_array_types < MAX_ATYPE) {
+               if (afunc != str_array_func && ! afunc[AFUNC(atypeof)])
                        return FALSE;
-               atypes[num_atypes++] = afunc;
-               if (afunc[0])   /* execute init routine if any */
-                       (void) (*afunc[0])(NULL, NULL);
+               array_types[num_array_types++] = afunc;
+               if (afunc[AFUNC(ainit)])        /* execute init routine if any 
*/
+                       (void) (*afunc[AFUNC(ainit)])(NULL, NULL);
                return TRUE;
        }
        return FALSE;
@@ -108,21 +97,19 @@ make_array()
 }              
 
 
-/* init_array --- (re)initialize an array node */
+/* null_array --- force symbol to be an empty typeless array */
 
 void
-init_array(NODE *symbol)
+null_array(NODE *symbol)
 {
        symbol->type = Node_var_array;
        symbol->array_funcs = null_array_func;
        symbol->buckets = NULL;
        symbol->table_size = symbol->array_size = 0;
        symbol->array_capacity = 0;
-
+       symbol->flags = 0;
        assert(symbol->xarray == NULL);
-       /* symbol->xarray = NULL; */
-
-       /* flags, vname, parent_array not (re)initialized */
+       /* vname, parent_array not (re)initialized */
 }
 
 
@@ -132,20 +119,21 @@ static NODE **
 null_lookup(NODE *symbol, NODE *subs)
 {
        int i;
-       array_ptr *afunc = NULL;
+       afunc_t *afunc = NULL;
 
        assert(symbol->table_size == 0);
 
-       /* Check which array type wants to accept this sub; traverse
+       /*
+        * Check which array type wants to accept this sub; traverse
         * array type list in reverse order.
         */
-       for (i = num_atypes - 1; i >= 1; i--) {
-               afunc = atypes[i];
-               if (afunc[1](symbol, subs) != NULL)
+       for (i = num_array_types - 1; i >= 1; i--) {
+               afunc = array_types[i];
+               if (afunc[AFUNC(atypeof)](symbol, subs) != NULL)
                        break;
        }
        if (i == 0 || afunc == NULL)
-               afunc = atypes[0];      /* default is str_array_func */
+               afunc = array_types[0]; /* default is str_array_func */
        symbol->array_funcs = afunc;
 
        /* We have the right type of array; install the subscript */
@@ -153,9 +141,9 @@ null_lookup(NODE *symbol, NODE *subs)
 }
 
 
-/* null_afunc --- dummy function for an empty array */
+/* null_afunc --- default function for array interface */
 
-static NODE **
+NODE **
 null_afunc(NODE *symbol ATTRIBUTE_UNUSED, NODE *subs ATTRIBUTE_UNUSED)
 {
        return NULL;
@@ -171,7 +159,8 @@ null_dump(NODE *symbol, NODE *subs ATTRIBUTE_UNUSED)
 }
 
 
-/* r_in_array --- test whether the array element symbol[subs] exists or not,
+/*
+ * r_in_array --- test whether the array element symbol[subs] exists or not,
  *     return pointer to value if it does.
  */
 
@@ -331,14 +320,14 @@ array_vname(const NODE *symbol)
 
 
 /*
- *  get_array --- proceed to the actual Node_var_array,
+ *  force_array --- proceed to the actual Node_var_array,
  *     change Node_var_new to an array.
  *     If canfatal and type isn't good, die fatally,
  *     otherwise return the final actual value.
  */
 
 NODE *
-get_array(NODE *symbol, int canfatal)
+force_array(NODE *symbol, int canfatal)
 {
        NODE *save_symbol = symbol;
        int isparam = FALSE;
@@ -352,7 +341,7 @@ get_array(NODE *symbol, int canfatal)
 
        switch (symbol->type) {
        case Node_var_new:
-               init_array(symbol);
+               null_array(symbol);
                symbol->parent_array = NULL;    /* main array has no parent */
                /* fall through */
        case Node_var_array:
@@ -446,7 +435,8 @@ concat_exp(int nargs, int do_subsep)
 }
 
 
-/* adjust_fcall_stack: remove subarray(s) of symbol[] from
+/*
+ * adjust_fcall_stack: remove subarray(s) of symbol[] from
  *     function call stack.
  */
 
@@ -494,7 +484,8 @@ adjust_fcall_stack(NODE *symbol, int nsubs)
                        && symbol->parent_array != NULL
                        && nsubs > 0
                ) {
-                       /* 'symbol' is a subarray, and 'r' is the same subarray:
+                       /*
+                        * 'symbol' is a subarray, and 'r' is the same subarray:
                         *
                         *   function f(c, d) { delete c[0]; .. }
                         *   BEGIN { a[0][0] = 1; f(a, a[0]); .. }
@@ -505,9 +496,8 @@ adjust_fcall_stack(NODE *symbol, int nsubs)
                         *   BEGIN { a[0][0] = 1; f(a[0], a[0]); ...}  
                         */
 
-                       init_array(r);
+                       null_array(r);
                        r->parent_array = NULL;
-                       r->flags = 0;
                        continue;
                }                       
 
@@ -515,7 +505,8 @@ adjust_fcall_stack(NODE *symbol, int nsubs)
                for (n = n->parent_array; n != NULL; n = n->parent_array) {
                        assert(n->type == Node_var_array);
                        if (n == symbol) {
-                               /* 'r' is a subarray of 'symbol':
+                               /*
+                                * 'r' is a subarray of 'symbol':
                                 *
                                 *    function f(c, d) { delete c; .. use d as 
array .. }
                                 *    BEGIN { a[0][0] = 1; f(a, a[0]); .. }
@@ -523,9 +514,8 @@ adjust_fcall_stack(NODE *symbol, int nsubs)
                                 *    BEGIN { a[0][0][0][0] = 1; f(a[0], 
a[0][0][0]); .. }
                                 *
                                 */
-                               init_array(r);
+                               null_array(r);
                                r->parent_array = NULL;
-                               r->flags = 0;
                                break;
                        }
                }
@@ -769,7 +759,8 @@ do_adump(int nargs)
        static NODE ndump;
        long depth = 0;
 
-       /* depth < 0, no index and value info.
+       /*
+        * depth < 0, no index and value info.
         *       = 0, main array index and value info; does not descend into 
sub-arrays.
         *       > 0, descends into 'depth' sub-arrays, and prints index and 
value info.
         */
@@ -1268,7 +1259,8 @@ assoc_list(NODE *symbol, const char *sort_str, SORT_CTXT 
sort_ctxt)
 { "@unsorted",         0,                      AINDEX },
 };
 
-       /* N.B.: AASC and ADESC are hints to the specific array types.
+       /*
+        * N.B.: AASC and ADESC are hints to the specific array types.
         *      See cint_list() in cint_array.c.
         */
 
@@ -1336,7 +1328,8 @@ assoc_list(NODE *symbol, const char *sort_str, SORT_CTXT 
sort_ctxt)
                (code + 1)->expr_count = 4;     /* function takes 4 arguments */
                code->nexti = bcalloc(Op_stop, 1, 0);   
 
-               /* make non-redirected getline, exit, `next' and `nextfile' 
fatal in
+               /*
+                * make non-redirected getline, exit, `next' and `nextfile' 
fatal in
                 * callback function by setting currule in interpret()
                 * to undefined (0).
                 */
diff --git a/awk.h b/awk.h
index a4b8761..d522911 100644
--- a/awk.h
+++ b/awk.h
@@ -341,7 +341,7 @@ typedef union bucket_item {
 struct exp_instruction;
 
 typedef int (*Func_print)(FILE *, const char *, ...);
-typedef struct exp_node **(*array_ptr)(struct exp_node *, struct exp_node *);
+typedef struct exp_node **(*afunc_t)(struct exp_node *, struct exp_node *);
 
 /*
  * NOTE - this struct is a rather kludgey -- it is packed to minimize
@@ -354,7 +354,7 @@ typedef struct exp_node {
                                struct exp_node *lptr;
                                struct exp_instruction *li;
                                long ll;
-                               array_ptr *lp;
+                               afunc_t *lp;
                        } l;
                        union {
                                struct exp_node *rptr;
@@ -505,9 +505,8 @@ typedef struct exp_node {
 #define xarray         sub.nodep.rn
 #define parent_array   sub.nodep.x.extra 
 
-/* array_funcs[0] is the array initialization function and
- * array_funcs[1] is the index type checking function
- */
+#define ainit          array_funcs[0]
+#define atypeof                array_funcs[1]
 #define alookup        array_funcs[2]
 #define aexists        array_funcs[3]
 #define aclear         array_funcs[4]
@@ -517,6 +516,9 @@ typedef struct exp_node {
 #define adump          array_funcs[8]
 #define NUM_AFUNCS     9               /* # of entries in array_funcs */
 
+/* array func to index mapping */
+#define AFUNC(F) (& ((NODE *) 0)->F - ((NODE *) 0)->array_funcs)
+
 /* Node_array_ref: */
 #define orig_array lnode
 #define prev_array rnode
@@ -984,6 +986,8 @@ enum block_id {
        BLOCK_MAX       /* count */
 };     
 
+typedef int (*Func_pre_exec)(INSTRUCTION **);
+typedef void (*Func_post_exec)(INSTRUCTION *);
 
 #ifndef LONG_MAX
 #define LONG_MAX ((long)(~(1L << (sizeof (long) * 8 - 1))))
@@ -1030,8 +1034,10 @@ extern NODE *(*str2number)(NODE *);
 extern NODE *(*format_val)(const char *, int, NODE *);
 extern int (*cmp_numbers)(const NODE *, const NODE *);
 
-typedef int (*Func_pre_exec)(INSTRUCTION **);
-typedef void (*Func_post_exec)(INSTRUCTION *);
+/* built-in array types */
+extern afunc_t str_array_func[];
+extern afunc_t cint_array_func[];
+extern afunc_t int_array_func[];
 
 #if __GNUC__ < 2
 extern NODE *_t;       /* used as temporary in macros */
@@ -1175,10 +1181,10 @@ extern STACK_ITEM *stack_top;
 #if __GNUC__ >= 2
 
 #define POP_ARRAY()    ({ NODE *_t = POP(); \
-               _t->type == Node_var_array ? _t : get_array(_t, TRUE); })
+               _t->type == Node_var_array ? _t : force_array(_t, TRUE); })
 
 #define POP_PARAM()    ({ NODE *_t = POP(); \
-               _t->type == Node_var_array ? _t : get_array(_t, FALSE); })
+               _t->type == Node_var_array ? _t : force_array(_t, FALSE); })
 
 #define POP_SCALAR()   ({ NODE *_t = POP(); _t->type != Node_var_array ? _t \
                : (fatal(_("attempt to use array `%s' in a scalar context"), 
array_vname(_t)), _t);})
@@ -1191,10 +1197,10 @@ extern STACK_ITEM *stack_top;
 #else  /* not __GNUC__ */
 
 #define POP_ARRAY()    (_t = POP(), \
-               _t->type == Node_var_array ? _t : get_array(_t, TRUE))
+               _t->type == Node_var_array ? _t : force_array(_t, TRUE))
 
 #define POP_PARAM()    (_t = POP(), \
-               _t->type == Node_var_array ? _t : get_array(_t, FALSE))
+               _t->type == Node_var_array ? _t : force_array(_t, FALSE))
 
 #define POP_SCALAR()   (_t = POP(), _t->type != Node_var_array ? _t \
                : (fatal(_("attempt to use array `%s' in a scalar context"), 
array_vname(_t)), _t))
@@ -1364,12 +1370,13 @@ ADELETE = 0x100,        /* need a single index; for use 
in do_delete_loop */
 };
 
 extern NODE *make_array(void);
-extern void init_array(NODE *symbol);
-extern NODE *get_array(NODE *symbol, int canfatal);
+extern void null_array(NODE *symbol);
+extern NODE *force_array(NODE *symbol, int canfatal);
 extern const char *make_aname(const NODE *symbol);
 extern const char *array_vname(const NODE *symbol);
 extern void array_init(void);
-extern int register_array_func(array_ptr *afunc);
+extern int register_array_func(afunc_t *afunc);
+extern NODE **null_afunc(NODE *symbol, NODE *subs);
 extern void set_SUBSEP(void);
 extern NODE *concat_exp(int nargs, int do_subsep);
 extern NODE *r_in_array(NODE *symbol, NODE *subs);
diff --git a/cint_array.c b/cint_array.c
index f82eb4b..136f9ad 100644
--- a/cint_array.c
+++ b/cint_array.c
@@ -37,7 +37,8 @@ extern NODE **is_integer(NODE *symbol, NODE *subs);
 static int NHAT = 10; 
 static long THRESHOLD;
 
-/* What is the optimium NHAT ? timing results suggest that 10 is a good choice,
+/*
+ * What is the optimium NHAT ? timing results suggest that 10 is a good choice,
  * although differences aren't that significant for > 10.
  */
 
@@ -55,7 +56,7 @@ static NODE **cint_dump(NODE *symbol, NODE *ndump);
 static void cint_print(NODE *symbol);
 #endif
 
-array_ptr cint_array_func[] = {
+afunc_t cint_array_func[] = {
        cint_array_init,
        is_uinteger,
        cint_lookup,
@@ -138,16 +139,21 @@ static const long power_two_table[] = {
  *
  */
 
-/* cint_array_init ---  check relevant environment variables */
+/* cint_array_init ---  array initialization routine */
 
 static NODE **
 cint_array_init(NODE *symbol ATTRIBUTE_UNUSED, NODE *subs ATTRIBUTE_UNUSED)
 {
-       long newval;
+       if (symbol == NULL) {
+               long newval;
+
+               /* check relevant environment variables */
+               if ((newval = getenv_long("NHAT")) > 1 && newval < INT32_BIT)
+                       NHAT = newval;
+               THRESHOLD = power_two_table[NHAT + 1];
+       } else
+               null_array(symbol);
 
-       if ((newval = getenv_long("NHAT")) > 1 && newval < INT32_BIT)
-               NHAT = newval;
-       THRESHOLD = power_two_table[NHAT + 1];
        return (NODE **) ! NULL;
 }
 
@@ -233,13 +239,11 @@ xinstall:
 
        symbol->table_size++;
        if (xn == NULL) {
-               extern array_ptr int_array_func[];
-               extern array_ptr str_array_func[];
-
                xn = symbol->xarray = make_array();
                xn->vname = symbol->vname;      /* shallow copy */
 
-               /* Avoid using assoc_lookup(xn, subs) which may lead
+               /*
+                * Avoid using assoc_lookup(xn, subs) which may lead
                 * to infinite recursion.
                 */
 
@@ -298,7 +302,7 @@ cint_clear(NODE *symbol, NODE *subs ATTRIBUTE_UNUSED)
        }
 
        efree(symbol->nodes);
-       init_array(symbol);     /* re-initialize symbol */
+       symbol->ainit(symbol, NULL);    /* re-initialize symbol */
        return NULL;
 }
 
@@ -335,7 +339,7 @@ cint_remove(NODE *symbol, NODE *subs)
 
        if (xn == NULL && symbol->table_size == 0) {
                efree(symbol->nodes);
-               init_array(symbol);     /* re-initialize array 'symbol' */
+               symbol->ainit(symbol, NULL);    /* re-initialize array 'symbol' 
*/
        } else if(xn != NULL && symbol->table_size == xn->table_size) {
                /* promote xn to symbol */
 
@@ -469,7 +473,6 @@ cint_dump(NODE *symbol, NODE *ndump)
        AWKNUM kb = 0;
        extern AWKNUM int_kilobytes(NODE *symbol);
        extern AWKNUM str_kilobytes(NODE *symbol);
-       extern array_ptr int_array_func[];
 
        indent_level = ndump->alevel;
 
@@ -563,7 +566,8 @@ cint_hash(long k)
 
        /* Find the Floor(log base 2 of 32-bit integer) */
 
-       /* Warren Jr., Henry S. (2002). Hacker's Delight.
+       /*
+        * Warren Jr., Henry S. (2002). Hacker's Delight.
         * Addison Wesley. pp. pp. 215. ISBN 978-0201914658.
         *
         *      r = 0;
@@ -575,7 +579,8 @@ cint_hash(long k)
         */
 
 
-       /* Slightly different code copied from:
+       /*
+        * Slightly different code copied from:
         *
         * http://www-graphics.stanford.edu/~seander/bithacks.html
         * Bit Twiddling Hacks
@@ -1014,9 +1019,10 @@ tree_print(NODE *tree, size_t bi, int indent_level)
 
 /*--------------------- leaf (linear 1-D) array --------------------*/
 
-/* leaf_lookup --- find an integer subscript in the array; Install it if
-       it isn't there.
-*/
+/*
+ * leaf_lookup --- find an integer subscript in the array; Install it if
+ *     it isn't there.
+ */
 
 static inline NODE **
 leaf_lookup(NODE *symbol, NODE *array, long k, long size, long base)
diff --git a/ext.c b/ext.c
index 0f56849..f2919db 100644
--- a/ext.c
+++ b/ext.c
@@ -213,7 +213,7 @@ get_actual_argument(int i, int optional, int want_array)
 
        if (t->type == Node_var_new) {
                if (want_array)
-                       return get_array(t, FALSE);
+                       return force_array(t, FALSE);
                else {
                        t->type = Node_var;
                        t->var_value = dupnode(Nnull_string);
diff --git a/int_array.c b/int_array.c
index 0fa3764..bc413c5 100644
--- a/int_array.c
+++ b/int_array.c
@@ -45,7 +45,7 @@ static inline NODE **int_find(NODE *symbol, long k, uint32_t 
hash1);
 static NODE **int_insert(NODE *symbol, long k, uint32_t hash1);
 static void grow_int_table(NODE *symbol);
 
-array_ptr int_array_func[] = {
+afunc_t int_array_func[] = {
        int_array_init,
        is_integer,
        int_lookup,
@@ -58,19 +58,23 @@ array_ptr int_array_func[] = {
 };
 
 
-/* int_array_init --- check relevant environment variables */
+/* int_array_init --- array initialization routine */
 
 static NODE **
-int_array_init(NODE *symbol ATTRIBUTE_UNUSED, NODE *subs ATTRIBUTE_UNUSED)
+int_array_init(NODE *symbol, NODE *subs ATTRIBUTE_UNUSED)
 {
-       long newval;
+       if (symbol == NULL) {   /* first time */
+               long newval;
+
+               /* check relevant environment variables */
+               if ((newval = getenv_long("INT_CHAIN_MAX")) > 0)
+                       INT_CHAIN_MAX = newval;
+       } else
+               null_array(symbol);
 
-       if ((newval = getenv_long("INT_CHAIN_MAX")) > 0)
-               INT_CHAIN_MAX = newval;
        return (NODE **) ! NULL;
 }
 
-
 /* is_integer --- check if subscript is an integer */
 
 NODE **
@@ -147,7 +151,8 @@ is_integer(NODE *symbol, NODE *subs)
 }
 
 
-/* int_lookup --- Find SYMBOL[SUBS] in the assoc array.  Install it with value 
""
+/*
+ * int_lookup --- Find SYMBOL[SUBS] in the assoc array.  Install it with value 
""
  * if it isn't there. Returns a pointer ala get_lhs to where its value is 
stored.
  */
 
@@ -160,7 +165,8 @@ int_lookup(NODE *symbol, NODE *subs)
        NODE **lhs;
        NODE *xn;
 
-       /* N.B: symbol->table_size is the total # of non-integers 
(symbol->xarray)
+       /*
+        * N.B: symbol->table_size is the total # of non-integers 
(symbol->xarray)
         *      and integer elements. Also, symbol->xarray must have at least 
one
         *      item in it, and can not exist if there are no integer elements.
         *      In that case, symbol->xarray is promoted to 'symbol' (See 
int_remove).
@@ -207,7 +213,8 @@ int_lookup(NODE *symbol, NODE *subs)
 }
 
 
-/* int_exists --- test whether the array element symbol[subs] exists or not,
+/*
+ * int_exists --- test whether the array element symbol[subs] exists or not,
  *     return pointer to value if it does.
  */
 
@@ -266,8 +273,7 @@ int_clear(NODE *symbol, NODE *subs ATTRIBUTE_UNUSED)
        }
        if (symbol->buckets != NULL)
                efree(symbol->buckets);
-       init_array(symbol);     /* re-initialize symbol */
-       symbol->flags &= ~ARRAYMAXED;
+       symbol->ainit(symbol, NULL);    /* re-initialize symbol */
        return NULL;
 }
 
@@ -338,9 +344,7 @@ removed:
                BUCKET *head = symbol->buckets[hash1];
 
                assert(b->aicount == 1);
-               /* move the last element from head
-                * to bucket to make it full.
-                */
+               /* move the last element from head to bucket to make it full. */
                i = --head->aicount;    /* head has one less element */
                b->ainum[1] = head->ainum[i];
                b->aivalue[1] = head->aivalue[i];
@@ -356,8 +360,7 @@ removed:
        symbol->table_size--;
        if (xn == NULL && symbol->table_size == 0) {
                efree(symbol->buckets);
-               init_array(symbol);     /* re-initialize array 'symbol' */
-               symbol->flags &= ~ARRAYMAXED;
+               symbol->ainit(symbol, NULL);    /* re-initialize array 'symbol' 
*/
        } else if (xn != NULL && symbol->table_size == xn->table_size) {
                /* promote xn (str_array) to symbol */
                xn->flags &= ~XARRAY;
@@ -658,14 +661,13 @@ static uint32_t
 int_hash(uint32_t k, uint32_t hsize)
 {
 
-/* Code snippet copied from:
+/*
+ * Code snippet copied from:
  *     Hash functions (http://www.azillionmonkeys.com/qed/hash.html).
  *     Copyright 2004-2008 by Paul Hsieh. Licenced under LGPL 2.1.
  */
 
-       /* This is the final mixing function used by Paul Hsieh
-        * in SuperFastHash.
-        */
+       /* This is the final mixing function used by Paul Hsieh in 
SuperFastHash. */
  
        k ^= k << 3;
        k += k >> 5;
@@ -708,9 +710,7 @@ int_insert(NODE *symbol, long k, uint32_t hash1)
 
        b = symbol->buckets[hash1];
 
-       /* Only the first bucket in the chain can be partially full,
-        * but is never empty.
-        */ 
+       /* Only the first bucket in the chain can be partially full, but is 
never empty. */ 
 
        if (b == NULL || (i = b->aicount) == 2) {
                getbucket(b);
diff --git a/interpret.h b/interpret.h
index 83b908c..acb8d21 100644
--- a/interpret.h
+++ b/interpret.h
@@ -521,10 +521,11 @@ mod:
                        break;
 
                case Op_store_sub:
-                       /* array[sub] assignment optimization,
+                       /*
+                        * array[sub] assignment optimization,
                         * see awkgram.y (optimize_assignment)
                         */
-                       t1 = get_array(pc->memory, TRUE);       /* array */
+                       t1 = force_array(pc->memory, TRUE);     /* array */
                        t2 = mk_sub(pc->expr_count);    /* subscript */
                        lhs = assoc_lookup(t1, t2);
                        if ((*lhs)->type == Node_var_array) {
@@ -538,7 +539,8 @@ mod:
                        break;
 
                case Op_store_var:
-                       /* simple variable assignment optimization,
+                       /*
+                        * simple variable assignment optimization,
                         * see awkgram.y (optimize_assignment)
                         */
        
diff --git a/str_array.c b/str_array.c
index 1b3a33f..a452dac 100644
--- a/str_array.c
+++ b/str_array.c
@@ -55,9 +55,9 @@ static NODE **str_list(NODE *symbol, NODE *subs);
 static NODE **str_copy(NODE *symbol, NODE *newsymb);
 static NODE **str_dump(NODE *symbol, NODE *ndump);
 
-array_ptr str_array_func[] = {
+afunc_t str_array_func[] = {
        str_array_init,
-       (array_ptr) 0,
+       (afunc_t) 0,
        str_lookup,
        str_exists,
        str_clear,
@@ -77,18 +77,23 @@ static unsigned long awk_hash(const char *s, size_t len, 
unsigned long hsize, si
 unsigned long (*hash)(const char *s, size_t len, unsigned long hsize, size_t 
*code) = awk_hash;
 
 
-/* str_array_init --- check relevant environment variables */
+/* str_array_init --- array initialization routine */
 
 static NODE **
 str_array_init(NODE *symbol ATTRIBUTE_UNUSED, NODE *subs ATTRIBUTE_UNUSED)
 {
-       long newval;
-       const char *val;
+       if (symbol == NULL) {           /* first time */
+               long newval;
+               const char *val;
+
+               /* check relevant environment variables */
+               if ((newval = getenv_long("STR_CHAIN_MAX")) > 0)
+                       STR_CHAIN_MAX = newval;
+               if ((val = getenv("AWK_HASH")) != NULL && strcmp(val, "gst") == 
0)
+                       hash = gst_hash_string;
+       } else
+               null_array(symbol);
 
-       if ((newval = getenv_long("STR_CHAIN_MAX")) > 0)
-               STR_CHAIN_MAX = newval;
-       if ((val = getenv("AWK_HASH")) != NULL && strcmp(val, "gst") == 0)
-               hash = gst_hash_string;
        return (NODE **) ! NULL;
 }
 
@@ -217,8 +222,7 @@ str_clear(NODE *symbol, NODE *subs ATTRIBUTE_UNUSED)
 
        if (symbol->buckets != NULL)
                efree(symbol->buckets);
-       init_array(symbol);     /* re-initialize symbol */
-       symbol->flags &= ~ARRAYMAXED;
+       symbol->ainit(symbol, NULL);    /* re-initialize symbol */
        return NULL;
 }
 
@@ -264,8 +268,7 @@ str_remove(NODE *symbol, NODE *subs)
                        if (--symbol->table_size == 0) {
                                if (symbol->buckets != NULL)
                                        efree(symbol->buckets);
-                               init_array(symbol);     /* re-initialize symbol 
*/
-                               symbol->flags &= ~ARRAYMAXED;
+                               symbol->ainit(symbol, NULL);    /* 
re-initialize symbol */
                        }
 
                        return (NODE **) ! NULL;        /* return success */
diff --git a/symbol.c b/symbol.c
index 57ca7be..ebe86c0 100644
--- a/symbol.c
+++ b/symbol.c
@@ -259,7 +259,7 @@ make_symbol(char *name, NODETYPE type)
        memset(r, '\0', sizeof(NODE));
        hp->hvalue = r;
        if (type == Node_var_array)
-               init_array(r);
+               null_array(r);
        else if (type == Node_var)
                r->var_value = dupnode(Nnull_string);
        r->vname = name;

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

Summary of changes:
 ChangeLog    |   16 ++++++++++
 array.c      |   95 +++++++++++++++++++++++++++-------------------------------
 awk.h        |   35 +++++++++++++--------
 cint_array.c |   44 +++++++++++++++-----------
 ext.c        |    2 +-
 int_array.c  |   48 ++++++++++++++--------------
 interpret.h  |    8 +++--
 str_array.c  |   29 ++++++++++--------
 symbol.c     |    2 +-
 9 files changed, 153 insertions(+), 126 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

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