summaryrefslogtreecommitdiff
path: root/XSUB.h
diff options
context:
space:
mode:
authorSteffen Mueller <smueller@cpan.org>2011-08-11 13:21:05 +0200
committerSteffen Mueller <smueller@cpan.org>2011-08-11 13:21:05 +0200
commite64345f82d66a32f6da47acf482e7e6c9282b433 (patch)
tree45b83f2edfaedc9a1ee543327344546d4f23a2ee /XSUB.h
parent5179f97822e5dcfebaf2a3fb412a1523d4009429 (diff)
downloadperl-e64345f82d66a32f6da47acf482e7e6c9282b433.tar.gz
API to explicitly select to export XSUB symbols or not
This adds a few additional macros to XSUB.h: XS_INTERNAL and XS_EXTERNAL are versions of the XS macro that explicitly use internal (static) linking or not. XSPROTO_INTERNAL and XSPROTO_EXTERNAL are the obvious equivalents for XSPROTO (which is apparently not public yet we support its use in SWIG...). The XS and XSPROTO macros themselves are not defined to not use STATIC, but this may (should?) be changed in the future.
Diffstat (limited to 'XSUB.h')
-rw-r--r--XSUB.h48
1 files changed, 41 insertions, 7 deletions
diff --git a/XSUB.h b/XSUB.h
index 5b5e3c81d2..630fe7c4dd 100644
--- a/XSUB.h
+++ b/XSUB.h
@@ -50,6 +50,15 @@ Used to access elements on the XSUB's stack.
Macro to declare an XSUB and its C parameter list. This is handled by
C<xsubpp>.
+=for apidoc AmU||XS_INTERNAL
+Macro to declare an XSUB and its C parameter list without exporting the symbols.
+This is handled by C<xsubpp> and generally preferable over exporting the XSUB
+symbols unnecessarily. This is handled by C<xsubpp>.
+
+=for apidoc AmU||XS_EXTERNAL
+Macro to declare an XSUB and its C parameter list explicitly exporting the symbols.
+This is handled by C<xsubpp>.
+
=for apidoc Ams||dAX
Sets up the C<ax> variable.
This is usually handled automatically by C<xsubpp> by calling C<dXSARGS>.
@@ -107,27 +116,52 @@ is a lexical $_ in scope.
* 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)
+
+/* XSPROTO_INTERNAL and XS_INTERNAL are the static-linkage variants
+ * of the default XSPROTO/XS macros. They are enabled by
+ * a special XS verb that is still tbd.
+ *
+ * XSPROTO_EXTERNAL/XS_EXTERNAL are (for now) exactly the same as
+ * XSPROTO/XS, but if the default wrt. linkage changes in future, they
+ * will allow users to explicitly mark XSUBs for exporting their
+ * symbols.
+ */
+
+#define XSPROTO_EXTERNAL(name) void name(pTHX_ CV* cv)
+#define XSPROTO_INTERNAL(name) STATIC void name(pTHX_ CV* cv)
+#define XSPROTO(name) XSPROTO_EXTERNAL(name)
#undef XS
+#undef XS_EXTERNAL
+#undef XS_INTERNAL
#if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
-# define XS(name) __declspec(dllexport) XSPROTO(name)
+# define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO_EXTERNAL(name)
+# define XS_INTERNAL(name) __declspec(dllexport) XSPROTO_INTERNAL(name)
#endif
#if defined(__SYMBIAN32__)
-# define XS(name) EXPORT_C XSPROTO(name)
+# define XS_EXTERNAL(name) EXPORT_C XSPROTO_EXTERNAL(name)
+# define XS_INTERNAL(name) EXPORT_C XSPROTO_INTERNAL(name)
#endif
-#ifndef XS
+#ifndef XS_EXTERNAL
# if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
-# define XS(name) void name(pTHX_ CV* cv __attribute__unused__)
+# 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(name) extern "C" XSPROTO(name)
+# define XS_EXTERNAL(name) extern "C" XSPROTO_EXTERNAL(name)
+# define XS_INTERNAL(name) extern "C" XSPROTO_INTERNAL(name)
# else
-# define XS(name) XSPROTO(name)
+# define XS_EXTERNAL(name) XSPROTO_EXTERNAL(name)
+# define XS_INTERNAL(name) XSPROTO_INTERNAL(name)
# endif
# endif
#endif
+/* We currently default to exporting XSUB symbols */
+#define XS(name) XS_EXTERNAL(name)
+/* Apparently needed for SWIG: */
+#define XSPROTO(name) XSPROTO_EXTERNAL(name)
+
#define dAX const I32 ax = (I32)(MARK - PL_stack_base + 1)
#define dAXMARK \