summaryrefslogtreecommitdiff
path: root/pad.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2013-06-30 20:26:34 -0700
committerFather Chrysostomos <sprout@cpan.org>2013-07-25 23:48:02 -0700
commit137da2b05b4b7628115049f343163bdaf2c30dbb (patch)
treef67f94858229947447c68a9676d49af49c593d4b /pad.c
parentd2440203227a535b62a2078d898d0bd993ceac78 (diff)
downloadperl-137da2b05b4b7628115049f343163bdaf2c30dbb.tar.gz
[perl #79908] Stop sub inlining from breaking closures
When a closure closes over a variable, it references the variable itself, as opposed to taking a snapshot of its value. This was broken by the constant optimisation added for constant.pm’s sake: { my $x; sub () { $x }; # takes a snapshot of the current value of $x } constant.pm no longer uses that mechanism, except on older perls, so we can remove this hack, causing code like this this to start work- ing again: BEGIN{ my $x = 5; *foo = sub(){$x}; $x = 6 } print foo; # now prints 6, not 5
Diffstat (limited to 'pad.c')
-rw-r--r--pad.c19
1 files changed, 0 insertions, 19 deletions
diff --git a/pad.c b/pad.c
index 8407ba60ee..83082a5c90 100644
--- a/pad.c
+++ b/pad.c
@@ -2183,25 +2183,6 @@ S_cv_clone(pTHX_ CV *proto, CV *cv, CV *outside)
cv_dump(cv, "To");
);
- if (CvCONST(cv)) {
- /* Constant sub () { $x } closing over $x - see lib/constant.pm:
- * The prototype was marked as a candiate for const-ization,
- * so try to grab the current const value, and if successful,
- * turn into a const sub:
- */
- SV* const const_sv = op_const_sv(CvSTART(cv), cv);
- if (const_sv) {
- SvREFCNT_dec_NN(cv);
- /* For this calling case, op_const_sv returns a *copy*, which we
- donate to newCONSTSUB. Yes, this is ugly, and should be killed.
- Need to fix how lib/constant.pm works to eliminate this. */
- cv = newCONSTSUB(CvSTASH(proto), NULL, const_sv);
- }
- else {
- CvCONST_off(cv);
- }
- }
-
return cv;
}