varargs works!

at least for printf, and probably for other methods accepting Strings

need more tests cases!
This commit is contained in:
gabriel.pettier 2012-08-26 17:52:19 +02:00
parent 708b2d075f
commit 858bff6e25
3 changed files with 7 additions and 7 deletions

View File

@ -294,7 +294,7 @@ cdef jobject convert_pyarray_to_java(JNIEnv *j_env, definition, pyarray) except
j_env[0].SetObjectArrayElement( j_env[0].SetObjectArrayElement(
j_env, <jobjectArray>ret, i, NULL) j_env, <jobjectArray>ret, i, NULL)
elif isinstance(arg, basestring) and \ elif isinstance(arg, basestring) and \
definition == 'Ljava/lang/String;': definition in ('Ljava/lang/String;', 'Ljava/lang/Object;'):
j_string = j_env[0].NewStringUTF( j_string = j_env[0].NewStringUTF(
j_env, <bytes>arg) j_env, <bytes>arg)
j_env[0].SetObjectArrayElement( j_env[0].SetObjectArrayElement(
@ -309,9 +309,9 @@ cdef jobject convert_pyarray_to_java(JNIEnv *j_env, definition, pyarray) except
j_env[0].SetObjectArrayElement( j_env[0].SetObjectArrayElement(
j_env, <jobjectArray>ret, i, jo.obj) j_env, <jobjectArray>ret, i, jo.obj)
else: else:
raise JavaException('Invalid variable used for L array') raise JavaException('Invalid variable used for L array', definition, pyarray)
else: else:
raise JavaException('Invalid array definition') raise JavaException('Invalid array definition', definition, pyarray)
return <jobject>ret return <jobject>ret

View File

@ -740,16 +740,16 @@ cdef class JavaMultipleMethod(object):
if score <= 0: if score <= 0:
continue continue
scores.append((score, signature, args_)) scores.append((score, signature))
if not scores: if not scores:
raise JavaException('No methods matching your arguments') raise JavaException('No methods matching your arguments')
scores.sort() scores.sort()
score, signature, args_ = scores[-1] score, signature = scores[-1]
jm = methods[signature] jm = methods[signature]
jm.j_self = self.j_self jm.j_self = self.j_self
return jm.__call__(*args_) return jm.__call__(*args)
class JavaStaticMethod(JavaMethod): class JavaStaticMethod(JavaMethod):

View File

@ -13,4 +13,4 @@ class ImplementationTest(unittest.TestCase):
def test_printf(self): def test_printf(self):
System = autoclass('java.lang.System') System = autoclass('java.lang.System')
System.out.printf('hi\n') System.out.printf('hi\n')
System.out.printf('hi %s\n', 'jnius') System.out.printf('hi %s %s\n', 'jnius', 'other string')