pyjnius/jnius/jnius_env.pxi

26 lines
616 B
Cython
Raw Normal View History

cdef JNIEnv *default_env = NULL
cdef extern int gettid()
cdef JavaVM *jvm = NULL
2014-05-09 07:22:56 +00:00
cdef JNIEnv *get_jnienv() except NULL:
global default_env
# first call, init.
if default_env == NULL:
default_env = get_platform_jnienv()
2014-05-09 07:22:56 +00:00
if default_env == NULL:
return NULL
default_env[0].GetJavaVM(default_env, &jvm)
# 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
def detach():
jvm[0].DetachCurrentThread(jvm)