summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2022-07-20 15:05:21 +1200
committerOlly Betts <olly@survex.com>2022-10-05 12:40:15 +1300
commit4ac3c87a299368e22151bac3cae11e62cf23c730 (patch)
tree76d861abb572d942429d3d71999db138b4ecca0e /Lib
parentabc1c59c4e67f912c409a2bb6b8f70f0e2809c9e (diff)
downloadswig-4ac3c87a299368e22151bac3cae11e62cf23c730.tar.gz
Sort out predefined SWIG-specific macros
Ensure that SWIG_VERSION is defined both at SWIG-time and in the generated C/C++ wrapper code (it was only defined in the wrapper for some target languages previously). SWIGGO and SWIGJAVASCRIPT are now defined in the generated wrappers to match behaviour for all other target languages. Stop defining SWIGVERSION in the wrapper. This only happened as a side-effect of how SWIG_VERSION was defined but was never documented and is redundant. The new testcase also checks that SWIG is defined at SWIG-time but not in the generated wrapper, and that exactly one of a list of target-language specific macros is defined. Fixes #1050
Diffstat (limited to 'Lib')
-rw-r--r--Lib/csharp/csharp.swg2
-rw-r--r--Lib/go/go.swg2
-rw-r--r--Lib/guile/guile.i2
-rw-r--r--Lib/java/java.swg2
-rw-r--r--Lib/lua/lua.swg2
-rw-r--r--Lib/mzscheme/mzscheme.swg2
-rw-r--r--Lib/ocaml/ocaml.i2
-rw-r--r--Lib/php/php.swg2
-rw-r--r--Lib/typemaps/README1
-rw-r--r--Lib/typemaps/swigmacros.swg10
-rw-r--r--Lib/typemaps/swigversion.swg17
11 files changed, 35 insertions, 9 deletions
diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg
index 1f80d12a1..8514a7705 100644
--- a/Lib/csharp/csharp.swg
+++ b/Lib/csharp/csharp.swg
@@ -4,6 +4,8 @@
* C# typemaps
* ----------------------------------------------------------------------------- */
+%include <typemaps/swigversion.swg>
+
%include <csharphead.swg>
/* The ctype, imtype and cstype typemaps work together and so there should be one of each.
diff --git a/Lib/go/go.swg b/Lib/go/go.swg
index 348ae5f0d..47486ab75 100644
--- a/Lib/go/go.swg
+++ b/Lib/go/go.swg
@@ -4,6 +4,8 @@
* Go configuration module.
* ------------------------------------------------------------ */
+%include <typemaps/swigversion.swg>
+
%include <gostring.swg>
/* Code insertion directives */
diff --git a/Lib/guile/guile.i b/Lib/guile/guile.i
index ef270d74b..10438f483 100644
--- a/Lib/guile/guile.i
+++ b/Lib/guile/guile.i
@@ -4,6 +4,8 @@
* SWIG Configuration File for Guile.
* ----------------------------------------------------------------------------- */
+%include <typemaps/swigversion.swg>
+
/* Macro for inserting Scheme code into the stub */
#define %scheme %insert("scheme")
#define %goops %insert("goops")
diff --git a/Lib/java/java.swg b/Lib/java/java.swg
index 8719818bb..28eb8fd0d 100644
--- a/Lib/java/java.swg
+++ b/Lib/java/java.swg
@@ -4,6 +4,8 @@
* Java typemaps
* ----------------------------------------------------------------------------- */
+%include <typemaps/swigversion.swg>
+
%include <javahead.swg>
/* The jni, jtype and jstype typemaps work together and so there should be one of each.
diff --git a/Lib/lua/lua.swg b/Lib/lua/lua.swg
index 12c635d77..263c3966f 100644
--- a/Lib/lua/lua.swg
+++ b/Lib/lua/lua.swg
@@ -5,6 +5,8 @@
* This file is parsed by SWIG before reading any other interface file.
* ----------------------------------------------------------------------------- */
+%include <typemaps/swigversion.swg>
+
/* -----------------------------------------------------------------------------
* includes
* ----------------------------------------------------------------------------- */
diff --git a/Lib/mzscheme/mzscheme.swg b/Lib/mzscheme/mzscheme.swg
index f45c87250..8ded91f3e 100644
--- a/Lib/mzscheme/mzscheme.swg
+++ b/Lib/mzscheme/mzscheme.swg
@@ -5,6 +5,8 @@
* This file is parsed by SWIG before reading any other interface file.
* ----------------------------------------------------------------------------- */
+%include <typemaps/swigversion.swg>
+
/* Include headers */
%runtime "swigrun.swg" // Common C API type-checking code
%runtime "swigerrors.swg" // SWIG errors
diff --git a/Lib/ocaml/ocaml.i b/Lib/ocaml/ocaml.i
index cc26d1859..117d0a9b5 100644
--- a/Lib/ocaml/ocaml.i
+++ b/Lib/ocaml/ocaml.i
@@ -4,6 +4,8 @@
* SWIG Configuration File for Ocaml
* ----------------------------------------------------------------------------- */
+%include <typemaps/swigversion.swg>
+
/* Insert common stuff */
%insert(runtime) "swigrun.swg"
diff --git a/Lib/php/php.swg b/Lib/php/php.swg
index 04b7075b7..b22166593 100644
--- a/Lib/php/php.swg
+++ b/Lib/php/php.swg
@@ -4,6 +4,8 @@
* PHP configuration file
* ----------------------------------------------------------------------------- */
+%include <typemaps/swigversion.swg>
+
// Default to generating PHP type declarations (for PHP >= 8) except for
// cases which are liable to cause compatibility issues with existing
// bindings.
diff --git a/Lib/typemaps/README b/Lib/typemaps/README
index 65134578d..22a0fc0bb 100644
--- a/Lib/typemaps/README
+++ b/Lib/typemaps/README
@@ -48,6 +48,7 @@ std_strings.swg Common macros to implemented the std::string/std::wstring typem
strings.swg Common macros and typemaps for string and wstring (char *, wchar_t *)
swigmacros.swg Basic macros
+swigversion.swg Define SWIG_VERSION
fragments.swg Macros for fragment manipulations
diff --git a/Lib/typemaps/swigmacros.swg b/Lib/typemaps/swigmacros.swg
index 687b0680e..7db6871d4 100644
--- a/Lib/typemaps/swigmacros.swg
+++ b/Lib/typemaps/swigmacros.swg
@@ -109,15 +109,7 @@ nocppval
#endif
%enddef
-/* insert the SWIGVERSION in the interface and the wrapper code */
-#if SWIG_VERSION
-%insert("header") {
-%define_as(SWIGVERSION, SWIG_VERSION)
-%#define SWIG_VERSION SWIGVERSION
-}
-#endif
-
-
+%include <typemaps/swigversion.swg>
/* -----------------------------------------------------------------------------
* Casting operators
diff --git a/Lib/typemaps/swigversion.swg b/Lib/typemaps/swigversion.swg
new file mode 100644
index 000000000..18f897cad
--- /dev/null
+++ b/Lib/typemaps/swigversion.swg
@@ -0,0 +1,17 @@
+/* -----------------------------------------------------------------------------
+ * Define SWIG_VERSION
+ * ----------------------------------------------------------------------------- */
+
+/* Define SWIG_VERSION in the interface and the wrapper code.
+ *
+ * Best practice is to use SWIG-time checks for SWIG_VERSION, but SWIG_VERSION
+ * was unintentionally defined like this for many years, and while it was never
+ * documented there are likely user interface files which rely on it.
+ */
+%define %define_swig_version_()%#define SWIG_VERSION_ SWIG_VERSION %enddef
+%insert("header") {
+%define_swig_version_()
+%#define SWIG_VERSION SWIG_VERSION_
+%#undef SWIG_VERSION_
+}
+#undef %define_swig_version_