threads::shared 1.24 (phase 2)
[p5sagit/p5-mst-13.2.git] / ext / Devel / PPPort / PPPort_pm.PL
index 269895b..5a8c227 100644 (file)
@@ -4,13 +4,13 @@
 #
 ################################################################################
 #
-#  $Revision: 28 $
+#  $Revision: 59 $
 #  $Author: mhx $
-#  $Date: 2004/08/13 12:49:22 +0200 $
+#  $Date: 2008/01/04 10:47:38 +0100 $
 #
 ################################################################################
 #
-#  Version 3.x, Copyright (C) 2004, Marcus Holland-Moritz.
+#  Version 3.x, Copyright (C) 2004-2008, Marcus Holland-Moritz.
 #  Version 2.x, Copyright (C) 2001, Paul Marquess.
 #  Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
 #
@@ -27,7 +27,7 @@ my $INCLUDE = 'parts/inc';
 my $DPPP = 'DPPP_';
 
 my %embed = map { ( $_->{name} => $_ ) }
-            parse_embed(qw(parts/embed.fnc parts/apidoc.fnc));
+            parse_embed(qw(parts/embed.fnc parts/apidoc.fnc parts/ppport.fnc));
 
 my(%provides, %prototypes, %explicit);
 
@@ -47,15 +47,15 @@ $data =~ s{^(.*)__PROVIDED_API__(\s*?)^}
   for (keys %explicit) {
     length > $len and $len = length;
   }
-  my $format = sprintf "%%-%ds  %%-%ds  %%-%ds", $len+2, $len+5, $len+12;
+  my $format = sprintf '%%-%ds  %%-%ds  %%s', $len+2, $len+5;
   $len = 3*$len + 23;
 
-$data =~ s/^(.*)__EXPLICIT_API__(\s*?)^/
-           sprintf("$1$format\n", 'Function', 'Static Request', 'Global Request') .
+$data =~ s!^(.*)__EXPLICIT_API__(\s*?)^!
+           sprintf("$1$format\n", 'Function / Variable', 'Static Request', 'Global Request') .
            $1 . '-'x$len . "\n" .
-           join('', map { sprintf "$1$format\n", "$_()", "NEED_$_", "NEED_${_}_GLOBAL" }
+           join('', map { sprintf "$1$format\n", $explicit{$_} eq 'var' ? $_ : "$_()", "NEED_$_", "NEED_${_}_GLOBAL" }
                     sort keys %explicit)
-          /gem;
+          !gem;
 }
 
 my %raw_base = %{&parse_todo('parts/base')};
@@ -68,14 +68,21 @@ for (keys %raw_todo) {
 
 # check consistency
 for (@api) {
-  if (exists $raw_todo{$_}) {
-    warn "$INCLUDE/$provides{$_} provides $_, which is still marked "
-         . "todo for " . format_version($raw_todo{$_}) . "\n";
+  if (exists $raw_todo{$_} and exists $raw_base{$_}) {
+    if ($raw_base{$_} eq $raw_todo{$_}) {
+      warn "$INCLUDE/$provides{$_} provides $_, which is still marked "
+           . "todo for " . format_version($raw_todo{$_}) . "\n";
+    }
+    else {
+      check(2, "$_ was ported back to " . format_version($raw_todo{$_}) .
+               " (baseline revision: " . format_version($raw_base{$_}) . ").");
+    }
   }
 }
 
 my @perl_api;
 for (keys %provides) {
+  next if /^Perl_(.*)/ && exists $embed{$1};
   next if exists $embed{$_};
   push @perl_api, $_;
   check(2, "No API definition for provided element $_ found.");
@@ -119,7 +126,7 @@ $data =~ s{^__UNSUPPORTED_API__(\s*?)^}
           {join "\n", @todo}gem;
 
 $data =~ s{__MIN_PERL__}{5.003}g;
-$data =~ s{__MAX_PERL__}{5.9.2}g;
+$data =~ s{__MAX_PERL__}{5.10.0}g;
 
 open FH, ">PPPort.pm" or die "PPPort.pm: $!\n";
 print FH $data;
@@ -148,7 +155,7 @@ sub include
 
   for (keys %{$data->{prototypes}}) {
     $prototypes{$_} = $data->{prototypes}{$_};
-    $data->{implementation} =~ s/^$_(?=\s*\()/$DPPP($_)/g;
+    $data->{implementation} =~ s/^$_(?=\s*\()/$DPPP(my_$_)/mg;
   }
 
   my $out = $data->{implementation};
@@ -182,6 +189,32 @@ sub expand
               )
             \s*$}
             {expand_undefined($2, $1, $3)}gemx;
+  $code =~ s{^([^\S\r\n]*)__NEED_VAR__\s+(.*?)\s+(\w+)(?:\s*=\s*([^;]+?)\s*;\s*)?$}
+            {expand_need_var($1, $3, $2, $4)}gem;
+  return $code;
+}
+
+sub expand_need_var
+{
+  my($indent, $var, $type, $init) = @_;
+
+  $explicit{$var} = 'var';
+
+  my $myvar = "$DPPP(my_$var)";
+
+  my $code = <<ENDCODE;
+#if defined(NEED_$var)
+static $type $myvar = $init;
+#elif defined(NEED_${var}_GLOBAL)
+$type $myvar = $init;
+#else
+extern $type $myvar;
+#endif
+#define $var $myvar
+ENDCODE
+
+  $code =~ s/^/$indent/mg;
+
   return $code;
 }
 
@@ -190,7 +223,7 @@ sub expand_undefined
   my($macro, $withargs, $def) = @_;
   my $rv = "#ifndef $macro\n#  define ";
 
-  if (defined $def) {
+  if (defined $def && $def =~ /\S/) {
     $rv .= sprintf "%-30s %s", $withargs, $def;
   }
   else {
@@ -213,16 +246,7 @@ sub expand_pp_expr
 {
   my $expr = shift;
 
-  if ($expr =~ /^\s*version\s*(<|>|==|!=|>=|<=)\s*([\d._]+)\s*$/i) {
-    my($op, $ver) = ($1, $2);
-    my($r, $v, $s) = parse_version($ver);
-    $r == 5 or die "only Perl revision 5 is supported\n";
-    $op eq '=='     and return "((PERL_VERSION == $v) && (PERL_SUBVERSION == $s))";
-    $op eq '!='     and return "((PERL_VERSION != $v) || (PERL_SUBVERSION != $s))";
-    $op =~ /([<>])/ and return "((PERL_VERSION $1 $v) || ((PERL_VERSION == $v) && (PERL_SUBVERSION $op $s)))";
-  }
-
-  if ($expr =~ /^\s*need\s*(\w+)\s*$/i) {
+  if ($expr =~ /^\s*need\s+(\w+)\s*$/i) {
     my $func = $1;
     my $e = $embed{$func} or die "unknown API function '$func' in NEED\n";
     my $proto = make_prototype($e);
@@ -236,9 +260,9 @@ sub expand_pp_expr
       warn "found no prototype for $func\n";;
     }
 
-    $explicit{$func} = 1;
+    $explicit{$func} = 'func';
 
-    $proto =~ s/\b$func(?=\s*\()/$DPPP($func)/;
+    $proto =~ s/\b$func(?=\s*\()/$DPPP(my_$func)/;
     my $embed = make_embed($e);
 
     return "defined(NEED_$func)\n"
@@ -250,10 +274,9 @@ sub expand_pp_expr
          . "\n"
          . "$embed\n"
          . "\n"
-         . "#if defined(NEED_$func) || defined(NEED_${func}_GLOBAL)"
+         . "#if defined(NEED_$func) || defined(NEED_${func}_GLOBAL)";
   }
 
-
   die "cannot expand preprocessor expression '$expr'\n";
 }
 
@@ -262,14 +285,15 @@ sub make_embed
   my $f = shift;
   my $n = $f->{name};
   my $a = do { my $x = 'a'; join ',', map { $x++ } 1 .. @{$f->{args}} };
+  my $lastarg = ${$f->{args}}[-1];
 
   if ($f->{flags}{n}) {
     if ($f->{flags}{p}) {
-      return "#define $n $DPPP($n)\n" .
-             "#define Perl_$n $DPPP($n)";
+      return "#define $n $DPPP(my_$n)\n" .
+             "#define Perl_$n $DPPP(my_$n)";
     }
     else {
-      return "#define $n $DPPP($n)";
+      return "#define $n $DPPP(my_$n)";
     }
   }
   else {
@@ -279,11 +303,20 @@ sub make_embed
 #endif
 UNDEF
     if ($f->{flags}{p}) {
-      return $undef . "#define $n($a) $DPPP($n)(aTHX_ $a)\n" .
-                      "#define Perl_$n $DPPP($n)";
+      if ($f->{flags}{f}) {
+        return "#define Perl_$n $DPPP(my_$n)";
+      }
+      elsif (@$lastarg && $lastarg->[0] =~ /\.\.\./) {
+        return $undef . "#define $n $DPPP(my_$n)\n" .
+                        "#define Perl_$n $DPPP(my_$n)";
+      }
+      else {
+        return $undef . "#define $n($a) $DPPP(my_$n)(aTHX_ $a)\n" .
+                        "#define Perl_$n $DPPP(my_$n)";
+      }
     }
     else {
-      return $undef . "#define $n($a) $DPPP($n)(aTHX_ $a)";
+      return $undef . "#define $n($a) $DPPP(my_$n)(aTHX_ $a)";
     }
   }
 }
@@ -302,19 +335,23 @@ __DATA__
 #
 #  !!!!! Do NOT edit this file directly! -- Edit PPPort_pm.PL instead. !!!!!
 #
+#  This file was automatically generated from the definition files in the
+#  parts/inc/ subdirectory by PPPort_pm.PL. To learn more about how all this
+#  works, please read the F<HACKERS> file that came with this distribution.
+#
 ################################################################################
 #
 #  Perl/Pollution/Portability
 #
 ################################################################################
 #
-#  $Revision: 28 $
+#  $Revision: 59 $
 #  $Author: mhx $
-#  $Date: 2004/08/13 12:49:22 +0200 $
+#  $Date: 2008/01/04 10:47:38 +0100 $
 #
 ################################################################################
 #
-#  Version 3.x, Copyright (C) 2004, Marcus Holland-Moritz.
+#  Version 3.x, Copyright (C) 2004-2008, Marcus Holland-Moritz.
 #  Version 2.x, Copyright (C) 2001, Paul Marquess.
 #  Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
 #
@@ -347,10 +384,10 @@ contains a series of macros and, if explicitly requested, functions that
 allow XS modules to be built using older versions of Perl. Currently,
 Perl versions from __MIN_PERL__ to __MAX_PERL__ are supported.
 
-This module is used by C<h2xs> to write the file F<ppport.h>. 
+This module is used by C<h2xs> to write the file F<ppport.h>.
 
 =head2 Why use ppport.h?
+
 You should use F<ppport.h> in modern code so that your code will work
 with the widest range of Perl interpreters possible, without significant
 additional work.
@@ -369,7 +406,7 @@ They are most probably no XS writers. Also, don't make F<ppport.h>
 optional. Rather, just take the most recent copy of F<ppport.h> that
 you can find (e.g. by generating it with the latest C<Devel::PPPort>
 release from CPAN), copy it into your project, adjust your project to
-use it, and distribute the header along with your module. 
+use it, and distribute the header along with your module.
 
 =head2 Running ppport.h
 
@@ -378,7 +415,7 @@ that can check your source code. It will suggest hints and portability
 notes, and can even make suggestions on how to change your code. You
 can run it like any other Perl program:
 
-    perl ppport.h
+    perl ppport.h [options] [files]
 
 It also has embedded documentation, so you can use
 
@@ -451,7 +488,7 @@ Version 3.x was ported back to CPAN by Marcus Holland-Moritz.
 
 =head1 COPYRIGHT
 
-Version 3.x, Copyright (C) 2004, Marcus Holland-Moritz.
+Version 3.x, Copyright (C) 2004-2008, Marcus Holland-Moritz.
 
 Version 2.x, Copyright (C) 2001, Paul Marquess.
 
@@ -468,30 +505,25 @@ See L<h2xs>, L<ppport.h>.
 
 package Devel::PPPort;
 
-require DynaLoader;
 use strict;
-use vars qw($VERSION @ISA $data);
-
-$VERSION = do { my @r = '$Snapshot: /Devel-PPPort/3.00 $' =~ /(\d+\.\d+(?:_\d+)?)/; @r ? $r[0] : '9.99' };
+use vars qw($VERSION $data);
 
-@ISA = qw(DynaLoader);
-
-bootstrap Devel::PPPort;
+$VERSION = do { my @r = '$Snapshot: /Devel-PPPort/3.14 $' =~ /(\d+\.\d+(?:_\d+)?)/; @r ? $r[0] : '9.99' };
 
+sub _init_data
 {
   $data = do { local $/; <DATA> };
-  my $now = localtime;
   my $pkg = 'Devel::PPPort';
   $data =~ s/__PERL_VERSION__/$]/g;
   $data =~ s/__VERSION__/$VERSION/g;
-  $data =~ s/__DATE__/$now/g;
   $data =~ s/__PKG__/$pkg/g;
-  $data =~ s/^POD\s//gm;
+  $data =~ s/^\|>//gm;
 }
 
 sub WriteFile
 {
   my $file = shift || 'ppport.h';
+  defined $data or _init_data();
   my $copy = $data;
   $copy =~ s/\bppport\.h\b/$file/g;
 
@@ -511,21 +543,20 @@ __DATA__
 /*
 ----------------------------------------------------------------------
 
-    ppport.h -- Perl/Pollution/Portability Version __VERSION__ 
-   
-    Automatically created by __PKG__ running under
-    perl __PERL_VERSION__ on __DATE__.
-    
+    ppport.h -- Perl/Pollution/Portability Version __VERSION__
+
+    Automatically created by __PKG__ running under perl __PERL_VERSION__.
+
     Do NOT edit this file directly! -- Edit PPPort_pm.PL and the
     includes in parts/inc/ instead.
+
     Use 'perldoc ppport.h' to view the documentation below.
 
 ----------------------------------------------------------------------
 
 SKIP
 
-%include ppphdoc { indent => 'POD ' }
+%include ppphdoc { indent => '|>' }
 
 %include ppphbin
 
@@ -548,8 +579,12 @@ __DATA__
 
 %include uv
 
+%include memory
+
 %include misc
 
+%include variables
+
 %include threads
 
 %include mPUSH
@@ -564,14 +599,34 @@ __DATA__
 
 %include format
 
+%include SvREFCNT
+
+%include newSVpv
+
 %include SvPV
 
+%include Sv_set
+
+%include sv_xpvf
+
+%include shared_pv
+
+%include warn
+
+%include pvs
+
 %include magic
 
 %include cop
 
 %include grok
 
+%include snprintf
+
+%include exception
+
+%include strlfuncs
+
 #endif /* _P_P_PORTABILITY_H_ */
 
 /* End of File ppport.h */