Skip to content

Commit

Permalink
simplify IO::Storable.make_null, fixes IO::Storable warning on empty -
Browse files Browse the repository at this point in the history
…fix #448
  • Loading branch information
mohawk2 committed Jan 30, 2024
1 parent 5b0cced commit 4de3705
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- fix modulo for ulonglong and on Windows
- update Opt::Simplex docs (#452) - thanks @KJ7LNW
- fix Graphics::OpenGLQ on MacOS Ventura (#452) - thanks @deriamis
- fix IO::Storable warning on empty (#448) - thanks @djerius for report

2.084 2023-05-21
- reduce size of PDL_KLUDGE_COPY_X macro to <4096 in line with C standard, to fix for older clang on many BSD
Expand Down
8 changes: 0 additions & 8 deletions IO/Storable/storable.pd
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,8 @@ void
make_null(sv)
SV *sv
CODE:
/* we basically mimic pdl_null but without letting
* it give us a it->sv ! We have our own to which we
* connect below
*/
pdl *it = PDL->pdlnew();
if (!it) PDL->pdl_barf("Failed to create new pdl");
it->datatype = PDL_B;
it->data = PDL->smalloc((STRLEN) (PDL->howbig(it->datatype)));
it->datasv = newSVpv(it->data,PDL->howbig(it->datatype));
it->data = SvPV_nolen((SV *)it->datasv);
/* connect pdl struct to this sv */
sv_setiv(SvRV(sv),PTR2IV(it));
it->sv = SvRV(sv);
Expand Down
15 changes: 13 additions & 2 deletions IO/Storable/t/storable.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ $serialized = freeze $x;
$oldx = thaw $serialized;
# $oldx->dump;

ok(sum(abs($x-$oldx))==0, 'PDL freeze/thaw');
is sum(abs($x-$oldx)), 0, 'PDL freeze/thaw';

$x = double '1';
$serialized = freeze $x;
$dthaw = thaw $serialized;
is $dthaw, $x, 'PDL freeze/thaw of PDL scalar';

# $oldb = thaw $serialized;
# $oldc = thaw $serialized;
Expand Down Expand Up @@ -49,7 +54,7 @@ $pfreeze = $phash->freeze;
$phthaw = thaw $pfreeze;

ok(all($phthaw == $phash), 'PDL has-a works with freeze/thaw');
ok(UNIVERSAL::isa($phthaw,'HASH'), 'PDL is a hash');
isa_ok($phthaw,'HASH', 'PDL is a hash');

# Test that freeze + thaw results in new object
$seq1 = sequence(3);
Expand All @@ -66,6 +71,12 @@ $seq2->slice('2') .= 8;
ok(! all($seq2 == $seq2_dc), 'Initialization from dclone object') or
diag($seq2, $seq2_dc);

{
my @w;
local $SIG{__WARN__} = sub { push @w, @_ };
thaw( freeze pdl([]) );
is "@w", '', 'no warnings';
}

# Now test reading from files
testLoad($_) foreach( qw(t/storable_new_amd64.dat t/storable_old_amd64.dat) );
Expand Down

0 comments on commit 4de3705

Please sign in to comment.