[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: parameter type is incorrectly reported by typeof()
From: |
Andrew J. Schorr |
Subject: |
Re: parameter type is incorrectly reported by typeof() |
Date: |
Tue, 16 Nov 2021 11:21:36 -0500 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Oops, forgot the debug printf patch. Now attached.
On Tue, Nov 16, 2021 at 11:20:43AM -0500, Andrew J. Schorr wrote:
> Hi,
>
> On Tue, Nov 16, 2021 at 01:38:22AM -0700, arnold@skeeve.com wrote:
> > The first 'untyped' is from the BEGIN and is correct. The second
> > one is also correct. The third one is what you're asking about.
>
> Yes.
>
> > I think this is because `x' in the function comes from Node_param_list,
> > and when a value is fetched, it gets the null string. Maybe the
> > type here should also be turned into unassigned. It's very subtle
> > though and needs looking at in a debugger.
> >
> > If I have some time I'll look at it. Or feel free to beat me to it.
>
> Simpler version:
>
> bash-4.2$ cat /tmp/test1.awk
> function f(x) {
> #print typeof(x)
> y = x
> print typeof(x)
> }
>
> BEGIN {
> #print typeof(x)
> f(x)
> }
>
> It prints "untyped", and from debugging, I see that the node
> type is 11 (Node_array_ref). That strikes me as odd.
>
> bash-4.2$ ./gawk -D -f /tmp/test1.awk
> gawk> dump
>
> # BEGIN
>
> [ 7:0x12d9a48] Op_rule : [in_rule = BEGIN] [source_file =
> /tmp/test1.awk]
> [ 9:0x12d72b0] Op_push_param : x
> [ 9:0x12d8558] Op_func_call : [func_name = f] [arg_count = 1]
> [ :0x12d7378] Op_pop :
> [ :0x12d7148] Op_no_op :
> [ :0x12d71e8] Op_atexit :
> [ :0x12d73a0] Op_stop :
> [ :0x12d7198] Op_no_op :
> [ :0x12d71c0] Op_after_beginfile :
> [ :0x12d7170] Op_no_op :
> [ :0x12d7418] Op_after_endfile :
>
> # Function: f (x)
>
> [ 1:0x12d99a8] Op_func : [param_cnt = 1] [source_file =
> /tmp/test1.awk]
> [ 3:0x12d7288] Op_push : x
> [ 3:0x12d7238] Op_store_var : y
> [ 4:0x12d72d8] Op_push_arg_untyped : x
> [ 4:0x12d7260] Op_builtin : typeof [arg_count = 1]
> [ 4:0x12d7210] Op_K_print : [expr_count = 1] [redir_type = ""]
> [ :0x12d7300] Op_push_i : Nnull_string
> [MALLOC|STRING|STRCUR|NUMCUR|NUMBER]
> [ :0x12d7328] Op_K_return :
>
> The Op_store_var code in interpret.h assigns the results of
> POP_SCALAR to y, but that's somehow a different NODE than what is
> passed to do_typeof.
>
> I did just enough debugging to get myself confused. With the attached
> patch containing debugging printfs, one sees:
>
> bash-4.2$ ./gawk -f /tmp/test1.awk
> debug: popped scalar 0x1799140 with type 1 [Node_val] flags 31
> [MALLOC|STRING|STRCUR|NUMCUR|NUMBER]
> debug: typeof(0x17b0200) with type 11 [Node_array_ref] flags 0 []
> untyped
>
> Whereas for this script:
>
> bash-4.2$ cat /tmp/test.awk
> BEGIN {
> # print typeof(x)
> y = x
> print typeof(x)
> }
>
> One sees:
>
> bash-4.2$ ./gawk -f /tmp/test.awk
> debug: popped scalar 0x9ba140 with type 1 [Node_val] flags 31
> [MALLOC|STRING|STRCUR|NUMCUR|NUMBER]
> debug: typeof(0x9ba140) with type 1 [Node_val] flags 31
> [MALLOC|STRING|STRCUR|NUMCUR|NUMBER]
> unassigned
>
> Yet the logic is basically the same:
> [ 1:0x259a9c8] Op_rule : [in_rule = BEGIN] [source_file =
> /tmp/test.awk]
> [ 3:0x25982a8] Op_push : x
> [ 3:0x2598230] Op_store_var : y
> [ 4:0x25982f8] Op_push_arg_untyped : x
> [ 4:0x2598280] Op_builtin : typeof [arg_count = 1]
> [ 4:0x2598258] Op_K_print : [expr_count = 1] [redir_type = ""]
> [ :0x2598168] Op_no_op :
> [ :0x2598208] Op_atexit :
> [ :0x2598320] Op_stop :
> [ :0x25981b8] Op_no_op :
> [ :0x25981e0] Op_after_beginfile :
> [ :0x2598190] Op_no_op :
> [ :0x2598398] Op_after_endfile :
>
> Regards,
> Andy
debug.patch
Description: Text document