diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2020-08-28 18:23:47 +0100 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2020-08-28 18:23:47 +0100 |
commit | b018c32f9d0ba963560fa08da84802c23c41d89d (patch) | |
tree | 2672d566388b5ca1aba3d221b43c5df6c541c237 /Lib/java | |
parent | 70e78d41256be5524f2dfb166abbcb7abdc97b6e (diff) | |
download | swig-b018c32f9d0ba963560fa08da84802c23c41d89d.tar.gz |
Fix crashes in swig_connect_director during director class construction.
Occurs when using the director class from multiple threads - a race condition
initialising block scope static variables.
Block scope static variables are guaranteed to be thread safe in C++11,
so the fix is guaranteed when using C++11. However, most modern compilers
also fix it when using C++03/C++98.
Closes #1862
Diffstat (limited to 'Lib/java')
-rw-r--r-- | Lib/java/director.swg | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/java/director.swg b/Lib/java/director.swg index d3bd162ec..e911a3da7 100644 --- a/Lib/java/director.swg +++ b/Lib/java/director.swg @@ -215,6 +215,15 @@ namespace Swig { } }; + struct SwigDirectorMethod { + const char *name; + const char *desc; + jmethodID methid; + SwigDirectorMethod(JNIEnv *jenv, jclass baseclass, const char *name, const char *desc) : name(name), desc(desc) { + methid = jenv->GetMethodID(baseclass, name, desc); + } + }; + /* Java object wrapper */ JObjectWrapper swig_self_; @@ -238,6 +247,11 @@ namespace Swig { } } + jclass swig_new_global_ref(JNIEnv *jenv, const char *classname) { + jclass clz = jenv->FindClass(classname); + return clz ? (jclass)jenv->NewGlobalRef(clz) : 0; + } + public: Director(JNIEnv *jenv) : swig_jvm_((JavaVM *) NULL), swig_self_() { /* Acquire the Java VM pointer */ |