End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
Fiddle::Function.new
new(ptr,
args,
ret_type,
abi = DEFAULT,
name: nil,
need_gvl: false)
ext/fiddle/function.c
View on GitHub ↗
static VALUE
initialize(int argc, VALUE argv[], VALUE self)
{
ffi_cif * cif;
VALUE ptr, arg_types, ret_type, abi, kwargs;
VALUE name = Qnil;
VALUE need_gvl = Qfalse;
int c_ret_type;
bool is_variadic = false;
ffi_abi c_ffi_abi;
void *cfunc;
rb_scan_args(argc, argv, "31:", &ptr, &arg_types, &ret_type, &abi, &kwargs);
rb_iv_set(self, "@closure", ptr);
if (!NIL_P(kwargs)) {
enum {
kw_name,
kw_need_gvl,
kw_max_,
};
static ID kw[kw_max_];
VALUE args[kw_max_];
if (!kw[0]) {
kw[kw_name] = rb_intern_const("name");
kw[kw_need_gvl] = rb_intern_const("need_gvl");
}
rb_get_kwargs(kwargs, kw, 0, kw_max_, args);
if (args[kw_name] != Qundef) {
name = args[kw_name];
}
if (args[kw_need_gvl] != Qundef) {
need_gvl = args[kw_need_gvl];
}
}
rb_iv_set(self, "@name", name);
rb_iv_set(self, "@need_gvl", need_gvl);
ptr = rb_Integer(ptr);
cfunc = NUM2PTR(ptr);
PTR2NUM(cfunc);
c_ffi_abi = NIL_P(abi) ? FFI_DEFAULT_ABI : NUM2INT(abi);
abi = INT2FIX(c_ffi_abi);
ret_type = rb_fiddle_type_ensure(ret_type);
c_ret_type = NUM2INT(ret_type);
(void)INT2FFI_TYPE(c_ret_type); /* raise */
ret_type = INT2FIX(c_ret_type);
arg_types = normalize_argument_types("argument types",
arg_types,
&is_variadic);
#ifndef HAVE_FFI_PREP_CIF_VAR
if (is_variadic) {
rb_raise(rb_eNotImpError,
"ffi_prep_cif_var() is required in libffi "
"for variadic arguments");
}
#endif
rb_iv_set(self, "@ptr", ptr);
rb_iv_set(self, "@argument_types", arg_types);
rb_iv_set(self, "@return_type", ret_type);
rb_iv_set(self, "@abi", abi);
rb_iv_set(self, "@is_variadic", is_variadic ? Qtrue : Qfalse);
TypedData_Get_Struct(self, ffi_cif, &function_data_type, cif);
cif->arg_types = NULL;
return self;
}
Constructs a Function object.
-
ptris a referenced function, of aFiddle::Handle -
argsis anArrayof arguments, passed to theptrfunction -
ret_typeis the return type of the function -
abiis the ABI of the function -
nameis the name of the function -
need_gvlis whether GVL is needed to call the function