From 858bff6e25043426d394bf18f98f71c6269ba7c5 Mon Sep 17 00:00:00 2001 From: "gabriel.pettier" Date: Sun, 26 Aug 2012 17:52:19 +0200 Subject: [PATCH] varargs works! at least for printf, and probably for other methods accepting Strings need more tests cases! --- jnius/jnius_conversion.pxi | 6 +++--- jnius/jnius_export_class.pxi | 6 +++--- tests/test_implementation.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/jnius/jnius_conversion.pxi b/jnius/jnius_conversion.pxi index aee4e7d..4a06326 100644 --- a/jnius/jnius_conversion.pxi +++ b/jnius/jnius_conversion.pxi @@ -294,7 +294,7 @@ cdef jobject convert_pyarray_to_java(JNIEnv *j_env, definition, pyarray) except j_env[0].SetObjectArrayElement( j_env, ret, i, NULL) elif isinstance(arg, basestring) and \ - definition == 'Ljava/lang/String;': + definition in ('Ljava/lang/String;', 'Ljava/lang/Object;'): j_string = j_env[0].NewStringUTF( j_env, arg) 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, ret, i, jo.obj) else: - raise JavaException('Invalid variable used for L array') + raise JavaException('Invalid variable used for L array', definition, pyarray) else: - raise JavaException('Invalid array definition') + raise JavaException('Invalid array definition', definition, pyarray) return ret diff --git a/jnius/jnius_export_class.pxi b/jnius/jnius_export_class.pxi index 87ac930..6be86db 100644 --- a/jnius/jnius_export_class.pxi +++ b/jnius/jnius_export_class.pxi @@ -740,16 +740,16 @@ cdef class JavaMultipleMethod(object): if score <= 0: continue - scores.append((score, signature, args_)) + scores.append((score, signature)) if not scores: raise JavaException('No methods matching your arguments') scores.sort() - score, signature, args_ = scores[-1] + score, signature = scores[-1] jm = methods[signature] jm.j_self = self.j_self - return jm.__call__(*args_) + return jm.__call__(*args) class JavaStaticMethod(JavaMethod): diff --git a/tests/test_implementation.py b/tests/test_implementation.py index 22cb046..bf5e37e 100644 --- a/tests/test_implementation.py +++ b/tests/test_implementation.py @@ -13,4 +13,4 @@ class ImplementationTest(unittest.TestCase): def test_printf(self): System = autoclass('java.lang.System') System.out.printf('hi\n') - System.out.printf('hi %s\n', 'jnius') + System.out.printf('hi %s %s\n', 'jnius', 'other string')