gawk-diffs
[Top][All Lists]
Advanced

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

[SCM] gawk branch, feature/mdim-start-again, created. gawk-4.1.0-4753-g3


From: Arnold Robbins
Subject: [SCM] gawk branch, feature/mdim-start-again, created. gawk-4.1.0-4753-g342bd54e
Date: Wed, 29 Jun 2022 01:04:40 -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/mdim-start-again has been created
        at  342bd54e3e87c0b127fcdb1296f4b4ca96b863fd (commit)

- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=342bd54e3e87c0b127fcdb1296f4b4ca96b863fd

commit 342bd54e3e87c0b127fcdb1296f4b4ca96b863fd
Author: Arnold D. Robbins <arnold@skeeve.com>
Date:   Wed Jun 29 08:04:10 2022 +0300

    New branch to continue on mdim stuff. Sigh.

diff --git a/ChangeLog b/ChangeLog
index 31d95383..28bb59ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -64,17 +64,46 @@
        an array.
        (api_impl): Add hook for api_destroy_array.
 
+2022-06-03         Arnold D. Robbins     <arnold@skeeve.com>
+
+       * awk.h (elem_new_to_scalar): Add declaration.
+       * eval.c (elem_new_to_scalar): No longer static. Make it handle
+       things when valref is > 1. Returns a NODE * instead of being void.
+       (cmp_scalars): Change usage of elem_new_to_scalar().
+       * interpret.h (r_interpret): Op_push*: Make Node_elem_new into
+       a separate case, using elem_new_to_scalar().
+       * array.c (force_array): For Node_elem_new, clear symbol->stptr.
+       * eval.r (r_get_lhs): Use efree() intstead of free() in Node_elem_new
+       case.
+
 2022-06-02         Arnold D. Robbins     <arnold@skeeve.com>
 
        * builtin.c (do_sub): Fix memory corruption when substituting
        into a value that is a typed regex. Thanks to valgrind.
 
+2022-06-02         Arnold D. Robbins     <arnold@skeeve.com>
+
+       Fix a nasty memory corruption problem. Thanks to
+       Andrew Schorr for the report.
+
+       * eval.c (r_get_lhs): Handle Node_elem_new separately
+       to free the string value. This was not the problem.
+       * interpret.h (r_interpret): For Op_assign, when turning
+       Node_elem_new into the null string, DEREF the old value
+       and dupnode the new one. THIS was the problem.
+
 2022-05-24         Adam Van Scyoc        <avanscy@g.clemson.edu>
 
        * awkgram.y (make_assignable): Handle Op_field_assign.
        Avoids a core dump upon a certain kind of syntax error;
        see test/getlnfa.awk.
 
+2022-05-22         Arnold D. Robbins     <arnold@skeeve.com>
+
+       * array.c (force_array): When converting Node_elem_new to an array,
+       release the string storage. Thanks to valgrind, by way of Andrew
+       Schorr, for the report.
+
 2022-05-11         Arnold D. Robbins     <arnold@skeeve.com>
 
        * profile.c (pp_list): Typo fix in a comment.
@@ -111,16 +140,86 @@
        merged.
        * profile.c (pprint): Improve code for Op_K_switch, Op_K_case.
 
+2022-04-20         Arnold D. Robbins     <arnold@skeeve.com>
+
+       * mpfr.c (mpg_force_number): Small whitespace fix.
+       * node.c (r_force_number): Ditto.
+
 2022-04-18         Arnold D. Robbins     <arnold@skeeve.com>
 
        * gawkbug.in: Small changes.
 
+2022-04-06         Arnold D. Robbins     <arnold@skeeve.com>
+
+       Further cleanups.
+
+       * array.c (new_array_element): Set s->stfmt to STFMT_UNUSED.
+       * awk.h (force_string_fmt): No need to set s->stfmt anymore.
+       * builtin.c (do_typeof): Collapse Node_var_new and Node_elem_new
+       cases.
+       * symbol.c (print_vars): Node_elem_new can't be in a top level
+       variable. Remove check and add a call to cant_happen if some
+       other node type is received.
+       * NEWS: Updated.
+
 2022-04-01         Arnold D. Robbins     <arnold@skeeve.com>
 
        Small fix from the persistent-gawk guys.
 
        * profile.c (pprint): Use estrdup instead of strdup.
 
+2022-03-31         Arnold D. Robbins     <arnold@skeeve.com>
+
+       * array.c (new_array_element): Make a full null string instead of
+       an empty node; it can be more easily converted to scalar that way.
+       * awk.h (force_string_fmt): Change the node type, remove NUMBER flag,
+       set STFMT_UNUSED.
+       * cint_array.c (lear_clear): Remove check for not equal Node_elem_new.
+       * int_array.c (int_clear): Ditto.
+       * str_array.c (str_clear): Ditto.
+       * eval.c (elem_new_to_scalar): Now only needs to change the node type.
+       * interpret.h (r_interpret): Treat Node_elem_new like Node_val, and
+       UPREF it when pushed. Remove test before DEREFing when popping.
+       * mpfr.c (mpg_force_number): Simplify converting Node_elem_new to
+       Node_val. Fix the string value.
+       * node.c (r_force_number): Ditto.
+
+2022-03-28         Arnold D. Robbins     <arnold@skeeve.com>
+
+       Allow unreferenced array elements to turn into subarrays.
+
+       * awk.h (Node_elem_new): New node type.
+       (new_array_element): Add declaration.
+       (POP_ARRAY): Handle Node_elem_new.
+       (force_string_fmt): Ditto. Make sure valref has the right value.
+       * array.c (force_array): Handle Node_elem_new.
+       (do_sort_up_value_type): Ditto.
+       (new_array_element): New function, creates Node_elem_new node.
+       * builtin.c (do_length): Handle Node_elem_new.
+       (do_typeof): Ditto.
+       * cint_array.c (leaf_lookup): Use new_array_element() when creating
+       a new element.
+       (left_clear): Don't unref Node_elem_new.
+       * debug.c (print_symbol, do_set_var,watchpont_triggered,
+       initialize_watch_item, print_memory, do_print_f): Handle Node_elem_new.
+       * eval.c (nodetypes): Add Node_elem_new.
+       (r_get_lhs, setup_frame): Handle Node_elem_new.
+       (elem_new_to_scalar): New function.
+       (cmp_scalars): Use elem_new_to_scalar.
+       * ext.c (get_actual_argument): Handle Node_elem_new.
+       * gawkapi.c (api_get_argument, api_set_argument, node_to_awk_value,
+       api_sym_update): Handle Node_elem_new.
+       * int_array.c (int_clear): Don't unref Node_elem_new.
+       (int_insert): Use new_array_element() when creating a new element.
+       * interpret.h (r_interpret): Handle Node_elem_new as appropriate.
+       * mpfr.c (mpg_force_number): Handle Node_elem_new.Make sure valref has
+       the right value.
+       * node.c (r_force_number): Ditto.
+       * str_array.c (str_lookup): Use new_array_element() when creating a
+       new element.
+       (str_clear): Don't unref Node_elem_new.
+       * symbol.c (print_vars): Handle Node_elem_new.
+
 2022-03-27         Arnold D. Robbins     <arnold@skeeve.com>
 
        Allow nested indirect function calls. Thanks to
diff --git a/NEWS b/NEWS
index 1f7f66e6..3e8f5673 100644
--- a/NEWS
+++ b/NEWS
@@ -49,6 +49,9 @@ allowing gawk to preserve the contents of its variables and 
arrays
 between runs. THIS IS AN EXPERIMENTAL FEATURE!  For more information,
 see the manual.
 
+10. Some subtle issues with untyped array elements being passed to
+functions have been fixed.
+
 Changes from 5.1.1 to 5.1.2
 ---------------------------
 
diff --git a/array.c b/array.c
index cbed1254..4361b51c 100644
--- a/array.c
+++ b/array.c
@@ -315,7 +315,7 @@ array_vname(const NODE *symbol)
 
 /*
  *  force_array --- proceed to the actual Node_var_array,
- *     change Node_var_new to an array.
+ *     change Node_var_new or Node_elem_new to an array.
  *     If canfatal and type isn't good, die fatally,
  *     otherwise return the final actual value.
  */
@@ -334,6 +334,11 @@ force_array(NODE *symbol, bool canfatal)
        }
 
        switch (symbol->type) {
+       case Node_elem_new:
+               efree(symbol->stptr);
+               symbol->stptr = NULL;
+               symbol->stlen = 0;
+               /* fall through */
        case Node_var_new:
                symbol->xarray = NULL;  /* make sure union is as it should be */
                null_array(symbol);
@@ -1166,6 +1171,7 @@ do_sort_up_value_type(const void *p1, const void *p2)
                Node_func,
                Node_ext_func,
                Node_var_new,
+               Node_elem_new,
                Node_var,
                Node_var_array,
                Node_val,
@@ -1429,3 +1435,26 @@ assoc_list(NODE *symbol, const char *sort_str, 
sort_context_t sort_ctxt)
 
        return list;
 }
+
+/* new_array_element --- return a new empty element node */
+
+NODE *
+new_array_element(void)
+{
+       NODE *n = make_number(0.0);
+       char *sp;
+
+       emalloc(sp, char *, 2, "new_array_element");
+       sp[0] = sp[1] = '\0';
+
+       n->stptr = sp;
+       n->stlen = 0;
+       n->stfmt = STFMT_UNUSED;
+
+       n->flags |= (MALLOC|STRING|STRCUR);
+
+       n->type = Node_elem_new;
+       n->valref = 1;
+
+       return n;
+}
diff --git a/awk.h b/awk.h
index f89b0866..6ff88677 100644
--- a/awk.h
+++ b/awk.h
@@ -258,6 +258,7 @@ typedef enum nodevals {
        Node_var,               /* scalar variable, lnode is value */
        Node_var_array,         /* array is ptr to elements, table_size num of 
eles */
        Node_var_new,           /* newly created variable, may become an array 
*/
+       Node_elem_new,          /* newly created array element, may become a 
subarray */
        Node_param_list,        /* lnode is a variable, rnode is more list */
        Node_func,              /* lnode is param. list, rnode is body */
        Node_ext_func,          /* extension function, code_ptr is builtin code 
*/
@@ -1445,6 +1446,7 @@ extern NODE *do_asorti(int nargs);
 extern unsigned long (*hash)(const char *s, size_t len, unsigned long hsize, 
size_t *code);
 extern void init_env_array(NODE *env_node);
 extern void init_argv_array(NODE *argv_node, NODE *shadow_node);
+extern NODE *new_array_element(void);
 /* awkgram.c */
 extern NODE *variable(int location, char *name, NODETYPE type);
 extern int parse_program(INSTRUCTION **pcode, bool from_eval);
@@ -1559,6 +1561,7 @@ extern STACK_ITEM *grow_stack(void);
 extern void dump_fcall_stack(FILE *fp);
 extern int register_exec_hook(Func_pre_exec preh, Func_post_exec posth);
 extern NODE **r_get_field(NODE *n, Func_ptr *assign, bool reference);
+extern NODE *elem_new_to_scalar(NODE *n);
 /* ext.c */
 extern NODE *do_ext(int nargs);
 void load_ext(const char *lib_name);   /* temporary */
@@ -1849,7 +1852,8 @@ POP_ARRAY(bool check_for_untyped)
        NODE *t = POP();
        static bool warned = false;
 
-       if (do_lint && ! warned && check_for_untyped && t->type == 
Node_var_new) {
+       if (do_lint && ! warned && check_for_untyped
+           && (t->type == Node_var_new || t->type == Node_elem_new)) {
                warned = true;
                lintwarn(_("behavior of `for' loop on untyped variable is not 
defined by POSIX"));
        }
@@ -1942,6 +1946,13 @@ dupnode(NODE *n)
 static inline NODE *
 force_string_fmt(NODE *s, const char *fmtstr, int fmtidx)
 {
+       if (s->type == Node_elem_new) {
+               s->type = Node_val;
+               s->flags &= ~NUMBER;
+
+               return s;
+       }
+
        if ((s->flags & STRCUR) != 0
                && (s->stfmt == STFMT_UNUSED || (s->stfmt == fmtidx
 #ifdef HAVE_MPFR
diff --git a/builtin.c b/builtin.c
index 3a38a478..75825742 100644
--- a/builtin.c
+++ b/builtin.c
@@ -591,7 +591,7 @@ do_length(int nargs)
 
                size = assoc_length(tmp);
                return make_number(size);
-       } else if (tmp->type == Node_var_new) {
+       } else if (tmp->type == Node_var_new || tmp->type == Node_elem_new) {
                // this can happen from an indirect call
                DEREF(tmp);
                tmp = dupnode(Nnull_string);
@@ -4342,6 +4342,7 @@ do_typeof(int nargs)
                }
                break;
        case Node_var_new:
+       case Node_elem_new:
                res = "untyped";
                deref = false;
                break;
diff --git a/cint_array.c b/cint_array.c
index 91947766..3e0393c9 100644
--- a/cint_array.c
+++ b/cint_array.c
@@ -1068,7 +1068,7 @@ leaf_lookup(NODE *symbol, NODE *array, long k, long size, 
long base)
        lhs = array->nodes + (k - base); /* leaf element */
        if (*lhs == NULL) {
                array->table_size++;    /* one more element in leaf array */
-               *lhs = dupnode(Nnull_string);
+               *lhs = new_array_element();
        }
        return lhs;
 }
diff --git a/debug.c b/debug.c
index 2849a4c1..f602a199 100644
--- a/debug.c
+++ b/debug.c
@@ -967,6 +967,9 @@ print_symbol(NODE *r, bool isparam)
        case Node_var_new:
                fprintf(out_fp, "untyped variable\n");
                break;
+       case Node_elem_new:
+               fprintf(out_fp, "untyped element\n");
+               break;
        case Node_var:
                if (! isparam && r->var_update)
                        r->var_update();
@@ -1241,6 +1244,7 @@ do_set_var(CMDARG *arg, int cmd ATTRIBUTE_UNUSED)
 
                switch (r->type) {
                case Node_var_new:
+               case Node_elem_new:
                        r->type = Node_var;
                        r->var_value = dupnode(Nnull_string);
                        /* fall through */
@@ -1730,6 +1734,7 @@ watchpoint_triggered(struct list_item *w)
                        t2 = symbol;
                        break;
                case Node_var_new:
+               case Node_elem_new:
                        break;
                default:
                        cant_happen("unexpected symbol type %s", 
nodetype2str(symbol->type));
@@ -1806,7 +1811,7 @@ initialize_watch_item(struct list_item *w)
                r = *get_field(field_num, NULL);
                w->cur_value = dupnode(r);
        } else {
-               if (symbol->type == Node_var_new)
+               if (symbol->type == Node_var_new || symbol->type == 
Node_elem_new)
                        w->cur_value = (NODE *) 0;
                else if (symbol->type == Node_var) {
                        r = symbol->var_value;
@@ -3753,6 +3758,10 @@ print_memory(NODE *m, NODE *func, Func_print print_func, 
FILE *fp)
                print_func(fp, "%s", m->vname);
                break;
 
+       case Node_elem_new:
+               print_func(fp, "element - %p", m);
+               break;
+
        default:
                print_func(fp, "?");  /* can't happen */
        }
@@ -5109,7 +5118,7 @@ do_print_f(CMDARG *arg, int cmd ATTRIBUTE_UNUSED)
                        r = find_symbol(name, NULL);
                        if (r == NULL)
                                goto done;
-                       if (r->type == Node_var_new)
+                       if (r->type == Node_var_new || r->type == Node_elem_new)
                                tmp[i] = Nnull_string;
                        else if (r->type != Node_var) {
                                d_error(_("`%s' is not a scalar variable"), 
name);
diff --git a/eval.c b/eval.c
index c6f8bcb9..e292cab6 100644
--- a/eval.c
+++ b/eval.c
@@ -238,6 +238,7 @@ static const char *const nodetypes[] = {
        "Node_var",
        "Node_var_array",
        "Node_var_new",
+       "Node_elem_new",
        "Node_param_list",
        "Node_func",
        "Node_ext_func",
@@ -1167,6 +1168,14 @@ r_get_lhs(NODE *n, bool reference)
                n->var_value = dupnode(Nnull_string);
                break;
 
+       case Node_elem_new:
+               efree(n->stptr);
+               n->stptr = NULL;
+               n->stlen = 0;
+               n->type = Node_var;
+               n->var_value = dupnode(Nnull_string);
+               break;
+
        case Node_var:
                break;
 
@@ -1313,6 +1322,7 @@ setup_frame(INSTRUCTION *pc)
                switch (m->type) {
                case Node_var_new:
                case Node_var_array:
+               case Node_elem_new:
                        r->type = Node_array_ref;
                        r->orig_array = r->prev_array = m;
                        break;
@@ -1534,6 +1544,10 @@ cmp_scalars(scalar_cmp_t comparison_type)
 
        t2 = POP_SCALAR();
        t1 = TOP();
+
+       t1 = elem_new_to_scalar(t1);
+       t2 = elem_new_to_scalar(t2);
+
        if (t1->type == Node_var_array) {
                DEREF(t2);
                fatal(_("attempt to use array `%s' in a scalar context"), 
array_vname(t1));
@@ -1872,3 +1886,20 @@ init_interpret()
                interpret = r_interpret;
 }
 
+/* elem_new_to_scalar --- convert Node_elem_new to untyped scalar */
+
+NODE *
+elem_new_to_scalar(NODE *n)
+{
+       if (n->type != Node_elem_new)
+               return n;
+
+       if (n->valref > 1) {
+               unref(n);
+               return dupnode(Nnull_string);
+       }
+
+       n->type = Node_val;
+
+       return n;
+}
diff --git a/ext.c b/ext.c
index 30e52aae..3d643c01 100644
--- a/ext.c
+++ b/ext.c
@@ -200,7 +200,7 @@ get_actual_argument(NODE *t, int i, bool want_array)
        pc = TOP()->code_ptr;   /* Op_ext_builtin instruction */
        fname = (pc + 1)->func_name;
 
-       if (t->type == Node_var_new) {
+       if (t->type == Node_var_new || t->type == Node_elem_new) {
                if (want_array)
                        return force_array(t, false);
                else {
diff --git a/gawkapi.c b/gawkapi.c
index 01157d52..93cd9b15 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -69,7 +69,7 @@ api_get_argument(awk_ext_id_t id, size_t count,
                return awk_false;
 
        /* if type is undefined */
-       if (arg->type == Node_var_new) {
+       if (arg->type == Node_var_new || arg->type == Node_elem_new) {
                if (wanted == AWK_UNDEFINED)
                        return awk_true;
                else if (wanted == AWK_ARRAY) {
@@ -124,7 +124,7 @@ api_set_argument(awk_ext_id_t id,
                return awk_false;
 
        if (   (arg = get_argument(count)) == NULL
-           || arg->type != Node_var_new)
+           || (arg->type != Node_var_new && arg->type != Node_elem_new))
                return awk_false;
 
        arg = get_array_argument(arg, count);
@@ -564,6 +564,7 @@ node_to_awk_value(NODE *node, awk_value_t *val, 
awk_valtype_t wanted)
 
        switch (node->type) {
        case Node_var_new:      /* undefined variable */
+       case Node_elem_new:     /* undefined element */
                val->val_type = AWK_UNDEFINED;
                if (wanted == AWK_UNDEFINED) {
                        ret = awk_true;
@@ -896,10 +897,13 @@ api_sym_update(awk_ext_id_t id,
 
        efree((void *) full_name);
 
-       if ((node->type == Node_var && value->val_type != AWK_ARRAY) || 
node->type == Node_var_new) {
+       if ((node->type == Node_var && value->val_type != AWK_ARRAY)
+           || node->type == Node_var_new
+           || node->type == Node_elem_new) {
                unref(node->var_value);
                node->var_value = awk_value_to_node(value);
-               if (node->type == Node_var_new && value->val_type != 
AWK_UNDEFINED)
+               if ((node->type == Node_var_new || node->type == Node_elem_new)
+                   && value->val_type != AWK_UNDEFINED)
                        node->type = Node_var;
 
                return awk_true;
diff --git a/int_array.c b/int_array.c
index 382aa799..8752413e 100644
--- a/int_array.c
+++ b/int_array.c
@@ -792,7 +792,7 @@ int_insert(NODE *symbol, long k, uint32_t hash1)
        }
 
        b->ainum[i] = k;
-       b->aivalue[i] = dupnode(Nnull_string);
+       b->aivalue[i] = new_array_element();
        b->aicount++;
        return & b->aivalue[i];
 }
diff --git a/interpret.h b/interpret.h
index bed2dfe8..29fc7fce 100644
--- a/interpret.h
+++ b/interpret.h
@@ -224,6 +224,20 @@ uninitialized_scalar:
                                                                
save_symbol->vname);
                                if (op != Op_push_arg_untyped)
                                        m = dupnode(Nnull_string);
+                               UPREF(m);
+                               PUSH(m);
+                               break;
+
+                       case Node_elem_new:
+                               if (op != Op_push_arg_untyped) {
+                                       /* convert untyped to scalar */
+                                       m = elem_new_to_scalar(m);
+                               }
+                               if (do_lint)
+                                       lintwarn(isparam ?
+                                               _("reference to uninitialized 
argument `%s'") :
+                                               _("reference to uninitialized 
variable `%s'"),
+                                                               
save_symbol->vname);
                                PUSH(m);
                                break;
 
@@ -320,7 +334,7 @@ uninitialized_scalar:
                                }
                        }
 
-                       if (r->type == Node_val)
+                       if (r->type == Node_val || r->type == Node_elem_new)
                                UPREF(r);
                        PUSH(r);
                        break;
@@ -353,6 +367,11 @@ uninitialized_scalar:
                                t2 = force_string(t2);
                                r->vname = estrdup(t2->stptr, t2->stlen);       
/* the subscript in parent array */
                                assoc_set(t1, t2, r);
+                       } else if (r->type == Node_elem_new) {
+                               r = force_array(r, false);
+                               r->parent_array = t1;
+                               t2 = force_string(t2);
+                               r->vname = estrdup(t2->stptr, t2->stlen);       
/* the subscript in parent array */
                        } else if (r->type != Node_var_array) {
                                t2 = force_string(t2);
                                fatal(_("attempt to use scalar `%s[\"%.*s\"]' 
as an array"),
@@ -389,7 +408,7 @@ uninitialized_scalar:
                         * be stored in SYMTAB:
                         *      1. Variables that don"t yet have a value 
(Node_var_new)
                         *      2. Variables that have a value (Node_var)
-                        *      3. Values that awk code stuck into SYMTAB not 
related to variables (Node_value)
+                        *      3. Values that awk code stuck into SYMTAB not 
related to variables (Node_val)
                         * For 1, since we are giving it a value, we have to 
change the type to Node_var.
                         * For 1 and 2, we have to step through the Node_var to 
get to the value.
                         * For 3, we fatal out. This avoids confusion on things 
like
@@ -713,7 +732,7 @@ mod:
                         * SYMTAB is a little more messy.  Three possibilities 
for SYMTAB:
                         *      1. Variables that don"t yet have a value 
(Node_var_new)
                         *      2. Variables that have a value (Node_var)
-                        *      3. Values that awk code stuck into SYMTAB not 
related to variables (Node_value)
+                        *      3. Values that awk code stuck into SYMTAB not 
related to variables (Node_val)
                         * For 1, since we are giving it a value, we have to 
change the type to Node_var.
                         * For 1 and 2, we have to step through the Node_var to 
get to the value.
                         * For 3, we fatal out. This avoids confusion on things 
like
@@ -844,6 +863,10 @@ mod:
                        lhs = POP_ADDRESS();
                        r = TOP_SCALAR();
                        unref(*lhs);
+                       if (r->type == Node_elem_new) {
+                               DEREF(r);
+                               r = dupnode(Nnull_string);
+                       }
                        UPREF(r);
                        UNFIELD(*lhs, r);
                        REPLACE(r);
@@ -1074,7 +1097,7 @@ arrayfor:
                        (void) POP_CODE();
                        while (arg_count-- > 0) {
                                t1 = POP();
-                               if (t1->type == Node_val)
+                               if (t1->type == Node_val || t1->type == 
Node_elem_new)
                                        DEREF(t1);
                        }
                        free_api_string_copies();
diff --git a/mpfr.c b/mpfr.c
index 7f61b692..a8834c39 100644
--- a/mpfr.c
+++ b/mpfr.c
@@ -349,6 +349,15 @@ mpg_force_number(NODE *n)
 {
        char *cp, *cpend;
 
+       if (n->type == Node_elem_new) {
+               n->type = Node_val;
+               n->flags &= ~STRING;
+               n->stptr[0] = '0';      // STRCUR is still set
+               n->stlen = 1;
+
+               return n;
+       }
+
        if ((n->flags & NUMCUR) != 0)
                return n;
        n->flags |= NUMCUR;
diff --git a/node.c b/node.c
index cbf5c56e..904e3d08 100644
--- a/node.c
+++ b/node.c
@@ -61,6 +61,15 @@ r_force_number(NODE *n)
        char save;
        char *ptr;
 
+       if (n->type == Node_elem_new) {
+               n->type = Node_val;
+               n->flags &= ~STRING;
+               n->stptr[0] = '0';      // STRCUR is still set
+               n->stlen = 1;
+
+               return n;
+       }
+
        if ((n->flags & NUMCUR) != 0)
                return n;
 
diff --git a/pc/ChangeLog b/pc/ChangeLog
index e012e4b3..15287b22 100644
--- a/pc/ChangeLog
+++ b/pc/ChangeLog
@@ -1,3 +1,7 @@
+2022-06-02         Arnold D. Robbins     <arnold@skeeve.com>
+
+       * Makefile.tst: Regenerated.
+
 2022-05-24         Adam Van Scyoc        <avanscy@g.clemson.edu>
 
        * Makefile.tst: Regenerated.
@@ -18,6 +22,10 @@
 
        * Makefile.tst: Regenerated.
 
+2022-03-28         Arnold D. Robbins     <arnold@skeeve.com>
+
+       * Makefile.tst: Regenerated.
+
 2022-03-27         Arnold D. Robbins     <arnold@skeeve.com>
 
        * Makefile.tst: Regenerated.
diff --git a/pc/Makefile.tst b/pc/Makefile.tst
index e07a22ed..54d86dca 100644
--- a/pc/Makefile.tst
+++ b/pc/Makefile.tst
@@ -202,6 +202,7 @@ GAWK_EXT_TESTS = \
        indirectcall3 indirectbuiltin2 \
        inf-nan-torture intarray iolint isarrayunset lint lintexp \
        lintindex lintint lintlength lintold lintplus lintset lintwarn \
+       mdim1 mdim2 mdim3 \
        manyfiles match1 match2 match3 mbstr1 mbstr2 mixed1 mktime \
        modifiers muldimposix nastyparm negtime next nondec nondec2 \
        nonfatal1 nonfatal2 nonfatal3 nsawk1a nsawk1b nsawk1c nsawk2a \
@@ -3007,6 +3008,21 @@ lintwarn:
        @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk  --lint >_$@ 2>&1 || echo EXIT 
CODE: $$? >>_$@
        @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
 
+mdim1:
+       @echo $@
+       @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk  >_$@ 2>&1 || echo EXIT CODE: 
$$? >>_$@
+       @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+mdim2:
+       @echo $@
+       @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk  >_$@ 2>&1 || echo EXIT CODE: 
$$? >>_$@
+       @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+mdim3:
+       @echo $@
+       @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk  >_$@ 2>&1 || echo EXIT CODE: 
$$? >>_$@
+       @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
 match1:
        @echo $@
        @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk  >_$@ 2>&1 || echo EXIT CODE: 
$$? >>_$@
diff --git a/str_array.c b/str_array.c
index 08704312..101ad0b9 100644
--- a/str_array.c
+++ b/str_array.c
@@ -217,7 +217,7 @@ str_lookup(NODE *symbol, NODE *subs)
        b->ahname = subs;
        b->ahname_str = subs->stptr;
        b->ahname_len = subs->stlen;
-       b->ahvalue = dupnode(Nnull_string);
+       b->ahvalue = new_array_element();
        b->ahcode = code1;
        return & (b->ahvalue);
 }
diff --git a/symbol.c b/symbol.c
index 5ac5656d..d8a8b49f 100644
--- a/symbol.c
+++ b/symbol.c
@@ -497,6 +497,8 @@ print_vars(NODE **table, int (*print_func)(FILE *, const 
char *, ...), FILE *fp)
                        print_func(fp, "untyped variable\n");
                else if (r->type == Node_var)
                        valinfo(r->var_value, print_func, fp);
+               else
+                       cant_happen("unexpected node type: %s", 
nodetype2str(r->type));
        }
 }
 
diff --git a/test/ChangeLog b/test/ChangeLog
index 3f263224..7bd6b3c8 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2022-06-02         Arnold D. Robbins     <arnold@skeeve.com>
+
+       * Makefile.am (EXTRA_DIST): mdim3: new test.
+       * mdim3.awk, mdim3.ok: New files.
+
 2022-05-24         Adam Van Scyoc        <avanscy@g.clemson.edu>
 
        * Makefile.am (EXTRA_DIST): getlnfa, new test.
@@ -28,10 +33,19 @@
        * profile5.ok, profile10.ok, profile11.ok: Updated after code changes.
        * profile17.awk, profile17.ok: New files.
 
+2022-03-31         Arnold D. Robbins     <arnold@skeeve.com>
+
+       * aadelete1.awk, aadelete1.ok: Changed to sync with code changes.
+
 2022-03-30         Arnold D. Robbins     <arnold@skeeve.com>
 
        * delarprm2.awk, delarprm2.ok: Changes to make test more helpful.
 
+2022-03-27         Arnold D. Robbins     <arnold@skeeve.com>
+
+       * Makefile.am (EXTRA_DIST): mdim1, mdim2: new tests.
+       * mdim1.awk, mdim1.ok, mdim2.awk, mdim2.ok: New files.
+
 2022-03-27         Arnold D. Robbins     <arnold@skeeve.com>
 
        * Makefile.am (EXTRA_DIST): indirectcall3, new test.
diff --git a/test/Makefile.am b/test/Makefile.am
index fd73e646..fe4872f9 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -678,6 +678,12 @@ EXTRA_DIST = \
        manglprm.ok \
        manyfiles.awk \
        manyfiles.ok \
+       mdim1.awk \
+       mdim1.ok \
+       mdim2.awk \
+       mdim2.ok \
+       mdim3.awk \
+       mdim3.ok \
        modifiers.sh \
        modifiers.ok \
        muldimposix.awk \
@@ -1476,6 +1482,7 @@ GAWK_EXT_TESTS = \
        indirectcall3 indirectbuiltin2 \
        inf-nan-torture intarray iolint isarrayunset lint lintexp \
        lintindex lintint lintlength lintold lintplus lintset lintwarn \
+       mdim1 mdim2 mdim3 \
        manyfiles match1 match2 match3 mbstr1 mbstr2 mixed1 mktime \
        modifiers muldimposix nastyparm negtime next nondec nondec2 \
        nonfatal1 nonfatal2 nonfatal3 nsawk1a nsawk1b nsawk1c nsawk2a \
diff --git a/test/Makefile.in b/test/Makefile.in
index 2673a17b..f838d388 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -945,6 +945,12 @@ EXTRA_DIST = \
        manglprm.ok \
        manyfiles.awk \
        manyfiles.ok \
+       mdim1.awk \
+       mdim1.ok \
+       mdim2.awk \
+       mdim2.ok \
+       mdim3.awk \
+       mdim3.ok \
        modifiers.sh \
        modifiers.ok \
        muldimposix.awk \
@@ -1743,6 +1749,7 @@ GAWK_EXT_TESTS = \
        indirectcall3 indirectbuiltin2 \
        inf-nan-torture intarray iolint isarrayunset lint lintexp \
        lintindex lintint lintlength lintold lintplus lintset lintwarn \
+       mdim1 mdim2 mdim3 \
        manyfiles match1 match2 match3 mbstr1 mbstr2 mixed1 mktime \
        modifiers muldimposix nastyparm negtime next nondec nondec2 \
        nonfatal1 nonfatal2 nonfatal3 nsawk1a nsawk1b nsawk1c nsawk2a \
@@ -4711,6 +4718,21 @@ lintwarn:
        @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk  --lint >_$@ 2>&1 || echo EXIT 
CODE: $$? >>_$@
        @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
 
+mdim1:
+       @echo $@
+       @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk  >_$@ 2>&1 || echo EXIT CODE: 
$$? >>_$@
+       @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+mdim2:
+       @echo $@
+       @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk  >_$@ 2>&1 || echo EXIT CODE: 
$$? >>_$@
+       @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+mdim3:
+       @echo $@
+       @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk  >_$@ 2>&1 || echo EXIT CODE: 
$$? >>_$@
+       @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
 match1:
        @echo $@
        @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk  >_$@ 2>&1 || echo EXIT CODE: 
$$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index 899b4ec7..3015eb34 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -1728,6 +1728,21 @@ lintwarn:
        @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk  --lint >_$@ 2>&1 || echo EXIT 
CODE: $$? >>_$@
        @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
 
+mdim1:
+       @echo $@
+       @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk  >_$@ 2>&1 || echo EXIT CODE: 
$$? >>_$@
+       @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+mdim2:
+       @echo $@
+       @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk  >_$@ 2>&1 || echo EXIT CODE: 
$$? >>_$@
+       @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+mdim3:
+       @echo $@
+       @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk  >_$@ 2>&1 || echo EXIT CODE: 
$$? >>_$@
+       @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
 match1:
        @echo $@
        @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk  >_$@ 2>&1 || echo EXIT CODE: 
$$? >>_$@
diff --git a/test/aadelete1.awk b/test/aadelete1.awk
index 2484a057..158d2aa3 100644
--- a/test/aadelete1.awk
+++ b/test/aadelete1.awk
@@ -8,7 +8,7 @@ BEGIN {
        print length(a), length(a[1])
        delete a
        print length(a), length(a[1]), length(a)
-       a[1][1] = 11
+       a[1][1] = 11    # this used to fatal, now it no longer does.
 }
 
 function f(c, b) {
diff --git a/test/aadelete1.ok b/test/aadelete1.ok
index d4b678b5..c3e29d26 100644
--- a/test/aadelete1.ok
+++ b/test/aadelete1.ok
@@ -2,5 +2,3 @@
 1
 1 1
 0 0 1
-gawk: aadelete1.awk:11: fatal: attempt to use scalar `a["1"]' as an array
-EXIT CODE: 2
diff --git a/test/typeof3.awk b/test/typeof3.awk
index d148f373..2f864f45 100644
--- a/test/typeof3.awk
+++ b/test/typeof3.awk
@@ -15,5 +15,5 @@ BEGIN {
 BEGIN {
        print typeof(x)
        print typeof(a[1])
-       a[1][2] # fatals on this
+       a[1][2] # this used to fatal, it no longer does
 }
diff --git a/test/typeof3.ok b/test/typeof3.ok
index a6cd6c4a..f9026b08 100644
--- a/test/typeof3.ok
+++ b/test/typeof3.ok
@@ -4,6 +4,4 @@ regexp
 number
 4
 number
-unassigned
-gawk: typeof3.awk:18: fatal: attempt to use scalar `a["1"]' as an array
-EXIT CODE: 2
+untyped

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


hooks/post-receive
-- 
gawk



reply via email to

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