Skip to content

Commit

Permalink
(perl #134179) include regexps in the seen objects table on retrieve
Browse files Browse the repository at this point in the history
Also, bless the regexp object, so freezing/thawing bless qr//, "Foo"
returns a "Foo" blesses regexp.
  • Loading branch information
tonycoz committed Jun 11, 2019
1 parent 7948efd commit 16f2ddb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions dist/Storable/Storable.xs
Original file line number Diff line number Diff line change
Expand Up @@ -6808,8 +6808,7 @@ static SV *retrieve_regexp(pTHX_ stcxt_t *cxt, const char *cname) {
SV *sv;
dSP;
I32 count;

PERL_UNUSED_ARG(cname);
HV *stash;

ENTER;
SAVETMPS;
Expand Down Expand Up @@ -6857,6 +6856,8 @@ static SV *retrieve_regexp(pTHX_ stcxt_t *cxt, const char *cname) {

sv = SvRV(re_ref);
SvREFCNT_inc(sv);
stash = cname ? gv_stashpv(cname, GV_ADD) : 0;
SEEN_NN(sv, stash, 0);

FREETMPS;
LEAVE;
Expand Down
4 changes: 3 additions & 1 deletion dist/Storable/t/regexp.t
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ while (<DATA>) {
}
}

plan tests => 9 + 3*scalar(@tests);
plan tests => 10 + 3*scalar(@tests);

SKIP:
{
Expand Down Expand Up @@ -75,6 +75,8 @@ SKIP:
ok(!eval { dclone($re) }, "should fail to clone, even with use re 'eval'");
}

is(ref(dclone(bless qr//, "Foo")), "Foo", "check reblessed regexps");

for my $test (@tests) {
my ($code, $not, $match, $matchc, $name) = @$test;
my $qr = eval $code;
Expand Down
10 changes: 9 additions & 1 deletion dist/Storable/t/weak.t
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ sub BEGIN {
}

use Test::More 'no_plan';
use Storable qw (store retrieve freeze thaw nstore nfreeze);
use Storable qw (store retrieve freeze thaw nstore nfreeze dclone);
require 'testlib.pl';
our $file;
use strict;
Expand Down Expand Up @@ -143,3 +143,11 @@ foreach (@tests) {
$stored = nfreeze $input;
tester($stored, \&freeze_and_thaw, $testsub, 'network string');
}

{
# [perl #134179] sv_upgrade from type 7 down to type 1
my $foo = [qr//,[]];
weaken($foo->[1][0][0] = $foo->[1]);
my $out = dclone($foo); # croaked here
is_deeply($out, $foo, "check they match");
}

0 comments on commit 16f2ddb

Please sign in to comment.