Skip to content
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

Closed
p5pRT opened this issue Jul 2, 2004 · 6 comments
Closed

[PATCH] Storable::dclone fails for tied elements #7400

p5pRT opened this issue Jul 2, 2004 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Jul 2, 2004

Migrated from rt.perl.org#30563 (status was 'resolved')

Searchable as RT30563$

@p5pRT
Copy link
Author

p5pRT commented Jul 2, 2004

From @eserte

This is a bug report for perl from slavenr@​devpc01.iconmobile.de,
generated with the help of perlbug 1.35 running under perl v5.9.2.


The following code fails with current Storable versions (where %x is a
tied hash)

  dclone $x{something}

with the error message "not a reference". It seems that the internal do_store
function sees the argument as a lvalue only and fails to use it as a
reference. The patch below fixes the problem for bleedperl and perl5.8.4,
but use with caution. The patch does NOT work for perl5.6.2. I'll try
other perl versions later.

#
#
# To apply this patch​:
# STEP 1​: Chdir to the source directory.
# STEP 2​: Run the 'applypatch' program with this patch file as input.
#
# If you do not have 'applypatch', it is part of the 'makepatch' package
# that you can fetch from the Comprehensive Perl Archive Network​:
# http​://www.perl.com/CPAN/authors/Johan_Vromans/makepatch-x.y.tar.gz
# In the above URL, 'x' should be 2 or higher.
#
# To apply this patch without the use of 'applypatch'​:
# STEP 1​: Chdir to the source directory.
# STEP 2​: Run the 'patch' program with this file as input.
#
#### End of Preamble ####

#### Patch data follows ####
diff -up '/usr/local/dist/cpan-manually/perl-5.9.x/ext/Storable/Storable.xs' 'Storable/Storable.xs'
Index​: ./Storable.xs

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'
Index: ./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
+}
#### End of Patch data ####

#### ApplyPatch data follows ####
# Data version : 1.0
# Date generated : Fri Jul 2 13​:29​:33 2004
# Generated by : makepatch 2.00_11*
# Recurse directories : Yes
# Excluded files : (\A|/).*\~\Z
# (\A|/).*\.a\Z
# (\A|/).*\.bak\Z
# (\A|/).*\.BAK\Z
# (\A|/).*\.elc\Z
# (\A|/).*\.exe\Z
# (\A|/).*\.gz\Z
# (\A|/).*\.ln\Z
# (\A|/).*\.o\Z
# (\A|/).*\.obj\Z
# (\A|/).*\.olb\Z
# (\A|/).*\.old\Z
# (\A|/).*\.orig\Z
# (\A|/).*\.rej\Z
# (\A|/).*\.so\Z
# (\A|/).*\.Z\Z
# (\A|/)\.del\-.*\Z
# (\A|/)\.make\.state\Z
# (\A|/)\.nse_depinfo\Z
# (\A|/)core\Z
# (\A|/)tags\Z
# (\A|/)TAGS\Z
# p 'Storable.xs' 166157 1088767765 0100664
# p 't/dclone.t' 2101 1088767198 0100775
#### End of ApplyPatch data ####

#### End of Patch kit [created​: Fri Jul 2 13​:29​:33 2004] ####
#### Patch checksum​: 89 3009 6035 ####
#### Checksum​: 107 3632 57513 ####



Flags​:
  category=library
  severity=medium


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​:
  Platform​:
  osname=linux, osvers=2.4.20-18.8, archname=i686-linux
  uname='linux devpc01.iconmobile.de 2.4.20-18.8 #1 thu may 29 08​:57​:39 edt 2003 i686 i686 i386 gnulinux '
  config_args='-ds -e -Dprefix=/usr/perl5.9.2d -Doptimize=-g -Dusedevel'
  hint=recommended, useposix=true, d_sigaction=define
  usethreads=undef useithreads=undef usemultiplicity=undef
  useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
  use64bitint=undef use64bitall=undef uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-DDEBUGGING -fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
  optimize='-g',
  cppflags='-DDEBUGGING -fno-strict-aliasing -pipe -I/usr/include/gdbm'
  ccversion='', gccversion='3.2 20020903 (Red Hat Linux 8.0 3.2-7)', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=4, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags =' -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib
  libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
  perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
  libc=/lib/libc-2.2.93.so, so=so, useshrplib=false, libperl=libperl.a
  gnulibc_version='2.2.93'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
  cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches​:
  DEVEL22511


@​INC for perl v5.9.2​:
  /usr/perl5.9.2d/lib/5.9.2/i686-linux
  /usr/perl5.9.2d/lib/5.9.2
  /usr/perl5.9.2d/lib/site_perl/5.9.2/i686-linux
  /usr/perl5.9.2d/lib/site_perl/5.9.2
  /usr/perl5.9.2d/lib/site_perl
  .


Environment for perl v5.9.2​:
  HOME=/home/slavenr
  LANG=en_US.UTF-8
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/usr/X11R6/bin​:/usr/X11/bin​:/usr/local/bin​:/usr/ucb​:/usr/bin​:/bin​:/usr/gnu/bin​:/usr/TeX/bin​:/usr/etc​:/usr/local/lib​:/usr/local/etc​:/usr/local/sbin​:/usr/sbin​:/sbin​:/home/slavenr/bin/linux​:/home/slavenr/bin/sh​:/home/slavenr/bin​:/usr/www/bin​:/usr/sepia/bin​:/usr/informix/online/bin​:/usr/local/Hughes/bin​:/usr/motif/bin​:/usr/cctb/bin​:/usr/sas​:/usr/ocs/bin​:/home/autos/bin​:/usr/games​:/home/pub/bin/linux​:/home/pub/bin​:/home/pub/bin/pbmplus​:/home/slavenr/devel/fahrinfo​:/home/slavenr/devel​:/opt/kde2/bin​:/opt/kde/bin​:/opt/gnome/bin​:/epoc/nokia60/epoc32/tools​:/usr/local/er6/bin/
  PERL_BADLANG (unset)
  SHELL=/bin/tcsh

@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2005

From @smpeters

[srezic@​iconmobile.com - Fri Jul 02 04​:32​:11 2004]​:

This is a bug report for perl from slavenr@​devpc01.iconmobile.de,
generated with the help of perlbug 1.35 running under perl v5.9.2.

-----------------------------------------------------------------

The following code fails with current Storable versions (where %x is a
tied hash)

dclone $x\{something\}

with the error message "not a reference". It seems that the internal
do_store
function sees the argument as a lvalue only and fails to use it as a
reference. The patch below fixes the problem for bleedperl and
perl5.8.4,
but use with caution. The patch does NOT work for perl5.6.2. I'll try
other perl versions later.

I'm assuming that the fact that this patch wasn't applied was because it does not work with
older Perls. If that's the case, can this patch be rejected as is?

@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2005

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2005

From @eserte

[srezic@​iconmobile.com - Fri Jul 02 04​:32​:11 2004]​:

Here's a complete sample script to make testing easier​:

#!perl
use Tie​::Hash;
use Storable qw(dclone);

tie %t, "Tie​::StdHash";
$t{a} = [1,2,3];

dclone $t{a};
__END__

If the "tie" is removed, then Storable works as expected.

Regards,
  Slaven

@p5pRT
Copy link
Author

p5pRT commented Oct 29, 2005

From @smpeters

[srezic - Thu Apr 28 02​:06​:42 2005]​:

[srezic@​iconmobile.com - Fri Jul 02 04​:32​:11 2004]​:

Here's a complete sample script to make testing easier​:

#!perl
use Tie​::Hash;
use Storable qw(dclone);

tie %t, "Tie​::StdHash";
$t{a} = [1,2,3];

dclone $t{a};
__END__

Thanks! Your patch has been applied as change #25881.

@p5pRT
Copy link
Author

p5pRT commented Oct 29, 2005

@smpeters - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant