Re: Debugger in beta3
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / xsubpp
index 3113c62..8d8e6dc 100755 (executable)
@@ -76,13 +76,12 @@ perl(1), perlxs(1), perlxstut(1), perlapi(1)
 =cut
 
 # Global Constants
-$XSUBPP_version = "1.929";
+$XSUBPP_version = "1.933";
 require 5.002;
 
 sub Q ;
 
-$FH_string = 'File0000' ;
-*FH = $FH_string ;
+$FH = 'File0000' ;
 
 $usage = "Usage: xsubpp [-v] [-C++] [-except] [-prototypes] [-noversioncheck] [-s pattern] [-typemap typemap]... file.xs\n";
 
@@ -405,8 +404,14 @@ sub VERSIONCHECK_handler ()
 
 sub PROTOTYPE_handler ()
 {
+    my $specified ;
+
+    death("Error: Only 1 PROTOTYPE definition allowed per xsub") 
+        if $proto_in_this_xsub ++ ;
+
     for (;  !/^$BLOCK_re/o;  $_ = shift(@line)) {
        next unless /\S/;
+       $specified = 1 ;
        TrimWhitespace($_) ;
         if ($_ eq 'DISABLE') {
           $ProtoThisXSUB = 0 
@@ -422,7 +427,12 @@ sub PROTOTYPE_handler ()
             $ProtoThisXSUB = C_string($_) ;
         }
     }
+
+    # If no prototype specified, then assume empty prototype ""
+    $ProtoThisXSUB = 2 unless $specified ;
+
     $ProtoUsed = 1 ;
+
 }
 
 sub PROTOTYPES_handler ()
@@ -448,9 +458,6 @@ sub INCLUDE_handler ()
  
     TrimWhitespace($_) ;
  
-    # If the filename is enclosed in quotes, remove them.
-    s/^'([^']*)'$/$1/ or s/^"([^"]*)"$/$1/ ;
-
     death("INCLUDE: filename missing")
         unless $_ ;
 
@@ -470,13 +477,13 @@ sub INCLUDE_handler ()
         Line            => \@line,
         LineNo          => \@line_no,
         Filename        => $filename,
-        Handle          => $FH_string,
+        Handle          => $FH,
         }) ;
  
-    ++ $FH_string ;
+    ++ $FH ;
 
     # open the new file
-    open ($FH_string, "$_") or death("Cannot open '$_': $!") ;
+    open ($FH, "$_") or death("Cannot open '$_': $!") ;
  
     print Q<<"EOF" ;
 #
@@ -484,11 +491,17 @@ sub INCLUDE_handler ()
 #
 EOF
 
-    *FH = $FH_string ;
     $filename = $_ ;
 
-    # Prime the pump by reading the first line
-    $lastline = <FH> ;
+    # Prime the pump by reading the first 
+    # non-blank line
+
+    # skip leading blank lines
+    while (<$FH>) {
+        last unless /^\s*$/ ;
+    }
+
+    $lastline = $_ ;
     $lastline_no = $. ;
  
 }
@@ -504,9 +517,9 @@ sub PopFile()
     -- $IncludedFiles{$filename}
         unless $isPipe ;
 
-    close FH ;
+    close $FH ;
 
-    *FH         = $data->{Handle} ;
+    $FH         = $data->{Handle} ;
     $filename   = $data->{Filename} ;
     $lastline   = $data->{LastLine} ;
     $lastline_no = $data->{LastLineNo} ;
@@ -581,7 +594,7 @@ sub Q {
     $text;
 }
 
-open(FH, $filename) or die "cannot open $filename: $!\n";
+open($FH, $filename) or die "cannot open $filename: $!\n";
 
 # Identify the version of xsubpp used
 print <<EOM ;
@@ -596,7 +609,7 @@ print <<EOM ;
 EOM
  
 
-while (<FH>) {
+while (<$FH>) {
     last if ($Module, $Package, $Prefix) =
        /^MODULE\s*=\s*([\w:]+)(?:\s+PACKAGE\s*=\s*([\w:]+))?(?:\s+PREFIX\s*=\s*(\S+))?\s*$/;
     print $_;
@@ -607,14 +620,14 @@ $lastline    = $_;
 $lastline_no = $.;
 
 
-# Read next xsub into @line from ($lastline, <FH>).
+# Read next xsub into @line from ($lastline, <$FH>).
 sub fetch_para {
     # parse paragraph
     @line = ();
     @line_no = () ;
     if (! defined $lastline) {
         return 1 if PopFile() ;
-        return 0 ; 
+        return 0 ;
     }
 
     if ($lastline =~
@@ -638,11 +651,11 @@ sub fetch_para {
        }
 
        # Read next line and continuation lines
-       last unless defined($lastline = <FH>);
+       last unless defined($lastline = <$FH>);
        $lastline_no = $.;
        my $tmp_line;
        $lastline .= $tmp_line
-           while ($lastline =~ /\\$/ && defined($tmp_line = <FH>));
+           while ($lastline =~ /\\$/ && defined($tmp_line = <$FH>));
            
        chomp $lastline;
        $lastline =~ s/^\s+$//;
@@ -673,6 +686,7 @@ while (fetch_para()) {
     undef($wantRETVAL) ;
     undef(%arg_list) ;
     undef(@proto_arg) ;
+    undef($proto_in_this_xsub) ;
     $ProtoThisXSUB = $WantPrototypes ;
 
     $_ = shift(@line);
@@ -926,7 +940,12 @@ EOF
 
     # Build the prototype string for the xsub
     if ($ProtoThisXSUB) {
-        if ($ProtoThisXSUB != 1) {
+        if ($ProtoThisXSUB == 2) {
+            # User has specified empty prototype
+            $ProtoXSUB{$pname} = '""'
+        }
+        elsif ($ProtoThisXSUB != 1) {
+            # User has specified a prototype
             $ProtoXSUB{$pname} = '"' . $ProtoThisXSUB . '"'
         }
         else {
@@ -986,7 +1005,7 @@ for (@Func_name) {
 #        XSANY.any_i32 = $value ;
 EOF
             print Q<<"EOF" if $proto ;
-#        sv_setpv(cv, $ProtoXSUB{$pname}) ;
+#        sv_setpv((SV*)cv, $ProtoXSUB{$pname}) ;
 EOF
         }
     }