Formats in closures called outside closures → crash
authorFather Chrysostomos <sprout@cpan.org>
Fri, 29 Jun 2012 03:28:09 +0000 (20:28 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 29 Jun 2012 03:29:14 +0000 (20:29 -0700)
commitaf41786fe5732d5ec7932b946eec99a695ac6e43
tree618156ae2d68d31ad8b1e4ab097d3f75e02212f6
parentcc4aa37cf0381fa64942b6fb2777fcec81dbc43d
Formats in closures called outside closures → crash

If a format closing over lexical variables is defined inside a clo-
sure, it must only be called directly inside that closure, not from
any other eval, sub, or format.

Calling it from anywhere else started causing a crash in 5.10.0,
because the format would try to close over variables in the currently-
running sub, using padoffsets intended for a completely unrelated pad.

This commit stops it from crashing by checking whether the currently-
running sub is a clone of the format’s outer sub (a closure proto-
type).  If it is not, the outer closure prototype is used, resulting
in ‘Variable is not available’ warnings.

This makes things work as well as they did in 5.8.  Ideally, we should
search the call stack for the topmost clone of the format’s outer sub;
but I’m saving that for another commit.
pad.c
t/comp/form_scope.t