pyjnius/jnius/jnius_localref.pxi

26 lines
566 B
Cython
Raw Normal View History

2012-08-20 07:35:14 +00:00
cdef class LocalRef:
cdef jobject obj
cdef JNIEnv *env
def __cinit__(self):
self.obj = NULL
self.env = NULL
def __dealloc__(self):
if self.obj != NULL:
self.env[0].DeleteGlobalRef(self.env, self.obj)
2012-08-20 07:35:14 +00:00
self.obj = NULL
self.env = NULL
cdef void create(self, JNIEnv *env, jobject obj):
self.env = env
self.obj = env[0].NewGlobalRef(env, obj)
2012-08-20 07:35:14 +00:00
cdef LocalRef create_local_ref(JNIEnv *env, jobject obj):
cdef LocalRef ret = LocalRef()
ret.create(env, obj)
return ret