2012-08-20 07:35:14 +00:00
|
|
|
|
|
|
|
cdef class LocalRef:
|
|
|
|
cdef jobject obj
|
|
|
|
|
|
|
|
def __cinit__(self):
|
|
|
|
self.obj = NULL
|
|
|
|
|
|
|
|
def __dealloc__(self):
|
2013-06-24 15:58:20 +00:00
|
|
|
cdef JNIEnv *j_env
|
2012-08-20 07:35:14 +00:00
|
|
|
if self.obj != NULL:
|
2013-06-24 15:58:20 +00:00
|
|
|
j_env = get_jnienv()
|
|
|
|
j_env[0].DeleteGlobalRef(j_env, self.obj)
|
2012-08-20 07:35:14 +00:00
|
|
|
self.obj = NULL
|
|
|
|
|
|
|
|
cdef void create(self, JNIEnv *env, jobject obj):
|
2013-03-13 17:53:25 +00:00
|
|
|
self.obj = env[0].NewGlobalRef(env, obj)
|
2012-08-20 07:35:14 +00:00
|
|
|
|
2013-04-28 17:14:14 +00:00
|
|
|
def __repr__(self):
|
|
|
|
return '<LocalRef obj=0x{:x} at 0x{:x}>'.format(
|
|
|
|
<long><void *>self.obj, id(self))
|
|
|
|
|
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
|
|
|
|
|