b8876f
From 59ef97c7af81ab6faba749d88b558a55da41c249 Mon Sep 17 00:00:00 2001
b8876f
From: Zefram <zefram@fysh.org>
b8876f
Date: Sun, 22 Jan 2017 07:26:34 +0000
b8876f
Subject: [PATCH] fix special-case recreation of *::
b8876f
MIME-Version: 1.0
b8876f
Content-Type: text/plain; charset=UTF-8
b8876f
Content-Transfer-Encoding: 8bit
b8876f
b8876f
Ported to 5.24.1:
b8876f
b8876f
commit 120921acd4cf27bb932a725a8cf5c957652b22eb
b8876f
Author: Zefram <zefram@fysh.org>
b8876f
Date:   Sun Jan 22 07:26:34 2017 +0000
b8876f
b8876f
    fix special-case recreation of *::
b8876f
b8876f
    If *:: is called for then as a special case it is looked up as
b8876f
    $::{"main::"}.  If $::{"main::"} has been deleted, then that hash entry
b8876f
    is recreated.  But formerly it was only recreated as an undef scalar,
b8876f
    which broke things relying on glob lookup returning a glob.  Now in
b8876f
    that special case the recreated hash entry is initialised as a glob,
b8876f
    and populated with the customary recursive reference to the main stash.
b8876f
    Fixes [perl #129869].
b8876f
b8876f
Signed-off-by: Petr Písař <ppisar@redhat.com>
b8876f
---
b8876f
 gv.c         | 11 +++++++++--
b8876f
 t/op/stash.t |  9 ++++++++-
b8876f
 2 files changed, 17 insertions(+), 3 deletions(-)
b8876f
b8876f
diff --git a/gv.c b/gv.c
b8876f
index c89a3e7..3fda9b9 100644
b8876f
--- a/gv.c
b8876f
+++ b/gv.c
b8876f
@@ -1642,8 +1642,15 @@ S_parse_gv_stash_name(pTHX_ HV **stash, GV **gv, const char **name,
b8876f
                 name_cursor++;
b8876f
             *name = name_cursor+1;
b8876f
             if (*name == name_end) {
b8876f
-                if (!*gv)
b8876f
-                    *gv = MUTABLE_GV(*hv_fetchs(PL_defstash, "main::", TRUE));
b8876f
+                if (!*gv) {
b8876f
+		    *gv = MUTABLE_GV(*hv_fetchs(PL_defstash, "main::", TRUE));
b8876f
+		    if (SvTYPE(*gv) != SVt_PVGV) {
b8876f
+			gv_init_pvn(*gv, PL_defstash, "main::", 6,
b8876f
+				    GV_ADDMULTI);
b8876f
+			GvHV(*gv) =
b8876f
+			    MUTABLE_HV(SvREFCNT_inc_simple(PL_defstash));
b8876f
+		    }
b8876f
+		}
b8876f
                 return TRUE;
b8876f
             }
b8876f
         }
b8876f
diff --git a/t/op/stash.t b/t/op/stash.t
b8876f
index 7ac379b..d6fded4 100644
b8876f
--- a/t/op/stash.t
b8876f
+++ b/t/op/stash.t
b8876f
@@ -7,7 +7,7 @@ BEGIN {
b8876f
 
b8876f
 BEGIN { require "./test.pl"; }
b8876f
 
b8876f
-plan( tests => 54 );
b8876f
+plan( tests => 55 );
b8876f
 
b8876f
 # Used to segfault (bug #15479)
b8876f
 fresh_perl_like(
b8876f
@@ -355,3 +355,10 @@ is runperl(
b8876f
    ),
b8876f
    "ok\n",
b8876f
    "[perl #128238] non-stashes in stashes";
b8876f
+
b8876f
+is runperl(
b8876f
+    prog => '%:: = (); print *{q|::|}, qq|\n|',
b8876f
+    stderr => 1,
b8876f
+   ),
b8876f
+   "*main::main::\n",
b8876f
+   "[perl #129869] lookup %:: by name after clearing %::";
b8876f
-- 
b8876f
2.7.4
b8876f