develooper Front page | perl.perl5.porters | Postings from May 2003

Re: [perl #22104] Can't call Storable::thaw from inside of DB_File filter function

Thread Previous
From:
Mark Jason Dominus
Date:
May 5, 2003 08:02
Subject:
Re: [perl #22104] Can't call Storable::thaw from inside of DB_File filter function
Message ID:
20030505150300.19755.qmail@plover.com

> On my system, this program:
> 
>         use Storable;
>         use DB_File;
>         tie %hash,  'DB_File', undef;
>         my $db = tied %hash;
>         $db->filter_store_value(sub { Storable::freeze($_) });
>         $db->filter_fetch_value(sub { Storable::thaw($_) });
>         $hash{k} = [1,2,3];
>         print @{$hash{k}};
> 
> Delivers this message:
> 
>         Storable binary image v32.82 more recent than I am (v2.5) at
>         ../../lib/Storable.pm (autosplit into
>         ../../lib/auto/Storable/thaw.al) line 358, at /tmp/BUG.pl line
>         7
> 
> Line 7 is the 'Storable::thaw' line.  A stack trace shows that control
> reaches the 'print' line, which implicitly calls the DB_File
> fetch_calue filter, which calls Storable::thaw, which croaks.
> 
> I cannot reproduce this error with the 'freeze' function, 
> and I cannot reproduce it without DB_File.
> 


Shortly after I sent this, I figured out what it meant.  My DB_File
filter was using the wrong calling convention:

>         $db->filter_store_value(sub { Storable::freeze($_) });

It should have been

          $db->filter_store_value(sub { $_ = Storable::freeze($_) });

As a result, the value actually being stored was the old, unfrozen
version of $_, which looked like "ARRAY(0x436c1d)".  Apparently the
first few bytes of a frozen string are a version number.  On 'thaw',
Storable was interpreting "ARRAY(0x436c1d)" as a frozen string, and
then deciding that it didn't know how to unfreeze such a string.

So the bug was in me, not in Storable or DB_File.

However, I think the error message could have been clearer:

>         Storable binary image v32.82 more recent than I am (v2.5) at
>         ../../lib/Storable.pm (autosplit into
>         ../../lib/auto/Storable/thaw.al) line 358, at /tmp/BUG.pl line
>         7

I didn't understand the meaning of 'binary image'.  I thought it
refered to a version mismatch between the Storable.so and the
Storable.pm file; hence my bug report.  If it means 'frozen string' I
wish it would say something more like 'frozen string'.

Also, the message implies an assumption that the argument string was
indeed a properly frozen string, one which happened to have been
generated by Storable v32.82.  This assumption is dead wrong.

I understand that the idea here is to allow the string format to
change between versions of Storable; then new Storables would be able
to thaw out strings in both old and new formats.  The feature makes
sense; my only gripe is with the error message.

I would have understood this much more quickly if it had said
something like

        Malformed frozen string argument (possibly created by Storable
        v32.82 ?) at ...

Then I would have known to disregard the weird v32.82 stuff.  


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About