summaryrefslogtreecommitdiff
path: root/pp_ctl.c
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2015-12-14 11:55:14 +0000
committerDavid Mitchell <davem@iabyn.com>2016-02-03 09:18:33 +0000
commit3645bb38857eea14050e831b248aa4c4e05ea3a2 (patch)
tree7f58bdab45b40b494162a63e2577dcda556593fc /pp_ctl.c
parentf7a874b868f5a21432be489ac4efc417525c52f6 (diff)
downloadperl-3645bb38857eea14050e831b248aa4c4e05ea3a2.tar.gz
pp_leavesublv(): croak on *all* PADTMPs
pp_leavesublv() generally croaks on returned PADTMPs when called in lvalue context. However, an exception was made in scalar context if the PADTMP had set magic. This was to allow for things like sub :lvalue { $tied{foo} } and sub :lvalue { substr($foo,1,2) } However, it was later found that in places like pp_substr(), when returning a PVLV, it should return a new mortal rather than upgrading its pad target to PVLV, because the PVLV holds a reference to $foo which then gets delayed being freed indefinitely. Since places like pp_susbtr() no longer return lvalue PADTMPs, there's no longer any need to make a special exception in pp_leavesublv(). I've added an assertion to the effect that PADTMPs don't have set container magic, but I've added the assert to pp_leavesub() rather than pp_leavesublv(), since the former is much likely to be used in many weird situations and edge cases that would quickly flush out any false assumptions. If this assumption is wrong and the exception needs to be re-instated in pp_leavesublv(), then presumably it needs adding to the ARRAY context branch too - I'm assuming that its previous absence there was an oversight; i.e. sub foo :lvalue { $tied{foo}, substr($foo,1,2) } foo() = (1,2); should work too.
Diffstat (limited to 'pp_ctl.c')
-rw-r--r--pp_ctl.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index c81df19895..b49f86dd3c 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -2337,8 +2337,7 @@ PP(pp_leavesublv)
if (gimme == G_SCALAR) {
if (CxLVAL(cx) && !ref) { /* Leave it as it is if we can. */
if (MARK <= SP) {
- if ((SvPADTMP(TOPs) || SvREADONLY(TOPs)) &&
- !SvSMAGICAL(TOPs)) {
+ if ((SvPADTMP(TOPs) || SvREADONLY(TOPs))) {
what =
SvREADONLY(TOPs) ? (TOPs == &PL_sv_undef) ? "undef"
: "a readonly value" : "a temporary";