Skip to content

Commit

Permalink
Allow mapping into a hash entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Leont committed Oct 29, 2017
1 parent 6b39764 commit 0336f80
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,6 +1,7 @@
Revision history for File-Map

{{$NEXT}}
- Fix mapping into a hash element
- Fix compilation warning by giving boot function a proper return type
- Take into account sleep 0.1 may sleep a little less

Expand Down
2 changes: 2 additions & 0 deletions lib/File/Map.xs
Expand Up @@ -538,6 +538,7 @@ _mmap_impl(var, length, prot, flags, fd, offset, utf8 = 0)

magical = initialize_mmap_info(aTHX_ address, length, correction, flags);
reset_var(var, magical);
SvSETMAGIC(var);
add_magic(aTHX_ var, magical, &mmap_table, prot & PROT_WRITE, utf8);
}
else {
Expand All @@ -549,6 +550,7 @@ _mmap_impl(var, length, prot, flags, fd, offset, utf8 = 0)
sv_setpvn(var, "", 0);

magical = initialize_mmap_info(aTHX_ SvPV_nolen(var), 0, 0, flags);
SvSETMAGIC(var);
add_magic(aTHX_ var, magical, &empty_table, prot & PROT_WRITE, utf8);
}

Expand Down
8 changes: 7 additions & 1 deletion t/10-basics.t
Expand Up @@ -5,7 +5,7 @@ use warnings;
use File::Map qw/:map lock_map advise/;
use IO::Handle;
use Scalar::Util qw/tainted/;
use Test::More tests => 22;
use Test::More tests => 24;
use Test::Warnings;
use Test::Fatal qw/lives_ok/;

Expand Down Expand Up @@ -35,6 +35,12 @@ close $self or die "Couldn't close self: $!";
lives_ok { unmap($mmaped) } "Unmapping";
}

{
my %hash;
lives_ok { map_file($hash{map}, $0) } 'mapping self into a hash';
is($hash{map}, $slurped, 'Correctly autovifivies hash entry');
}

open my $copy, "+<:raw", undef or die "Couldn't create tempfile: $!";
$copy->autoflush(1);
print $copy $slurped;
Expand Down
5 changes: 1 addition & 4 deletions t/20-errors.t
Expand Up @@ -5,7 +5,7 @@ use warnings;

use File::Map qw/:map lock_map sync advise/;
use IO::Socket::INET;
use Test::More tests => 27;
use Test::More tests => 26;
use Test::Warnings 0.005 qw/warning warnings/;
use Test::Fatal qw/exception lives_ok dies_ok/;
BEGIN {
Expand Down Expand Up @@ -86,9 +86,6 @@ SKIP: {
like(exception { map_handle my ($map), $fh; }, qr/Can't map fake filehandle/, 'Mapping a scalar string handle throws an error');
}

my %hash;
lives_ok { map_anonymous $hash{'foo'}, 4096 } 'mapping a hash element shouldn\'t croak';

my $x;
my $y = \$x;

Expand Down

0 comments on commit 0336f80

Please sign in to comment.