Commit ed22e9ba authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

unix/modjni: Move type analysis logic to new_jobject(), for reuse.

parent dcbe936c
......@@ -205,10 +205,20 @@ STATIC const mp_obj_type_t jobject_type = {
};
STATIC mp_obj_t new_jobject(jobject jo) {
if (JJ(IsInstanceOf, jo, String_class)) {
const char *s = JJ(GetStringUTFChars, jo, NULL);
mp_obj_t ret = mp_obj_new_str(s, strlen(s), false);
JJ(ReleaseStringUTFChars, jo, s);
return ret;
} else if (JJ(IsInstanceOf, jo, Class_class)) {
return new_jclass(jo);
} else {
mp_obj_jobject_t *o = m_new_obj(mp_obj_jobject_t);
o->base.type = &jobject_type;
o->obj = jo;
return o;
}
}
......@@ -272,31 +282,18 @@ STATIC bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out) {
#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;
mp_obj_t ret;
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 if (MATCH(jtypesig, "java.lang.String")) {
ret_string:;
const char *s = JJ(GetStringUTFChars, arg, NULL);
ret = mp_obj_new_str(s, strlen(s), false);
JJ(ReleaseStringUTFChars, arg, s);
return ret;
} else {
while (*jtypesig != ' ' && *jtypesig) {
if (*jtypesig == '.') {
// Non-primitive, object type
if (JJ(IsInstanceOf, arg, String_class)) {
goto ret_string;
} else if (JJ(IsInstanceOf, arg, Class_class)) {
return new_jclass(arg);
} else {
return new_jobject(arg);
}
}
jtypesig++;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment