4 # define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj)
5 # define RB_OBJ_STRING(obj) (obj)
8 # define RB_OBJ_CLASSNAME(obj) rb_obj_classname(obj)
9 # define RB_OBJ_STRING(obj) StringValueCStr(obj)
14 #define MAX_ARGS (SIZE_MAX / (sizeof(void *) + sizeof(fiddle_generic)) - 1)
16 #define Check_Max_Args(name, len) \
17 Check_Max_Args_(name, len, "")
18 #define Check_Max_Args_Long(name, len) \
19 Check_Max_Args_(name, len, "l")
20 #define Check_Max_Args_(name, len, fmt) \
21 if ((size_t)(len) < MAX_ARGS) { \
25 rb_raise(rb_eTypeError, \
26 name" is so large that it can cause integer overflow (%"fmt"d)", \
34 if (ptr->arg_types)
xfree(ptr->arg_types);
41 ffi_cif *ptr = (ffi_cif *)p;
46 #if !defined(FFI_NO_RAW_API) || !FFI_NO_RAW_API
47 size += ffi_raw_size(ptr);
94 ffi_type **arg_types, *rtype;
96 VALUE ptr,
args, ret_type, abi, kwds, ary;
101 rb_scan_args(argc, argv,
"31:", &ptr, &args, &ret_type, &abi, &kwds);
125 rb_iv_set(
self,
"@return_type", ret_type);
132 arg_types =
xcalloc(len + 1,
sizeof(ffi_type *));
138 arg_types[len] =
NULL;
140 result = ffi_prep_cif(cif, nabi, len, rtype, arg_types);
155 VALUE cfunc, types, cPointer;
157 VALUE alloc_buffer = 0;
172 for (i = 0; i <
argc; i++) {
180 generic_args =
ALLOCV(alloc_buffer,
181 (
size_t)(argc + 1) *
sizeof(
void *) + (
size_t)argc *
sizeof(
fiddle_generic));
182 values = (
void **)((
char *)generic_args + (size_t)argc *
sizeof(
fiddle_generic));
184 for (i = 0; i <
argc; i++) {
192 }
else if(cPointer !=
CLASS_OF(src)) {
199 values[
i] = (
void *)&generic_args[i];
203 ffi_call(cif,
NUM2PTR(cfunc), &retval, values);
262 #ifdef HAVE_CONST_FFI_STDCALL
#define VALUE2GENERIC(_type, _src, _dst)
VALUE rb_ary_subseq(VALUE ary, long beg, long len)
#define TypedData_Get_Struct(obj, type, data_type, sval)
static VALUE initialize(int argc, VALUE argv[], VALUE self)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_raise(VALUE exc, const char *fmt,...)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
#define Check_Max_Args_Long(name, len)
static void deallocate(void *p)
void rb_hash_foreach(VALUE hash, int(*func)(ANYARGS), VALUE farg)
VALUE rb_class_new_instance(int, VALUE *, VALUE)
RUBY_EXTERN VALUE rb_cObject
#define RB_OBJ_STRING(obj)
VALUE rb_iv_get(VALUE, const char *)
static VALUE function_call(int argc, VALUE argv[], VALUE self)
void rb_define_const(VALUE, const char *, VALUE)
void rb_ary_store(VALUE ary, long idx, VALUE val)
static int parse_keyword_arg_i(VALUE key, VALUE value, VALUE self)
#define INT2FFI_TYPE(_type)
VALUE rb_const_get(VALUE, ID)
VALUE rb_iv_set(VALUE, const char *, VALUE)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
#define Check_Max_Args(name, len)
static VALUE allocate(VALUE klass)
#define RARRAY_LENINT(ary)
VALUE rb_fiddle_new_function(VALUE address, VALUE arg_types, VALUE ret_type)
const rb_data_type_t function_data_type
#define TypedData_Make_Struct(klass, type, data_type, sval)
#define GENERIC2VALUE(_type, _retval)
void Init_fiddle_function(void)
static size_t function_memsize(const void *p)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)