Backport XS_(IN|EX)TERNAL, be explicit about linkage
authorSteffen Mueller <smueller@cpan.org>
Sun, 28 Aug 2011 15:51:06 +0000 (17:51 +0200)
committerSteffen Mueller <smueller@cpan.org>
Sun, 28 Aug 2011 15:51:06 +0000 (17:51 +0200)
With XS(name) defaulting to exporting symbols again since the
previous commit, ExtUtils::ParseXS will now instead use explicit
XS_EXTERNAL/XS_INTERNAL in its place. This allows backporting
of the linkage changes to perls as old as 5.10.0 (and possibly
further).

Porting/Maintainers.pl
dist/ExtUtils-ParseXS/Changes
dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm
dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Constants.pm
dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/CountLines.pm
dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Utilities.pm

index 4804a07..5e1361a 100755 (executable)
@@ -753,7 +753,7 @@ use File::Glob qw(:case);
     'ExtUtils::ParseXS' =>
        {
        'MAINTAINER'    => 'smueller',
-       'DISTRIBUTION'  => 'SMUELLER/ExtUtils-ParseXS-3.03_02.tar.gz',
+       'DISTRIBUTION'  => 'SMUELLER/ExtUtils-ParseXS-3.04_01.tar.gz',
        'FILES'         => q[dist/ExtUtils-ParseXS],
        'UPSTREAM'      => 'blead',
        },
index 0dd4405..c47ac64 100644 (file)
@@ -1,5 +1,17 @@
 Revision history for Perl extension ExtUtils::ParseXS.
 
+3.04_01 - Sun Aug 28 17:50:00 CET 2011
+
+  - The XSUB.h changes to make XS(name) use XS_INTERNAL(name)
+    by default (which were in the 5.15.2 dev release of perl)
+    have been reverted since too many CPAN modules expect to
+    be able to refer to XSUBs declared with XS(name).
+    Instead, ExtUtils::ParseXS will define a copy of the
+    XS_INTERNAL/XS_EXTERNAL macros as necessary going back to
+    perl 5.10.0 (which is the oldest perl I had for testing).
+    By default, ExtUtils::ParseXS will use XS_INTERNAL(name)
+    instead of XS(name).
+
 3.04 - Thu Aug 25 08:20:00 CET 2011
 
   - Stable release based on 3.03_03, no functional changes.
index 35cf321..08d6ac1 100644 (file)
@@ -11,7 +11,7 @@ use Symbol;
 
 our $VERSION;
 BEGIN {
-  $VERSION = '3.04';
+  $VERSION = '3.04_01';
 }
 use ExtUtils::ParseXS::Constants $VERSION;
 use ExtUtils::ParseXS::CountLines $VERSION;
@@ -502,8 +502,8 @@ EOM
     # print function header
     print Q(<<"EOF");
 #$externC
-#XS(XS_${Full_func_name}); /* prototype to pass -Wmissing-prototypes */
-#XS(XS_${Full_func_name})
+#XS_EUPXS(XS_${Full_func_name}); /* prototype to pass -Wmissing-prototypes */
+#XS_EUPXS(XS_${Full_func_name})
 #[[
 ##ifdef dVAR
 #    dVAR; dXSARGS;
@@ -880,8 +880,8 @@ EOF
 
   if ($self->{Overload}) { # make it findable with fetchmethod
     print Q(<<"EOF");
-#XS(XS_$self->{Packid}_nil); /* prototype to pass -Wmissing-prototypes */
-#XS(XS_$self->{Packid}_nil)
+#XS_EUPXS(XS_$self->{Packid}_nil); /* prototype to pass -Wmissing-prototypes */
+#XS_EUPXS(XS_$self->{Packid}_nil)
 #{
 #   dXSARGS;
 #   XSRETURN_EMPTY;
@@ -1476,10 +1476,8 @@ sub EXPORT_XSUB_SYMBOLS_handler {
   my $xs_impl = $1 eq 'ENABLE' ? 'XS_EXTERNAL' : 'XS_INTERNAL';
 
   print Q(<<"EOF");
-##if (PERL_REVISION == 5 && (PERL_VERSION > 15 || (PERL_VERSION == 15 && PERL_SUBVERSION > 0)))
-##undef XS
-##define XS(name) $xs_impl(name)
-##endif
+##undef XS_EUPXS
+##define XS_EUPXS(name) $xs_impl(name)
 EOF
 }
 
index 378ffd8..003123d 100644 (file)
@@ -3,7 +3,7 @@ use strict;
 use warnings;
 use Symbol;
 
-our $VERSION = '3.04';
+our $VERSION = '3.04_01';
 
 =head1 NAME
 
index c30e8fa..48753f1 100644 (file)
@@ -1,7 +1,7 @@
 package ExtUtils::ParseXS::CountLines;
 use strict;
 
-our $VERSION = '3.04';
+our $VERSION = '3.04_01';
 
 our $SECTION_END_MARKER;
 
index 489b1b4..831bb7b 100644 (file)
@@ -6,7 +6,7 @@ use File::Spec;
 use lib qw( lib );
 use ExtUtils::ParseXS::Constants ();
 
-our $VERSION = '3.04';
+our $VERSION = '3.04_01';
 
 our (@ISA, @EXPORT_OK);
 @ISA = qw(Exporter);
@@ -455,14 +455,88 @@ sub standard_XS_defs {
 #  define PERL_UNUSED_VAR(var) if (0) var = var
 #endif
 
-/* Starting from 5.15.2, XS(name) defines a static function (==internal)
- * and the XS_EXTERNAL macro is used for functions that must not be static
+
+/* This stuff is not part of the API! You have been warned. */
+#ifndef PERL_VERSION_DECIMAL
+#  define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
+#endif
+#ifndef PERL_DECIMAL_VERSION
+#  define PERL_DECIMAL_VERSION \\
+         PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
+#endif
+#ifndef PERL_VERSION_GE
+#  define PERL_VERSION_GE(r,v,s) \\
+         (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
+#endif
+#ifndef PERL_VERSION_LE
+#  define PERL_VERSION_LE(r,v,s) \\
+         (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
+#endif
+
+/* XS_INTERNAL is the explicit static-linkage variant of the default
+ * XS macro.
+ *
+ * XS_EXTERNAL is the same as XS_INTERNAL except it does not include
+ * "STATIC", ie. it exports XSUB symbols. You probably don't want that
+ * for anything but the BOOT XSUB.
+ *
+ * See XSUB.h in core!
+ */
+
+
+/* TODO: This might be compatible further back than 5.10.0. */
+#if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1)
+#  undef XS_EXTERNAL
+#  undef XS_INTERNAL
+#  if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
+#    define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
+#    define XS_INTERNAL(name) __declspec(dllexport) STATIC XSPROTO(name)
+#  endif
+#  if defined(__SYMBIAN32__)
+#    define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
+#    define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
+#  endif
+#  ifndef XS_EXTERNAL
+#    if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
+#      define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
+#      define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
+#    else
+#      ifdef __cplusplus
+#        define XS_EXTERNAL(name) extern "C" XSPROTO(name)
+#        define XS_INTERNAL(name) static XSPROTO(name)
+#      else
+#        define XS_EXTERNAL(name) XSPROTO(name)
+#        define XS_INTERNAL(name) STATIC XSPROTO(name)
+#      endif
+#    endif
+#  endif
+#endif
+
+/* perl >= 5.10.0 && perl <= 5.15.1 */
+
+
+/* The XS_EXTERNAL macro is used for functions that must not be static
  * like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL
  * macro defined, the best we can do is assume XS is the same.
+ * Dito for XS_INTERNAL.
  */
 #ifndef XS_EXTERNAL
 #  define XS_EXTERNAL(name) XS(name)
 #endif
+#ifndef XS_INTERNAL
+#  define XS_INTERNAL(name) XS(name)
+#endif
+
+/* Now, finally, after all this mess, we want an ExtUtils::ParseXS
+ * internal macro that we're free to redefine for varying linkage due
+ * to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use
+ * XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to!
+ */
+
+/* default to internal */
+#undef XS_EUPXS
+#define XS_EUPXS(name) XS_INTERNAL(name)
+
 EOF
 
   print <<"EOF";