Cleanup SWIG_VERSION definition

Add Swig_obligatory_macros which must be called by each
target language to define SWIG_VERSION correctly
in the generated code, as well as the language specific
macro SWIGXXX where XXX is the target language name.

Drop the #ifdef SWIGXXX that was previously generated -
I can't see the point of this and if users are defining
this macro somehow, then users will need to change this

Closes #1050
This commit is contained in:
William S Fulton 2022-10-13 19:46:51 +01:00
commit 46f7501d94
31 changed files with 68 additions and 76 deletions

View file

@ -399,7 +399,7 @@ public:
Swig_banner(f_begin);
Printf(f_runtime, "\n\n#ifndef SWIGCSHARP\n#define SWIGCSHARP\n#endif\n\n");
Swig_obligatory_macros(f_runtime, "CSHARP");
if (directorsEnabled()) {
Printf(f_runtime, "#define SWIG_DIRECTORS\n");

View file

@ -472,7 +472,7 @@ public:
Swig_banner(f_begin);
Printf(f_runtime, "\n\n#ifndef SWIGD\n#define SWIGD\n#endif\n\n");
Swig_obligatory_macros(f_runtime, "D");
if (directorsEnabled()) {
Printf(f_runtime, "#define SWIG_DIRECTORS\n");

View file

@ -512,6 +512,9 @@ private:
Swig_register_filebyname("cgo_comment_typedefs", f_cgo_comment_typedefs);
Swig_banner(f_c_begin);
Swig_obligatory_macros(f_c_runtime, "GO");
if (CPlusPlus) {
Printf(f_c_begin, "\n// source: %s\n\n", swig_filename);
} else {
@ -519,7 +522,6 @@ private:
}
Printf(f_c_runtime, "#define SWIGMODULE %s\n", module);
Printf(f_c_runtime, "#ifndef SWIGGO\n#define SWIGGO\n#endif\n\n");
if (gccgo_flag) {
Printf(f_c_runtime, "#define SWIGGO_PREFIX %s\n", go_prefix);

View file

@ -321,7 +321,7 @@ public:
Swig_banner(f_begin);
Printf(f_runtime, "\n\n#ifndef SWIGGUILE\n#define SWIGGUILE\n#endif\n\n");
Swig_obligatory_macros(f_runtime, "GUILE");
/* Write out directives and declarations */

View file

@ -456,7 +456,7 @@ public:
Swig_banner(f_begin);
Printf(f_runtime, "\n\n#ifndef SWIGJAVA\n#define SWIGJAVA\n#endif\n\n");
Swig_obligatory_macros(f_runtime, "JAVA");
if (directorsEnabled()) {
Printf(f_runtime, "#define SWIG_DIRECTORS\n");

View file

@ -1615,7 +1615,7 @@ int JSCEmitter::initialize(Node *n) {
Swig_banner(f_wrap_cpp);
Printf(f_runtime, "#ifndef SWIGJAVASCRIPT\n#define SWIGJAVASCRIPT\n#endif\n\n");
Swig_obligatory_macros(f_runtime, "JAVASCRIPT");
return SWIG_OK;
}
@ -1947,7 +1947,7 @@ int V8Emitter::initialize(Node *n) {
Swig_banner(f_wrap_cpp);
Printf(f_runtime, "#ifndef SWIGJAVASCRIPT\n#define SWIGJAVASCRIPT\n#endif\n\n");
Swig_obligatory_macros(f_runtime, "JAVASCRIPT");
return SWIG_OK;
}

View file

@ -329,7 +329,7 @@ public:
/* Standard stuff for the SWIG runtime section */
Swig_banner(f_begin);
Printf(f_runtime, "\n\n#ifndef SWIGLUA\n#define SWIGLUA\n#endif\n\n");
Swig_obligatory_macros(f_runtime, "LUA");
emitLuaFlavor(f_runtime);

View file

@ -911,25 +911,11 @@ int SWIG_main(int argc, char *argv[], const TargetLanguageModule *tlm) {
Preprocessor_define((DOH *) "SWIG 1", 0);
Preprocessor_define((DOH *) "__STDC__", 0);
// Set the SWIG version value in format 0xAABBCC from package version expected to be in format A.B.C
String *package_version = NewString(PACKAGE_VERSION); /* Note that the fakeversion has not been set at this point */
char *token = strtok(Char(package_version), ".");
String *vers = NewString("SWIG_VERSION 0x");
int count = 0;
while (token) {
int len = (int)strlen(token);
assert(len == 1 || len == 2);
Printf(vers, "%s%s", (len == 1) ? "0" : "", token);
token = strtok(NULL, ".");
count++;
}
Delete(package_version);
assert(count == 3); // Check version format is correct
/* Turn on contracts */
String *vers = Swig_package_version_hex();
Preprocessor_define(vers, 0);
Delete(vers);
Swig_contract_mode_set(1);
Preprocessor_define(vers, 0);
/* Turn off directors mode */
Wrapper_director_mode_set(0);

View file

@ -147,7 +147,7 @@ public:
Swig_banner(f_begin);
Printf(f_runtime, "\n\n#ifndef SWIGMZSCHEME\n#define SWIGMZSCHEME\n#endif\n\n");
Swig_obligatory_macros(f_runtime, "MZSCHEME");
module = Getattr(n, "name");

View file

@ -276,7 +276,7 @@ public:
Swig_banner(f_begin);
Printf(f_runtime, "\n\n#ifndef SWIGOCAML\n#define SWIGOCAML\n#endif\n\n");
Swig_obligatory_macros(f_runtime, "OCAML");
Printf(f_runtime, "#define SWIG_MODULE \"%s\"\n", module);
/* Module name */

View file

@ -190,7 +190,7 @@ public:
Swig_banner(f_begin);
Printf(f_runtime, "\n\n#ifndef SWIGOCTAVE\n#define SWIGOCTAVE\n#endif\n\n");
Swig_obligatory_macros(f_runtime, "OCTAVE");
Printf(f_runtime, "#define SWIG_name_d \"%s\"\n", module);
Printf(f_runtime, "#define SWIG_name %s\n", module);

View file

@ -319,7 +319,7 @@ public:
Swig_banner(f_begin);
Printf(f_runtime, "\n\n#ifndef SWIGPERL\n#define SWIGPERL\n#endif\n\n");
Swig_obligatory_macros(f_runtime, "PERL");
if (directorsEnabled()) {
Printf(f_runtime, "#define SWIG_DIRECTORS\n");

View file

@ -609,6 +609,12 @@ public:
Swig_banner(f_begin);
Swig_obligatory_macros(f_runtime, "PHP");
if (directorsEnabled()) {
Printf(f_runtime, "#define SWIG_DIRECTORS\n");
}
// We need to include php.h before string.h gets included, at least with
// PHP 8.2. Otherwise string.h is included without _GNU_SOURCE being
// included and memrchr() doesn't get declared, and then inline code in
@ -636,12 +642,6 @@ public:
"# endif\n"
"#endif\n\n");
Printf(f_runtime, "#ifndef SWIGPHP\n#define SWIGPHP\n#endif\n\n");
if (directorsEnabled()) {
Printf(f_runtime, "#define SWIG_DIRECTORS\n");
}
/* Set the module name */
module = Copy(Getattr(n, "name"));
cap_module = NewStringf("%(upper)s", module);

View file

@ -587,7 +587,7 @@ public:
Swig_banner(f_begin);
Printf(f_runtime, "\n\n#ifndef SWIGPYTHON\n#define SWIGPYTHON\n#endif\n\n");
Swig_obligatory_macros(f_runtime, "PYTHON");
if (directorsEnabled()) {
Printf(f_runtime, "#define SWIG_DIRECTORS\n");

View file

@ -740,8 +740,7 @@ int R::top(Node *n) {
Swig_banner(f_begin);
Printf(f_runtime, "\n\n#ifndef SWIGR\n#define SWIGR\n#endif\n\n");
Swig_obligatory_macros(f_runtime, "R");
Swig_banner_target_lang(s_init, "#");
outputCommandLineArguments(s_init);

View file

@ -1087,7 +1087,7 @@ public:
Swig_banner(f_begin);
Printf(f_runtime, "\n\n#ifndef SWIGRUBY\n#define SWIGRUBY\n#endif\n\n");
Swig_obligatory_macros(f_runtime, "RUBY");
if (directorsEnabled()) {
Printf(f_runtime, "#define SWIG_DIRECTORS\n");

View file

@ -200,7 +200,7 @@ public:
/* Output module initialization code */
Swig_banner(beginSection);
Printf(runtimeSection, "\n\n#ifndef SWIGSCILAB\n#define SWIGSCILAB\n#endif\n\n");
Swig_obligatory_macros(runtimeSection, "SCILAB");
// Gateway header source merged with wrapper source in nobuilder mode
if (!generateBuilder)

View file

@ -161,7 +161,7 @@ public:
Swig_banner(f_begin);
Printf(f_runtime, "\n\n#ifndef SWIGTCL\n#define SWIGTCL\n#endif\n\n");
Swig_obligatory_macros(f_runtime, "TCL");
/* Set the module name, namespace, and prefix */