diff options
author | Nicholas Clark <nick@ccl4.org> | 2008-05-21 09:18:00 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2008-05-21 09:18:00 +0000 |
commit | e99d581a4aaa3c92d0b0dda6799157fe7a569f31 (patch) | |
tree | 9d4280f426101a8027cbee9439636d0798e557f2 /ext/POSIX | |
parent | 99978bb4f628eeae8af4cb3f5bf7d42e615e2d36 (diff) | |
download | perl-e99d581a4aaa3c92d0b0dda6799157fe7a569f31.tar.gz |
Eliminate POSIX::int_macro_int, and all the complex AUTOLOAD fandango
that creates closures round it. Instead, wrap WEXITSTATUS, WIFEXITED,
WIFSIGNALED, WIFSTOPPED, WSTOPSIG and WTERMSIG directly with XS.
The shared library is slightly larger, but dynamic memory usage savings
beat this, even within one thread of one process. Simpler code too.
p4raw-id: //depot/perl@33896
Diffstat (limited to 'ext/POSIX')
-rw-r--r-- | ext/POSIX/POSIX.pm | 18 | ||||
-rw-r--r-- | ext/POSIX/POSIX.xs | 174 |
2 files changed, 27 insertions, 165 deletions
diff --git a/ext/POSIX/POSIX.pm b/ext/POSIX/POSIX.pm index 2ceba9fba6..0a5553bbe3 100644 --- a/ext/POSIX/POSIX.pm +++ b/ext/POSIX/POSIX.pm @@ -4,7 +4,7 @@ use warnings; our(@ISA, %EXPORT_TAGS, @EXPORT_OK, @EXPORT, $AUTOLOAD, %SIGRT) = (); -our $VERSION = "1.15"; +our $VERSION = "1.16"; use AutoLoader; @@ -35,10 +35,6 @@ sub usage; XSLoader::load 'POSIX', $VERSION; -my %NON_CONSTS - = (map {($_,1)} qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED WSTOPSIG - WTERMSIG)); - sub AUTOLOAD { no strict; no warnings 'uninitialized'; @@ -50,15 +46,9 @@ sub AUTOLOAD { local $! = 0; my $constname = $AUTOLOAD; $constname =~ s/.*:://; - if ($NON_CONSTS{$constname}) { - my ($val, $error) = &int_macro_int($constname, $_[0]); - croak $error if $error; - *$AUTOLOAD = sub { &int_macro_int($constname, $_[0]) }; - } else { - my ($error, $val) = constant($constname); - croak $error if $error; - *$AUTOLOAD = sub { $val }; - } + my ($error, $val) = constant($constname); + croak $error if $error; + *$AUTOLOAD = sub { $val }; goto &$AUTOLOAD; } diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs index b61b0a6d1c..41d66a69c8 100644 --- a/ext/POSIX/POSIX.xs +++ b/ext/POSIX/POSIX.xs @@ -394,116 +394,6 @@ not_here(const char *s) #include "const-c.inc" -/* These were implemented in the old "constant" subroutine. They are actually - macros that take an integer argument and return an integer result. */ -static int -int_macro_int (const char *name, STRLEN len, IV *arg_result) { - /* Initially switch on the length of the name. */ - /* This code has been edited from a "constant" function generated by: - -use ExtUtils::Constant qw (constant_types C_constant XS_constant); - -my $types = {map {($_, 1)} qw(IV)}; -my @names = (qw(WEXITSTATUS WIFEXITED - WIFSIGNALED WIFSTOPPED WSTOPSIG WTERMSIG)); - -print constant_types(); # macro defs -foreach (C_constant ("POSIX", 'int_macro_int', 'IV', $types, undef, 5, @names) ) { - print $_, "\n"; # C constant subs -} -print "#### XS Section:\n"; -print XS_constant ("POSIX", $types); - */ - - switch (len) { - case 8: - /* Names all of length 8. */ - /* WSTOPSIG WTERMSIG */ - /* Offset 1 gives the best switch position. */ - switch (name[1]) { - case 'S': - if (memEQ(name, "WSTOPSIG", 8)) { - /* ^ */ -#ifdef WSTOPSIG - int i = *arg_result; - *arg_result = WSTOPSIG(WMUNGE(i)); - return PERL_constant_ISIV; -#else - return PERL_constant_NOTDEF; -#endif - } - break; - case 'T': - if (memEQ(name, "WTERMSIG", 8)) { - /* ^ */ -#ifdef WTERMSIG - int i = *arg_result; - *arg_result = WTERMSIG(WMUNGE(i)); - return PERL_constant_ISIV; -#else - return PERL_constant_NOTDEF; -#endif - } - break; - } - break; - case 9: - if (memEQ(name, "WIFEXITED", 9)) { -#ifdef WIFEXITED - int i = *arg_result; - *arg_result = WIFEXITED(WMUNGE(i)); - return PERL_constant_ISIV; -#else - return PERL_constant_NOTDEF; -#endif - } - break; - case 10: - if (memEQ(name, "WIFSTOPPED", 10)) { -#ifdef WIFSTOPPED - int i = *arg_result; - *arg_result = WIFSTOPPED(WMUNGE(i)); - return PERL_constant_ISIV; -#else - return PERL_constant_NOTDEF; -#endif - } - break; - case 11: - /* Names all of length 11. */ - /* WEXITSTATUS WIFSIGNALED */ - /* Offset 1 gives the best switch position. */ - switch (name[1]) { - case 'E': - if (memEQ(name, "WEXITSTATUS", 11)) { - /* ^ */ -#ifdef WEXITSTATUS - int i = *arg_result; - *arg_result = WEXITSTATUS(WMUNGE(i)); - return PERL_constant_ISIV; -#else - return PERL_constant_NOTDEF; -#endif - } - break; - case 'I': - if (memEQ(name, "WIFSIGNALED", 11)) { - /* ^ */ -#ifdef WIFSIGNALED - int i = *arg_result; - *arg_result = WIFSIGNALED(WMUNGE(i)); - return PERL_constant_ISIV; -#else - return PERL_constant_NOTDEF; -#endif - } - break; - } - break; - } - return PERL_constant_NOTFOUND; -} - static void restore_sigmask(pTHX_ SV *osset_sv) { @@ -756,47 +646,29 @@ MODULE = POSIX PACKAGE = POSIX INCLUDE: const-xs.inc -void -int_macro_int(sv, iv) - PREINIT: - dXSTARG; - STRLEN len; - int type; - INPUT: - SV * sv; - const char * s = SvPV(sv, len); - IV iv; - PPCODE: - /* Change this to int_macro_int(s, len, &iv, &nv); - if you need to return both NVs and IVs */ - type = int_macro_int(s, len, &iv); - /* Return 1 or 2 items. First is error message, or undef if no error. - Second, if present, is found value */ - switch (type) { - case PERL_constant_NOTFOUND: - sv = sv_2mortal(newSVpvf("%s is not a valid POSIX macro", s)); - EXTEND(SP, 1); - PUSHs(&PL_sv_undef); - PUSHs(sv); - break; - case PERL_constant_NOTDEF: - sv = sv_2mortal(newSVpvf( - "Your vendor has not defined POSIX macro %s, used", s)); - EXTEND(SP, 1); - PUSHs(&PL_sv_undef); - PUSHs(sv); - break; - case PERL_constant_ISIV: - PUSHi(iv); - break; - default: - sv = sv_2mortal(newSVpvf( - "Unexpected return type %d while processing POSIX macro %s, used", - type, s)); - EXTEND(SP, 1); - PUSHs(&PL_sv_undef); - PUSHs(sv); - } +int +WEXITSTATUS(status) + int status + +int +WIFEXITED(status) + int status + +int +WIFSIGNALED(status) + int status + +int +WIFSTOPPED(status) + int status + +int +WSTOPSIG(status) + int status + +int +WTERMSIG(status) + int status int isalnum(charstring) |