13 #if defined(MACOSX) || defined(__linux) || defined(__OpenBSD__)
14 #define DONT_USE_FFI_CLOSURE_ALLOC
21 #ifndef DONT_USE_FFI_CLOSURE_ALLOC
22 ffi_closure_free(cls->
pcl);
24 munmap(cls->
pcl,
sizeof(*cls->
pcl));
38 #if !defined(FFI_NO_RAW_API) || !FFI_NO_RAW_API
39 size += ffi_raw_size(&cls->
cif);
41 size +=
sizeof(*cls->
argv);
42 size +=
sizeof(ffi_closure);
66 for (i = 0; i <
argc; i++) {
109 rb_ary_push(params, LL2NUM(*(LONG_LONG *)args[i]));
111 case -TYPE_LONG_LONG:
112 rb_ary_push(params, ULL2NUM(*(
unsigned LONG_LONG *)args[i]));
136 *(ffi_sarg *)resp =
NUM2INT(ret);
147 *(
double *)resp =
NUM2DBL(ret);
150 *(
float *)resp = (
float)
NUM2DBL(ret);
154 *(LONG_LONG *)resp = NUM2LL(ret);
156 case -TYPE_LONG_LONG:
157 *(
unsigned LONG_LONG *)resp = NUM2ULL(ret);
171 &closure_data_type, closure);
173 #ifndef DONT_USE_FFI_CLOSURE_ALLOC
174 closure->
pcl = ffi_closure_alloc(
sizeof(ffi_closure), &closure->
code);
176 closure->
pcl = mmap(
NULL,
sizeof(ffi_closure), PROT_READ | PROT_WRITE,
177 MAP_ANON | MAP_PRIVATE, -1, 0);
195 if (2 ==
rb_scan_args(rbargc, argv,
"21", &ret, &args, &abi))
196 abi =
INT2NUM(FFI_DEFAULT_ABI);
204 cl->
argv = (ffi_type **)
xcalloc(argc + 1,
sizeof(ffi_type *));
206 for (i = 0; i <
argc; i++) {
218 result = ffi_prep_cif(cif,
NUM2INT(abi), argc,
222 if (FFI_OK != result)
225 #ifndef DONT_USE_FFI_CLOSURE_ALLOC
226 result = ffi_prep_closure_loc(pcl, cif,
callback,
227 (
void *)
self, cl->
code);
229 result = ffi_prep_closure(pcl, cif,
callback, (
void *)
self);
230 cl->
code = (
void *)pcl;
231 i = mprotect(pcl,
sizeof(*pcl), PROT_READ | PROT_EXEC);
237 if (FFI_OK != result)
static long NUM2LONG(VALUE x)
static VALUE UINT2NUM(unsigned int v)
#define TypedData_Get_Struct(obj, type, data_type, sval)
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_ary_tmp_new(long capa)
static VALUE INT2NUM(int v)
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)
void callback(ffi_cif *cif, void *resp, void **args, void *ctx)
RUBY_EXTERN VALUE rb_cObject
static VALUE to_i(VALUE self)
VALUE rb_iv_get(VALUE, const char *)
const rb_data_type_t closure_data_type
#define INT2FFI_TYPE(_type)
static void dealloc(void *ptr)
VALUE rb_const_get(VALUE, ID)
VALUE rb_funcall2(VALUE, ID, int, const VALUE *)
Calls a method.
#define RB_GC_GUARD(object)
VALUE rb_iv_set(VALUE, const char *, VALUE)
static VALUE initialize(int rbargc, VALUE argv[], VALUE self)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
#define RARRAY_LENINT(ary)
void rb_sys_fail(const char *mesg)
VALUE rb_float_new(double)
static VALUE allocate(VALUE klass)
static VALUE ULONG2NUM(unsigned long v)
#define TypedData_Make_Struct(klass, type, data_type, sval)
void Init_fiddle_closure()
return rb_funcall(q->proc, ID_call, 0)
VALUE rb_define_module(const char *name)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
static size_t closure_memsize(const void *ptr)