From 2d961f6deff76f15f1e5c200d92c2ea6139bcdd2 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Wed, 21 Apr 2010 18:47:07 +0100 Subject: [PATCH] follow up fix for fd69380d5d5b95ef16e2521cf4251b34ee0ce151 The original fix for tied elements losing magic had a bug that was masked by a bool casting issue. Once the casting was fixed, the bug surfaced: elements of @+ lost their values when returned from a sub. By removing the TEMP flag from the regdatum PVLV, we force it to be copied when returned. --- av.c | 2 ++ t/op/magic.t | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/av.c b/av.c index fb853a6..94b5f2c 100644 --- a/av.c +++ b/av.c @@ -245,6 +245,8 @@ Perl_av_fetch(pTHX_ register AV *av, I32 key, I32 lval) sv = sv_newmortal(); sv_upgrade(sv, SVt_PVLV); mg_copy(MUTABLE_SV(av), sv, 0, key); + if (!tied_magic) /* for regdata, force leavesub to make copies */ + SvTEMP_off(sv); LvTYPE(sv) = 't'; LvTARG(sv) = sv; /* fake (SV**) */ return &(LvTARG(sv)); diff --git a/t/op/magic.t b/t/op/magic.t index bef4922..60d81ae 100644 --- a/t/op/magic.t +++ b/t/op/magic.t @@ -466,13 +466,13 @@ is "@+", "10 1 6 10"; # Test for bug [perl #27839] { - local $TODO = "fixing a casting issue revealed broken behaviour in this test"; my $x; sub f { "abc" =~ /(.)./; $x = "@+"; return @+; }; + "pqrstuvwxyz" =~ /..(....)../; # prime @+ etc in this scope my @y = f(); is $x, "@y", "return a magic array ($x) vs (@y)"; -- 2.7.4