Skip to content

Commit

Permalink
Fixed 2 bugs
Browse files Browse the repository at this point in the history
Made it handle reference assignments correctly
Fixed a compilation bug on non-threaded builds
  • Loading branch information
Leont committed Nov 8, 2009
1 parent 3124790 commit 02eb57a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/File/Map.xs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ static void mmap_fixup(pTHX_ SV* var, struct mmap_info* info, const char* string
}

Copy(string, info->fake_address, MIN(len, info->fake_length), char);
if (SvROK(var))
sv_unref_flags(var, SV_IMMEDIATE_UNREF);
if (SvPOK(var))
SvPV_free(var);
reset_var(var, info);
Expand Down Expand Up @@ -307,15 +309,16 @@ static struct mmap_info* get_mmap_magic(pTHX_ SV* var, const char* funcname) {
return (struct mmap_info*) magic->mg_ptr;
}

#ifdef USE_ITHREADS
static void magic_end(pTHX_ void* pre_info) {
struct mmap_info* info = (struct mmap_info*) pre_info;
info->owner = NULL;
MUTEX_UNLOCK(&info->data_mutex);
}
#endif

#define YES &PL_sv_yes

/*#define MAP_CONSTANT(cons) hv_store(map_constants, #cons, sizeof #cons - 1, newSVuv(cons), 0)*/
#define MAP_CONSTANT(cons) STMT_START {\
newCONSTSUB(stash, #cons, newSVuv(cons));\
av_push(constants, newSVuv(cons));\
Expand All @@ -329,7 +332,7 @@ PROTOTYPES: DISABLED

BOOT:
AV* constants = newAV();
hv_store(get_hv("File::Map::EXPORT_TAGS", TRUE), "constants", 9, newRV((SV*) constants), 0);
hv_store(get_hv("File::Map::EXPORT_TAGS", TRUE), "constants", 9, newRV_inc((SV*) constants), 0);
AV* export_ok = get_av("File::Map::EXPORT_OK", TRUE);
HV* stash = get_hv("File::Map::", FALSE);
MAP_CONSTANT(PROT_NONE);
Expand Down
7 changes: 6 additions & 1 deletion t/10-basics.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use strict;
use warnings;
use File::Map qw/:map lock_map sync/;
use IO::Handle;
use Test::More tests => 19;
use Test::More tests => 20;
use Test::Warn;
use Test::Exception;

Expand Down Expand Up @@ -57,6 +57,11 @@ print $copy $slurped;
no warnings 'substr';
$mmaped = 1;
like($mmaped, qr/^1/, '$mmaped should be like 1');

my $ref = \$slurped;
my $strval = "$ref";
$mmaped = $ref;
like($mmaped, qr/^\Q$strval\E/, '$mmaped should handle reference assignment');
}
}

Expand Down

0 comments on commit 02eb57a

Please sign in to comment.