@@ -205,10 +205,20 @@ STATIC const mp_obj_type_t jobject_type = {
205205};
206206
207207STATIC mp_obj_t new_jobject (jobject jo ) {
208- mp_obj_jobject_t * o = m_new_obj (mp_obj_jobject_t );
209- o -> base .type = & jobject_type ;
210- o -> obj = jo ;
211- return o ;
208+ if (JJ (IsInstanceOf , jo , String_class )) {
209+ const char * s = JJ (GetStringUTFChars , jo , NULL );
210+ mp_obj_t ret = mp_obj_new_str (s , strlen (s ), false);
211+ JJ (ReleaseStringUTFChars , jo , s );
212+ return ret ;
213+ } else if (JJ (IsInstanceOf , jo , Class_class )) {
214+ return new_jclass (jo );
215+ } else {
216+ mp_obj_jobject_t * o = m_new_obj (mp_obj_jobject_t );
217+ o -> base .type = & jobject_type ;
218+ o -> obj = jo ;
219+ return o ;
220+ }
221+
212222}
213223
214224
@@ -272,30 +282,17 @@ STATIC bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out) {
272282#define MATCH (s , static ) (!strncmp(s, static, sizeof(static) - 1))
273283STATIC mp_obj_t jvalue2py (const char * jtypesig , jobject arg ) {
274284 const char * org_jtype = jtypesig ;
275- mp_obj_t ret ;
276285 if (arg == NULL || MATCH (jtypesig , "void" )) {
277286 return mp_const_none ;
278287 } else if (MATCH (jtypesig , "boolean" )) {
279288 return mp_obj_new_bool ((bool )arg );
280289 } else if (MATCH (jtypesig , "int" )) {
281290 return mp_obj_new_int ((mp_int_t )arg );
282- } else if (MATCH (jtypesig , "java.lang.String" )) {
283- ret_string :;
284- const char * s = JJ (GetStringUTFChars , arg , NULL );
285- ret = mp_obj_new_str (s , strlen (s ), false);
286- JJ (ReleaseStringUTFChars , arg , s );
287- return ret ;
288291 } else {
289292 while (* jtypesig != ' ' && * jtypesig ) {
290293 if (* jtypesig == '.' ) {
291294 // Non-primitive, object type
292- if (JJ (IsInstanceOf , arg , String_class )) {
293- goto ret_string ;
294- } else if (JJ (IsInstanceOf , arg , Class_class )) {
295- return new_jclass (arg );
296- } else {
297- return new_jobject (arg );
298- }
295+ return new_jobject (arg );
299296 }
300297 jtypesig ++ ;
301298 }
0 commit comments