summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2010-07-26 10:52:48 +0200
committerRicardo Signes <rjbs@cpan.org>2011-01-03 18:14:30 -0500
commita4627a69c8d4a15fc159373ecb6d31ae2a37f310 (patch)
tree0e2ba6e65cec80cf8be985ec07369566f74d0eaa
parentcaf6e827b53462b205889120ddfd0289e30e49ab (diff)
downloadperl-a4627a69c8d4a15fc159373ecb6d31ae2a37f310.tar.gz
[perl #75656] lvalue subs don't copy on write
The attached patch teaches pp_leavesublv about kine. For the record, a binary search points its digit at: From: Nicholas Clark <nick@ccl4.org> Date: Mon, 6 Jun 2005 09:08:45 +0000 (+0000) Subject: Shared hash key scalars can be safely copied as shared hash key scalars Shared hash key scalars can be safely copied as shared hash key scalars all the time.
-rw-r--r--pp_hot.c5
-rw-r--r--t/op/sub_lval.t7
2 files changed, 10 insertions, 2 deletions
diff --git a/pp_hot.c b/pp_hot.c
index 3371e889ea..ee699ef105 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -2555,7 +2555,10 @@ PP(pp_leavesublv)
if (MARK == SP) {
/* Temporaries are bad unless they happen to be elements
* of a tied hash or array */
- if (SvFLAGS(TOPs) & (SVs_TEMP | SVs_PADTMP | SVf_READONLY) &&
+ if ((SvFLAGS(TOPs) & (SVs_TEMP | SVs_PADTMP) ||
+ (SvFLAGS(TOPs) & (SVf_READONLY | SVf_FAKE))
+ == SVf_READONLY
+ ) &&
!(SvRMAGICAL(TOPs) && mg_find(TOPs, PERL_MAGIC_tiedelem))) {
LEAVE;
cxstack_ix--;
diff --git a/t/op/sub_lval.t b/t/op/sub_lval.t
index c20ffac7be..f754782148 100644
--- a/t/op/sub_lval.t
+++ b/t/op/sub_lval.t
@@ -3,7 +3,7 @@ BEGIN {
@INC = '../lib';
require './test.pl';
}
-plan tests=>71;
+plan tests=>73;
sub a : lvalue { my $a = 34; ${\(bless \$a)} } # Return a temporary
sub b : lvalue { ${\shift} }
@@ -570,3 +570,8 @@ Execution of - aborted due to compilation errors.
lval_decl = 5;
is($x, 5, "subroutine declared with lvalue before definition retains lvalue. [perl #68758]");
}
+
+sub fleen : lvalue { $pnare }
+$pnare = __PACKAGE__;
+ok eval { fleen = 1 }, "lvalues can return COWs (CATTLE?) [perl #75656]";\
+is $pnare, 1, 'and returning CATTLE actually works';