Skip to content

Commit 31dd312

Browse files
committed
unix/modffi: Allow to compile modffi in OBJ_REPR_D mode.
1 parent 55ad083 commit 31dd312

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

unix/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ nanbox:
180180
BUILD=build-nanbox \
181181
PROG=micropython_nanbox \
182182
MICROPY_FORCE_32BIT=1 \
183-
MICROPY_PY_FFI=0
184183

185184
freedos:
186185
$(MAKE) \

unix/modffi.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ STATIC mp_obj_t mod_ffi_func(mp_obj_t rettype, mp_obj_t addr_in, mp_obj_t argtyp
227227
}
228228
MP_DEFINE_CONST_FUN_OBJ_3(mod_ffi_func_obj, mod_ffi_func);
229229

230-
STATIC void call_py_func(ffi_cif *cif, void *ret, void** args, mp_obj_t func) {
230+
STATIC void call_py_func(ffi_cif *cif, void *ret, void** args, void *func) {
231231
mp_obj_t pyargs[cif->nargs];
232232
for (uint i = 0; i < cif->nargs; i++) {
233233
pyargs[i] = mp_obj_new_int(*(mp_int_t*)args[i]);
234234
}
235-
mp_obj_t res = mp_call_function_n_kw(func, cif->nargs, 0, pyargs);
235+
mp_obj_t res = mp_call_function_n_kw(MP_OBJ_FROM_PTR(func), cif->nargs, 0, pyargs);
236236

237237
if (res != mp_const_none) {
238238
*(ffi_arg*)ret = mp_obj_int_get_truncated(res);
@@ -262,7 +262,7 @@ STATIC mp_obj_t mod_ffi_callback(mp_obj_t rettype_in, mp_obj_t func_in, mp_obj_t
262262
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Error in ffi_prep_cif"));
263263
}
264264

265-
res = ffi_prep_closure_loc(o->clo, &o->cif, call_py_func, func_in, o->func);
265+
res = ffi_prep_closure_loc(o->clo, &o->cif, call_py_func, MP_OBJ_TO_PTR(func_in), o->func);
266266
if (res != FFI_OK) {
267267
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "ffi_prep_closure_loc"));
268268
}
@@ -297,7 +297,7 @@ STATIC mp_obj_t ffimod_addr(mp_obj_t self_in, mp_obj_t symname_in) {
297297
if (sym == NULL) {
298298
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ENOENT)));
299299
}
300-
return mp_obj_new_int((mp_int_t)sym);
300+
return mp_obj_new_int((uintptr_t)sym);
301301
}
302302
MP_DEFINE_CONST_FUN_OBJ_2(ffimod_addr_obj, ffimod_addr);
303303

@@ -372,16 +372,16 @@ STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
372372
} else if (MP_OBJ_IS_STR(a)) {
373373
const char *s = mp_obj_str_get_str(a);
374374
values[i] = (ffi_arg)(intptr_t)s;
375-
} else if (((mp_obj_base_t*)a)->type->buffer_p.get_buffer != NULL) {
376-
mp_obj_base_t *o = (mp_obj_base_t*)a;
375+
} else if (((mp_obj_base_t*)MP_OBJ_TO_PTR(a))->type->buffer_p.get_buffer != NULL) {
376+
mp_obj_base_t *o = (mp_obj_base_t*)MP_OBJ_TO_PTR(a);
377377
mp_buffer_info_t bufinfo;
378-
int ret = o->type->buffer_p.get_buffer(o, &bufinfo, MP_BUFFER_READ); // TODO: MP_BUFFER_READ?
378+
int ret = o->type->buffer_p.get_buffer(MP_OBJ_FROM_PTR(o), &bufinfo, MP_BUFFER_READ); // TODO: MP_BUFFER_READ?
379379
if (ret != 0) {
380380
goto error;
381381
}
382382
values[i] = (ffi_arg)(intptr_t)bufinfo.buf;
383383
} else if (MP_OBJ_IS_TYPE(a, &fficallback_type)) {
384-
mp_obj_fficallback_t *p = a;
384+
mp_obj_fficallback_t *p = MP_OBJ_TO_PTR(a);
385385
values[i] = (ffi_arg)(intptr_t)p->func;
386386
} else {
387387
goto error;
@@ -421,7 +421,7 @@ STATIC const mp_obj_type_t ffifunc_type = {
421421

422422
STATIC void fficallback_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
423423
(void)kind;
424-
mp_obj_fficallback_t *self = self_in;
424+
mp_obj_fficallback_t *self = MP_OBJ_TO_PTR(self_in);
425425
mp_printf(print, "<fficallback %p>", self->func);
426426
}
427427

@@ -435,19 +435,19 @@ STATIC const mp_obj_type_t fficallback_type = {
435435

436436
STATIC void ffivar_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
437437
(void)kind;
438-
mp_obj_ffivar_t *self = self_in;
438+
mp_obj_ffivar_t *self = MP_OBJ_TO_PTR(self_in);
439439
// Variable value printed as cast to int
440440
mp_printf(print, "<ffivar @%p: 0x%x>", self->var, *(int*)self->var);
441441
}
442442

443443
STATIC mp_obj_t ffivar_get(mp_obj_t self_in) {
444-
mp_obj_ffivar_t *self = self_in;
444+
mp_obj_ffivar_t *self = MP_OBJ_TO_PTR(self_in);
445445
return mp_binary_get_val_array(self->type, self->var, 0);
446446
}
447447
MP_DEFINE_CONST_FUN_OBJ_1(ffivar_get_obj, ffivar_get);
448448

449449
STATIC mp_obj_t ffivar_set(mp_obj_t self_in, mp_obj_t val_in) {
450-
mp_obj_ffivar_t *self = self_in;
450+
mp_obj_ffivar_t *self = MP_OBJ_TO_PTR(self_in);
451451
mp_binary_set_val_array(self->type, self->var, 0, val_in);
452452
return mp_const_none;
453453
}
@@ -464,7 +464,7 @@ STATIC const mp_obj_type_t ffivar_type = {
464464
{ &mp_type_type },
465465
.name = MP_QSTR_ffivar,
466466
.print = ffivar_print,
467-
.locals_dict = (mp_obj_t)&ffivar_locals_dict,
467+
.locals_dict = (mp_obj_dict_t*)&ffivar_locals_dict,
468468
};
469469

470470
// Generic opaque storage object (unused)
@@ -483,7 +483,7 @@ STATIC mp_obj_t mod_ffi_open(size_t n_args, const mp_obj_t *args) {
483483
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_ffi_open_obj, 1, 2, mod_ffi_open);
484484

485485
STATIC mp_obj_t mod_ffi_as_bytearray(mp_obj_t ptr, mp_obj_t size) {
486-
return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void*)mp_obj_int_get_truncated(ptr));
486+
return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void*)(uintptr_t)mp_obj_int_get_truncated(ptr));
487487
}
488488
MP_DEFINE_CONST_FUN_OBJ_2(mod_ffi_as_bytearray_obj, mod_ffi_as_bytearray);
489489

0 commit comments

Comments
 (0)