lua: Unexpected NULL with nested self references

François Perrad francois.perrad at gadz.org
Sat Jul 30 15:38:04 UTC 2011


2011/7/29 Aaron Faanes <dafrito at gmail.com>:
> (If there's a better list for this, let me know and ignore the rest ;) )
>
> I ran into a problem compiling some old lua code I had lying around. I
> managed to isolate the cause of the exception in the following example:
>
> ---
>
> local instance = {};
>
> function instance:Constructor()
>     function self:Bar() end;
>     function self:Bar() end; -- Null PMC access here!
> end;
>
> instance:Constructor()
>
> ---
>
> I receive the following exception:
>
> lua.pbc: nullpmc.lua:5: Null PMC access in set_pmc_keyed()
> stack traceback:
>     nullpmc.lua:5: in function 'instance.Constructor_13'
>     nullpmc.lua:8: in main chunk
>     [PIR]: in function 'docall'
>     [PIR]: in function 'handle_script'
>     [PIR]: in function 'main'
>
> I've been picking apart the generated code, trying to see what's causing the
> issue. The null
> access is due to the generated PIR referring to "self" in two different
> ways. The following
> is, hopefully, a useful snippet:
>
> .annotate 'line', 4
>     .const "Sub" fct_17 = "post18"
>     newclosure $P19, fct_17
>     $P20 = subr."getfenv"()
>     $P19."setfenv"($P20)
>     set param_self_1[k_Bar], $P19
> .annotate 'line', 5
>     .const "Sub" fct_23 = "post24"
>     newclosure $P25, fct_23
>     $P26 = subr."getfenv"()
>     $P25."setfenv"($P26)
>     find_lex $P27, "self_2"
>     set $P27[k_Bar], $P25
>
> As you can see, the first use of self is "param_self_1", which is expected,
> but the second use of
> self is the non-existent "self_2".
>
> If you look at the PAST generated, "self_2" can be found inside self:Bar()
> as the unique name for the
> implicit self. I haven't been able to determine how that name managed to
> pollute the outer symbol table.
>
> I hope this bug report helps! Let me know if I should file this somewhere
> (or if I require a sanity check).

Thanks for this detailed report.
Fixed in https://github.com/fperrad/lua/commit/d73d0858608592ff44ced8b55285afcf54205621

François Perrad

>
> --
> Aaron Faanes <dafrito at gmail.com>
>
> _______________________________________________
> http://lists.parrot.org/mailman/listinfo/parrot-dev
>
>


More information about the parrot-dev mailing list