8000 unix/modjni: Get building under coverage and nanbox builds. · andrewleech/micropython@6623d7a · GitHub
[go: up one dir, main page]

Skip to content

Commit 6623d7a

Browse files
committed
unix/modjni: Get building under coverage and nanbox builds.
Changes made: - make use of MP_OBJ_TO_PTR and MP_OBJ_FROM_PTR where necessary - fix shadowing of index variable i, renamed to j - fix type of above variable to size_t to prevent comparison warning - fix shadowing of res variable - use "(void)" instead of "()" for functions that take no arguments
1 parent 11573fc commit 6623d7a

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

ports/unix/modjni.c

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ STATIC void print_jobject(const mp_print_t *print, jobject obj) {
118118
// jclass
119119

120120
STATIC void jclass_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
121-
mp_obj_jclass_t *self = self_in;
121+
mp_obj_jclass_t *self = MP_OBJ_TO_PTR(self_in);
122122
if (kind == PRINT_REPR) {
123123
mp_printf(print, "<jclass @%p \"", self->cls);
124124
}
@@ -131,7 +131,7 @@ STATIC void jclass_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kin
131131
STATIC void jclass_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) {
132132
if (dest[0] == MP_OBJ_NULL) {
133133
// load attribute
134-
mp_obj_jclass_t *self = self_in;
134+
mp_obj_jclass_t *self = MP_OBJ_TO_PTR(self_in);
135135
const char *attr = qstr_str(attr_in);
136136

137137
jstring field_name = JJ(NewStringUTF, attr);
@@ -151,15 +151,15 @@ STATIC void jclass_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) {
151151
o->meth = NULL;
152152
o->obj = self->cls;
153153
o->is_static = true;
154-
dest[0] = o;
154+
dest[0] = MP_OBJ_FROM_PTR(o);
155155
}
156156
}
157157

158158
STATIC mp_obj_t jclass_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
159159
if (n_kw != 0) {
160160
mp_raise_TypeError("kwargs not supported");
161161
}
162-
mp_obj_jclass_t *self = self_in;
162+
mp_obj_jclass_t *self = MP_OBJ_TO_PTR(self_in);
163163

164164
jarray methods = JJ(CallObjectMethod, self->cls, Class_getConstructors_mid);
165165

@@ -186,13 +186,13 @@ STATIC mp_obj_t new_jclass(jclass jc) {
186186
mp_obj_jclass_t *o = m_new_obj(mp_obj_jclass_t);
187187
o->base.type = &jclass_type;
188188
o->cls = jc;
189-
return o;
189+
return MP_OBJ_FROM_PTR(o);
190190
}
191191

192192
// jobject
193193

194194
STATIC void jobject_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
195-
mp_obj_jobject_t *self = self_in;
195+
mp_obj_jobject_t *self = MP_OBJ_TO_PTR(self_in);
196196
if (kind == PRINT_REPR) {
197197
mp_printf(print, "<jobject @%p \"", self->obj);
198198
}
@@ -205,7 +205,7 @@ STATIC void jobject_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
205205
STATIC void jobject_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) {
206206
if (dest[0] == MP_OBJ_NULL) {
207207
// load attribute
208-
mp_obj_jobject_t *self = self_in;
208+
mp_obj_jobject_t *self = MP_OBJ_TO_PTR(self_in);
209209

210210
const char *attr = qstr_str(attr_in);
211211
jclass obj_class = JJ(GetObjectClass, self->obj);
@@ -229,7 +229,7 @@ STATIC void jobject_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) {
229229
o->meth = NULL;
230230
o->obj = self->obj;
231231
o->is_static = false;
232-
dest[0] = o;
232+
dest[0] = MP_OBJ_FROM_PTR(o);
233233
}
234234
}
235235

@@ -242,7 +242,7 @@ STATIC void get_jclass_name(jobject obj, char *buf) {
242242
}
243243

244244
STATIC mp_obj_t jobject_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
245-
mp_obj_jobject_t *self = self_in;
245+
mp_obj_jobject_t *self = MP_OBJ_TO_PTR(self_in);
246246
mp_uint_t idx = mp_obj_get_int(index);
247247
char class_name[64];
248248
get_jclass_name(self->obj, class_name);
@@ -292,7 +292,7 @@ return MP_OBJ_NULL;
292292
}
293293

294294
STATIC mp_obj_t jobject_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
295-
mp_obj_jobject_t *self = self_in;
295+
mp_obj_jobject_t *self = MP_OBJ_TO_PTR(self_in);
296296
switch (op) {
297297
case MP_UNARY_OP_BOOL:
298298
case MP_UNARY_OP_LEN: {
@@ -317,7 +317,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(subscr_load_adaptor_obj, subscr_load_adaptor);
317317
// .getiter special method which returns iterator which works in terms
318318
// of object subscription.
319319
STATIC mp_obj_t subscr_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) {
320-
mp_obj_t dest[2] = {(mp_obj_t)&subscr_load_adaptor_obj, self_in};
320+
mp_obj_t dest[2] = {MP_OBJ_FROM_PTR(&subscr_load_adaptor_obj), self_in};
321321
return mp_obj_new_getitem_iter(dest, iter_buf);
322322
}
323323

@@ -346,7 +346,7 @@ STATIC mp_obj_t new_jobject(jobject jo) {
346346
mp_obj_jobject_t *o = m_new_obj(mp_obj_jobject_t);
347347
o->base.type = &jobject_type;
348348
o->obj = jo;
349-
return o;
349+
return MP_OBJ_FROM_PTR(o);
350350
}
351351

352352
}
@@ -356,7 +356,7 @@ STATIC mp_obj_t new_jobject(jobject jo) {
356356

357357
STATIC void jmethod_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
358358
(void)kind;
359-
mp_obj_jmethod_t *self = self_in;
359+
mp_obj_jmethod_t *self = MP_OBJ_TO_PTR(self_in);
360360
// Variable value printed as cast to int
361361
mp_printf(print, "<jmethod '%s'>", qstr_str(self->name));
362362
}
@@ -408,7 +408,7 @@ STATIC bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out) {
408408
if (!is_object) {
409409
return false;
410410
}
411-
mp_obj_jobject_t *jo = arg;
411+
mp_obj_jobject_t *jo = MP_OBJ_TO_PTR(arg);
412412
if (!MATCH(expected_type, "java.lang.Object")) {
413413
char class_name[64];
414414
get_jclass_name(jo->obj, class_name);
@@ -490,8 +490,8 @@ STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool
490490
// printf("name=%p meth_name=%s\n", name, meth_name);
491491

492492
bool found = true;
493-
for (int i = 0; i < n_args && *arg_types != ')'; i++) {
494-
if (!py2jvalue(&arg_types, args[i], &jargs[i])) {
493+
for (size_t j = 0; j < n_args && *arg_types != ')'; j++) {
494+
if (!py2jvalue(&arg_types, args[j], &jargs[j])) {
495495
goto next_method;
496496
}
497497

@@ -507,13 +507,12 @@ STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool
507507
if (found) {
508508
// printf("found!\n");
509509
jmethodID method_id = JJ(FromReflectedMethod, meth);
510-
jobject res;
511-
mp_obj_t ret;
512510
if (is_constr) {
513511
JJ(ReleaseStringUTFChars, name_o, decl);
514-
res = JJ(NewObjectA, obj, method_id, jargs);
512+
jobject res = JJ(NewObjectA, obj, method_id, jargs);
515513
return new_jobject(res);
516514
} else {
515+
mp_obj_t ret;
517516
if (MATCH(ret_type, "void")) {
518517
JJ(CallVoidMethodA, obj, method_id, jargs);
519518
check_exception();
@@ -527,7 +526,7 @@ STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool
527526
check_exception();
528527
ret = mp_obj_new_bool(res);
529528
} else if (is_object_type(ret_type)) {
530-
res = JJ(CallObjectMethodA, obj, method_id, jargs);
529+
jobject res = JJ(CallObjectMethodA, obj, method_id, jargs);
531530
check_exception();
532531
ret = new_jobject(res);
533532
} else {
@@ -556,7 +555,7 @@ STATIC mp_obj_t jmethod_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
556555
if (n_kw != 0) {
557556
mp_raise_TypeError("kwargs not supported");
558557
}
559-
mp_obj_jmethod_t *self = self_in;
558+
mp_obj_jmethod_t *self = MP_OBJ_TO_PTR(self_in);
560559

561560
const char *name = qstr_str(self->name);
562561
// jstring meth_name = JJ(NewStringUTF, name);
@@ -585,7 +584,7 @@ STATIC const mp_obj_type_t jmethod_type = {
585584
#define LIBJVM_SO "libjvm.so"
586585
#endif
587586

588-
STATIC void create_jvm() {
587+
STATIC void create_jvm(void) {
589588
JavaVMInitArgs args;
590589
JavaVMOption options;
591590
options.optionString = "-Djava.class.path=.";
@@ -648,7 +647,7 @@ STATIC mp_obj_t mod_jni_cls(mp_obj_t cls_name_in) {
648647
mp_obj_jclass_t *o = m_new_obj(mp_obj_jclass_t);
649648
o->base.type = &jclass_type;
650649
o->cls = cls;
651-
return o;
650+
return MP_OBJ_FROM_PTR(o);
652651
}
653652
MP_DEFINE_CONST_FUN_OBJ_1(mod_jni_cls_obj, mod_jni_cls);
654653

@@ -661,7 +660,7 @@ STATIC mp_obj_t mod_jni_array(mp_obj_t type_in, mp_obj_t size_in) {
661660

662661
if (MP_OBJ_IS_TYPE(type_in, &jclass_type)) {
663662

664-
mp_obj_jclass_t *jcls = type_in;
663+
mp_obj_jclass_t *jcls = MP_OBJ_TO_PTR(type_in);
665664
res = JJ(NewObjectArray, size, jcls->cls, NULL);
666665

667666
} else if (MP_OBJ_IS_STR(type_in)) {
@@ -700,8 +699,8 @@ STATIC mp_obj_t mod_jni_array(mp_obj_t type_in, mp_obj_t size_in) {
700699
MP_DEFINE_CONST_FUN_OBJ_2(mod_jni_array_obj, mod_jni_array);
701700

702701

703-
STATIC mp_obj_t mod_jni_env() {
704-
return mp_obj_new_int((mp_int_t)env);
702+
STATIC mp_obj_t mod_jni_env(void) {
703+
return mp_obj_new_int((mp_int_t)(uintptr_t)env);
705704
}
706705
MP_DEFINE_CONST_FUN_OBJ_0(mod_jni_env_obj, mod_jni_env);
707706

0 commit comments

Comments
 (0)
0