New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATCH] Storable::dclone fails for tied elements #7400
Comments
From @eserteThis is a bug report for perl from slavenr@devpc01.iconmobile.de, The following code fails with current Storable versions (where %x is a dclone $x{something} with the error message "not a reference". It seems that the internal do_store # #### Patch data follows #### Inline Patch--- ./Storable.xs Tue Jun 22 14:53:24 2004
+++ ./Storable.xs Fri Jul 2 13:29:25 2004
@@ -6021,6 +6021,14 @@ SV *dclone(pTHX_ SV *sv)
clean_context(aTHX_ cxt);
/*
+ * Tied elements seem to need special handling.
+ */
+
+ if (SvTYPE(sv) == SVt_PVLV && SvRMAGICAL(sv) && mg_find(sv, 'p')) {
+ mg_get(sv);
+ }
+
+ /*
* do_store() optimizes for dclone by not freeing its context, should
* we need to allocate one because we're deep cloning from a hook.
*/
diff -up '/usr/local/dist/cpan-manually/perl-5.9.x/ext/Storable/t/dclone.t' 'Storable/t/dclone.t'
Inline Patch--- ./t/dclone.t Sat Jun 1 06:26:44 2002
+++ ./t/dclone.t Fri Jul 2 13:19:58 2004
@@ -24,7 +24,7 @@ sub BEGIN {
use Storable qw(dclone);
-print "1..10\n";
+print "1..12\n";
$a = 'toto';
$b = \$a;
@@ -90,3 +90,21 @@ my $clone = dclone($empty_string_obj);
print ref $clone eq ref $empty_string_obj &&
$$clone eq $$empty_string_obj &&
$$clone eq '' ? "ok 10\n" : "not ok 10\n";
+
+# Do not fail if Tie::Hash and/or Tie::StdHash is not available
+if (eval { require Tie::Hash; scalar keys %Tie::StdHash:: }) {
+ tie my %tie, "Tie::StdHash" or die $!;
+ $tie{array} = [1,2,3,4];
+ $tie{hash} = {1,2,3,4};
+ my $clone_array = dclone $tie{array};
+ print "not " unless "@$clone_array" eq "@{$tie{array}}";
+ print "ok 11\n";
+ my $clone_hash = dclone $tie{hash};
+ print "not " unless $clone_hash->{1} eq $tie{hash}{1};
+ print "ok 12\n";
+} else {
+ print <<EOF;
+ok 11 # skip No Tie::StdHash available
+ok 12 # skip No Tie::StdHash available
+EOF
+}
#### ApplyPatch data follows #### #### End of Patch kit [created: Fri Jul 2 13:29:33 2004] #### Flags: Site configuration information for perl v5.9.2: Configured by slavenr at Mon Jun 21 09:50:18 CEST 2004. Summary of my perl5 (revision 5 version 9 subversion 2 patch 22963) configuration: Locally applied patches: @INC for perl v5.9.2: Environment for perl v5.9.2: |
From @smpeters
I'm assuming that the fact that this patch wasn't applied was because it does not work with |
The RT System itself - Status changed from 'new' to 'open' |
From @eserte
Here's a complete sample script to make testing easier: #!perl tie %t, "Tie::StdHash"; dclone $t{a}; If the "tie" is removed, then Storable works as expected. Regards, |
From @smpeters
Thanks! Your patch has been applied as change #25881. |
@smpeters - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#30563 (status was 'resolved')
Searchable as RT30563$
The text was updated successfully, but these errors were encountered: