summaryrefslogtreecommitdiff
path: root/t/op/magic.t
diff options
context:
space:
mode:
authorDagfinn Ilmari Mannsåker <ilmari@ilmari.org>2015-09-18 17:40:01 +0100
committerDavid Mitchell <davem@iabyn.com>2015-10-18 12:04:27 +0100
commit395391414ee1260c2b34a5f6a353908cc9d48d3f (patch)
tree9e8d4baaf15db0bc4e9fb35bd72e0d8801b19ad3 /t/op/magic.t
parentbdae4172ce49ee233037d3e6af7dbeea521d0562 (diff)
downloadperl-395391414ee1260c2b34a5f6a353908cc9d48d3f.tar.gz
Delay @ISA magic while unshifting
pp_unshift() first calls av_unshift(), which prepends the the requisite number of undefs, then calls av_store() for each item. However, unlike pp_push() it was not setting PL_delaymagic around the av_store() loop, so when unshifting onto @ISA, its magic would be triggered while there were still undefs in the array, causig the following spurious warning: $ perl -wE 'package Foo; unshift @ISA, qw(A B)' Use of uninitialized value in unshift at -e line 1. Also fix pp_push() to save and restore PL_delaymagic instead of clearing it, so that e.g. unshifting a tied value with FETCH pushing onto another @ISA doesn't erroneously clear the value from underneath the unshift.
Diffstat (limited to 't/op/magic.t')
-rw-r--r--t/op/magic.t23
1 files changed, 22 insertions, 1 deletions
diff --git a/t/op/magic.t b/t/op/magic.t
index 4a8006db2e..da7532e695 100644
--- a/t/op/magic.t
+++ b/t/op/magic.t
@@ -5,7 +5,7 @@ BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
require './test.pl';
- plan (tests => 190);
+ plan (tests => 192);
}
# Test that defined() returns true for magic variables created on the fly,
@@ -681,6 +681,27 @@ $_ = ${^E_NCODING};
pass('can read ${^E_NCODING} without blowing up');
is $_, undef, '${^E_NCODING} is undef';
+{
+ my $warned = 0;
+ local $SIG{__WARN__} = sub { ++$warned if $_[0] =~ /Use of uninitialized value in unshift/; print "# @_"; };
+ unshift @RT12608::A::ISA, qw(RT12608::B RT12608::C);
+ is $warned, 0, '[perl #126082] unshifting onto @ISA doesn\'t trigger set magic for each item';
+}
+
+{
+ my $warned = 0;
+ local $SIG{__WARN__} = sub { ++$warned if $_[0] =~ /Use of uninitialized value in unshift/; print "# @_"; };
+
+ my $x; tie $x, 'RT12608::F';
+ unshift @RT12608::X::ISA, $x, "RT12608::Z";
+ is $warned, 0, '[perl #126082] PL_delaymagic correctly/saved restored when pushing/unshifting onto @ISA';
+
+ package RT12608::F;
+ use parent 'Tie::Scalar';
+ sub TIESCALAR { bless {}; }
+ sub FETCH { push @RT12608::G::ISA, "RT12608::H"; "RT12608::Y"; }
+}
+
# ^^^^^^^^^ New tests go here ^^^^^^^^^
SKIP: {