This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
make qr/(?{ __SUB__ })/ safe
authorDavid Mitchell <davem@iabyn.com>
Wed, 24 Apr 2013 15:29:42 +0000 (16:29 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 24 Apr 2013 15:40:15 +0000 (16:40 +0100)
commita453e28ae209e82ef2533e2e2bfe25490fd60654
tree09fa23d3eb05b5f03e5b0c09b936b0ec5389ce26
parent5fbe83117ea59ccad42477c465113c7550a3675d
make qr/(?{ __SUB__ })/ safe

(See RT #113928)

Formerly, __SUB__ within a code block within a qr// returned
a pointer to the "hidden" anon CV that implements the qr// closure. Since
this was never designed to be called directly, it would SEGV if you tried.

The easiest way to make this safe is to skip any CXt_SUB frames that
are marked as CXp_SUB_RE: i.e. skip any subs that are there just to
execute code blocks. For a qr//, this means that we return the sub which
the pattern match is embedded in.

Also, document the behaviour of __SUB__ within code blocks as being
subject to change. It could be argued for example that in these cases it
should return undef. But with the 5.18.0 release a month or two away, just
make it safe for now, and revisit the semantics later if necessary.
pod/perlfunc.pod
pod/perlsub.pod
pp_ctl.c
t/re/reg_eval_scope.t