Make global SWIG_CException::PendingException thread-local
This allows different threads to use the same library concurrently without corrupting each other's exceptions. Note that this requires C++11 support for wrapper compilation too. If this really turns out to be a problem, we could always just #define thread_local as compiler-specific equivalent such as "__thread" for gcc or "__declspec(thread)" for MSVC, which are available since forever.
This commit is contained in:
parent
c7fa9126ce
commit
38b76bb7c6
1 changed files with 2 additions and 2 deletions
|
|
@ -40,7 +40,7 @@ public:
|
||||||
private:
|
private:
|
||||||
friend void SWIG_CException_Raise(int code, const char* msg);
|
friend void SWIG_CException_Raise(int code, const char* msg);
|
||||||
|
|
||||||
static SWIG_CException* PendingException;
|
static thread_local SWIG_CException* PendingException;
|
||||||
|
|
||||||
SWIG_CException(int code, const char* msg) : code(code), msg(strdup(msg)) { }
|
SWIG_CException(int code, const char* msg) : code(code), msg(strdup(msg)) { }
|
||||||
~SWIG_CException() { free(const_cast<char*>(msg)); }
|
~SWIG_CException() { free(const_cast<char*>(msg)); }
|
||||||
|
|
@ -53,7 +53,7 @@ private:
|
||||||
// This part is implementation only and doesn't need to be seen by SWIG.
|
// This part is implementation only and doesn't need to be seen by SWIG.
|
||||||
%{
|
%{
|
||||||
#ifndef SWIG_CException_DEFINED
|
#ifndef SWIG_CException_DEFINED
|
||||||
SWIG_CException *SWIG_CException::PendingException = 0;
|
thread_local SWIG_CException *SWIG_CException::PendingException = 0;
|
||||||
|
|
||||||
SWIGEXPORTC void SWIG_CException_Raise(int code, const char* msg) {
|
SWIGEXPORTC void SWIG_CException_Raise(int code, const char* msg) {
|
||||||
delete SWIG_CException::PendingException;
|
delete SWIG_CException::PendingException;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue