[Perl] Ayuda en Instalacion de un Modulo
noel vazquez lopez
nvazquez@eljorullo.com.mx
13 Dec 2001 19:05:39 -0500
--=-Z0BhkRejYKBV0c+ixk8/
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Holas.
Instale un modulo que se llam CGI-MxScreen el cual a la hora de
utilizarlo desde adentro de un cgi, dice....
Can't locate Time/HiRes.pm in @INC (@INC contains:
/usr/lib/perl5/5.00503/i386... mas directorios) at
/usr/lib/perl5/site_perl/5.005/CGI/MxScreen.pm line 38
BEGIN failed--compilation aborted at
/usr/lib/perl5/site_perl/5.005/CGI/MxScreen.pm line 38
Baje el modulo Time-HiRes-01.20.tar.gz genero el make
perl MakeFile.Pl
pero al hacer el=20
make
dice
/(?:(?>"[^()]+)|\((??{ })\))*/: Sequence (??...) not recognized
make: *** [HiRes.c] Error 2
Bueno el make genera un comando asi.
/usr/bin/perl /usr/lib/perl5/5.00503/ExtUtils/xsubpp -nolinenumbers
-typemap /usr/lib/perl5/5.00503/ExtUtils/typemap HiRes.xs > HiRes.xsc &&
mv HiRes.xsc HiRes.c
Chequ=E9 el codigo en xsubpp que es donde creo tiene el error, por que
tienes una linea igual a la del error.Anexo el archivo.xsubpp.
Gracias.
--=-Z0BhkRejYKBV0c+ixk8/
Content-Disposition: attachment; filename=xsubpp
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1
#!./miniperl
=3Dhead1 NAME
xsubpp - compiler to convert Perl XS code into C code
=3Dhead1 SYNOPSIS
B<xsubpp> [B<-v>] [B<-C++>] [B<-except>] [B<-s pattern>] [B<-prototypes>] [=
B<-noversioncheck>] [B<-nolinenumbers>] [B<-nooptimize>] [B<-typemap typema=
p>] ... file.xs
=3Dhead1 DESCRIPTION
This compiler is typically run by the makefiles created by L<ExtUtils::Make=
Maker>.
I<xsubpp> will compile XS code into C code by embedding the constructs
necessary to let C functions manipulate Perl values and creates the glue
necessary to let Perl access those functions. The compiler uses typemaps t=
o
determine how to map C function parameters and variables to Perl values.
The compiler will search for typemap files called I<typemap>. It will use
the following search path to find default typemaps, with the rightmost
typemap taking precedence.
../../../typemap:../../typemap:../typemap:typemap
=3Dhead1 OPTIONS
Note that the C<XSOPT> MakeMaker option may be used to add these options to
any makefiles generated by MakeMaker.
=3Dover 5
=3Ditem B<-C++>
Adds ``extern "C"'' to the C code.
=3Ditem B<-except>
Adds exception handling stubs to the C code.
=3Ditem B<-typemap typemap>
Indicates that a user-supplied typemap should take precedence over the
default typemaps. This option may be used multiple times, with the last
typemap having the highest precedence.
=3Ditem B<-v>
Prints the I<xsubpp> version number to standard output, then exits.
=3Ditem B<-prototypes>
By default I<xsubpp> will not automatically generate prototype code for
all xsubs. This flag will enable prototypes.
=3Ditem B<-noversioncheck>
Disables the run time test that determines if the object file (derived
from the C<.xs> file) and the C<.pm> files have the same version
number.
=3Ditem B<-nolinenumbers>
Prevents the inclusion of `#line' directives in the output.
=3Ditem B<-nooptimize>
Disables certain optimizations. The only optimization that is currently
affected is the use of I<target>s by the output C code (see L<perlguts>).
This may significantly slow down the generated code, but this is the way
B<xsubpp> of 5.005 and earlier operated.
=3Ditem B<-noinout>
Disable recognition of C<IN>, C<OUT_LIST> and C<INOUT_LIST> declarations.
=3Ditem B<-noargtypes>
Disable recognition of ANSI-like descriptions of function signature.
=3Dback
=3Dhead1 ENVIRONMENT
No environment variables are used.
=3Dhead1 AUTHOR
Larry Wall
=3Dhead1 MODIFICATION HISTORY
See the file F<changes.pod>.
=3Dhead1 SEE ALSO
perl(1), perlxs(1), perlxstut(1)
=3Dcut
require 5.002;
use Cwd;
use vars '$cplusplus';
use vars '%v';
use Config;
sub Q ;
# Global Constants
$XSUBPP_version =3D "1.9508";
my ($Is_VMS, $SymSet);
if ($^O eq 'VMS') {
$Is_VMS =3D 1;
# Establish set of global symbols with max length 28, since xsubpp
# will later add the 'XS_' prefix.
require ExtUtils::XSSymSet;
$SymSet =3D new ExtUtils::XSSymSet 28;
}
$FH =3D 'File0000' ;
$usage =3D "Usage: xsubpp [-v] [-C++] [-except] [-prototypes] [-noversionch=
eck] [-nolinenumbers] [-nooptimize] [-noinout] [-noargtypes] [-s pattern] [=
-typemap typemap]... file.xs\n";
$proto_re =3D "[" . quotemeta('\$%&*@;') . "]" ;
# mjn
$OBJ =3D 1 if $Config{'ccflags'} =3D~ /PERL_OBJECT/i;
$except =3D "";
$WantPrototypes =3D -1 ;
$WantVersionChk =3D 1 ;
$ProtoUsed =3D 0 ;
$WantLineNumbers =3D 1 ;
$WantOptimize =3D 1 ;
my $process_inout =3D 1;
my $process_argtypes =3D 1;
SWITCH: while (@ARGV and $ARGV[0] =3D~ /^-./) {
$flag =3D shift @ARGV;
$flag =3D~ s/^-// ;
$spat =3D quotemeta shift, next SWITCH if $flag eq 's';
$cplusplus =3D 1, next SWITCH if $flag eq 'C++';
$WantPrototypes =3D 0, next SWITCH if $flag eq 'noprototypes';
$WantPrototypes =3D 1, next SWITCH if $flag eq 'prototypes';
$WantVersionChk =3D 0, next SWITCH if $flag eq 'noversioncheck';
$WantVersionChk =3D 1, next SWITCH if $flag eq 'versioncheck';
# XXX left this in for compat
$WantCAPI =3D 1, next SWITCH if $flag eq 'object_capi';
$except =3D " TRY", next SWITCH if $flag eq 'except';
push(@tm,shift), next SWITCH if $flag eq 'typemap';
$WantLineNumbers =3D 0, next SWITCH if $flag eq 'nolinenumbers';
$WantLineNumbers =3D 1, next SWITCH if $flag eq 'linenumbers';
$WantOptimize =3D 0, next SWITCH if $flag eq 'nooptimize';
$WantOptimize =3D 1, next SWITCH if $flag eq 'optimize';
$process_inout =3D 0, next SWITCH if $flag eq 'noinout';
$process_inout =3D 1, next SWITCH if $flag eq 'inout';
$process_argtypes =3D 0, next SWITCH if $flag eq 'noargtypes';
$process_argtypes =3D 1, next SWITCH if $flag eq 'argtypes';
(print "xsubpp version $XSUBPP_version\n"), exit
if $flag eq 'v';
die $usage;
}
if ($WantPrototypes =3D=3D -1)
{ $WantPrototypes =3D 0}
else
{ $ProtoUsed =3D 1 }
@ARGV =3D=3D 1 or die $usage;
($dir, $filename) =3D $ARGV[0] =3D~ m#(.*)/(.*)#
or ($dir, $filename) =3D $ARGV[0] =3D~ m#(.*)\\(.*)#
or ($dir, $filename) =3D $ARGV[0] =3D~ m#(.*[>\]])(.*)#
or ($dir, $filename) =3D ('.', $ARGV[0]);
chdir($dir);
$pwd =3D cwd();
++ $IncludedFiles{$ARGV[0]} ;
my(@XSStack) =3D ({type =3D> 'none'}); # Stack of conditionals and INCLUDEs
my($XSS_work_idx, $cpp_next_tmp) =3D (0, "XSubPPtmpAAAA");
sub TrimWhitespace
{
$_[0] =3D~ s/^\s+|\s+$//go ;
}
sub TidyType
{
local ($_) =3D @_ ;
# rationalise any '*' by joining them into bunches and removing whitesp=
ace
s#\s*(\*+)\s*#$1#g;
s#(\*+)# $1 #g ;
# change multiple whitespace into a single space
s/\s+/ /g ;
=20
# trim leading & trailing whitespace
TrimWhitespace($_) ;
$_ ;
}
$typemap =3D shift @ARGV;
foreach $typemap (@tm) {
die "Can't find $typemap in $pwd\n" unless -r $typemap;
}
unshift @tm, qw(../../../../lib/ExtUtils/typemap ../../../lib/ExtUtils/type=
map
../../lib/ExtUtils/typemap ../../../typemap ../../typemap
../typemap typemap);
foreach $typemap (@tm) {
next unless -e $typemap ;
# skip directories, binary files etc.
warn("Warning: ignoring non-text typemap file '$typemap'\n"), next=20
unless -T $typemap ;
open(TYPEMAP, $typemap)=20
or warn ("Warning: could not open typemap file '$typemap': $!\n"), next;
$mode =3D 'Typemap';
$junk =3D "" ;
$current =3D \$junk;
while (<TYPEMAP>) {
next if /^\s*#/;
my $line_no =3D $. + 1;=20
if (/^INPUT\s*$/) { $mode =3D 'Input'; $current =3D \$junk; next; }
if (/^OUTPUT\s*$/) { $mode =3D 'Output'; $current =3D \$junk; next; }
if (/^TYPEMAP\s*$/) { $mode =3D 'Typemap'; $current =3D \$junk; next; }
if ($mode eq 'Typemap') {
chomp;
my $line =3D $_ ;
TrimWhitespace($_) ;
# skip blank lines and comment lines
next if /^$/ or /^#/ ;
my($type,$kind, $proto) =3D /^\s*(.*?\S)\s+(\S+)\s*($proto_re*)\s*$/ o=
r
warn("Warning: File '$typemap' Line $. '$line' TYPEMAP entry needs 2 or 3=
columns\n"), next;
$type =3D TidyType($type) ;
$type_kind{$type} =3D $kind ;
# prototype defaults to '$'
$proto =3D "\$" unless $proto ;
warn("Warning: File '$typemap' Line $. '$line' Invalid prototyp=
e '$proto'\n")=20
unless ValidProtoString($proto) ;
$proto_letter{$type} =3D C_string($proto) ;
}
elsif (/^\s/) {
$$current .=3D $_;
}
elsif ($mode eq 'Input') {
s/\s+$//;
$input_expr{$_} =3D '';
$current =3D \$input_expr{$_};
}
else {
s/\s+$//;
$output_expr{$_} =3D '';
$current =3D \$output_expr{$_};
}
}
close(TYPEMAP);
}
foreach $key (keys %input_expr) {
$input_expr{$key} =3D~ s/\n+$//;
}
$bal =3D qr[(?:(?>[^()]+)|\((??{ $bal })\))*]; # ()-balanced
$cast =3D qr[(?:\(\s*SV\s*\*\s*\)\s*)?]; # Optional (SV*) cast
$size =3D qr[,\s* (??{ $bal }) ]x; # Third arg (to setpvn)
foreach $key (keys %output_expr) {
use re 'eval';
my ($t, $with_size, $arg, $sarg) =3D
($output_expr{$key} =3D~
m[^ \s+ sv_set ( [iunp] ) v (n)? # Type, is_setpvn
\s* \( \s* $cast \$arg \s* ,
\s* ( (??{ $bal }) ) # Set from
( (??{ $size }) )? # Possible sizeof set-from
\) \s* ; \s* $
]x);
$targetable{$key} =3D [$t, $with_size, $arg, $sarg] if $t;
}
$END =3D "!End!\n\n"; # "impossible" keyword (multiple newline)
# Match an XS keyword
$BLOCK_re=3D '\s*(' . join('|', qw(
REQUIRE BOOT CASE PREINIT INPUT INIT CODE PPCODE OUTPUT=20
CLEANUP ALIAS ATTRS PROTOTYPES PROTOTYPE VERSIONCHECK INCLUDE
SCOPE INTERFACE INTERFACE_MACRO C_ARGS POSTCALL
)) . "|$END)\\s*:";
# Input: ($_, @line) =3D=3D unparsed input.
# Output: ($_, @line) =3D=3D (rest of line, following lines).
# Return: the matched keyword if found, otherwise 0
sub check_keyword {
$_ =3D shift(@line) while !/\S/ && @line;
s/^(\s*)($_[0])\s*:\s*(?:#.*)?/$1/s && $2;
}
my ($C_group_rex, $C_arg);
# Group in C (no support for comments or literals)
$C_group_rex =3D qr/ [({\[]
(?: (?> [^()\[\]{}]+ ) | (??{ $C_group_rex }) )*
[)}\]] /x ;
# Chunk in C without comma at toplevel (no comments):
$C_arg =3D qr/ (?: (?> [^()\[\]{},"']+ )
| (??{ $C_group_rex })
| " (?: (?> [^\\"]+ )
| \\.
)* " # String literal
| ' (?: (?> [^\\']+ ) | \\. )* ' # Char literal
)* /xs;
if ($WantLineNumbers) {
{
package xsubpp::counter;
sub TIEHANDLE {
my ($class, $cfile) =3D @_;
my $buf =3D "";
$SECTION_END_MARKER =3D "#line --- \"$cfile\"";
$line_no =3D 1;
bless \$buf;
}
sub PRINT {
my $self =3D shift;
for (@_) {
$$self .=3D $_;
while ($$self =3D~ s/^([^\n]*\n)//) {
my $line =3D $1;
++ $line_no;
$line =3D~ s|^\#line\s+---(?=3D\s)|#line $line_no|;
print STDOUT $line;
}
}
}
sub PRINTF {
my $self =3D shift;
my $fmt =3D shift;
$self->PRINT(sprintf($fmt, @_));
}
sub DESTROY {
# Not necessary if we're careful to end with a "\n"
my $self =3D shift;
print STDOUT $$self;
}
}
my $cfile =3D $filename;
$cfile =3D~ s/\.xs$/.c/i or $cfile .=3D ".c";
tie(*PSEUDO_STDOUT, 'xsubpp::counter', $cfile);
select PSEUDO_STDOUT;
}
sub print_section {
# the "do" is required for right semantics
do { $_ =3D shift(@line) } while !/\S/ && @line;
=20
print("#line ", $line_no[@line_no - @line -1], " \"$filename\"\n")
if $WantLineNumbers && !/^\s*#\s*line\b/ && !/^#if XSubPPtmp/;
for (; defined($_) && !/^$BLOCK_re/o; $_ =3D shift(@line)) {
print "$_\n";
}
print "$xsubpp::counter::SECTION_END_MARKER\n" if $WantLineNumbers;
}
sub merge_section {
my $in =3D '';
=20
while (!/\S/ && @line) {
$_ =3D shift(@line);
}
=20
for (; defined($_) && !/^$BLOCK_re/o; $_ =3D shift(@line)) {
$in .=3D "$_\n";
}
chomp $in;
return $in;
}
sub process_keyword($)
{
my($pattern) =3D @_ ;
my $kwd ;
&{"${kwd}_handler"}()=20
while $kwd =3D check_keyword($pattern) ;
}
sub CASE_handler {
blurt ("Error: `CASE:' after unconditional `CASE:'")
if $condnum && $cond eq '';
$cond =3D $_;
TrimWhitespace($cond);
print " ", ($condnum++ ? " else" : ""), ($cond ? " if ($cond)\n" : "\=
n");
$_ =3D '' ;
}
sub INPUT_handler {
for (; !/^$BLOCK_re/o; $_ =3D shift(@line)) {
last if /^\s*NOT_IMPLEMENTED_YET/;
next unless /\S/; # skip blank lines=20
TrimWhitespace($_) ;
my $line =3D $_ ;
# remove trailing semicolon if no initialisation
s/\s*;$//g unless /[=3D;+].*\S/ ;
# check for optional initialisation code
my $var_init =3D '' ;
$var_init =3D $1 if s/\s*([=3D;+].*)$//s ;
$var_init =3D~ s/"/\\"/g;
s/\s+/ /g;
my ($var_type, $var_addr, $var_name) =3D /^(.*?[^&\s])\s*(\&?)\s*\b(\w+)$/=
s
or blurt("Error: invalid argument declaration '$line'"), next;
# Check for duplicate definitions
blurt ("Error: duplicate definition of argument '$var_name' ignored"), nex=
t
if $arg_list{$var_name}++=20
or defined $arg_types{$var_name} and not $processing_arg_with_types;
$thisdone |=3D $var_name eq "THIS";
$retvaldone |=3D $var_name eq "RETVAL";
$var_types{$var_name} =3D $var_type;
# XXXX This check is a safeguard against the unfinished conversion of
# generate_init(). When generate_init() is fixed,
# one can use 2-args map_type() unconditionally.
if ($var_type =3D~ / \( \s* \* \s* \) /x) {
# Function pointers are not yet supported with &output_init!
print "\t" . &map_type($var_type, $var_name);
$name_printed =3D 1;
} else {
print "\t" . &map_type($var_type);
$name_printed =3D 0;
}
$var_num =3D $args_match{$var_name};
$proto_arg[$var_num] =3D ProtoString($var_type)=20
if $var_num ;
$func_args =3D~ s/\b($var_name)\b/&$1/ if $var_addr;
if ($var_init =3D~ /^[=3D;]\s*NO_INIT\s*;?\s*$/
or $in_out{$var_name} and $in_out{$var_name} =3D~ /^OUT/
and $var_init !~ /\S/) {
if ($name_printed) {
print ";\n";
} else {
print "\t$var_name;\n";
}
} elsif ($var_init =3D~ /\S/) {
&output_init($var_type, $var_num, $var_name, $var_init, $name_printed)=
;
} elsif ($var_num) {
# generate initialization code
&generate_init($var_type, $var_num, $var_name, $name_printed);
} else {
print ";\n";
}
}
}
sub OUTPUT_handler {
for (; !/^$BLOCK_re/o; $_ =3D shift(@line)) {
next unless /\S/;
if (/^\s*SETMAGIC\s*:\s*(ENABLE|DISABLE)\s*/) {
$DoSetMagic =3D ($1 eq "ENABLE" ? 1 : 0);
next;
}
my ($outarg, $outcode) =3D /^\s*(\S+)\s*(.*?)\s*$/s ;
blurt ("Error: duplicate OUTPUT argument '$outarg' ignored"), next
if $outargs{$outarg} ++ ;
if (!$gotRETVAL and $outarg eq 'RETVAL') {
# deal with RETVAL last
$RETVAL_code =3D $outcode ;
$gotRETVAL =3D 1 ;
next ;
}
blurt ("Error: OUTPUT $outarg not an argument"), next
unless defined($args_match{$outarg});
blurt("Error: No input definition for OUTPUT argument '$outarg' - ignored"=
), next
unless defined $var_types{$outarg} ;
$var_num =3D $args_match{$outarg};
if ($outcode) {
print "\t$outcode\n";
print "\tSvSETMAGIC(ST(" , $var_num-1 , "));\n" if $DoSetMagic;
} else {
&generate_output($var_types{$outarg}, $var_num, $outarg, $DoSetMagic);
}
delete $in_out{$outarg} # No need to auto-OUTPUT=20
if exists $in_out{$outarg} and $in_out{$outarg} =3D~ /OUT$/;
}
}
sub C_ARGS_handler() {
my $in =3D merge_section();
=20
TrimWhitespace($in);
$func_args =3D $in;
}=20
sub INTERFACE_MACRO_handler() {
my $in =3D merge_section();
=20
TrimWhitespace($in);
if ($in =3D~ /\s/) { # two
($interface_macro, $interface_macro_set) =3D split ' ', $in;
} else {
$interface_macro =3D $in;
$interface_macro_set =3D 'UNKNOWN_CVT'; # catch later
}
$interface =3D 1; # local
$Interfaces =3D 1; # global
}
sub INTERFACE_handler() {
my $in =3D merge_section();
=20
TrimWhitespace($in);
=20
foreach (split /[\s,]+/, $in) {
$Interfaces{$_} =3D $_;
}
print Q<<"EOF";
# XSFUNCTION =3D $interface_macro($ret_type,cv,XSANY.any_dptr);
EOF
$interface =3D 1; # local
$Interfaces =3D 1; # global
}
sub CLEANUP_handler() { print_section() }=20
sub PREINIT_handler() { print_section() }=20
sub POSTCALL_handler() { print_section() }=20
sub INIT_handler() { print_section() }=20
sub GetAliases
{
my ($line) =3D @_ ;
my ($orig) =3D $line ;
my ($alias) ;
my ($value) ;
# Parse alias definitions
# format is
# alias =3D value alias =3D value ...
while ($line =3D~ s/^\s*([\w:]+)\s*=3D\s*(\w+)\s*//) {
$alias =3D $1 ;
$orig_alias =3D $alias ;
$value =3D $2 ;
# check for optional package definition in the alias
$alias =3D $Packprefix . $alias if $alias !~ /::/ ;
=20
# check for duplicate alias name & duplicate value
Warn("Warning: Ignoring duplicate alias '$orig_alias'")
if defined $XsubAliases{$alias} ;
Warn("Warning: Aliases '$orig_alias' and '$XsubAliasValues{$value}' have i=
dentical values")
if $XsubAliasValues{$value} ;
$XsubAliases =3D 1;
$XsubAliases{$alias} =3D $value ;
$XsubAliasValues{$value} =3D $orig_alias ;
}
blurt("Error: Cannot parse ALIAS definitions from '$orig'")
if $line ;
}
sub ATTRS_handler ()
{
for (; !/^$BLOCK_re/o; $_ =3D shift(@line)) {
next unless /\S/;
TrimWhitespace($_) ;
push @Attributes, $_;
}
}
sub ALIAS_handler ()
{
for (; !/^$BLOCK_re/o; $_ =3D shift(@line)) {
next unless /\S/;
TrimWhitespace($_) ;
GetAliases($_) if $_ ;
}
}
sub REQUIRE_handler ()
{
# the rest of the current line should contain a version number
my ($Ver) =3D $_ ;
TrimWhitespace($Ver) ;
death ("Error: REQUIRE expects a version number")
unless $Ver ;
# check that the version number is of the form n.n
death ("Error: REQUIRE: expected a number, got '$Ver'")
unless $Ver =3D~ /^\d+(\.\d*)?/ ;
death ("Error: xsubpp $Ver (or better) required--this is only $XSUBPP_v=
ersion.")
unless $XSUBPP_version >=3D $Ver ;=20
}
sub VERSIONCHECK_handler ()
{
# the rest of the current line should contain either ENABLE or
# DISABLE
=20
TrimWhitespace($_) ;
=20
# check for ENABLE/DISABLE
death ("Error: VERSIONCHECK: ENABLE/DISABLE")
unless /^(ENABLE|DISABLE)/i ;
=20
$WantVersionChk =3D 1 if $1 eq 'ENABLE' ;
$WantVersionChk =3D 0 if $1 eq 'DISABLE' ;
=20
}
sub PROTOTYPE_handler ()
{
my $specified ;
death("Error: Only 1 PROTOTYPE definition allowed per xsub")=20
if $proto_in_this_xsub ++ ;
for (; !/^$BLOCK_re/o; $_ =3D shift(@line)) {
next unless /\S/;
$specified =3D 1 ;
TrimWhitespace($_) ;
if ($_ eq 'DISABLE') {
$ProtoThisXSUB =3D 0=20
}
elsif ($_ eq 'ENABLE') {
$ProtoThisXSUB =3D 1=20
}
else {
# remove any whitespace
s/\s+//g ;
death("Error: Invalid prototype '$_'")
unless ValidProtoString($_) ;
$ProtoThisXSUB =3D C_string($_) ;
}
}
# If no prototype specified, then assume empty prototype ""
$ProtoThisXSUB =3D 2 unless $specified ;
$ProtoUsed =3D 1 ;
}
sub SCOPE_handler ()
{
death("Error: Only 1 SCOPE declaration allowed per xsub")=20
if $scope_in_this_xsub ++ ;
for (; !/^$BLOCK_re/o; $_ =3D shift(@line)) {
next unless /\S/;
TrimWhitespace($_) ;
if ($_ =3D~ /^DISABLE/i) {
$ScopeThisXSUB =3D 0=20
}
elsif ($_ =3D~ /^ENABLE/i) {
$ScopeThisXSUB =3D 1=20
}
}
}
sub PROTOTYPES_handler ()
{
# the rest of the current line should contain either ENABLE or
# DISABLE=20
TrimWhitespace($_) ;
# check for ENABLE/DISABLE
death ("Error: PROTOTYPES: ENABLE/DISABLE")
unless /^(ENABLE|DISABLE)/i ;
$WantPrototypes =3D 1 if $1 eq 'ENABLE' ;
$WantPrototypes =3D 0 if $1 eq 'DISABLE' ;
$ProtoUsed =3D 1 ;
}
sub INCLUDE_handler ()
{
# the rest of the current line should contain a valid filename
=20
TrimWhitespace($_) ;
=20
death("INCLUDE: filename missing")
unless $_ ;
death("INCLUDE: output pipe is illegal")
if /^\s*\|/ ;
# simple minded recursion detector
death("INCLUDE loop detected")
if $IncludedFiles{$_} ;
++ $IncludedFiles{$_} unless /\|\s*$/ ;
# Save the current file context.
push(@XSStack, {
type =3D> 'file',
LastLine =3D> $lastline,
LastLineNo =3D> $lastline_no,
Line =3D> \@line,
LineNo =3D> \@line_no,
Filename =3D> $filename,
Handle =3D> $FH,
}) ;
=20
++ $FH ;
# open the new file
open ($FH, "$_") or death("Cannot open '$_': $!") ;
=20
print Q<<"EOF" ;
#
#/* INCLUDE: Including '$_' from '$filename' */
#
EOF
$filename =3D $_ ;
# Prime the pump by reading the first=20
# non-blank line
# skip leading blank lines
while (<$FH>) {
last unless /^\s*$/ ;
}
$lastline =3D $_ ;
$lastline_no =3D $. ;
=20
}
=20
sub PopFile()
{
return 0 unless $XSStack[-1]{type} eq 'file' ;
my $data =3D pop @XSStack ;
my $ThisFile =3D $filename ;
my $isPipe =3D ($filename =3D~ /\|\s*$/) ;
=20
-- $IncludedFiles{$filename}
unless $isPipe ;
close $FH ;
$FH =3D $data->{Handle} ;
$filename =3D $data->{Filename} ;
$lastline =3D $data->{LastLine} ;
$lastline_no =3D $data->{LastLineNo} ;
@line =3D @{ $data->{Line} } ;
@line_no =3D @{ $data->{LineNo} } ;
if ($isPipe and $? ) {
-- $lastline_no ;
print STDERR "Error reading from pipe '$ThisFile': $! in $filename,=
line $lastline_no\n" ;
exit 1 ;
}
print Q<<"EOF" ;
#
#/* INCLUDE: Returning to '$filename' from '$ThisFile' */
#
EOF
return 1 ;
}
sub ValidProtoString ($)
{
my($string) =3D @_ ;
if ( $string =3D~ /^$proto_re+$/ ) {
return $string ;
}
return 0 ;
}
sub C_string ($)
{
my($string) =3D @_ ;
$string =3D~ s[\\][\\\\]g ;
$string ;
}
sub ProtoString ($)
{
my ($type) =3D @_ ;
$proto_letter{$type} or "\$" ;
}
sub check_cpp {
my @cpp =3D grep(/^\#\s*(?:if|e\w+)/, @line);
if (@cpp) {
my ($cpp, $cpplevel);
for $cpp (@cpp) {
if ($cpp =3D~ /^\#\s*if/) {
$cpplevel++;
} elsif (!$cpplevel) {
Warn("Warning: #else/elif/endif without #if in this function");
print STDERR " (precede it with a blank line if the matching #if is ou=
tside the function)\n"
if $XSStack[-1]{type} eq 'if';
return;
} elsif ($cpp =3D~ /^\#\s*endif/) {
$cpplevel--;
}
}
Warn("Warning: #if without #endif in this function") if $cpplevel;
}
}
sub Q {
my($text) =3D @_;
$text =3D~ s/^#//gm;
$text =3D~ s/\[\[/{/g;
$text =3D~ s/\]\]/}/g;
$text;
}
open($FH, $filename) or die "cannot open $filename: $!\n";
# Identify the version of xsubpp used
print <<EOM ;
/*
* This file was generated automatically by xsubpp version $XSUBPP_version =
from the=20
* contents of $filename. Do not edit this file, edit $filename instead.
*
* ANY CHANGES MADE HERE WILL BE LOST!=20
*
*/
EOM
=20
print("#line 1 \"$filename\"\n")
if $WantLineNumbers;
firstmodule:
while (<$FH>) {
if (/^=3D/) {
my $podstartline =3D $.;
do {
if (/^=3Dcut\s*$/) {
print("/* Skipped embedded POD. */\n");
printf("#line %d \"$filename\"\n", $. + 1)
if $WantLineNumbers;
next firstmodule
}
} while (<$FH>);
# At this point $. is at end of file so die won't state the start
# of the problem, and as we haven't yet read any lines &death won't
# show the correct line in the message either.
die ("Error: Unterminated pod in $filename, line $podstartline\n")
unless $lastline;
}
last if ($Module, $Package, $Prefix) =3D
/^MODULE\s*=3D\s*([\w:]+)(?:\s+PACKAGE\s*=3D\s*([\w:]+))?(?:\s+PREFIX\s*=
=3D\s*(\S+))?\s*$/;
if ($OBJ) {
s/#if(?:def\s|\s+defined)\s*(\(__cplusplus\)|__cplusplus)/#if defin=
ed(__cplusplus) && !defined(PERL_OBJECT)/;
}
print $_;
}
&Exit unless defined $_;
print "$xsubpp::counter::SECTION_END_MARKER\n" if $WantLineNumbers;
$lastline =3D $_;
$lastline_no =3D $.;
# Read next xsub into @line from ($lastline, <$FH>).
sub fetch_para {
# parse paragraph
death ("Error: Unterminated `#if/#ifdef/#ifndef'")
if !defined $lastline && $XSStack[-1]{type} eq 'if';
@line =3D ();
@line_no =3D () ;
return PopFile() if !defined $lastline;
if ($lastline =3D~
/^MODULE\s*=3D\s*([\w:]+)(?:\s+PACKAGE\s*=3D\s*([\w:]+))?(?:\s+PREFIX\s*=
=3D\s*(\S+))?\s*$/) {
$Module =3D $1;
$Package =3D defined($2) ? $2 : ''; # keep -w happy
$Prefix =3D defined($3) ? $3 : ''; # keep -w happy
$Prefix =3D quotemeta $Prefix ;
($Module_cname =3D $Module) =3D~ s/\W/_/g;
($Packid =3D $Package) =3D~ tr/:/_/;
$Packprefix =3D $Package;
$Packprefix .=3D "::" if $Packprefix ne "";
$lastline =3D "";
}
for(;;) {
# Skip embedded PODs=20
while ($lastline =3D~ /^=3D/) {
while ($lastline =3D <$FH>) {
last if ($lastline =3D~ /^=3Dcut\s*$/);
}
death ("Error: Unterminated pod") unless $lastline;
$lastline =3D <$FH>;
chomp $lastline;
$lastline =3D~ s/^\s+$//;
}
if ($lastline !~ /^\s*#/ ||
# CPP directives:
# ANSI: if ifdef ifndef elif else endif define undef
# line error pragma
# gcc: warning include_next
# obj-c: import
# others: ident (gcc notes that some cpps have this one)
$lastline =3D~ /^#[ \t]*(?:(?:if|ifn?def|elif|else|endif|define|undef|=
pragma|error|warning|line\s+\d+|ident)\b|(?:include(?:_next)?|import)\s*["<=
].*[>"])/) {
last if $lastline =3D~ /^\S/ && @line && $line[-1] eq "";
push(@line, $lastline);
push(@line_no, $lastline_no) ;
}
# Read next line and continuation lines
last unless defined($lastline =3D <$FH>);
$lastline_no =3D $.;
my $tmp_line;
$lastline .=3D $tmp_line
while ($lastline =3D~ /\\$/ && defined($tmp_line =3D <$FH>));
chomp $lastline;
$lastline =3D~ s/^\s+$//;
}
pop(@line), pop(@line_no) while @line && $line[-1] eq "";
1;
}
PARAGRAPH:
while (fetch_para()) {
# Print initial preprocessor statements and blank lines
while (@line && $line[0] !~ /^[^\#]/) {
my $line =3D shift(@line);
print $line, "\n";
next unless $line =3D~ /^\#\s*((if)(?:n?def)?|elsif|else|endif)\b/;
my $statement =3D $+;
if ($statement eq 'if') {
$XSS_work_idx =3D @XSStack;
push(@XSStack, {type =3D> 'if'});
} else {
death ("Error: `$statement' with no matching `if'")
if $XSStack[-1]{type} ne 'if';
if ($XSStack[-1]{varname}) {
push(@InitFileCode, "#endif\n");
push(@BootCode, "#endif");
}
my(@fns) =3D keys %{$XSStack[-1]{functions}};
if ($statement ne 'endif') {
# Hide the functions defined in other #if branches, and reset.
@{$XSStack[-1]{other_functions}}{@fns} =3D (1) x @fns;
@{$XSStack[-1]}{qw(varname functions)} =3D ('', {});
} else {
my($tmp) =3D pop(@XSStack);
0 while (--$XSS_work_idx
&& $XSStack[$XSS_work_idx]{type} ne 'if');
# Keep all new defined functions
push(@fns, keys %{$tmp->{other_functions}});
@{$XSStack[$XSS_work_idx]{functions}}{@fns} =3D (1) x @fns;
}
}
}
next PARAGRAPH unless @line;
if ($XSS_work_idx && !$XSStack[$XSS_work_idx]{varname}) {
# We are inside an #if, but have not yet #defined its xsubpp variable.
print "#define $cpp_next_tmp 1\n\n";
push(@InitFileCode, "#if $cpp_next_tmp\n");
push(@BootCode, "#if $cpp_next_tmp");
$XSStack[$XSS_work_idx]{varname} =3D $cpp_next_tmp++;
}
death ("Code is not inside a function"
." (maybe last function was ended by a blank line "
." followed by a statement on column one?)")
if $line[0] =3D~ /^\s/;
# initialize info arrays
undef(%args_match);
undef(%var_types);
undef(%defaults);
undef($class);
undef($static);
undef($elipsis);
undef($wantRETVAL) ;
undef($RETVAL_no_return) ;
undef(%arg_list) ;
undef(@proto_arg) ;
undef(@arg_with_types) ;
undef($processing_arg_with_types) ;
undef(%arg_types) ;
undef(@outlist) ;
undef(%in_out) ;
undef($proto_in_this_xsub) ;
undef($scope_in_this_xsub) ;
undef($interface);
undef($prepush_done);
$interface_macro =3D 'XSINTERFACE_FUNC' ;
$interface_macro_set =3D 'XSINTERFACE_FUNC_SET' ;
$ProtoThisXSUB =3D $WantPrototypes ;
$ScopeThisXSUB =3D 0;
$xsreturn =3D 0;
$_ =3D shift(@line);
while ($kwd =3D check_keyword("REQUIRE|PROTOTYPES|VERSIONCHECK|INCLUDE"=
)) {
&{"${kwd}_handler"}() ;
next PARAGRAPH unless @line ;
$_ =3D shift(@line);
}
if (check_keyword("BOOT")) {
&check_cpp;
push (@BootCode, "#line $line_no[@line_no - @line] \"$filename\"")
if $WantLineNumbers && $line[0] !~ /^\s*#\s*line\b/;
push (@BootCode, @line, "") ;
next PARAGRAPH ;
}
# extract return type, function name and arguments
($ret_type) =3D TidyType($_);
$RETVAL_no_return =3D 1 if $ret_type =3D~ s/^NO_OUTPUT\s+//;
# Allow one-line ANSI-like declaration
unshift @line, $2
if $process_argtypes
and $ret_type =3D~ s/^(.*?\w.*?)\s*\b(\w+\s*\(.*)/$1/s;
# a function definition needs at least 2 lines
blurt ("Error: Function definition too short '$ret_type'"), next PARAGR=
APH
unless @line ;
$static =3D 1 if $ret_type =3D~ s/^static\s+//;
$func_header =3D shift(@line);
blurt ("Error: Cannot parse function definition from '$func_header'"), =
next PARAGRAPH
unless $func_header =3D~ /^(?:([\w:]*)::)?(\w+)\s*\(\s*(.*?)\s*\)\s*(const=
)?\s*(;\s*)?$/s;
($class, $func_name, $orig_args) =3D ($1, $2, $3) ;
$class =3D "$4 $class" if $4;
($pname =3D $func_name) =3D~ s/^($Prefix)?/$Packprefix/;
($clean_func_name =3D $func_name) =3D~ s/^$Prefix//;
$Full_func_name =3D "${Packid}_$clean_func_name";
if ($Is_VMS) { $Full_func_name =3D $SymSet->addsym($Full_func_name); }
# Check for duplicate function definition
for $tmp (@XSStack) {
next unless defined $tmp->{functions}{$Full_func_name};
Warn("Warning: duplicate function definition '$clean_func_name' detected")=
;
last;
}
$XSStack[$XSS_work_idx]{functions}{$Full_func_name} ++ ;
%XsubAliases =3D %XsubAliasValues =3D %Interfaces =3D @Attributes =3D (=
);
$DoSetMagic =3D 1;
$orig_args =3D~ s/\\\s*/ /g; # process line continuations
my %only_outlist;
if ($process_argtypes and $orig_args =3D~ /\S/) {
my $args =3D "$orig_args ,";
if ($args =3D~ /^( (??{ $C_arg }) , )* $ /x) {
@args =3D ($args =3D~ /\G ( (??{ $C_arg }) ) , /xg);
for ( @args ) {
s/^\s+//;
s/\s+$//;
my $arg =3D $_;
my $default;
($arg, $default) =3D / ( [^=3D]* ) ( (?: =3D .* )? ) /x;
my ($pre, $name) =3D ($arg =3D~ /(.*?) \s* \b(\w+) \s* $ /x);
next unless length $pre;
my $out_type;
my $inout_var;
if ($process_inout and s/^(IN|IN_OUTLIST|OUTLIST|OUT|IN_OUT)\s+//) {
my $type =3D $1;
$out_type =3D $type if $type ne 'IN';
$arg =3D~ s/^(IN|IN_OUTLIST|OUTLIST|OUT|IN_OUT)\s+//;
}
if (/\W/) { # Has a type
push @arg_with_types, $arg;
# warn "pushing '$arg'\n";
$arg_types{$name} =3D $arg;
$_ =3D "$name$default";
}
$only_outlist{$_} =3D 1 if $out_type eq "OUTLIST";
push @outlist, $name if $out_type =3D~ /OUTLIST$/;
$in_out{$name} =3D $out_type if $out_type;
}
} else {
@args =3D split(/\s*,\s*/, $orig_args);
Warn("Warning: cannot parse argument list '$orig_args', fallback to sp=
lit");
}
} else {
@args =3D split(/\s*,\s*/, $orig_args);
for (@args) {
if ($process_inout and s/^(IN|IN_OUTLIST|OUTLIST|IN_OUT|OUT)\s+//) {
my $out_type =3D $1;
next if $out_type eq 'IN';
$only_outlist{$_} =3D 1 if $out_type eq "OUTLIST";
push @outlist, $name if $out_type =3D~ /OUTLIST$/;
$in_out{$_} =3D $out_type;
}
}
}
if (defined($class)) {
my $arg0 =3D ((defined($static) or $func_name eq 'new')
? "CLASS" : "THIS");
unshift(@args, $arg0);
($report_args =3D "$arg0, $report_args") =3D~ s/^\w+, $/$arg0/;
}
my $extra_args =3D 0;
@args_num =3D ();
$num_args =3D 0;
my $report_args =3D '';
foreach $i (0 .. $#args) {
if ($args[$i] =3D~ s/\.\.\.//) {
$elipsis =3D 1;
if ($args[$i] eq '' && $i =3D=3D $#args) {
$report_args .=3D ", ...";
pop(@args);
last;
}
}
if ($only_outlist{$args[$i]}) {
push @args_num, undef;
} else {
push @args_num, ++$num_args;
$report_args .=3D ", $args[$i]";
}
if ($args[$i] =3D~ /^([^=3D]*[^\s=3D])\s*=3D\s*(.*)/s) {
$extra_args++;
$args[$i] =3D $1;
$defaults{$args[$i]} =3D $2;
$defaults{$args[$i]} =3D~ s/"/\\"/g;
}
$proto_arg[$i+1] =3D "\$" ;
}
$min_args =3D $num_args - $extra_args;
$report_args =3D~ s/"/\\"/g;
$report_args =3D~ s/^,\s+//;
my @func_args =3D @args;
shift @func_args if defined($class);
for (@func_args) {
s/^/&/ if $in_out{$_};
}
$func_args =3D join(", ", @func_args);
@args_match{@args} =3D @args_num;
$PPCODE =3D grep(/^\s*PPCODE\s*:/, @line);
$CODE =3D grep(/^\s*CODE\s*:/, @line);
# Detect CODE: blocks which use ST(n)=3D or XST_m*(n,v)
# to set explicit return values.
$EXPLICIT_RETURN =3D ($CODE &&
("@line" =3D~ /(\bST\s*\([^;]*=3D) | (\bXST_m\w+\s*\()/x ));
$ALIAS =3D grep(/^\s*ALIAS\s*:/, @line);
$INTERFACE =3D grep(/^\s*INTERFACE\s*:/, @line);
$xsreturn =3D 1 if $EXPLICIT_RETURN;
# print function header
print Q<<"EOF";
#XS(XS_${Full_func_name}); /* prototype to pass -Wmissing-prototypes */
#XS(XS_${Full_func_name})
#[[
# dXSARGS;
EOF
print Q<<"EOF" if $ALIAS ;
# dXSI32;
EOF
print Q<<"EOF" if $INTERFACE ;
# dXSFUNCTION($ret_type);
EOF
if ($elipsis) {
$cond =3D ($min_args ? qq(items < $min_args) : 0);
}
elsif ($min_args =3D=3D $num_args) {
$cond =3D qq(items !=3D $min_args);
}
else {
$cond =3D qq(items < $min_args || items > $num_args);
}
print Q<<"EOF" if $except;
# char errbuf[1024];
# *errbuf =3D '\0';
EOF
if ($ALIAS)=20
{ print Q<<"EOF" if $cond }
# if ($cond)
# Perl_croak(aTHX_ "Usage: %s($report_args)", GvNAME(CvGV(cv)));
EOF
else=20
{ print Q<<"EOF" if $cond }
# if ($cond)
# Perl_croak(aTHX_ "Usage: $pname($report_args)");
EOF
#gcc -Wall: if an xsub has no arguments and PPCODE is used
#it is likely none of ST, XSRETURN or XSprePUSH macros are used
#hence `ax' (setup by dXSARGS) is unused
#XXX: could breakup the dXSARGS; into dSP;dMARK;dITEMS
#but such a move could break third-party extensions
print Q<<"EOF" if $PPCODE and $num_args =3D=3D 0;
# PERL_UNUSED_VAR(ax); /* -Wall */
EOF
print Q<<"EOF" if $PPCODE;
# SP -=3D items;
EOF
# Now do a block of some sort.
$condnum =3D 0;
$cond =3D ''; # last CASE: condidional
push(@line, "$END:");
push(@line_no, $line_no[-1]);
$_ =3D '';
&check_cpp;
while (@line) {
&CASE_handler if check_keyword("CASE");
print Q<<"EOF";
# $except [[
EOF
# do initialization of input variables
$thisdone =3D 0;
$retvaldone =3D 0;
$deferred =3D "";
%arg_list =3D () ;
$gotRETVAL =3D 0;
INPUT_handler() ;
process_keyword("INPUT|PREINIT|INTERFACE_MACRO|C_ARGS|ALIAS|ATTRS|PROTOTYP=
E|SCOPE") ;
print Q<<"EOF" if $ScopeThisXSUB;
# ENTER;
# [[
EOF
=09
if (!$thisdone && defined($class)) {
if (defined($static) or $func_name eq 'new') {
print "\tchar *";
$var_types{"CLASS"} =3D "char *";
&generate_init("char *", 1, "CLASS");
}
else {
print "\t$class *";
$var_types{"THIS"} =3D "$class *";
&generate_init("$class *", 1, "THIS");
}
}
# do code
if (/^\s*NOT_IMPLEMENTED_YET/) {
print "\n\tPerl_croak(aTHX_ \"$pname: not implemented yet\");\n";
$_ =3D '' ;
} else {
if ($ret_type ne "void") {
print "\t" . &map_type($ret_type, 'RETVAL') . ";\n"
if !$retvaldone;
$args_match{"RETVAL"} =3D 0;
$var_types{"RETVAL"} =3D $ret_type;
print "\tdXSTARG;\n"
if $WantOptimize and $targetable{$type_kind{$ret_type}};
}
if (@arg_with_types) {
unshift @line, @arg_with_types, $_;
$_ =3D "";
$processing_arg_with_types =3D 1;
INPUT_handler() ;
}
print $deferred;
process_keyword("INIT|ALIAS|ATTRS|PROTOTYPE|INTERFACE_MACRO|INTERFA=
CE|C_ARGS") ;
if (check_keyword("PPCODE")) {
print_section();
death ("PPCODE must be last thing") if @line;
print "\tLEAVE;\n" if $ScopeThisXSUB;
print "\tPUTBACK;\n\treturn;\n";
} elsif (check_keyword("CODE")) {
print_section() ;
} elsif (defined($class) and $func_name eq "DESTROY") {
print "\n\t";
print "delete THIS;\n";
} else {
print "\n\t";
if ($ret_type ne "void") {
print "RETVAL =3D ";
$wantRETVAL =3D 1;
}
if (defined($static)) {
if ($func_name eq 'new') {
$func_name =3D "$class";
} else {
print "${class}::";
}
} elsif (defined($class)) {
if ($func_name eq 'new') {
$func_name .=3D " $class";
} else {
print "THIS->";
}
}
$func_name =3D~ s/^($spat)//
if defined($spat);
$func_name =3D 'XSFUNCTION' if $interface;
print "$func_name($func_args);\n";
}
}
# do output variables
$gotRETVAL =3D 0; # 1 if RETVAL seen in OUTPUT section;
undef $RETVAL_code ; # code to set RETVAL (from OUTPUT section);
# $wantRETVAL set if 'RETVAL =3D' autogenerated
($wantRETVAL, $ret_type) =3D (0, 'void') if $RETVAL_no_return;
undef %outargs ;
process_keyword("POSTCALL|OUTPUT|ALIAS|ATTRS|PROTOTYPE");=20
&generate_output($var_types{$_}, $args_match{$_}, $_, $DoSetMagic)
for grep $in_out{$_} =3D~ /OUT$/, keys %in_out;
# all OUTPUT done, so now push the return value on the stack
if ($gotRETVAL && $RETVAL_code) {
print "\t$RETVAL_code\n";
} elsif ($gotRETVAL || $wantRETVAL) {
my $t =3D $WantOptimize && $targetable{$type_kind{$ret_type}};
my $var =3D 'RETVAL';
my $type =3D $ret_type;
# 0: type, 1: with_size, 2: how, 3: how_size
if ($t and not $t->[1] and $t->[0] eq 'p') {
# PUSHp corresponds to setpvn. Treate setpv directly
my $what =3D eval qq("$t->[2]");
warn $@ if $@;
print "\tsv_setpv(TARG, $what); XSprePUSH; PUSHTARG;\n";
$prepush_done =3D 1;
}
elsif ($t) {
my $what =3D eval qq("$t->[2]");
warn $@ if $@;
my $size =3D $t->[3];
$size =3D '' unless defined $size;
$size =3D eval qq("$size");
warn $@ if $@;
print "\tXSprePUSH; PUSH$t->[0]($what$size);\n";
$prepush_done =3D 1;
}
else {
# RETVAL almost never needs SvSETMAGIC()
&generate_output($ret_type, 0, 'RETVAL', 0);
}
}
$xsreturn =3D 1 if $ret_type ne "void";
my $num =3D $xsreturn;
my $c =3D @outlist;
print "\tXSprePUSH;" if $c and not $prepush_done;
print "\tEXTEND(SP,$c);\n" if $c;
$xsreturn +=3D $c;
generate_output($var_types{$_}, $num++, $_, 0, 1) for @outlist;
# do cleanup
process_keyword("CLEANUP|ALIAS|ATTRS|PROTOTYPE") ;
print Q<<"EOF" if $ScopeThisXSUB;
# ]]
EOF
print Q<<"EOF" if $ScopeThisXSUB and not $PPCODE;
# LEAVE;
EOF
# print function trailer
print Q<<EOF;
# ]]
EOF
print Q<<EOF if $except;
# BEGHANDLERS
# CATCHALL
# sprintf(errbuf, "%s: %s\\tpropagated", Xname, Xreason);
# ENDHANDLERS
EOF
if (check_keyword("CASE")) {
blurt ("Error: No `CASE:' at top of function")
unless $condnum;
$_ =3D "CASE: $_"; # Restore CASE: label
next;
}
last if $_ eq "$END:";
death(/^$BLOCK_re/o ? "Misplaced `$1:'" : "Junk at end of function");
}
print Q<<EOF if $except;
# if (errbuf[0])
# Perl_croak(aTHX_ errbuf);
EOF
if ($xsreturn) {
print Q<<EOF unless $PPCODE;
# XSRETURN($xsreturn);
EOF
} else {
print Q<<EOF unless $PPCODE;
# XSRETURN_EMPTY;
EOF
}
print Q<<EOF;
#]]
#
EOF
my $newXS =3D "newXS" ;
my $proto =3D "" ;
# Build the prototype string for the xsub
if ($ProtoThisXSUB) {
$newXS =3D "newXSproto";
if ($ProtoThisXSUB eq 2) {
# User has specified empty prototype
$proto =3D ', ""' ;
}
elsif ($ProtoThisXSUB ne 1) {
# User has specified a prototype
$proto =3D ', "' . $ProtoThisXSUB . '"';
}
else {
my $s =3D ';';
if ($min_args < $num_args) {
$s =3D '';=20
$proto_arg[$min_args] .=3D ";" ;
}
push @proto_arg, "$s\@"=20
if $elipsis ;
=20
$proto =3D ', "' . join ("", @proto_arg) . '"';
}
}
if (%XsubAliases) {
$XsubAliases{$pname} =3D 0=20
unless defined $XsubAliases{$pname} ;
while ( ($name, $value) =3D each %XsubAliases) {
push(@InitFileCode, Q<<"EOF");
# cv =3D newXS(\"$name\", XS_$Full_func_name, file);
# XSANY.any_i32 =3D $value ;
EOF
push(@InitFileCode, Q<<"EOF") if $proto;
# sv_setpv((SV*)cv$proto) ;
EOF
}
}=20
elsif (@Attributes) {
push(@InitFileCode, Q<<"EOF");
# cv =3D newXS(\"$pname\", XS_$Full_func_name, file);
# apply_attrs_string("$Package", cv, "@Attributes", 0);
EOF
}
elsif ($interface) {
while ( ($name, $value) =3D each %Interfaces) {
$name =3D "$Package\::$name" unless $name =3D~ /::/;
push(@InitFileCode, Q<<"EOF");
# cv =3D newXS(\"$name\", XS_$Full_func_name, file);
# $interface_macro_set(cv,$value) ;
EOF
push(@InitFileCode, Q<<"EOF") if $proto;
# sv_setpv((SV*)cv$proto) ;
EOF
}
}
else {
push(@InitFileCode,
" ${newXS}(\"$pname\", XS_$Full_func_name, file$proto);\n");
}
}
# print initialization routine
print Q<<"EOF";
##ifdef __cplusplus
#extern "C"
##endif
EOF
print Q<<"EOF";
#XS(boot_$Module_cname); /* prototype to pass -Wmissing-prototypes */
#XS(boot_$Module_cname)
EOF
print Q<<"EOF";
#[[
# dXSARGS;
EOF
#-Wall: if there is no $Full_func_name there are no xsubs in this .xs
#so `file' is unused
print Q<<"EOF" if $Full_func_name;
# char* file =3D __FILE__;
EOF
print Q "#\n";
print Q<<"EOF" if $WantVersionChk ;
# XS_VERSION_BOOTCHECK ;
#
EOF
print Q<<"EOF" if defined $XsubAliases or defined $Interfaces ;
# {
# CV * cv ;
#
EOF
print @InitFileCode;
print Q<<"EOF" if defined $XsubAliases or defined $Interfaces ;
# }
EOF
if (@BootCode)
{
print "\n /* Initialisation Section */\n\n" ;
@line =3D @BootCode;
print_section();
print "\n /* End of Initialisation Section */\n\n" ;
}
print Q<<"EOF";;
# XSRETURN_YES;
#]]
#
EOF
warn("Please specify prototyping behavior for $filename (see perlxs manual)=
\n")=20
unless $ProtoUsed ;
&Exit;
sub output_init {
local($type, $num, $var, $init, $name_printed) =3D @_;
local($arg) =3D "ST(" . ($num - 1) . ")";
if( $init =3D~ /^=3D/ ) {
if ($name_printed) {
eval qq/print " $init\\n"/;
} else {
eval qq/print "\\t$var $init\\n"/;
}
warn $@ if $@;
} else {
if( $init =3D~ s/^\+// && $num ) {
&generate_init($type, $num, $var, $name_printed);
} elsif ($name_printed) {
print ";\n";
$init =3D~ s/^;//;
} else {
eval qq/print "\\t$var;\\n"/;
warn $@ if $@;
$init =3D~ s/^;//;
}
$deferred .=3D eval qq/"\\n\\t$init\\n"/;
warn $@ if $@;
}
}
sub Warn
{
# work out the line number
my $line_no =3D $line_no[@line_no - @line -1] ;
=20
print STDERR "@_ in $filename, line $line_no\n" ;
}
sub blurt=20
{=20
Warn @_ ;
$errors ++=20
}
sub death
{
Warn @_ ;
exit 1 ;
}
sub generate_init {
local($type, $num, $var) =3D @_;
local($arg) =3D "ST(" . ($num - 1) . ")";
local($argoff) =3D $num - 1;
local($ntype);
local($tk);
$type =3D TidyType($type) ;
blurt("Error: '$type' not in typemap"), return=20
unless defined($type_kind{$type});
($ntype =3D $type) =3D~ s/\s*\*/Ptr/g;
($subtype =3D $ntype) =3D~ s/(?:Array)?(?:Ptr)?$//;
$tk =3D $type_kind{$type};
$tk =3D~ s/OBJ$/REF/ if $func_name =3D~ /DESTROY$/;
$type =3D~ tr/:/_/;
blurt("Error: No INPUT definition for type '$type', typekind '$type_kin=
d{$type}' found"), return
unless defined $input_expr{$tk} ;
$expr =3D $input_expr{$tk};
if ($expr =3D~ /DO_ARRAY_ELEM/) {
blurt("Error: '$subtype' not in typemap"), return=20
unless defined($type_kind{$subtype});
blurt("Error: No INPUT definition for type '$subtype', typekind '$t=
ype_kind{$subtype}' found"), return
unless defined $input_expr{$type_kind{$subtype}} ;
$subexpr =3D $input_expr{$type_kind{$subtype}};
$subexpr =3D~ s/\$type/\$subtype/g;
$subexpr =3D~ s/ntype/subtype/g;
$subexpr =3D~ s/\$arg/ST(ix_$var)/g;
$subexpr =3D~ s/\n\t/\n\t\t/g;
$subexpr =3D~ s/is not of (.*\")/[arg %d] is not of $1, ix_$var + 1/g;
$subexpr =3D~ s/\$var/${var}[ix_$var - $argoff]/;
$expr =3D~ s/DO_ARRAY_ELEM/$subexpr/;
}
if ($expr =3D~ m#/\*.*scope.*\*/#i) { # "scope" in C comments
$ScopeThisXSUB =3D 1;
}
if (defined($defaults{$var})) {
$expr =3D~ s/(\t+)/$1 /g;
$expr =3D~ s/ /\t/g;
if ($name_printed) {
print ";\n";
} else {
eval qq/print "\\t$var;\\n"/;
warn $@ if $@;
}
if ($defaults{$var} eq 'NO_INIT') {
$deferred .=3D eval qq/"\\n\\tif (items >=3D $num) {\\n$expr;\\n\\t}\\n"/=
;
} else {
$deferred .=3D eval qq/"\\n\\tif (items < $num)\\n\\t $var =3D $defaul=
ts{$var};\\n\\telse {\\n$expr;\\n\\t}\\n"/;
}
warn $@ if $@;
} elsif ($ScopeThisXSUB or $expr !~ /^\t\$var =3D/) {
if ($name_printed) {
print ";\n";
} else {
eval qq/print "\\t$var;\\n"/;
warn $@ if $@;
}
$deferred .=3D eval qq/"\\n$expr;\\n"/;
warn $@ if $@;
} else {
die "panic: do not know how to handle this branch for function pointer=
s"
if $name_printed;
eval qq/print "$expr;\\n"/;
warn $@ if $@;
}
}
sub generate_output {
local($type, $num, $var, $do_setmagic, $do_push) =3D @_;
local($arg) =3D "ST(" . ($num - ($num !=3D 0)) . ")";
local($argoff) =3D $num - 1;
local($ntype);
$type =3D TidyType($type) ;
if ($type =3D~ /^array\(([^,]*),(.*)\)/) {
print "\t$arg =3D sv_newmortal();\n";
print "\tsv_setpvn($arg, (char *)$var, $2 * sizeof($1));\n";
print "\tSvSETMAGIC($arg);\n" if $do_setmagic;
} else {
blurt("Error: '$type' not in typemap"), return
unless defined($type_kind{$type});
blurt("Error: No OUTPUT definition for type '$type', typekind '=
$type_kind{$type}' found"), return
unless defined $output_expr{$type_kind{$type}} ;
($ntype =3D $type) =3D~ s/\s*\*/Ptr/g;
$ntype =3D~ s/\(\)//g;
($subtype =3D $ntype) =3D~ s/(?:Array)?(?:Ptr)?$//;
$expr =3D $output_expr{$type_kind{$type}};
if ($expr =3D~ /DO_ARRAY_ELEM/) {
blurt("Error: '$subtype' not in typemap"), return
unless defined($type_kind{$subtype});
blurt("Error: No OUTPUT definition for type '$subtype', typ=
ekind '$type_kind{$subtype}' found"), return
unless defined $output_expr{$type_kind{$subtype}} ;
$subexpr =3D $output_expr{$type_kind{$subtype}};
$subexpr =3D~ s/ntype/subtype/g;
$subexpr =3D~ s/\$arg/ST(ix_$var)/g;
$subexpr =3D~ s/\$var/${var}[ix_$var]/g;
$subexpr =3D~ s/\n\t/\n\t\t/g;
$expr =3D~ s/DO_ARRAY_ELEM\n/$subexpr/;
eval "print qq\a$expr\a";
warn $@ if $@;
print "\t\tSvSETMAGIC(ST(ix_$var));\n" if $do_setmagic;
}
elsif ($var eq 'RETVAL') {
if ($expr =3D~ /^\t\$arg =3D new/) {
# We expect that $arg has refcnt 1, so we need to
# mortalize it.
eval "print qq\a$expr\a";
warn $@ if $@;
print "\tsv_2mortal(ST($num));\n";
print "\tSvSETMAGIC(ST($num));\n" if $do_setmagic;
}
elsif ($expr =3D~ /^\s*\$arg\s*=3D/) {
# We expect that $arg has refcnt >=3D1, so we need
# to mortalize it!
eval "print qq\a$expr\a";
warn $@ if $@;
print "\tsv_2mortal(ST(0));\n";
print "\tSvSETMAGIC(ST(0));\n" if $do_setmagic;
}
else {
# Just hope that the entry would safely write it
# over an already mortalized value. By
# coincidence, something like $arg =3D &sv_undef
# works too.
print "\tST(0) =3D sv_newmortal();\n";
eval "print qq\a$expr\a";
warn $@ if $@;
# new mortals don't have set magic
}
}
elsif ($do_push) {
print "\tPUSHs(sv_newmortal());\n";
$arg =3D "ST($num)";
eval "print qq\a$expr\a";
warn $@ if $@;
print "\tSvSETMAGIC($arg);\n" if $do_setmagic;
}
elsif ($arg =3D~ /^ST\(\d+\)$/) {
eval "print qq\a$expr\a";
warn $@ if $@;
print "\tSvSETMAGIC($arg);\n" if $do_setmagic;
}
}
}
sub map_type {
my($type, $varname) =3D @_;
$type =3D~ tr/:/_/;
$type =3D~ s/^array\(([^,]*),(.*)\).*/$1 */s;
if ($varname) {
if ($varname && $type =3D~ / \( \s* \* (?=3D \s* \) ) /xg) {
(substr $type, pos $type, 0) =3D " $varname ";
} else {
$type .=3D "\t$varname";
}
}
$type;
}
sub Exit {
# If this is VMS, the exit status has meaning to the shell, so we
# use a predictable value (SS$_Normal or SS$_Abort) rather than an
# arbitrary number.
# exit ($Is_VMS ? ($errors ? 44 : 1) : $errors) ;
exit ($errors ? 1 : 0);
}
--=-Z0BhkRejYKBV0c+ixk8/--