[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
[perl #60232] method cache not updated when dynamic subclass loaded through Storable::thaw
# New Ticket Created by laurent dami
# Please include the string: [perl #60232]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=60232 >
This is a bug report for perl from dami@cpan.org,
generated with the help of perlbug 1.36 running under perl 5.10.0.
-----------------------------------------------------------------
When Storable::thaw detects a class that is not already loaded,
it calls "require" to try to load it. If the class is not in a file,
but dynamically generated, we can put a coderef in @INC to
catch the load attempt, and generate the class on the fly.
This scheme worked fine in DBIx::DataModel on Perl<=5.8.8,
but no longer works on Perl5.10.0 (cf bug RT#40159).
Apparently when a class is dynamically created in response
to Storable::thaw, the method cache is not updated, and then
Storable fails to find the hook STORABLE_thaw.
I tried to insert a call to mro::invalidate_all_method_caches(),
but that doesn't solve the problem.
Attached is a code snippet that illustrates the problem.
Execution on Perl5.8.8
======================
d:\dami\Perl\Tst\Storable>perl dyn_subclass.pl store frozen
perl dyn_subclass.pl store frozen
class Foo::Bar dynamically created
d:\dami\Perl\Tst\Storable>perl dyn_subclass.pl retrieve frozen
perl dyn_subclass.pl retrieve frozen
class Foo::Bar dynamically created
hello, world
Execution on Perl5.10.0
=======================
d:\dami\Perl\Tst\Storable>perl dyn_subclass.pl store frozen
perl dyn_subclass.pl store frozen
class Foo::Bar dynamically created
d:\dami\Perl\Tst\Storable>perl dyn_subclass.pl retrieve frozen
perl dyn_subclass.pl retrieve frozen
class Foo::Bar dynamically created
No STORABLE_thaw defined for objects of class Foo::Bar (even after a "require Foo::Bar;") at ..\..\lib\Storable.pm (autosplit into ..\..\lib\auto\Storable\_retrieve.al) line 380, at dyn_subclass.pl line 81
-----------------------------------------------------------------
---
Flags:
category=library
severity=medium
---
Site configuration information for perl 5.10.0:
Configured by SYSTEM at Tue May 13 16:52:25 2008.
Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
Platform:
osname=MSWin32, osvers=5.00, archname=MSWin32-x86-multi-thread
uname=''
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc', ccflags ='-DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX -DHASATTRIBUTE -fno-strict-aliasing -mms-bitfields',
optimize='-O2',
cppflags='-DWIN32'
ccversion='', gccversion='3.4.2 (mingw-special)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='g++', ldflags ='-L"D:\Perl\lib\CORE"'
libpth=\lib
libs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lmsvcrt
perllibs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lmsvcrt
libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl510.lib
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-mdll -L"D:\Perl\lib\CORE"'
Locally applied patches:
ACTIVEPERL_LOCAL_PATCHES_ENTRY
33741 avoids segfaults invoking S_raise_signal() (on Linux)
33763 Win32 process ids can have more than 16 bits
32809 Load 'loadable object' with non-default file extension
32728 64-bit fix for Time::Local
---
@INC for perl 5.10.0:
d:/Perl/site/lib
d:/Perl/lib
.
---
Environment for perl 5.10.0:
HOME=D:\dami
LANG=fr
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=C:\Program Files\Fichiers communs\GTK\2.0\bin;d:\Perl\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\system32\nls;C:\WINDOWS\system32\nls\FRANCAIS;c:\Program Files\Novell\ZENworks\;C:\Program Files\ATI Technologies\ATI Control Panel;C:\Program Files\Novell\ZENworks\;D:\ProgFiles\MinGW\bin;D:\ProgFiles\MSys\1.0\bin;C:\BASISclient\cs\bin;C:\BASISclient\www\bin;C:\Program Files\Novell\SecureLogin;D:\ProgFiles\GTK\2.0\bin;d:\ProgFiles\TortoiseSVN\bin;D:\Progfiles\Subversion\bin;D:\ProgFiles\Berkeley_DB_4.6.21\bin;D:\ProgFiles\Berkeley_DB_4.6.21\bin\debug;Z:.;
PERL_BADLANG (unset)
SHELL=D:/ProgFiles/emacs-22.2/bin/cmdproxy.exe
package Subclassable;
sub subclass {
my ($class, $subclass) = @_;
# dynamic subclass creation
*{$subclass."::ISA"} = [qw/Subclassable/];
print STDERR "class $subclass dynamically created\n";
return $subclass;
}
sub hello {
my ($self) = @_;
print "hello, world\n";
}
# Support for Storable::{freeze,thaw} : just a stupid blank operation,
# but that will force Storable::thaw to try to reload the subclass ...
# and then we can catch it and generate it on the fly (see @INC below)
sub STORABLE_freeze {
my ($self, $is_cloning) = @_;
return if $is_cloning;
my $copy = {%$self};
return Storable::freeze($copy);
}
sub STORABLE_thaw {
my ($self, $is_cloning, $serialized) = @_;
return if $is_cloning;
my $copy = Storable::thaw($serialized);
%$self = %$copy;
}
# Add a coderef handler into @INC, so that when Storable::thaw tries to load
# a view, we take control, generate the View on the fly, and return
# a fake file to load.
push @INC, sub { # coderef into @INC: see L<perlfunc/require>
my ($coderef, $filename) = @_;
# transform $filename into classname
$filename =~ s[\.pm$][];
$filename =~ s[/][::]g;
# dynamic subclass creation
__PACKAGE__->subclass($filename);
# return a fake filehandle in memory so that "require" is happy
my $fake_file = "1";
open $fh, "<", \$fake_file or die $!;
return $fh;
};
package main;
use strict;
use warnings;
use Storable qw/store retrieve/;
use Data::Dumper;
my $usage = "$0 [store|retrieve] <filename>";
my $op = $ARGV[0] or die $usage;
my $file = $ARGV[1] or die $usage;
if ($op eq 'store') {
my $subclass = Subclassable->subclass('Foo::Bar');
my $foo = bless {}, $subclass;
store $foo, $file;
}
elsif ($op eq 'retrieve') {
my $foo = retrieve $file;
$foo->hello;
}
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]