5 # define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj) 6 # define RB_OBJ_STRING(obj) (obj) 9 # define RB_OBJ_CLASSNAME(obj) rb_obj_classname(obj) 10 # define RB_OBJ_STRING(obj) StringValueCStr(obj) 15 #define MAX_ARGS (SIZE_MAX / (sizeof(void *) + sizeof(fiddle_generic)) - 1) 17 #define Check_Max_Args(name, len) \ 18 Check_Max_Args_(name, len, "") 19 #define Check_Max_Args_Long(name, len) \ 20 Check_Max_Args_(name, len, "l") 21 #define Check_Max_Args_(name, len, fmt) \ 22 if ((size_t)(len) < MAX_ARGS) { \ 26 rb_raise(rb_eTypeError, \ 27 name" is so large that it can cause integer overflow (%"fmt"d)", \ 35 if (ptr->arg_types)
xfree(ptr->arg_types);
40 function_memsize(
const void *p)
42 ffi_cif *ptr = (ffi_cif *)p;
46 #if !defined(FFI_NO_RAW_API) || !FFI_NO_RAW_API 47 size += ffi_raw_size(ptr);
55 {0, deallocate, function_memsize,},
94 ffi_type **arg_types, *rtype;
96 VALUE ptr,
args, ret_type, abi, kwds, ary;
125 rb_iv_set(
self,
"@return_type", ret_type);
132 arg_types =
xcalloc(len + 1,
sizeof(ffi_type *));
140 result = ffi_prep_cif(cif, nabi, len, rtype, arg_types);
156 nogvl_ffi_call(
void *ptr)
170 VALUE cfunc, types, cPointer;
172 VALUE alloc_buffer = 0;
186 for (i = 0; i <
argc; i++) {
194 generic_args =
ALLOCV(alloc_buffer,
196 args.
values = (
void **)((
char *)generic_args +
199 for (i = 0; i <
argc; i++) {
207 }
else if(cPointer !=
CLASS_OF(src)) {
214 args.
values[i] = (
void *)&generic_args[i];
278 #ifdef HAVE_CONST_FFI_STDCALL #define VALUE2GENERIC(_type, _src, _dst)
VALUE rb_ary_subseq(VALUE ary, long beg, long len)
void rb_raise(VALUE exc, const char *fmt,...)
#define TypedData_Get_Struct(obj, type, data_type, sval)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
VALUE rb_iv_set(VALUE, const char *, VALUE)
VALUE rb_iv_get(VALUE, const char *)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE rb_Integer(VALUE)
Equivalent to Kernel#Integer in Ruby.
void rb_hash_foreach(VALUE hash, int(*func)(ANYARGS), VALUE farg)
RUBY_EXTERN VALUE rb_cObject
#define RB_OBJ_STRING(obj)
void rb_define_const(VALUE, const char *, VALUE)
void rb_ary_store(VALUE ary, long idx, VALUE val)
#define INT2FFI_TYPE(_type)
void * rb_thread_call_without_gvl(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2)
VALUE rb_const_get(VALUE, ID)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
#define Check_Max_Args(name, len)
#define RARRAY_LENINT(ary)
register unsigned int len
VALUE rb_fiddle_new_function(VALUE address, VALUE arg_types, VALUE ret_type)
#define RARRAY_AREF(a, i)
void rb_error_arity(int argc, int min, int max)
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
Allocates and initializes an instance of klass.
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)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)