Skip to content

Commit e632b1f

Browse files
committed
unix/modjni: Factor out is_object_type().
1 parent 941040e commit e632b1f

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

unix/modjni.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ typedef struct _mp_obj_jmethod_t {
7777
bool is_static;
7878
} mp_obj_jmethod_t;
7979

80+
// Utility functions
81+
82+
STATIC bool is_object_type(const char *jtypesig) {
83+
while (*jtypesig != ' ' && *jtypesig) {
84+
if (*jtypesig == '.') {
85+
return true;
86+
}
87+
jtypesig++;
88+
}
89+
return false;
90+
}
91+
8092
// jclass
8193

8294
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) {
281293
// it.
282294
#define MATCH(s, static) (!strncmp(s, static, sizeof(static) - 1))
283295
STATIC mp_obj_t jvalue2py(const char *jtypesig, jobject arg) {
284-
const char *org_jtype = jtypesig;
285296
if (arg == NULL || MATCH(jtypesig, "void")) {
286297
return mp_const_none;
287298
} else if (MATCH(jtypesig, "boolean")) {
288299
return mp_obj_new_bool((bool)arg);
289300
} else if (MATCH(jtypesig, "int")) {
290301
return mp_obj_new_int((mp_int_t)arg);
291-
} else {
292-
while (*jtypesig != ' ' && *jtypesig) {
293-
if (*jtypesig == '.') {
294-
// Non-primitive, object type
295-
return new_jobject(arg);
296-
}
297-
jtypesig++;
298-
}
302+
} else if (is_object_type(jtypesig)) {
303+
// Non-primitive, object type
304+
return new_jobject(arg);
299305
}
300306

301-
printf("Unknown return type: %s\n", org_jtype);
307+
printf("Unknown return type: %s\n", jtypesig);
302308

303309
return MP_OBJ_NULL;
304310
}

0 commit comments

Comments
 (0)