This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Need to quote the version number of perl in perlivp, now
[perl5.git] / XSUB.h
diff --git a/XSUB.h b/XSUB.h
index f7d04a8..a149115 100644 (file)
--- a/XSUB.h
+++ b/XSUB.h
@@ -96,32 +96,44 @@ is a lexical $_ in scope.
 
 #define ST(off) PL_stack_base[ax + (off)]
 
+/* XSPROTO() is also used by SWIG like this:
+ *
+ *     typedef XSPROTO(SwigPerlWrapper);
+ *     typedef SwigPerlWrapper *SwigPerlWrapperPtr;
+ *
+ * This code needs to be compilable under both C and C++.
+ *
+ * Don't forget to change the __attribute__unused__ version of XS()
+ * below too if you change XSPROTO() here.
+ */
+#define XSPROTO(name) void name(pTHX_ CV* cv)
+
 #undef XS
 #if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
-#  define XS(name) __declspec(dllexport) void name(pTHX_ CV* cv)
+#  define XS(name) __declspec(dllexport) XSPROTO(name)
 #endif
 #if defined(__SYMBIAN32__)
-#  define XS(name) EXPORT_C void name(pTHX_ CV* cv)
+#  define XS(name) EXPORT_C XSPROTO(name)
 #endif
 #ifndef XS
 #  if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
 #    define XS(name) void name(pTHX_ CV* cv __attribute__unused__)
 #  else
 #    ifdef __cplusplus
-#      define XS(name) extern "C" void name(pTHX_ CV* cv)
+#      define XS(name) extern "C" XSPROTO(name)
 #    else
-#      define XS(name) void name(pTHX_ CV* cv)
+#      define XS(name) XSPROTO(name)
 #    endif
 #  endif
 #endif
 
-#define dAX const I32 ax = MARK - PL_stack_base + 1
+#define dAX const I32 ax = (I32)(MARK - PL_stack_base + 1)
 
 #define dAXMARK                                \
        I32 ax = POPMARK;       \
        register SV **mark = PL_stack_base + ax++
 
-#define dITEMS I32 items = SP - MARK
+#define dITEMS I32 items = (I32)(SP - MARK)
 
 #if defined(lint) && defined(S_SPLINT_S) /* www.splint.org */
 #  define dXSARGS \
@@ -144,11 +156,13 @@ is a lexical $_ in scope.
 
 #ifdef __cplusplus
 #  define XSINTERFACE_CVT(ret,name) ret (*name)(...)
+#  define XSINTERFACE_CVT_ANON(ret) ret (*)(...)
 #else
 #  define XSINTERFACE_CVT(ret,name) ret (*name)()
+#  define XSINTERFACE_CVT_ANON(ret) ret (*)()
 #endif
 #define dXSFUNCTION(ret)               XSINTERFACE_CVT(ret,XSFUNCTION)
-#define XSINTERFACE_FUNC(ret,cv,f)     ((XSINTERFACE_CVT(ret,))(f))
+#define XSINTERFACE_FUNC(ret,cv,f)     ((XSINTERFACE_CVT_ANON(ret))(f))
 #define XSINTERFACE_FUNC_SET(cv,f)     \
                CvXSUBANY(cv).any_dxptr = (void (*) (pTHX_ void*))(f)
 
@@ -262,7 +276,7 @@ Rethrows a previously caught exception.  See L<perlguts/"Exception Handling">.
 
 #define XSRETURN(off)                                  \
     STMT_START {                                       \
-       IV tmpXSoff = (off);                            \
+       const IV tmpXSoff = (off);                      \
        PL_stack_sp = PL_stack_base + ax + (tmpXSoff - 1);      \
        return;                                         \
     } STMT_END