mirror of https://github.com/kivy/pyjnius.git
proxy: force GIL on invoke0, and add a special case for $Proxy name (android failed to FindClass)
This commit is contained in:
parent
44f1a338ac
commit
242245a6f4
|
@ -145,8 +145,15 @@ cdef convert_jobject_to_python(JNIEnv *j_env, bytes definition, jobject j_object
|
|||
return convert_jarray_to_python(j_env, r[1:], j_object)
|
||||
|
||||
if r not in jclass_register:
|
||||
from reflect import autoclass
|
||||
ret_jc = autoclass(r.replace('/', '.'))(noinstance=True)
|
||||
if r.startswith('$Proxy'):
|
||||
# only for $Proxy on android, don't use autoclass. The dalvik vm is
|
||||
# not able to give us introspection on that one (FindClass return
|
||||
# NULL).
|
||||
from .reflect import Object
|
||||
ret_jc = Object(noinstance=True)
|
||||
else:
|
||||
from reflect import autoclass
|
||||
ret_jc = autoclass(r.replace('/', '.'))(noinstance=True)
|
||||
else:
|
||||
ret_jc = jclass_register[r](noinstance=True)
|
||||
ret_jc.instanciate_from(create_local_ref(j_env, j_object))
|
||||
|
@ -339,7 +346,7 @@ cdef jobject convert_python_to_jobject(JNIEnv *j_env, definition, obj) except *:
|
|||
elif definition == 'I':
|
||||
retclass = j_env[0].FindClass(j_env, 'java/lang/Integer')
|
||||
retmidinit = j_env[0].GetMethodID(j_env, retclass, '<init>', '(I)V')
|
||||
j_ret[0].i = obj
|
||||
j_ret[0].i = int(obj)
|
||||
elif definition == 'J':
|
||||
retclass = j_env[0].FindClass(j_env, 'java/lang/Long')
|
||||
retmidinit = j_env[0].GetMethodID(j_env, retclass, '<init>', '(J)V')
|
||||
|
|
|
@ -27,7 +27,7 @@ def classpath():
|
|||
else:
|
||||
split_char = ':'
|
||||
|
||||
paths = [realpath('.'), join(dirname(__file__), 'src', 'org'), ]
|
||||
paths = [realpath('.'), join(dirname(__file__), 'src'), ]
|
||||
if 'CLASSPATH' not in environ:
|
||||
return split_char.join(paths)
|
||||
|
||||
|
|
|
@ -61,18 +61,18 @@ cdef class PythonJavaClass(object):
|
|||
|
||||
py_method = self.__javamethods__.get(key, None)
|
||||
if not py_method:
|
||||
print(''.join(
|
||||
print(''.join([
|
||||
'\n===== Python/java method missing ======',
|
||||
'\nPython class:', self,
|
||||
'\nPython class:', repr(self),
|
||||
'\nJava method name:', method_name,
|
||||
'\nSignature: ({}){}'.format(''.join(args_signature), ret_signature),
|
||||
'\n=======================================\n'))
|
||||
'\n=======================================\n']))
|
||||
raise NotImplemented('The method {} is not implemented'.format(key))
|
||||
|
||||
return py_method(*args)
|
||||
|
||||
cdef jobject invoke0(JNIEnv *j_env, jobject j_this, jobject j_proxy, jobject
|
||||
j_method, jobjectArray args) except *:
|
||||
j_method, jobjectArray args) with gil:
|
||||
from .reflect import get_signature, Method
|
||||
|
||||
# get the python object
|
||||
|
@ -142,7 +142,7 @@ cdef jobject invoke0(JNIEnv *j_env, jobject j_this, jobject j_proxy, jobject
|
|||
cdef create_proxy_instance(JNIEnv *j_env, py_obj, j_interfaces):
|
||||
from .reflect import autoclass
|
||||
Proxy = autoclass('java.lang.reflect.Proxy')
|
||||
NativeInvocationHandler = autoclass('jnius.NativeInvocationHandler')
|
||||
NativeInvocationHandler = autoclass('org.jnius.NativeInvocationHandler')
|
||||
ClassLoader = autoclass('java.lang.ClassLoader')
|
||||
|
||||
# convert strings to Class
|
||||
|
@ -156,7 +156,9 @@ cdef create_proxy_instance(JNIEnv *j_env, py_obj, j_interfaces):
|
|||
j_env[0].RegisterNatives(j_env, nih.j_cls, <JNINativeMethod *>invoke_methods, 1)
|
||||
|
||||
# create the proxy and pass it the invocation handler
|
||||
classLoader = ClassLoader.getSystemClassLoader()
|
||||
|
||||
cdef JavaClass j_obj = Proxy.newProxyInstance(
|
||||
ClassLoader.getSystemClassLoader(), j_interfaces, nih)
|
||||
classLoader, j_interfaces, nih)
|
||||
|
||||
return j_obj
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package jnius;
|
||||
package org.jnius;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
|
Loading…
Reference in New Issue