From: Vincent Pit Date: Wed, 17 Jun 2009 10:24:41 +0000 (+0200) Subject: Plain dereferencing shouldn't have a different behaviour X-Git-Tag: v0.02~8 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=7b43fe3caca2977c57aea3f812131d16378cab46;p=perl%2Fmodules%2Fautovivification.git Plain dereferencing shouldn't have a different behaviour --- diff --git a/autovivification.xs b/autovivification.xs index 9e10bb5..c0ff27c 100644 --- a/autovivification.xs +++ b/autovivification.xs @@ -274,7 +274,9 @@ STATIC OP *a_pp_rv2av(pTHX) { UV hint; dSP; - if (!SvOK(TOPs)) { + a_map_fetch(PL_op, &oi); + + if (PL_op != oi.root && !SvOK(TOPs)) { /* We always need to push an empty array to fool the pp_aelem() that comes * later. */ SV *av; @@ -284,8 +286,6 @@ STATIC OP *a_pp_rv2av(pTHX) { RETURN; } - a_map_fetch(PL_op, &oi); - return CALL_FPTR(oi.old_pp)(aTHX); } @@ -298,7 +298,7 @@ STATIC OP *a_pp_rv2hv(pTHX) { a_map_fetch(PL_op, &oi); - if (!SvOK(TOPs)) { + if (PL_op != oi.root && !SvOK(TOPs)) { if (oi.root->op_flags & OPf_MOD) { SV *hv; POPs; diff --git a/samples/hash2array.pl b/samples/hash2array.pl index 4e7ccaa..863ba88 100644 --- a/samples/hash2array.pl +++ b/samples/hash2array.pl @@ -40,7 +40,9 @@ while (<$hash_t>) { s{'%'}{'\@'}; print $array_t $_; } else { + s!(\ba\b)?(\s*)HASH\b!($1 ? 'an': '') . "$2ARRAY"!eg; s!->{([a-z])}!'->[' . num($1) . ']'!eg; + s!%(\{?)\$!\@$1\$!g; my $buf; my $suffix = $_; my ($bracket, $prefix); diff --git a/t/20-hash.t b/t/20-hash.t index ad82aae..d4cf269 100644 --- a/t/20-hash.t +++ b/t/20-hash.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 6 * 3 * 260; +use Test::More tests => 6 * 3 * 270; use lib 't/lib'; use autovivification::TestCases; @@ -111,6 +111,20 @@ $x->{a} = 1 # 1 for $x->{b}; () # '', undef, { a => 1, b => undef } # +delete $x->{a} = 1 # 1 for $x->{a}; () # '', undef, { a => 1 } # +store $x->{a} = 1 # 1 for $x->{b}; () # '', undef, { a => 1, b => undef } # +store +--- dereferencing --- + +$x # no warnings 'uninitialized'; my @a = %$x; () # ($strict ? qr/Can't use an undefined value as a HASH reference/ : ''), undef, undef +$x # no warnings 'uninitialized'; my @a = %$x; () # ($strict ? qr/Can't use an undefined value as a HASH reference/ : ''), undef, undef # +$x # no warnings 'uninitialized'; my @a = %$x; () # ($strict ? qr/Can't use an undefined value as a HASH reference/ : ''), undef, undef # +fetch +$x # no warnings 'uninitialized'; my @a = %$x; () # ($strict ? qr/Can't use an undefined value as a HASH reference/ : ''), undef, undef # +exists +$x # no warnings 'uninitialized'; my @a = %$x; () # ($strict ? qr/Can't use an undefined value as a HASH reference/ : ''), undef, undef # +delete +$x # no warnings 'uninitialized'; my @a = %$x; () # ($strict ? qr/Can't use an undefined value as a HASH reference/ : ''), undef, undef # +store + +$x->{a} = 1 # my @a = %$x; () # '', undef, { a => 1 } # +fetch +$x->{a} = 1 # my @a = %$x; () # '', undef, { a => 1 } # +exists +$x->{a} = 1 # my @a = %$x; () # '', undef, { a => 1 } # +delete +$x->{a} = 1 # my @a = %$x; () # '', undef, { a => 1 } # +store + --- exists --- $x # exists $x->{a} # '', '', { } diff --git a/t/21-array.t b/t/21-array.t index ed746c6..bf843d6 100644 --- a/t/21-array.t +++ b/t/21-array.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 6 * 3 * 260; +use Test::More tests => 6 * 3 * 270; use lib 't/lib'; use autovivification::TestCases; @@ -111,6 +111,20 @@ $x->[0] = 1 # 1 for $x->[1]; () # '', undef, [ 1, undef ] # +delete $x->[0] = 1 # 1 for $x->[0]; () # '', undef, [ 1 ] # +store $x->[0] = 1 # 1 for $x->[1]; () # '', undef, [ 1, undef ] # +store +--- dereferencing --- + +$x # no warnings 'uninitialized'; my @a = @$x; () # ($strict ? qr/Can't use an undefined value as an ARRAY reference/ : ''), undef, undef +$x # no warnings 'uninitialized'; my @a = @$x; () # ($strict ? qr/Can't use an undefined value as an ARRAY reference/ : ''), undef, undef # +$x # no warnings 'uninitialized'; my @a = @$x; () # ($strict ? qr/Can't use an undefined value as an ARRAY reference/ : ''), undef, undef # +fetch +$x # no warnings 'uninitialized'; my @a = @$x; () # ($strict ? qr/Can't use an undefined value as an ARRAY reference/ : ''), undef, undef # +exists +$x # no warnings 'uninitialized'; my @a = @$x; () # ($strict ? qr/Can't use an undefined value as an ARRAY reference/ : ''), undef, undef # +delete +$x # no warnings 'uninitialized'; my @a = @$x; () # ($strict ? qr/Can't use an undefined value as an ARRAY reference/ : ''), undef, undef # +store + +$x->[0] = 1 # my @a = @$x; () # '', undef, [ 1 ] # +fetch +$x->[0] = 1 # my @a = @$x; () # '', undef, [ 1 ] # +exists +$x->[0] = 1 # my @a = @$x; () # '', undef, [ 1 ] # +delete +$x->[0] = 1 # my @a = @$x; () # '', undef, [ 1 ] # +store + --- exists --- $x # exists $x->[0] # '', '', [ ] diff --git a/t/lib/autovivification/TestCases.pm b/t/lib/autovivification/TestCases.pm index 507a4d8..4170a37 100644 --- a/t/lib/autovivification/TestCases.pm +++ b/t/lib/autovivification/TestCases.pm @@ -10,14 +10,17 @@ sub import { *{caller().'::testcase_ok'} = \&testcase_ok; } +sub in_strict { (caller 0)[8] & (eval { strict::bits(@_) } || 0) }; + sub source { my ($var, $init, $code, $exp, $use, $global) = @_; my $decl = $global ? "our $var; local $var;" : "my $var;"; my $test = $var =~ /^[@%]/ ? "\\$var" : $var; return <