Skip to content

Commit b62371e

Browse files
committed
modffi: 64-bit cleanness (fixes actual bug in callback arg handling).
1 parent c0bc3bd commit b62371e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

unix/modffi.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ STATIC mp_obj_t ffimod_func(mp_uint_t n_args, const mp_obj_t *args) {
181181
if (sym == NULL) {
182182
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno)));
183183
}
184-
int nparams = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(args[3]));
184+
mp_int_t nparams = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(args[3]));
185185
mp_obj_ffifunc_t *o = m_new_obj_var(mp_obj_ffifunc_t, ffi_type*, nparams);
186186
o->base.type = &ffifunc_type;
187187

@@ -207,7 +207,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ffimod_func_obj, 4, 4, ffimod_func);
207207
STATIC void call_py_func(ffi_cif *cif, void *ret, void** args, mp_obj_t func) {
208208
mp_obj_t pyargs[cif->nargs];
209209
for (int i = 0; i < cif->nargs; i++) {
210-
pyargs[i] = mp_obj_new_int(*(int*)args[i]);
210+
pyargs[i] = mp_obj_new_int(*(mp_int_t*)args[i]);
211211
}
212212
mp_obj_t res = mp_call_function_n_kw(func, cif->nargs, 0, pyargs);
213213

@@ -217,7 +217,7 @@ STATIC void call_py_func(ffi_cif *cif, void *ret, void** args, mp_obj_t func) {
217217
STATIC mp_obj_t mod_ffi_callback(mp_obj_t rettype_in, mp_obj_t func_in, mp_obj_t paramtypes_in) {
218218
const char *rettype = mp_obj_str_get_str(rettype_in);
219219

220-
int nparams = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(paramtypes_in));
220+
mp_int_t nparams = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(paramtypes_in));
221221
mp_obj_fficallback_t *o = m_new_obj_var(mp_obj_fficallback_t, ffi_type*, nparams);
222222
o->base.type = &fficallback_type;
223223

@@ -376,6 +376,7 @@ STATIC const mp_obj_type_t fficallback_type = {
376376

377377
STATIC void ffivar_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
378378
mp_obj_ffivar_t *self = self_in;
379+
// Variable value printed as cast to int
379380
print(env, "<ffivar @%p: 0x%x>", self->var, *(int*)self->var);
380381
}
381382

0 commit comments

Comments
 (0)