From: Vincent Pit Date: Wed, 26 Oct 2011 21:33:18 +0000 (+0200) Subject: 'store' and 'delete' uvar magics don't need the uvar/clear hack X-Git-Tag: v0.47~2 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FVariable-Magic.git;a=commitdiff_plain;h=12570a1f39c0588d6ae68281b45ef1b7e6083958 'store' and 'delete' uvar magics don't need the uvar/clear hack --- diff --git a/Magic.xs b/Magic.xs index ca90b7f..5dc98a6 100644 --- a/Magic.xs +++ b/Magic.xs @@ -1305,7 +1305,7 @@ STATIC I32 vmg_svt_val(pTHX_ IV action, SV *sv) { } } - if (SvRMAGICAL(sv) && !tied) { + if (SvRMAGICAL(sv) && !tied && !(action & (HV_FETCH_ISSTORE|HV_DELETE))) { /* Temporarily hide the RMAGICAL flag of the hash so it isn't wrongly * mistaken for a tied hash by the rest of hv_common. It will be reset by * the op_ppaddr of a new fake op injected between the current and the next diff --git a/t/32-hash.t b/t/32-hash.t index 5cc5e1f..8ae273e 100644 --- a/t/32-hash.t +++ b/t/32-hash.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => (2 * 22 + 7) + (2 * 5 + 5) + 1; +use Test::More tests => (2 * 24 + 7) + (2 * 5 + 5) + 1; use Variable::Magic qw; @@ -23,11 +23,6 @@ my $s = watch { $h{foo} } +{ (fetch => 1) x VMG_UVAR }, 'assign element to'; is $s, $n{foo}, 'hash: assign element to correctly'; -for (1 .. 2) { - $s = watch { exists $h{foo} } +{ (exists => 1) x VMG_UVAR }, "exists ($_)"; - ok $s, "hash: exists correctly ($_)"; -} - my %b; watch { %b = %h } { }, 'assign to'; is_deeply \%b, \%n, 'hash: assign to correctly'; @@ -38,8 +33,22 @@ my @b = watch { @h{qw} } +{ (fetch => 2) x VMG_UVAR }, 'slice'; is_deeply \@b, [ @n{qw} ], 'hash: slice correctly'; +# exists + +watch { exists $h{bar} } +{ (exists => 1) x VMG_UVAR },'exists in void context'; + +for (1 .. 2) { + $s = watch { exists $h{bar} } +{ (exists => 1) x VMG_UVAR }, + "exists in scalar context ($_)"; + ok $s, "hash: exists correctly ($_)"; +} + watch { %h = () } { clear => 1 }, 'empty in list context'; +watch { $h{a} = -1; %h = (b => $h{a}) } + +{ (fetch => 1, store => 2, copy => 2) x VMG_UVAR, clear => 1 }, + 'empty and set in void context'; + watch { %h = (a => 1, d => 3) } +{ (store => 2, copy => 2) x VMG_UVAR, clear => 1 }, 'assign from list in void context';