Pre-YAPC consting fun
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / ParseXS.pm
index bd0e875..3e6e873 100644 (file)
@@ -17,8 +17,7 @@ my(@XSStack); # Stack of conditionals and INCLUDEs
 my($XSS_work_idx, $cpp_next_tmp);
 
 use vars qw($VERSION);
-$VERSION = '2.09_01';
-$VERSION = eval $VERSION;
+$VERSION = '2.10';
 
 use vars qw(%input_expr %output_expr $ProtoUsed @InitFileCode $FH $proto_re $Overload $errors $Fallback
            $cplusplus $hiertype $WantPrototypes $WantVersionChk $except $WantLineNumbers
@@ -55,6 +54,7 @@ sub process_file {
           argtypes => 1,
           typemap => [],
           output => \*STDOUT,
+          csuffix => '.c',
           %args,
          );
 
@@ -118,6 +118,7 @@ sub process_file {
   
   chdir($dir);
   my $pwd = cwd();
+  my $csuffix = $args{csuffix};
   
   if ($WantLineNumbers) {
     my $cfile;
@@ -125,7 +126,7 @@ sub process_file {
       $cfile = $args{outfile};
     } else {
       $cfile = $args{filename};
-      $cfile =~ s/\.xs$/.c/i or $cfile .= ".c";
+      $cfile =~ s/\.xs$/$csuffix/i or $cfile .= $csuffix;
     }
     tie(*PSEUDO_STDOUT, 'ExtUtils::ParseXS::CountLines', $cfile, $args{output});
     select PSEUDO_STDOUT;
@@ -195,8 +196,8 @@ sub process_file {
     $input_expr{$key} =~ s/;*\s+\z//;
   }
 
-  my ($bal, $cast, $size);
-  $bal = qr[(?:(?>[^()]+)|\((??{ $bal })\))*]; # ()-balanced
+  my ($cast, $size);
+  our $bal = qr[(?:(?>[^()]+)|\((??{ $bal })\))*]; # ()-balanced
   $cast = qr[(?:\(\s*SV\s*\*\s*\)\s*)?]; # Optional (SV*) cast
   $size = qr[,\s* (??{ $bal }) ]x; # Third arg (to setpvn)
 
@@ -224,7 +225,7 @@ sub process_file {
                                  )) . "|$END)\\s*:";
 
   
-  my ($C_group_rex, $C_arg);
+  our ($C_group_rex, $C_arg);
   # Group in C (no support for comments or literals)
   $C_group_rex = qr/ [({\[]
                       (?: (?> [^()\[\]{}]+ ) | (??{ $C_group_rex }) )*
@@ -358,7 +359,7 @@ EOF
           ." followed by a statement on column one?)")
       if $line[0] =~ /^\s/;
     
-    my ($class, $static, $elipsis, $wantRETVAL, $RETVAL_no_return);
+    my ($class, $externC, $static, $elipsis, $wantRETVAL, $RETVAL_no_return);
     my (@fake_INPUT_pre);      # For length(s) generated variables
     my (@fake_INPUT);
     
@@ -412,7 +413,8 @@ EOF
     blurt ("Error: Function definition too short '$ret_type'"), next PARAGRAPH
       unless @line ;
 
-    $static = 1 if $ret_type =~ s/^static\s+//;
+    $externC = 1 if $ret_type =~ s/^extern "C"\s+//;
+    $static  = 1 if $ret_type =~ s/^static\s+//;
 
     $func_header = shift(@line);
     blurt ("Error: Cannot parse function definition from '$func_header'"), next PARAGRAPH
@@ -554,8 +556,11 @@ EOF
 
     $xsreturn = 1 if $EXPLICIT_RETURN;
 
+    $externC = $externC ? qq[extern "C"] : "";
+
     # print function header
     print Q(<<"EOF");
+#$externC
 #XS(XS_${Full_func_name}); /* prototype to pass -Wmissing-prototypes */
 #XS(XS_${Full_func_name})
 #[[