2013-06-24 15:58:20 +00:00
|
|
|
|
2013-06-25 09:49:42 +00:00
|
|
|
cdef JNIEnv *default_env = NULL
|
|
|
|
|
|
|
|
cdef extern int gettid()
|
|
|
|
cdef JavaVM *jvm = NULL
|
2013-06-24 15:58:20 +00:00
|
|
|
|
2014-05-09 07:22:56 +00:00
|
|
|
cdef JNIEnv *get_jnienv() except NULL:
|
2013-06-25 09:49:42 +00:00
|
|
|
global default_env
|
2013-06-24 15:58:20 +00:00
|
|
|
# first call, init.
|
2013-06-25 09:49:42 +00:00
|
|
|
if default_env == NULL:
|
|
|
|
default_env = get_platform_jnienv()
|
2014-05-09 07:22:56 +00:00
|
|
|
if default_env == NULL:
|
|
|
|
return NULL
|
2013-06-25 09:49:42 +00:00
|
|
|
default_env[0].GetJavaVM(default_env, &jvm)
|
2013-06-24 15:58:20 +00:00
|
|
|
|
2013-06-25 09:49:42 +00:00
|
|
|
# return the current env attached to the thread
|
|
|
|
# XXX it threads are created from C (not java), we'll leak here.
|
|
|
|
cdef JNIEnv *env = NULL
|
|
|
|
jvm[0].AttachCurrentThread(jvm, &env, NULL)
|
|
|
|
return env
|
2013-06-24 16:36:58 +00:00
|
|
|
|
2015-02-07 18:33:19 +00:00
|
|
|
|
|
|
|
def detach():
|
|
|
|
jvm[0].DetachCurrentThread(jvm)
|
|
|
|
|