From: Цветко Л. <flo...@gm...> - 2011-10-12 09:06:03
|
Hi, I am currently using SWIG under cygwin/MacOS in an android project. I use SWIG to wrap my C++ classes in java. Lately, I've been adding callback/listeners classes. At this occasion, I've discovered the existence of directors feature. It's very nice, but I have three issues with it, it's the use of dynamic_cast (no rtti under Android), the use of AttachCurrentThread/DetachCurrentThread which would detach a thread that was not attached by SWIG directors and a small issue with non-standard jni headers (signature of AttachCurrentThread). I managed to patch Swig's "java/director.swg" file in "/usr/share/swig/..." What I would like to know is how can I instruct Swig to use the "director.swg" file from my source tree instead of the default one from "/usr/share/swig" so I don't have to patch swig installed files on each developer's computer. Thanks for any help, Florent Lagaye. |
From: William S F. <ws...@fu...> - 2011-10-13 06:15:26
|
On 12/10/11 10:05, Цветко ЛАГАЈОВИЋ wrote: > Hi, > > I am currently using SWIG under cygwin/MacOS in an android project. I > use SWIG to wrap my C++ classes in java. > > Lately, I've been adding callback/listeners classes. At this occasion, > I've discovered the existence of directors feature. > > It's very nice, but I have three issues with it, it's the use of > dynamic_cast (no rtti under Android), the use of > AttachCurrentThread/DetachCurrentThread which would detach a thread that > was not attached by SWIG directors and a small issue with non-standard > jni headers (signature of AttachCurrentThread). > > I managed to patch Swig's "java/director.swg" file in > "/usr/share/swig/..." What I would like to know is how can I instruct > Swig to use the "director.swg" file from my source tree instead of the > default one from "/usr/share/swig" so I don't have to patch swig > installed files on each developer's computer. > > Thanks for any help, Please post a patch with the changes that you have in place and I'll look at putting these in to the official version of SWIG with some suitable macro to enable. Is there a macro indicating an Android JDK rather than a normal JDK that could be used? Use swig -v to display the paths that it looks for files in. The ./swig_lib/java directory is probably the best place to put in your own version of director.swg. William |
From: Цветко Л. <flo...@gm...> - 2011-10-13 13:09:37
|
On Thu, Oct 13, 2011 at 8:15 AM, William S Fulton <ws...@fu...>wrote: > On 12/10/11 10:05, Цветко ЛАГАЈОВИЋ wrote: > >> Hi, >> >> I am currently using SWIG under cygwin/MacOS in an android project. I >> use SWIG to wrap my C++ classes in java. >> >> Lately, I've been adding callback/listeners classes. At this occasion, >> I've discovered the existence of directors feature. >> >> It's very nice, but I have three issues with it, it's the use of >> dynamic_cast (no rtti under Android), the use of >> AttachCurrentThread/**DetachCurrentThread which would detach a thread >> that >> was not attached by SWIG directors and a small issue with non-standard >> jni headers (signature of AttachCurrentThread). >> >> I managed to patch Swig's "java/director.swg" file in >> "/usr/share/swig/..." What I would like to know is how can I instruct >> Swig to use the "director.swg" file from my source tree instead of the >> default one from "/usr/share/swig" so I don't have to patch swig >> installed files on each developer's computer. >> >> Thanks for any help, >> > > Please post a patch with the changes that you have in place and I'll look > at putting these in to the official version of SWIG with some suitable macro > to enable. Is there a macro indicating an Android JDK rather than a normal > JDK that could be used? > > Use swig -v to display the paths that it looks for files in. The > ./swig_lib/java directory is probably the best place to put in your own > version of director.swg. > > William > Hi William, thanks for your answer. Here is the result of a diff between original director.swg and patched one: 1a2,4 > * See the LICENSE file for information on copyright, usage and redistribution > * of SWIG, and the README file for authors - http://www.swig.org/release.html . > * 114a118,119 > int env_status; > JNIEnv *g_env; 116a122,123 > > env_status = director_->swig_jvm_->GetEnv((void **)&g_env, JNI_VERSION_1_6); 118c125 < // 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 120c127 < director_->swig_jvm_->AttachCurrentThreadAsDaemon((void **) &jenv_, NULL); --- > director_->swig_jvm_->AttachCurrentThreadAsDaemon( &jenv_, NULL); 122c129 < director_->swig_jvm_->AttachCurrentThread((void **) &jenv_, NULL); --- > director_->swig_jvm_->AttachCurrentThread( &jenv_, NULL); 129c136,144 < director_->swig_jvm_->DetachCurrentThread(); --- > > if( env_status == JNI_EDETACHED ){ > director_->swig_jvm_->DetachCurrentThread(); > > } > I don't know of a macro that would be used by android's jni includes (I had a look in the jni.h file and did not see anything relevant). But maybe there's one. Regards, Florent Lagaye. |
From: William S F. <ws...@fu...> - 2011-12-15 20:26:35
|
On 13/10/11 14:09, Цветко ЛАГАЈОВИЋ wrote: > On Thu, Oct 13, 2011 at 8:15 AM, William S Fulton > <ws...@fu... <mailto:ws...@fu...>> wrote: > > On 12/10/11 10:05, Цветко ЛАГАЈОВИЋ wrote: > > Hi, > > I am currently using SWIG under cygwin/MacOS in an android > project. I > use SWIG to wrap my C++ classes in java. > > Lately, I've been adding callback/listeners classes. At this > occasion, > I've discovered the existence of directors feature. > > It's very nice, but I have three issues with it, it's the use of > dynamic_cast (no rtti under Android), the use of > AttachCurrentThread/__DetachCurrentThread which would detach a > thread that > was not attached by SWIG directors and a small issue with > non-standard > jni headers (signature of AttachCurrentThread). > > I managed to patch Swig's "java/director.swg" file in > "/usr/share/swig/..." What I would like to know is how can I > instruct > Swig to use the "director.swg" file from my source tree instead > of the > default one from "/usr/share/swig" so I don't have to patch swig > installed files on each developer's computer. > > Thanks for any help, > > > Please post a patch with the changes that you have in place and I'll > look at putting these in to the official version of SWIG with some > suitable macro to enable. Is there a macro indicating an Android JDK > rather than a normal JDK that could be used? > > Use swig -v to display the paths that it looks for files in. The > ./swig_lib/java directory is probably the best place to put in your > own version of director.swg. > > William > > Hi William, thanks for your answer. > > Here is the result of a diff between original director.swg and patched one: > > 1a2,4 > > * See the LICENSE file for information on copyright, usage and > redistribution > > * of SWIG, and the README file for authors - > http://www.swig.org/release.html . > > * > 114a118,119 > > int env_status; > > JNIEnv *g_env; > 116a122,123 > > > > env_status = director_->swig_jvm_->GetEnv((void **)&g_env, > JNI_VERSION_1_6); > 118c125 > < // 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 > 120c127 > < director_->swig_jvm_->AttachCurrentThreadAsDaemon((void **) > &jenv_, NULL); > --- > > director_->swig_jvm_->AttachCurrentThreadAsDaemon( &jenv_, NULL); > 122c129 > < director_->swig_jvm_->AttachCurrentThread((void **) &jenv_, NULL); > --- > > director_->swig_jvm_->AttachCurrentThread( &jenv_, NULL); > 129c136,144 > < director_->swig_jvm_->DetachCurrentThread(); > --- > > > > if( env_status == JNI_EDETACHED ){ > > director_->swig_jvm_->DetachCurrentThread(); > > > > } > > > > I don't know of a macro that would be used by android's jni includes (I > had a look in the jni.h file and did not see anything relevant). But > maybe there's one. __ANDROID__ is the correct macro and so I've used this for the fix for release in swig-2.0.5. William |
From: Sam H. <she...@gr...> - 2012-01-09 15:42:44
|
On Thu, Dec 15, 2011 at 3:26 PM, William S Fulton <ws...@fu...>wrote: > On 13/10/11 14:09, Цветко ЛАГАЈОВИЋ wrote: > > On Thu, Oct 13, 2011 at 8:15 AM, William S Fulton > > <ws...@fu... <mailto:ws...@fu...>> wrote: > > > > On 12/10/11 10:05, Цветко ЛАГАЈОВИЋ wrote: > > > > Hi, > > > > I am currently using SWIG under cygwin/MacOS in an android > > project. I > > use SWIG to wrap my C++ classes in java. > > > > Lately, I've been adding callback/listeners classes. At this > > occasion, > > I've discovered the existence of directors feature. > > > > It's very nice, but I have three issues with it, it's the use of > > dynamic_cast (no rtti under Android), the use of > > AttachCurrentThread/__DetachCurrentThread which would detach a > > thread that > > was not attached by SWIG directors and a small issue with > > non-standard > > jni headers (signature of AttachCurrentThread). > > > > I managed to patch Swig's "java/director.swg" file in > > "/usr/share/swig/..." What I would like to know is how can I > > instruct > > Swig to use the "director.swg" file from my source tree instead > > of the > > default one from "/usr/share/swig" so I don't have to patch swig > > installed files on each developer's computer. > > > > Thanks for any help, > > > > > > Please post a patch with the changes that you have in place and I'll > > look at putting these in to the official version of SWIG with some > > suitable macro to enable. Is there a macro indicating an Android JDK > > rather than a normal JDK that could be used? > > > > Use swig -v to display the paths that it looks for files in. The > > ./swig_lib/java directory is probably the best place to put in your > > own version of director.swg. > > > > William > > > > Hi William, thanks for your answer. > > > > Here is the result of a diff between original director.swg and patched > one: > > > > 1a2,4 > > > * See the LICENSE file for information on copyright, usage and > > redistribution > > > * of SWIG, and the README file for authors - > > http://www.swig.org/release.html > . > > > * > > 114a118,119 > > > int env_status; > > > JNIEnv *g_env; > > 116a122,123 > > > > > > env_status = director_->swig_jvm_->GetEnv((void **)&g_env, > > JNI_VERSION_1_6); > > 118c125 > > < // 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 > > 120c127 > > < director_->swig_jvm_->AttachCurrentThreadAsDaemon((void **) > > &jenv_, NULL); > > --- > > > director_->swig_jvm_->AttachCurrentThreadAsDaemon( &jenv_, > NULL); > > 122c129 > > < director_->swig_jvm_->AttachCurrentThread((void **) &jenv_, > NULL); > > --- > > > director_->swig_jvm_->AttachCurrentThread( &jenv_, NULL); > > 129c136,144 > > < director_->swig_jvm_->DetachCurrentThread(); > > --- > > > > > > if( env_status == JNI_EDETACHED ){ > > > director_->swig_jvm_->DetachCurrentThread(); > > > > > > } > > > > > > > I don't know of a macro that would be used by android's jni includes (I > > had a look in the jni.h file and did not see anything relevant). But > > maybe there's one. > > __ANDROID__ is the correct macro and so I've used this for the fix for > release in swig-2.0.5. > > William > > > ------------------------------------------------------------------------------ > 10 Tips for Better Server Consolidation > Server virtualization is being driven by many needs. > But none more important than the need to reduce IT complexity > while improving strategic productivity. Learn More! > http://www.accelacomm.com/jaw/sdnl/114/51507609/ > _______________________________________________ > Swig-user mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-user > Could the director not detaching be related to an issue we are having with a new thread being created for every callback out of c++ into java? Has anyone else noticed that issue? Thanks, Sam Hendley |
From: Sam H. <she...@gr...> - 2012-01-19 01:19:11
|
Hi William, I was looking at the changes you made to director.swg for the java version. The code I am looking is near line 130 in this file: http://swig.svn.sourceforge.net/viewvc/swig/trunk/Lib/java/director.swg?annotate=12868 One of the changes you made was to check the status to see if it was JNI_EDETACHED before we started and only detach the thread if it was. Shouldn't it therefore check what the state is before trying to attach the current thread? Also what condition are there that would cause that status to be anything but detached, a recursive call back into the native code from java? Would it also be possible to check the return value from the AttachCurrentThread calls? I don't know what error handling could be done in case of failure. We are still trying to get to the bottom of the escalating thread counts when we use our library so I may have more to ask/report in the coming weeks. Thanks Sam Hendley On Thu, Dec 15, 2011 at 3:26 PM, William S Fulton <ws...@fu...>wrote: > On 13/10/11 14:09, Цветко ЛАГАЈОВИЋ wrote: > > On Thu, Oct 13, 2011 at 8:15 AM, William S Fulton > > <ws...@fu... <mailto:ws...@fu...>> wrote: > > > > On 12/10/11 10:05, Цветко ЛАГАЈОВИЋ wrote: > > > > Hi, > > > > I am currently using SWIG under cygwin/MacOS in an android > > project. I > > use SWIG to wrap my C++ classes in java. > > > > Lately, I've been adding callback/listeners classes. At this > > occasion, > > I've discovered the existence of directors feature. > > > > It's very nice, but I have three issues with it, it's the use of > > dynamic_cast (no rtti under Android), the use of > > AttachCurrentThread/__DetachCurrentThread which would detach a > > thread that > > was not attached by SWIG directors and a small issue with > > non-standard > > jni headers (signature of AttachCurrentThread). > > > > I managed to patch Swig's "java/director.swg" file in > > "/usr/share/swig/..." What I would like to know is how can I > > instruct > > Swig to use the "director.swg" file from my source tree instead > > of the > > default one from "/usr/share/swig" so I don't have to patch swig > > installed files on each developer's computer. > > > > Thanks for any help, > > > > > > Please post a patch with the changes that you have in place and I'll > > look at putting these in to the official version of SWIG with some > > suitable macro to enable. Is there a macro indicating an Android JDK > > rather than a normal JDK that could be used? > > > > Use swig -v to display the paths that it looks for files in. The > > ./swig_lib/java directory is probably the best place to put in your > > own version of director.swg. > > > > William > > > > Hi William, thanks for your answer. > > > > Here is the result of a diff between original director.swg and patched > one: > > > > 1a2,4 > > > * See the LICENSE file for information on copyright, usage and > > redistribution > > > * of SWIG, and the README file for authors - > > http://www.swig.org/release.html > . > > > * > > 114a118,119 > > > int env_status; > > > JNIEnv *g_env; > > 116a122,123 > > > > > > env_status = director_->swig_jvm_->GetEnv((void **)&g_env, > > JNI_VERSION_1_6); > > 118c125 > > < // 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 > > 120c127 > > < director_->swig_jvm_->AttachCurrentThreadAsDaemon((void **) > > &jenv_, NULL); > > --- > > > director_->swig_jvm_->AttachCurrentThreadAsDaemon( &jenv_, > NULL); > > 122c129 > > < director_->swig_jvm_->AttachCurrentThread((void **) &jenv_, > NULL); > > --- > > > director_->swig_jvm_->AttachCurrentThread( &jenv_, NULL); > > 129c136,144 > > < director_->swig_jvm_->DetachCurrentThread(); > > --- > > > > > > if( env_status == JNI_EDETACHED ){ > > > director_->swig_jvm_->DetachCurrentThread(); > > > > > > } > > > > > > > I don't know of a macro that would be used by android's jni includes (I > > had a look in the jni.h file and did not see anything relevant). But > > maybe there's one. > > __ANDROID__ is the correct macro and so I've used this for the fix for > release in swig-2.0.5. > > William > > > ------------------------------------------------------------------------------ > 10 Tips for Better Server Consolidation > Server virtualization is being driven by many needs. > But none more important than the need to reduce IT complexity > while improving strategic productivity. Learn More! > http://www.accelacomm.com/jaw/sdnl/114/51507609/ > _______________________________________________ > Swig-user mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-user > |