From c7fa9126ce2abf6c8ba5799380c3415972d541dc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 26 Nov 2021 02:34:09 +0100 Subject: [PATCH] Use a unique prefix for SWIG_CException_Raise() This allows using different modules generated by SWIG in the same process without conflicts. --- Source/Modules/c.cxx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/Modules/c.cxx b/Source/Modules/c.cxx index 19083e1b8..8a47e8ac7 100644 --- a/Source/Modules/c.cxx +++ b/Source/Modules/c.cxx @@ -1390,6 +1390,14 @@ public: // Deal with exceptions support. if (exceptions_support_ == exceptions_support_enabled) { + // Redefine SWIG_CException_Raise() to have a unique prefix in the shared library built from SWIG-generated sources to allow using more than one extension + // in the same process without conflicts. This has to be done in this hackish way because we really need to change the name of the function itself, not + // its wrapper (which is not even generated). + Printv(f_runtime, + "#define SWIG_CException_Raise ", (ns_prefix ? ns_prefix : module_name), "_SWIG_CException_Raise\n", + NIL + ); + // We need to check if we have any %imported modules, as they would already define the exception support code and we want to have exactly one copy of it // in the generated shared library, so check for "import" nodes. if (find_first_named_import(n)) {