[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Assignments into FUNCTAB resulting either strange output or hanging
From: |
Andrew J. Schorr |
Subject: |
Re: Assignments into FUNCTAB resulting either strange output or hanging |
Date: |
Thu, 9 Sep 2021 08:49:31 -0400 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Wed, Sep 08, 2021 at 11:55:18AM -0400, Andrew J. Schorr wrote:
> Interesting. The docs say:
>
> "Any attempt to assign to an element of 'FUNCTAB' also causes a fatal error."
>
> So the main question in my mind is why these programs don't throw a fatal
> error.
>
> bash-4.2$ ./gawk 'BEGIN {print FUNCTAB[0] = 1}'
> gawk: cmd. line:1: fatal: cannot assign to elements of FUNCTAB
> bash-4.2$ ./gawk 'BEGIN {print FUNCTAB[0]}'
> 0
The debug dump of that last program is basically:
[ 2:0x1171188] Op_push_array : FUNCTAB
[ 2:0x11711b0] Op_push_i : 0 [MALLOC|NUMCUR|NUMBER|NUMINT]
[ 2:0x1171200] Op_subscript : [sub_count = 1]
[ 2:0x1171160] Op_K_print : [expr_count = 1] [redir_type = ""]
In interpret.h:Op_subscript, we have:
case Op_subscript:
t2 = mk_sub(pc->sub_count);
t1 = POP_ARRAY(false);
...
/* for FUNCTAB, get the name as the element value */
if (t1 == func_table) {
static bool warned = false;
if (do_lint_extensions && ! warned) {
warned = true;
lintwarn(_("FUNCTAB is a gawk extension"
));
}
r = t2;
} else {
/* make sure stuff like NF, NR, are up to date
*/
if (t1 == symbol_table)
update_global_values();
r = *assoc_lookup(t1, t2);
}
DEREF(t2);
...
if (r->type == Node_val)
UPREF(r);
PUSH(r);
break;
So when FUNCTAB[<blah>] is referenced, it returns <blah> as the value,
regardless of whether <blah> actually exists in the FUNCTAB table.
Is that what's wanted? Or should it throw a fatal error if <blah>
is not in the FUNCTAB table?
Possible patch attached.
Regards,
Andy
functab_subscript.patch
Description: Text document