Leopold Toetsch writes: > While trying to generate a small example that shows the memory > corruption problem reported by Steve, I came along these issues: > > a) [1] is .Sub, [2] is turned off > The subroutine prints main's $m - very likely wrong.
Well, Subs don't do anything with pads, so I'd say this is correct. > Q: Should the Sub get a NULL scratch pad, or a new empty scratch pad stack? Or just keep the existing one like current subs do. A top-level sub should be a closure under an empty pad stack. The following correspond to Perl code (approximately): > b) [1] is .Closure, [2] is turned off > The closure prints "main" - probably ok eval 'my $m = "main\n"; ' . 'print $m'; > c) [1] is .Closure, [2] is "newpad 0" > Lexical '$m' not found sub foo { print $m } { my $m = "main\n"; foo() } > d) [1] is .Closure, [2] is "newpad 1" > prints "main" my $m = "main\n"; sub { print $m }->(); > Q: What is correct? It looks to me as though they all are. Luke > .sub _main > new_pad 0 > new $P0, .PerlString > set $P0, "main\n" > store_lex -1, "$m", $P0 > .sym pmc foo > newsub foo, .Sub, _foo # [1] > .pcc_begin prototyped > .pcc_call foo > .pcc_end > pop_pad > end > .end > .sub _foo prototyped > # new_pad 1 # [2] > find_lex $P0, "$m" > print $P0 > # pop_pad > .pcc_begin_return > .pcc_end_return > .end > > leo >