Memoize::Storable: respect 'nstore' option not respected

Memoize(3perl) says:

                tie my %cache => 'Memoize::Storable', $filename, 'nstore';
                memoize 'function', SCALAR_CACHE => [HASH => \%cache];

        Include the ‘nstore’ option to have the "Storable" database
        written in ‘network order’.  (See Storable for more details
        about this.)

In fact the "nstore" option does no such thing.  Option parsing looks
like this:

        @options{@_} = ();

$self->{OPTIONS}{'nstore'} is accordingly set to undef.  Later
Memoize::Storable checks if the option is true, and since undef is
not true, the "else" branch is always taken.

        if ($self->{OPTIONS}{'nstore'}) {
                Storable::nstore($self->{H}, $self->{FILENAME});
        } else {
                Storable::store($self->{H}, $self->{FILENAME});
        }

Correcting the condition to (exists $self->{OPTIONS}{'nstore'}) fixes
it.

Noticed because git-svn, which uses the 'nstore' option for its
on-disk caches, was producing

        Byte order is not compatible at ../../lib/Storable.pm

when run using a perl with a different integer size (and hence
byteorder).

Reported by Tim Retout (RT#77790)

Bug-Debian: http://bugs.debian.org/587650
Bug: https://rt.cpan.org/Public/Bug/Display.html?id=77790
Forwarded: https://rt.cpan.org/Public/Bug/Display.html?id=77790

Gbp-Pq: Topic fixes
Gbp-Pq: Name memoize_storable_nstore.diff
This commit is contained in:
Jonathan Nieder 2012-07-27 10:35:07 -05:00 committed by openKylinBot
parent e1f7372956
commit b1521a81d3
2 changed files with 21 additions and 5 deletions

View File

@ -55,7 +55,7 @@ sub DESTROY {
require Carp if $Verbose;
my $self= shift;
print STDERR "Memoize::Storable::DESTROY(@_)\n" if $Verbose;
if ($self->{OPTIONS}{'nstore'}) {
if (exists $self->{OPTIONS}{'nstore'}) {
Storable::nstore($self->{H}, $self->{FILENAME});
} else {
Storable::store($self->{H}, $self->{FILENAME});

View File

@ -31,18 +31,34 @@ if ($@) {
exit 0;
}
print "1..4\n";
print "1..9\n";
$file = "storable$$";
1 while unlink $file;
tryout('Memoize::Storable', $file, 1); # Test 1..4
1 while unlink $file;
tryout('Memoize::Storable', $file, 5, 'nstore'); # Test 5..8
assert_netorder($file, 9); # Test 9
1 while unlink $file;
sub assert_netorder {
my ($file, $testno) = @_;
my $netorder = Storable::file_magic($file)->{'netorder'};
print ($netorder ? "ok $testno\n" : "not ok $testno\n");
}
sub tryout {
my ($tiepack, $file, $testno) = @_;
my ($tiepack, $file, $testno, $option) = @_;
if (defined $option) {
tie my %cache => $tiepack, $file, $option
or die $!;
} else {
tie my %cache => $tiepack, $file
or die $!;
}
memoize 'c5',
SCALAR_CACHE => [HASH => \%cache],