Skip to content

Commit bbaf68f

Browse files
committed
modffi: Implement 'O' type handling for func arguments.
1 parent 5345743 commit bbaf68f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

unix/modffi.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ typedef struct _mp_obj_ffifunc_t {
7676
mp_obj_base_t base;
7777
void *func;
7878
char rettype;
79+
const char *argtypes;
7980
ffi_cif cif;
8081
ffi_type *params[];
8182
} mp_obj_ffifunc_t;
@@ -181,13 +182,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(ffimod_close_obj, ffimod_close);
181182

182183
STATIC mp_obj_t make_func(mp_obj_t rettype_in, void *func, mp_obj_t argtypes_in) {
183184
const char *rettype = mp_obj_str_get_str(rettype_in);
185+
const char *argtypes = mp_obj_str_get_str(argtypes_in);
184186

185187
mp_int_t nparams = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(argtypes_in));
186188
mp_obj_ffifunc_t *o = m_new_obj_var(mp_obj_ffifunc_t, ffi_type*, nparams);
187189
o->base.type = &ffifunc_type;
188190

189191
o->func = func;
190192
o->rettype = *rettype;
193+
o->argtypes = argtypes;
191194

192195
mp_obj_t iterable = mp_getiter(argtypes_in);
193196
mp_obj_t item;
@@ -348,9 +351,12 @@ STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw,
348351

349352
ffi_arg values[n_args];
350353
void *valueptrs[n_args];
351-
for (uint i = 0; i < n_args; i++) {
354+
const char *argtype = self->argtypes;
355+
for (uint i = 0; i < n_args; i++, argtype++) {
352356
mp_obj_t a = args[i];
353-
if (a == mp_const_none) {
357+
if (*argtype == 'O') {
358+
values[i] = (ffi_arg)a;
359+
} else if (a == mp_const_none) {
354360
values[i] = 0;
355361
} else if (MP_OBJ_IS_INT(a)) {
356362
values[i] = mp_obj_int_get_truncated(a);

0 commit comments

Comments
 (0)