Permalink
Browse files

*Removed almost all prototypes*

  • Loading branch information...
1 parent d8f597f commit e102d034439c76d9abcd2c0df94c9d4e4debeb60 @Leont committed Mar 26, 2010
Showing with 29 additions and 47 deletions.
  1. +14 −16 lib/File/Map.pm
  2. +13 −29 lib/File/Map.xs
  3. +2 −2 t/20-errors.t
View
@@ -11,7 +11,6 @@ use warnings FATAL => 'all';
use Exporter 5.57 'import';
use XSLoader;
-use Symbol qw/qualify_to_ref/;
use Carp qw/croak/;
use Readonly 1.03;
@@ -45,40 +44,39 @@ Readonly our %PROTECTION_FOR => (
Readonly my $ANON_FH, -1;
-## no critic (ProhibitSubroutinePrototypes)
+## no critic (Subroutines::RequireArgUnpacking)
-sub map_handle(\$*@) {
- my ($var_ref, $glob, $mode, $offset, $length) = @_;
- my $fh = qualify_to_ref($glob, caller);
+sub map_handle {
+ my (undef, $fh, $mode, $offset, $length) = @_;
$offset ||= 0;
$length ||= (-s $fh) - $offset;
- _mmap_impl($var_ref, $length, $PROTECTION_FOR{ $mode || '<' }, MAP_SHARED | MAP_FILE, fileno $fh, $offset);
+ _mmap_impl($_[0], $length, $PROTECTION_FOR{ $mode || '<' }, MAP_SHARED | MAP_FILE, fileno $fh, $offset);
return;
}
-sub map_file(\$@) {
- my ($var_ref, $filename, $mode, $offset, $length) = @_;
+sub map_file {
+ my (undef, $filename, $mode, $offset, $length) = @_;
$mode ||= '<';
$offset ||= 0;
open my $fh, $mode, $filename or croak "Couldn't open file $filename: $!";
$length ||= (-s $fh) - $offset;
- _mmap_impl($var_ref, $length, $PROTECTION_FOR{$mode}, MAP_SHARED | MAP_FILE, fileno $fh, $offset);
+ _mmap_impl($_[0], $length, $PROTECTION_FOR{$mode}, MAP_SHARED | MAP_FILE, fileno $fh, $offset);
close $fh or croak "Couldn't close $filename after mapping: $!";
return;
}
-sub map_anonymous(\$@) {
- my ($var_ref, $length) = @_;
+sub map_anonymous {
+ my (undef, $length) = @_;
croak 'Zero length specified for anonymous map' if $length == 0;
- _mmap_impl($var_ref, $length, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, $ANON_FH, 0);
+ _mmap_impl($_[0], $length, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, $ANON_FH, 0);
return;
}
-sub sys_map(\$$$$*;$) { ## no critic (ProhibitManyArgs)
- my ($var_ref, $length, $protection, $flags, $glob, $offset) = @_;
- my $fd = ($flags & MAP_ANONYMOUS) ? $ANON_FH : fileno qualify_to_ref($glob, caller);
+sub sys_map { ## no critic (ProhibitManyArgs)
+ my (undef, $length, $protection, $flags, $fh, $offset) = @_;
+ my $fd = ($flags & MAP_ANONYMOUS) ? $ANON_FH : $fh;
$offset ||= 0;
- _mmap_impl($var_ref, $length, $protection, $flags, $fd, $offset);
+ _mmap_impl($_[0], $length, $protection, $flags, $fd, $offset);
return;
}
View
@@ -361,12 +361,6 @@ static int _is_stattable(pTHX_ int fd) {
#define is_stattable(fd) _is_stattable(aTHX_ fd)
-static SV* deref_var(pTHX_ SV* var_ref) {
- if (!SvROK(var_ref))
- Perl_croak(aTHX_ "Invalid argument");
- return SvRV(var_ref);
-}
-
static struct mmap_info* get_mmap_magic(pTHX_ SV* var, const char* funcname) {
MAGIC* magic;
if (!SvMAGICAL(var) || (magic = mg_find(var, PERL_MAGIC_uvar)) == NULL || magic->mg_private != MMAP_MAGIC_NUMBER)
@@ -474,7 +468,7 @@ BOOT:
void
_mmap_impl(var, length, prot, flags, fd, offset)
- SV* var = deref_var(aTHX_ ST(0));
+ SV* var;
size_t length;
int prot;
int flags;
@@ -503,9 +497,8 @@ _mmap_impl(var, length, prot, flags, fd, offset)
void
sync(var, sync = YES)
- SV* var = deref_var(aTHX_ ST(0));
+ SV* var;
SV* sync;
- PROTOTYPE: \$@
CODE:
struct mmap_info* info = get_mmap_magic(aTHX_ var, "sync");
IGNORE_EMPTY_MAP(info);
@@ -517,9 +510,8 @@ sync(var, sync = YES)
#ifdef __linux__
void
remap(var, new_size)
- SV* var = deref_var(aTHX_ ST(0));
+ SV* var;
size_t new_size;
- PROTOTYPE: \$@
CODE:
struct mmap_info* info = get_mmap_magic(aTHX_ var, "remap");
#ifdef USE_ITHREADS
@@ -537,16 +529,14 @@ remap(var, new_size)
void
unmap(var)
- SV* var = deref_var(aTHX_ ST(0));
- PROTOTYPE: \$
+ SV* var;
CODE:
get_mmap_magic(aTHX_ var, "unmap");
sv_unmagic(var, PERL_MAGIC_uvar);
void
pin(var)
- SV* var = deref_var(aTHX_ ST(0));
- PROTOTYPE: \$
+ SV* var;
CODE:
struct mmap_info* info = get_mmap_magic(aTHX_ var, "pin");
IGNORE_EMPTY_MAP(info);
@@ -555,8 +545,7 @@ pin(var)
void
unpin(var)
- SV* var = deref_var(aTHX_ ST(0));
- PROTOTYPE: \$
+ SV* var;
CODE:
struct mmap_info* info = get_mmap_magic(aTHX_ var, "unpin");
IGNORE_EMPTY_MAP(info);
@@ -565,9 +554,8 @@ unpin(var)
void
advise(var, name)
- SV* var = deref_var(aTHX_ ST(0));
+ SV* var;
SV* name;
- PROTOTYPE: \$@
CODE:
struct mmap_info* info = get_mmap_magic(aTHX_ var, "advise");
IGNORE_EMPTY_MAP(info);
@@ -582,9 +570,8 @@ advise(var, name)
void
protect(var, prot)
- SV* var = deref_var(aTHX_ ST(0));
+ SV* var;
SV* prot;
- PROTOTYPE: \$@
CODE:
struct mmap_info* info = get_mmap_magic(aTHX_ var, "protect");
int prot_val = protection_value(prot);
@@ -597,8 +584,7 @@ protect(var, prot)
void
lock_map(var)
- SV* var = deref_var(aTHX_ ST(0));
- PROTOTYPE: \$
+ SV* var;
CODE:
struct mmap_info* info = get_mmap_magic(aTHX_ var, "lock_map");
#ifdef USE_ITHREADS
@@ -613,8 +599,8 @@ lock_map(var)
void
wait_until(block, var)
SV* block;
- SV* var = deref_var(aTHX_ ST(1));
- PROTOTYPE: &\$
+ SV* var;
+ PROTOTYPE: &@
PPCODE:
struct mmap_info* info = get_mmap_magic(aTHX_ var, "wait_until");
if (info->owner != aTHX)
@@ -633,8 +619,7 @@ wait_until(block, var)
void
notify(var)
- SV* var = deref_var(aTHX_ ST(0));
- PROTOTYPE: \$
+ SV* var;
CODE:
struct mmap_info* info = get_mmap_magic(aTHX_ var, "notify");
if (info->owner != aTHX)
@@ -643,8 +628,7 @@ notify(var)
void
broadcast(var)
- SV* var = deref_var(aTHX_ ST(0));
- PROTOTYPE: \$
+ SV* var;
CODE:
struct mmap_info* info = get_mmap_magic(aTHX_ var, "broadcast");
if (info->owner != aTHX)
View
@@ -44,11 +44,11 @@ throws_ok { lock_map my $foo } qr/^Could not lock_map: this variable is not memo
throws_ok { map_anonymous my $foo, 0 } qr/^Zero length specified for anonymous map at /, 'Have to provide a length for anonymous maps';
-throws_ok { &map_anonymous("foo", 1000) } qr/^Invalid argument at /, 'Can\'t ignore prototypes';
+throws_ok { &map_anonymous('foo', 1000) } qr/^Modification of a read-only value attempted at /, 'Can\'t use literal as variable';
SKIP: {
skip "STDOUT is a file ", 1 if -f STDOUT;
- throws_ok { map_handle my $foo, STDOUT } qr/^Could not map: /, 'Can\'t map STDOUT';
+ throws_ok { map_handle my $foo, \*STDOUT } qr/^Could not map: /, 'Can\'t map STDOUT';
}
warning_is { advise $mmaped, 'sequential' } undef, 'advice $mmaped, \'readahead\'';

0 comments on commit e102d03

Please sign in to comment.