@@ -221,6 +221,7 @@ initialize(int rbargc, VALUE argv[], VALUE self)
221
221
{
222
222
VALUE ret ;
223
223
VALUE args ;
224
+ VALUE normalized_args ;
224
225
VALUE abi ;
225
226
fiddle_closure * cl ;
226
227
ffi_cif * cif ;
@@ -239,21 +240,26 @@ initialize(int rbargc, VALUE argv[], VALUE self)
239
240
240
241
cl -> argv = (ffi_type * * )xcalloc (argc + 1 , sizeof (ffi_type * ));
241
242
243
+ normalized_args = rb_ary_new_capa (argc );
242
244
for (i = 0 ; i < argc ; i ++ ) {
243
- int type = NUM2INT (RARRAY_AREF (args , i ));
244
- cl -> argv [i ] = INT2FFI_TYPE (type );
245
+ VALUE arg = rb_fiddle_type_ensure (RARRAY_AREF (args , i ));
246
+ rb_ary_push (normalized_args , arg );
247
+ cl -> argv [i ] = rb_fiddle_int_to_ffi_type (NUM2INT (arg ));
245
248
}
246
249
cl -> argv [argc ] = NULL ;
247
250
251
+ ret = rb_fiddle_type_ensure (ret );
248
252
rb_iv_set (self , "@ctype" , ret );
249
- rb_iv_set (self , "@args" , args );
253
+ rb_iv_set (self , "@args" , normalized_args );
250
254
251
255
cif = & cl -> cif ;
252
256
pcl = cl -> pcl ;
253
257
254
- result = ffi_prep_cif (cif , NUM2INT (abi ), argc ,
255
- INT2FFI_TYPE (NUM2INT (ret )),
256
- cl -> argv );
258
+ result = ffi_prep_cif (cif ,
259
+ NUM2INT (abi ),
260
+ argc ,
261
+ rb_fiddle_int_to_ffi_type (NUM2INT (ret )),
262
+ cl -> argv );
257
263
258
264
if (FFI_OK != result )
259
265
rb_raise (rb_eRuntimeError , "error prepping CIF %d" , result );
0 commit comments