@@ -221,6 +221,7 @@ initialize(int rbargc, VALUE argv[], VALUE self)
221221{
222222 VALUE ret ;
223223 VALUE args ;
224+ VALUE normalized_args ;
224225 VALUE abi ;
225226 fiddle_closure * cl ;
226227 ffi_cif * cif ;
@@ -239,21 +240,26 @@ initialize(int rbargc, VALUE argv[], VALUE self)
239240
240241 cl -> argv = (ffi_type * * )xcalloc (argc + 1 , sizeof (ffi_type * ));
241242
243+ normalized_args = rb_ary_new_capa (argc );
242244 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 ));
245248 }
246249 cl -> argv [argc ] = NULL ;
247250
251+ ret = rb_fiddle_type_ensure (ret );
248252 rb_iv_set (self , "@ctype" , ret );
249- rb_iv_set (self , "@args" , args );
253+ rb_iv_set (self , "@args" , normalized_args );
250254
251255 cif = & cl -> cif ;
252256 pcl = cl -> pcl ;
253257
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 );
257263
258264 if (FFI_OK != result )
259265 rb_raise (rb_eRuntimeError , "error prepping CIF %d" , result );
0 commit comments