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