diff --git a/jnius/jnius_export_class.pxi b/jnius/jnius_export_class.pxi index bff66bf..0e321d9 100644 --- a/jnius/jnius_export_class.pxi +++ b/jnius/jnius_export_class.pxi @@ -121,7 +121,7 @@ class MetaJavaClass(type): jf = value if not jf.is_static: continue - jf.set_resolve_info(j_env, jcs.j_cls, None, + jf.set_resolve_info(j_env, jcs.j_cls, name, __javaclass__) @@ -260,7 +260,7 @@ cdef class JavaClass(object): jf = value if jf.is_static: continue - jf.set_resolve_info(j_env, self.j_cls, self.j_self, + jf.set_resolve_info(j_env, self.j_cls, name, self.__javaclass__) def __repr__(self): @@ -275,7 +275,6 @@ cdef class JavaField(object): cdef jfieldID j_field cdef JNIEnv *j_env cdef jclass j_cls - cdef LocalRef j_self cdef bytes definition cdef object is_static cdef bytes name @@ -284,20 +283,18 @@ cdef class JavaField(object): def __cinit__(self, definition, **kwargs): self.j_field = NULL self.j_cls = NULL - self.j_self = None def __init__(self, definition, **kwargs): super(JavaField, self).__init__() self.definition = definition self.is_static = kwargs.get('static', False) - cdef void set_resolve_info(self, JNIEnv *j_env, jclass j_cls, LocalRef j_self, + cdef void set_resolve_info(self, JNIEnv *j_env, jclass j_cls, bytes name, bytes classname): j_env = get_jnienv() self.name = name self.classname = classname self.j_cls = j_cls - self.j_self = j_self cdef void ensure_field(self) except *: cdef JNIEnv *j_env = get_jnienv() @@ -315,12 +312,16 @@ cdef class JavaField(object): raise JavaException('Unable to found the field {0}'.format(self.name)) def __get__(self, obj, objtype): + cdef jobject j_self + self.ensure_field() if obj is None: return self.read_static_field() - return self.read_field() - cdef read_field(self): + j_self = (obj).j_self.obj + return self.read_field(j_self) + + cdef read_field(self, jobject j_self): cdef jboolean j_boolean cdef jbyte j_byte cdef jchar j_char @@ -335,7 +336,6 @@ cdef class JavaField(object): cdef object ret = None cdef JavaObject ret_jobject cdef JavaClass ret_jc - cdef jobject j_self = self.j_self.obj cdef JNIEnv *j_env = get_jnienv() # return type of the java method @@ -840,5 +840,3 @@ class JavaStaticField(JavaField): def __init__(self, definition, **kwargs): kwargs['static'] = True super(JavaStaticField, self).__init__(definition, **kwargs) - - diff --git a/tests/org/jnius/BasicsTest.java b/tests/org/jnius/BasicsTest.java index ed8dc44..c257822 100644 --- a/tests/org/jnius/BasicsTest.java +++ b/tests/org/jnius/BasicsTest.java @@ -43,6 +43,11 @@ public class BasicsTest { public double fieldD = 1.23456789; public String fieldString = new String("helloworld"); + public BasicsTest() {} + public BasicsTest(byte fieldBVal) { + fieldB = fieldBVal; + } + public boolean[] methodArrayZ() { boolean[] x = new boolean[3]; x[0] = x[1] = x[2] = true; @@ -93,7 +98,7 @@ public class BasicsTest { public boolean methodParamsZBCSIJFD(boolean x1, byte x2, char x3, short x4, int x5, long x6, float x7, double x8) { // ADD float / double, but dunno how to do with approx - return (x1 == true && x2 == 127 && x3 == 'k' && x4 == 32767 && + return (x1 == true && x2 == 127 && x3 == 'k' && x4 == 32767 && x5 == 2147483467 && x6 == 2147483467); } diff --git a/tests/test_basics.py b/tests/test_basics.py index 44e8084..3964561 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -50,6 +50,10 @@ class BasicsTest(unittest.TestCase): self.assertAlmostEquals(test.fieldF, 1.23456789) self.assertEquals(test.fieldD, 1.23456789) self.assertEquals(test.fieldString, 'helloworld') + test2 = autoclass('org.jnius.BasicsTest')(10) + self.assertEquals(test2.fieldB, 10) + self.assertEquals(test.fieldB, 127) + self.assertEquals(test2.fieldB, 10) def test_instances_methods_array(self): test = autoclass('org.jnius.BasicsTest')()