diff --git a/Doc/Manual/C.html b/Doc/Manual/C.html index 30c7ded2d..7f765f2a7 100644 --- a/Doc/Manual/C.html +++ b/Doc/Manual/C.html @@ -192,7 +192,7 @@ Wrapping C functions and variables is obviously performed in a straightforward w

-For each C function declared in the interface file a wrapper function with a prefix, required to make its name different from the original one, is created. The prefix for the global functions is module_, i.e. the name of the SWIG module followed by underscore. If nspace feature is used, the prefix for a function defined in a namespace is namespace_ -- note that it does not contain the module prefix, as it's not necessary to make a unique function name in this case. The wrapper function performs a call to the original function, and returns its result. For convenience, a #define func prefix_func is also provided in the generated header file to make it possible to call the function under its original name. If this is undesirable, SWIG_NO_WRAPPER_ALIASES can be predefined before including the wrapper header to disable these defines. +For each C function declared in the interface file a wrapper function with a prefix, required to make its name different from the original one, is created. The prefix for the global functions is module_, i.e. the name of the SWIG module followed by underscore. If nspace feature is used, the prefix for a function defined in a namespace is namespace_ -- note that it does not contain the module prefix, as it's not necessary to make a unique function name in this case. The wrapper function performs a call to the original function, and returns its result. For convenience, a #define func prefix_func can be provided in the generated header file to make it possible to call the function under its original name: predefine SWIG_DEFINE_WRAPPER_ALIASES before including the wrapper header to enable these defines, which are disabled by default to avoid accidental name clashes.

diff --git a/Examples/c/exception/runme.c b/Examples/c/exception/runme.c index b4181a5b2..907c0d2d4 100644 --- a/Examples/c/exception/runme.c +++ b/Examples/c/exception/runme.c @@ -5,6 +5,7 @@ #include #include +#define SWIG_DEFINE_WRAPPER_ALIASES #include "example_wrap.h" static void show_exception(const char* prefix) { diff --git a/Examples/c/simple/runme.c b/Examples/c/simple/runme.c index c690ffb98..49a1a8be7 100644 --- a/Examples/c/simple/runme.c +++ b/Examples/c/simple/runme.c @@ -1,5 +1,6 @@ #include +#define SWIG_DEFINE_WRAPPER_ALIASES #include "example_wrap.h" int main(int argc, char **argv) { diff --git a/Examples/test-suite/c/c_backend_cpp_exception_runme.c b/Examples/test-suite/c/c_backend_cpp_exception_runme.c index 314a9ece7..1759e4e31 100644 --- a/Examples/test-suite/c/c_backend_cpp_exception_runme.c +++ b/Examples/test-suite/c/c_backend_cpp_exception_runme.c @@ -1,4 +1,6 @@ #include + +#define SWIG_DEFINE_WRAPPER_ALIASES #include "c_backend_cpp_exception/c_backend_cpp_exception_wrap.h" int main() diff --git a/Examples/test-suite/c/c_backend_cpp_natural_std_string_runme.c b/Examples/test-suite/c/c_backend_cpp_natural_std_string_runme.c index f4ddc4836..b94753fd2 100644 --- a/Examples/test-suite/c/c_backend_cpp_natural_std_string_runme.c +++ b/Examples/test-suite/c/c_backend_cpp_natural_std_string_runme.c @@ -1,6 +1,8 @@ #include #include #include + +#define SWIG_DEFINE_WRAPPER_ALIASES #include "c_backend_cpp_natural_std_string/c_backend_cpp_natural_std_string_wrap.h" int main() diff --git a/Examples/test-suite/c/char_strings_runme.c b/Examples/test-suite/c/char_strings_runme.c index 92edce116..c1c5d89a6 100644 --- a/Examples/test-suite/c/char_strings_runme.c +++ b/Examples/test-suite/c/char_strings_runme.c @@ -2,6 +2,7 @@ #include #include +#define SWIG_DEFINE_WRAPPER_ALIASES #include "char_strings/char_strings_wrap.h" int main() { diff --git a/Examples/test-suite/c/cpp_basic_runme.c b/Examples/test-suite/c/cpp_basic_runme.c index e8397480c..656766479 100644 --- a/Examples/test-suite/c/cpp_basic_runme.c +++ b/Examples/test-suite/c/cpp_basic_runme.c @@ -1,3 +1,4 @@ +#define SWIG_DEFINE_WRAPPER_ALIASES #include "cpp_basic/cpp_basic_wrap.h" #include #include diff --git a/Examples/test-suite/c/cpp_basic_template_function_runme.c b/Examples/test-suite/c/cpp_basic_template_function_runme.c index 51ccdb0cf..2c984ce3e 100644 --- a/Examples/test-suite/c/cpp_basic_template_function_runme.c +++ b/Examples/test-suite/c/cpp_basic_template_function_runme.c @@ -1,4 +1,6 @@ #include + +#define SWIG_DEFINE_WRAPPER_ALIASES #include "cpp_basic_template_function/cpp_basic_template_function_wrap.h" int main() { diff --git a/Examples/test-suite/c/enums_runme.c b/Examples/test-suite/c/enums_runme.c index 00eb03647..6134ab0d6 100644 --- a/Examples/test-suite/c/enums_runme.c +++ b/Examples/test-suite/c/enums_runme.c @@ -1,6 +1,7 @@ #include #include +#define SWIG_DEFINE_WRAPPER_ALIASES #include "enums/enums_wrap.h" int main() { diff --git a/Examples/test-suite/c/exception_order_runme.c b/Examples/test-suite/c/exception_order_runme.c index a6483d86f..5cade5bc8 100644 --- a/Examples/test-suite/c/exception_order_runme.c +++ b/Examples/test-suite/c/exception_order_runme.c @@ -1,6 +1,7 @@ #include #include +#define SWIG_DEFINE_WRAPPER_ALIASES #include "exception_order/exception_order_wrap.h" int main() { diff --git a/Examples/test-suite/c/global_vars_runme.c b/Examples/test-suite/c/global_vars_runme.c index 917b2707e..161413d83 100644 --- a/Examples/test-suite/c/global_vars_runme.c +++ b/Examples/test-suite/c/global_vars_runme.c @@ -4,7 +4,7 @@ int main(int argc, const char *argv[]) { - init(); + global_vars_init(); assert(strcmp(b_get(), "string b") == 0); assert(x == 1234); diff --git a/Examples/test-suite/c/li_std_pair_runme.c b/Examples/test-suite/c/li_std_pair_runme.c index fbd41feea..c163a5177 100644 --- a/Examples/test-suite/c/li_std_pair_runme.c +++ b/Examples/test-suite/c/li_std_pair_runme.c @@ -1,3 +1,4 @@ +#define SWIG_DEFINE_WRAPPER_ALIASES #include "li_std_pair/li_std_pair_wrap.h" #include diff --git a/Examples/test-suite/c/operator_overload_runme.c b/Examples/test-suite/c/operator_overload_runme.c index ed0c8e450..7e7acb646 100644 --- a/Examples/test-suite/c/operator_overload_runme.c +++ b/Examples/test-suite/c/operator_overload_runme.c @@ -1,6 +1,7 @@ #include #include +#define SWIG_DEFINE_WRAPPER_ALIASES #include "operator_overload/operator_overload_wrap.h" #define assert(x,msg) if (!x) { printf("%d: %s\n", x, msg); exit(1); } diff --git a/Source/Modules/c.cxx b/Source/Modules/c.cxx index 8d6751867..61ffedd31 100644 --- a/Source/Modules/c.cxx +++ b/Source/Modules/c.cxx @@ -476,9 +476,8 @@ public: f_wrappers_types = NewString(""); f_wrappers_decl = NewString(""); - // We also define aliases for the global wrapper functions to allow calling them using their original names, but as this can result in problems (as usual - // when using the preprocessor), we provide a way to disable this by defining SWIG_NO_WRAPPER_ALIASES when compiling the generated code and so we use a - // separate section for this too. + // We may also define aliases for the global wrapper functions to allow calling them using their original names, but as this can result in problems (as + // usual when using the preprocessor), this is only done when SWIG_DEFINE_WRAPPER_ALIASES is defined, so use a separate section for this. f_wrappers_aliases = NIL; { @@ -504,7 +503,7 @@ public: Dump(f_wrappers_aliases, f_wrappers_h); Delete(f_wrappers_aliases); - Printv(f_wrappers_h, "#endif /* SWIG_NO_WRAPPER_ALIASES */\n", NIL); + Printv(f_wrappers_h, "#endif /* SWIG_DEFINE_WRAPPER_ALIASES */\n", NIL); } } // close wrapper header guard @@ -903,7 +902,7 @@ public: if (!f_wrappers_aliases) { // Allocate it on demand. f_wrappers_aliases = NewStringEmpty(); - Printv(f_wrappers_aliases, "#ifndef SWIG_NO_WRAPPER_ALIASES\n", NIL); + Printv(f_wrappers_aliases, "#ifdef SWIG_DEFINE_WRAPPER_ALIASES\n", NIL); } Printf(f_wrappers_aliases, "#define %s %s\n", name, wname);