Fix directors for Android and improve thread attachment/detachment in multi threading environments

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12868 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2011-12-10 15:00:35 +00:00
commit d9670b608e
2 changed files with 17 additions and 4 deletions

View file

@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.5 (in progress) Version 2.0.5 (in progress)
=========================== ===========================
2011-12-10: wsfulton
[Android/Java] Fix directors to compile on Android.
Added documentation and examples for Android.
2011-12-08: vadz 2011-12-08: vadz
Bug fix: Handle methods renamed or ignored in the base class correctly in the derived classes Bug fix: Handle methods renamed or ignored in the base class correctly in the derived classes
(they could be sometimes mysteriously not renamed or ignored there before). (they could be sometimes mysteriously not renamed or ignored there before).

View file

@ -112,21 +112,29 @@ namespace Swig {
class JNIEnvWrapper { class JNIEnvWrapper {
const Director *director_; const Director *director_;
JNIEnv *jenv_; JNIEnv *jenv_;
int env_status;
public: public:
JNIEnvWrapper(const Director *director) : director_(director), jenv_(0) { JNIEnvWrapper(const Director *director) : director_(director), jenv_(0), env_status(0) {
#if defined(__ANDROID__)
JNIEnv **jenv = &jenv_;
#else
void **jenv = (void **)&jenv_;
#endif
env_status = director_->swig_jvm_->GetEnv((void **)&jenv_, JNI_VERSION_1_2);
#if defined(SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON) #if defined(SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON)
// Attach a daemon thread to the JVM. Useful when the JVM should not wait for // Attach a daemon thread to the JVM. Useful when the JVM should not wait for
// the thread to exit upon shutdown. Only for jdk-1.4 and later. // the thread to exit upon shutdown. Only for jdk-1.4 and later.
director_->swig_jvm_->AttachCurrentThreadAsDaemon((void **) &jenv_, NULL); director_->swig_jvm_->AttachCurrentThreadAsDaemon(jenv, NULL);
#else #else
director_->swig_jvm_->AttachCurrentThread((void **) &jenv_, NULL); director_->swig_jvm_->AttachCurrentThread(jenv, NULL);
#endif #endif
} }
~JNIEnvWrapper() { ~JNIEnvWrapper() {
#if !defined(SWIG_JAVA_NO_DETACH_CURRENT_THREAD) #if !defined(SWIG_JAVA_NO_DETACH_CURRENT_THREAD)
// Some JVMs, eg jdk-1.4.2 and lower on Solaris have a bug and crash with the DetachCurrentThread call. // Some JVMs, eg jdk-1.4.2 and lower on Solaris have a bug and crash with the DetachCurrentThread call.
// However, without this call, the JVM hangs on exit when the thread was not created by the JVM and creates a memory leak. // However, without this call, the JVM hangs on exit when the thread was not created by the JVM and creates a memory leak.
director_->swig_jvm_->DetachCurrentThread(); if (env_status == JNI_EDETACHED)
director_->swig_jvm_->DetachCurrentThread();
#endif #endif
} }
JNIEnv *getJNIEnv() const { JNIEnv *getJNIEnv() const {