@@ -97,7 +97,6 @@ typedef struct _mp_obj_ffifunc_t {
97
97
ffi_type * params [];
98
98
} mp_obj_ffifunc_t ;
99
99
100
- #ifndef __CHERI_PURE_CAPABILITY__
101
100
typedef struct _mp_obj_fficallback_t {
102
101
mp_obj_base_t base ;
103
102
void * func ;
@@ -107,14 +106,11 @@ typedef struct _mp_obj_fficallback_t {
107
106
ffi_cif cif ;
108
107
ffi_type * params [];
109
108
} mp_obj_fficallback_t ;
110
- #endif
111
109
112
110
// STATIC const mp_obj_type_t opaque_type;
113
111
STATIC const mp_obj_type_t ffimod_type ;
114
112
STATIC const mp_obj_type_t ffifunc_type ;
115
- #ifndef __CHERI_PURE_CAPABILITY__
116
113
STATIC const mp_obj_type_t fficallback_type ;
117
- #endif
118
114
STATIC const mp_obj_type_t ffivar_type ;
119
115
120
116
#ifdef __CHERI_PURE_CAPABILITY__
@@ -285,14 +281,15 @@ STATIC mp_obj_t mod_ffi_func(mp_obj_t rettype, mp_obj_t addr_in, mp_obj_t argtyp
285
281
}
286
282
MP_DEFINE_CONST_FUN_OBJ_3 (mod_ffi_func_obj , mod_ffi_func );
287
283
288
- #ifndef __CHERI_PURE_CAPABILITY__
289
284
STATIC void call_py_func (ffi_cif * cif , void * ret , void * * args , void * user_data ) {
290
285
mp_obj_t pyargs [cif -> nargs ];
291
286
mp_obj_fficallback_t * o = user_data ;
292
287
mp_obj_t pyfunc = o -> pyfunc ;
293
288
294
289
for (uint i = 0 ; i < cif -> nargs ; i ++ ) {
295
- pyargs [i ] = mp_obj_new_int (* (mp_int_t * )args [i ]);
290
+ pyargs [i ] = (cif -> arg_types [i ] == & ffi_type_pointer )
291
+ ? mp_obj_new_cap (* (void * * )args [i ])
292
+ : mp_obj_new_int (* (mp_int_t * )args [i ]);
296
293
}
297
294
mp_obj_t res = mp_call_function_n_kw (pyfunc , cif -> nargs , 0 , pyargs );
298
295
@@ -381,7 +378,6 @@ STATIC mp_obj_t mod_ffi_callback(size_t n_args, const mp_obj_t *pos_args, mp_map
381
378
return MP_OBJ_FROM_PTR (o );
382
379
}
383
380
MP_DEFINE_CONST_FUN_OBJ_KW (mod_ffi_callback_obj , 3 , mod_ffi_callback );
384
- #endif
385
381
386
382
STATIC mp_obj_t ffimod_var (mp_obj_t self_in , mp_obj_t vartype_in , mp_obj_t symname_in ) {
387
383
mp_obj_ffimod_t * self = MP_OBJ_TO_PTR (self_in );
@@ -540,11 +536,9 @@ STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
540
536
goto error ;
541
537
}
542
538
values [i ].ffi = (ffi_arg )(intptr_t )bufinfo .buf ;
543
- #ifndef __CHERI_PURE_CAPABILITY__
544
539
} else if (mp_obj_is_type (a , & fficallback_type )) {
545
540
mp_obj_fficallback_t * p = MP_OBJ_TO_PTR (a );
546
541
values [i ].ffi = (ffi_arg )(intptr_t )p -> func ;
547
- #endif
548
542
} else {
549
543
goto error ;
550
544
}
@@ -567,7 +561,6 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE(
567
561
call , ffifunc_call
568
562
);
569
563
570
- #ifndef __CHERI_PURE_CAPABILITY__
571
564
// FFI callback for Python function
572
565
573
566
STATIC void fficallback_print (const mp_print_t * print , mp_obj_t self_in , mp_print_kind_t kind ) {
@@ -594,7 +587,6 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE(
594
587
print , fficallback_print ,
595
588
locals_dict , & fficallback_locals_dict
596
589
);
597
- #endif
598
590
// FFI variable
599
591
600
592
STATIC void ffivar_print (const mp_print_t * print , mp_obj_t self_in , mp_print_kind_t kind ) {
@@ -660,9 +652,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(mod_ffi_as_bytearray_obj, mod_ffi_as_bytearray);
660
652
STATIC const mp_rom_map_elem_t mp_module_ffi_globals_table [] = {
661
653
{ MP_ROM_QSTR (MP_QSTR___name__ ), MP_ROM_QSTR (MP_QSTR_ffi ) },
662
654
{ MP_ROM_QSTR (MP_QSTR_open ), MP_ROM_PTR (& mod_ffi_open_obj ) },
663
- #ifndef __CHERI_PURE_CAPABILITY__
664
655
{ MP_ROM_QSTR (MP_QSTR_callback ), MP_ROM_PTR (& mod_ffi_callback_obj ) },
665
- #endif
666
656
{ MP_ROM_QSTR (MP_QSTR_func ), MP_ROM_PTR (& mod_ffi_func_obj ) },
667
657
{ MP_ROM_QSTR (MP_QSTR_as_bytearray ), MP_ROM_PTR (& mod_ffi_as_bytearray_obj ) },
668
658
};
0 commit comments