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