e16460
From 16f2ddb794883529d5a3ad8326974a07aae7e567 Mon Sep 17 00:00:00 2001
e16460
From: Tony Cook <tony@develop-help.com>
e16460
Date: Mon, 10 Jun 2019 10:17:20 +1000
e16460
Subject: [PATCH] (perl #134179) include regexps in the seen objects table on
e16460
 retrieve
e16460
MIME-Version: 1.0
e16460
Content-Type: text/plain; charset=UTF-8
e16460
Content-Transfer-Encoding: 8bit
e16460
e16460
Also, bless the regexp object, so freezing/thawing bless qr//, "Foo"
e16460
returns a "Foo" blesses regexp.
e16460
e16460
Signed-off-by: Petr Písař <ppisar@redhat.com>
e16460
---
e16460
 dist/Storable/Storable.xs |  5 +++--
e16460
 dist/Storable/t/regexp.t  |  4 +++-
e16460
 dist/Storable/t/weak.t    | 10 +++++++++-
e16460
 3 files changed, 15 insertions(+), 4 deletions(-)
e16460
e16460
diff --git a/dist/Storable/Storable.xs b/dist/Storable/Storable.xs
e16460
index ed729c94a6..6a45d8adf2 100644
e16460
--- a/dist/Storable/Storable.xs
e16460
+++ b/dist/Storable/Storable.xs
e16460
@@ -6808,8 +6808,7 @@ static SV *retrieve_regexp(pTHX_ stcxt_t *cxt, const char *cname) {
e16460
     SV *sv;
e16460
     dSP;
e16460
     I32 count;
e16460
-
e16460
-    PERL_UNUSED_ARG(cname);
e16460
+    HV *stash;
e16460
 
e16460
     ENTER;
e16460
     SAVETMPS;
e16460
@@ -6857,6 +6856,8 @@ static SV *retrieve_regexp(pTHX_ stcxt_t *cxt, const char *cname) {
e16460
 
e16460
     sv = SvRV(re_ref);
e16460
     SvREFCNT_inc(sv);
e16460
+    stash = cname ? gv_stashpv(cname, GV_ADD) : 0;
e16460
+    SEEN_NN(sv, stash, 0);
e16460
     
e16460
     FREETMPS;
e16460
     LEAVE;
e16460
diff --git a/dist/Storable/t/regexp.t b/dist/Storable/t/regexp.t
e16460
index acf28cfec6..e7c6c7e94a 100644
e16460
--- a/dist/Storable/t/regexp.t
e16460
+++ b/dist/Storable/t/regexp.t
e16460
@@ -37,7 +37,7 @@ while (<DATA>) {
e16460
     }
e16460
 }
e16460
 
e16460
-plan tests => 9 + 3*scalar(@tests);
e16460
+plan tests => 10 + 3*scalar(@tests);
e16460
 
e16460
 SKIP:
e16460
 {
e16460
@@ -75,6 +75,8 @@ SKIP:
e16460
     ok(!eval { dclone($re) }, "should fail to clone, even with use re 'eval'");
e16460
 }
e16460
 
e16460
+is(ref(dclone(bless qr//, "Foo")), "Foo", "check reblessed regexps");
e16460
+
e16460
 for my $test (@tests) {
e16460
     my ($code, $not, $match, $matchc, $name) = @$test;
e16460
     my $qr = eval $code;
e16460
diff --git a/dist/Storable/t/weak.t b/dist/Storable/t/weak.t
e16460
index 220c70160f..48752fbec4 100644
e16460
--- a/dist/Storable/t/weak.t
e16460
+++ b/dist/Storable/t/weak.t
e16460
@@ -29,7 +29,7 @@ sub BEGIN {
e16460
 }
e16460
 
e16460
 use Test::More 'no_plan';
e16460
-use Storable qw (store retrieve freeze thaw nstore nfreeze);
e16460
+use Storable qw (store retrieve freeze thaw nstore nfreeze dclone);
e16460
 require 'testlib.pl';
e16460
 our $file;
e16460
 use strict;
e16460
@@ -143,3 +143,11 @@ foreach (@tests) {
e16460
   $stored = nfreeze $input;
e16460
   tester($stored, \&freeze_and_thaw, $testsub, 'network string');
e16460
 }
e16460
+
e16460
+{
e16460
+    # [perl #134179] sv_upgrade from type 7 down to type 1
e16460
+    my $foo = [qr//,[]];
e16460
+    weaken($foo->[1][0][0] = $foo->[1]);
e16460
+    my $out = dclone($foo); # croaked here
e16460
+    is_deeply($out, $foo, "check they match");
e16460
+}
e16460
-- 
e16460
2.20.1
e16460