diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-09-23 07:10:55 -0700 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-09-23 07:11:56 -0700 |
commit | e632b1fda71fd6c306b47b32c385dfdb1037e77c (patch) | |
tree | 577c8a58a91a124c763ecc77d16003d974f57d86 | |
parent | 941040e9e845a2032725a0e18d4d9daaaa986f0a (diff) | |
download | micropython-e632b1fda71fd6c306b47b32c385dfdb1037e77c.tar.gz micropython-e632b1fda71fd6c306b47b32c385dfdb1037e77c.zip |
unix/modjni: Factor out is_object_type().
-rw-r--r-- | unix/modjni.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/unix/modjni.c b/unix/modjni.c index 08c6ece4de..498fc565b5 100644 --- a/unix/modjni.c +++ b/unix/modjni.c @@ -77,6 +77,18 @@ typedef struct _mp_obj_jmethod_t { bool is_static; } mp_obj_jmethod_t; +// Utility functions + +STATIC bool is_object_type(const char *jtypesig) { + while (*jtypesig != ' ' && *jtypesig) { + if (*jtypesig == '.') { + return true; + } + jtypesig++; + } + return false; +} + // jclass STATIC void jclass_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { @@ -281,24 +293,18 @@ STATIC bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out) { // it. #define MATCH(s, static) (!strncmp(s, static, sizeof(static) - 1)) STATIC mp_obj_t jvalue2py(const char *jtypesig, jobject arg) { - const char *org_jtype = jtypesig; if (arg == NULL || MATCH(jtypesig, "void")) { return mp_const_none; } else if (MATCH(jtypesig, "boolean")) { return mp_obj_new_bool((bool)arg); } else if (MATCH(jtypesig, "int")) { return mp_obj_new_int((mp_int_t)arg); - } else { - while (*jtypesig != ' ' && *jtypesig) { - if (*jtypesig == '.') { - // Non-primitive, object type - return new_jobject(arg); - } - jtypesig++; - } + } else if (is_object_type(jtypesig)) { + // Non-primitive, object type + return new_jobject(arg); } - printf("Unknown return type: %s\n", org_jtype); + printf("Unknown return type: %s\n", jtypesig); return MP_OBJ_NULL; } |