summaryrefslogtreecommitdiff
path: root/ext/Fcntl
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2010-10-18 20:31:00 +0200
committerNicholas Clark <nick@ccl4.org>2010-10-18 20:31:00 +0200
commit923cc1bb816922fc7e3d923ecac3b09efc7690cc (patch)
tree000a67a6fe25b12170472d44fb07b1e81ac1e981 /ext/Fcntl
parent87eca6eccde7fa88e66a2fc2ad817978f8d1c549 (diff)
downloadperl-923cc1bb816922fc7e3d923ecac3b09efc7690cc.tar.gz
Convert Fcntl::S_IFMT to XS.
This removes the requirement to call XSLoader::load() at BEGIN time, which simplifies the Perl code further.
Diffstat (limited to 'ext/Fcntl')
-rw-r--r--ext/Fcntl/Fcntl.pm15
-rw-r--r--ext/Fcntl/Fcntl.xs7
-rw-r--r--ext/Fcntl/t/mode.t8
3 files changed, 18 insertions, 12 deletions
diff --git a/ext/Fcntl/Fcntl.pm b/ext/Fcntl/Fcntl.pm
index 1f6901940b..834d7ec205 100644
--- a/ext/Fcntl/Fcntl.pm
+++ b/ext/Fcntl/Fcntl.pm
@@ -59,10 +59,11 @@ use strict;
our($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $AUTOLOAD);
require Exporter;
+require XSLoader;
@ISA = qw(Exporter);
-BEGIN {
- $VERSION = '1.09';
-}
+$VERSION = '1.09';
+
+XSLoader::load();
# Items to export into callers namespace by default
# (move infrequently used names to @EXPORT_OK below)
@@ -209,14 +210,6 @@ BEGIN {
)],
);
-# Force the constants to become inlined
-BEGIN {
- require XSLoader;
- XSLoader::load();
-}
-
-sub S_IFMT { @_ ? ( $_[0] & _S_IFMT() ) : _S_IFMT() }
-
sub AUTOLOAD {
(my $constname = $AUTOLOAD) =~ s/.*:://;
die "&Fcntl::constant not defined" if $constname eq 'constant';
diff --git a/ext/Fcntl/Fcntl.xs b/ext/Fcntl/Fcntl.xs
index 2f8636621c..a66f66e725 100644
--- a/ext/Fcntl/Fcntl.xs
+++ b/ext/Fcntl/Fcntl.xs
@@ -78,6 +78,13 @@ S_IMODE(...)
}
PUSHu(SvUV(mode) & 07777);
+void
+S_IFMT(...)
+ PREINIT:
+ dXSTARG;
+ PPCODE:
+ PUSHu(items ? (SvUV(ST(0)) & S_IFMT) : S_IFMT);
+
BOOT:
{
CV *cv;
diff --git a/ext/Fcntl/t/mode.t b/ext/Fcntl/t/mode.t
index c7fa8d1c65..4bec2023ad 100644
--- a/ext/Fcntl/t/mode.t
+++ b/ext/Fcntl/t/mode.t
@@ -18,7 +18,7 @@ if (-c $devnull) {
push @tests, ['CHR', $devnull, (stat $devnull)[2]];
}
-plan(tests => 6 + 9 * @tests);
+plan(tests => 34 + 6 + 9 * @tests);
foreach (@tests) {
my ($type, $name, $mode) = @$_;
@@ -84,3 +84,9 @@ foreach ([S_ISREG => \&S_ISREG],
is(scalar @warnings, 1, '1 warning');
like($warnings[0], qr/^Use of uninitialized value/, 'expected warning');
}
+
+is (S_IFMT(), _S_IFMT(), 'S_IFMT()');
+is (S_IFMT(0), 0, 'S_IFMT(0)');
+for my $shift (0..31) {
+ is (S_IFMT(1 << $shift), ((1 << $shift) & _S_IFMT()), "S_IFMT(1 << $shift)");
+}