defined *{"!"} should not stop %! from working
authorFather Chrysostomos <sprout@cpan.org>
Fri, 13 Jan 2012 17:23:07 +0000 (09:23 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 14 Jan 2012 05:24:53 +0000 (21:24 -0800)
This is something I broke when merging is_magical_gv with
gv_fetchpvn_flags.

gv_fetchpvn_flags must make sure its *! glob is present in the sym-
bol table it loads Errno.  If it adds it afterwards it will clobber
another *! that Errno has autovivified and tied in the mean time.

gv.c
t/op/magic.t

diff --git a/gv.c b/gv.c
index 4b4d9a6..9da6c1a 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -1892,7 +1892,11 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
 
             /* magicalization must be done before require_tie_mod is called */
            if (sv_type == SVt_PVHV || sv_type == SVt_PVGV)
+           {
+               if (addmg) (void)hv_store(stash,name,len,(SV *)gv,0);
+               addmg = 0;
                require_tie_mod(gv, "!", newSVpvs("Errno"), "TIEHASH", 1);
+           }
 
            break;
        case '-':               /* $- */
index 6ddf2d8..494847f 100644 (file)
@@ -5,7 +5,7 @@ BEGIN {
     chdir 't' if -d 't';
     @INC = '../lib';
     require './test.pl';
-    plan (tests => 153);
+    plan (tests => 154);
 }
 
 # Test that defined() returns true for magic variables created on the fly,
@@ -416,7 +416,7 @@ SKIP: {
 }
 
 SKIP:  {
-    skip_if_miniperl("miniperl can't rely on loading %Errno", 1);
+    skip_if_miniperl("miniperl can't rely on loading %Errno", 2);
     # Make sure that Errno loading doesn't clobber $!
 
     undef %Errno::;
@@ -425,6 +425,14 @@ SKIP:  {
     open(FOO, "nonesuch"); # Generate ENOENT
     my %errs = %{"!"}; # Cause Errno.pm to be loaded at run-time
     ok ${"!"}{ENOENT};
+
+    # Make sure defined(*{"!"}) before %! does not stop %! from working
+    is
+      runperl(
+       prog => 'BEGIN { defined *{q-!-} } print qq-ok\n- if tied %!',
+      ),
+     "ok\n",
+     'defined *{"!"} does not stop %! from working';
 }
 
 # Check that we don't auto-load packages