16 #if defined(USE_FFI_CLOSURE_ALLOC) 17 #elif defined(__OpenBSD__) || defined(__APPLE__) || defined(__linux__) 18 # define USE_FFI_CLOSURE_ALLOC 0 19 #elif defined(RUBY_LIBFFI_MODVERSION) && RUBY_LIBFFI_MODVERSION < 3000005 && \ 20 (defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_AMD64)) 21 # define USE_FFI_CLOSURE_ALLOC 0 23 # define USE_FFI_CLOSURE_ALLOC 1 30 #if USE_FFI_CLOSURE_ALLOC 31 ffi_closure_free(cls->
pcl);
33 munmap(cls->
pcl,
sizeof(*cls->
pcl));
40 closure_memsize(
const void * ptr)
46 #if !defined(FFI_NO_RAW_API) || !FFI_NO_RAW_API 47 size += ffi_raw_size(&cls->
cif);
49 size +=
sizeof(*cls->
argv);
50 size +=
sizeof(ffi_closure);
57 {0, dealloc, closure_memsize,},
68 with_gvl_callback(
void *ptr)
83 for (i = 0; i <
argc; i++) {
128 case -TYPE_LONG_LONG:
171 *(LONG_LONG *)x->
resp = NUM2LL(ret);
173 case -TYPE_LONG_LONG:
174 *(
unsigned LONG_LONG *)x->
resp = NUM2ULL(ret);
194 (void)with_gvl_callback(&x);
201 allocate(
VALUE klass)
206 &closure_data_type, closure);
208 #if USE_FFI_CLOSURE_ALLOC 209 closure->
pcl = ffi_closure_alloc(
sizeof(ffi_closure), &closure->
code);
211 closure->
pcl = mmap(
NULL,
sizeof(ffi_closure), PROT_READ | PROT_WRITE,
212 MAP_ANON | MAP_PRIVATE, -1, 0);
231 abi =
INT2NUM(FFI_DEFAULT_ABI);
239 cl->
argv = (ffi_type **)
xcalloc(argc + 1,
sizeof(ffi_type *));
241 for (i = 0; i <
argc; i++) {
253 result = ffi_prep_cif(cif,
NUM2INT(abi), argc,
257 if (FFI_OK != result)
260 #if USE_FFI_CLOSURE_ALLOC 261 result = ffi_prep_closure_loc(pcl, cif, callback,
262 (
void *)
self, cl->
code);
264 result = ffi_prep_closure(pcl, cif, callback, (
void *)
self);
265 cl->
code = (
void *)pcl;
266 i = mprotect(pcl,
sizeof(*pcl), PROT_READ | PROT_EXEC);
272 if (FFI_OK != result)
void rb_raise(VALUE exc, const char *fmt,...)
#define TypedData_Get_Struct(obj, type, data_type, sval)
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_ary_tmp_new(long capa)
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)
RUBY_EXTERN VALUE rb_cObject
const rb_data_type_t closure_data_type
#define INT2FFI_TYPE(_type)
void rb_sys_fail(const char *mesg)
VALUE rb_const_get(VALUE, ID)
#define RARRAY_CONST_PTR(a)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
#define RARRAY_LENINT(ary)
#define RARRAY_AREF(a, i)
int ruby_thread_has_gvl_p(void)
RUBY_SYMBOL_EXPORT_BEGIN void * rb_thread_call_with_gvl(void *(*func)(void *), void *data1)
#define TypedData_Make_Struct(klass, type, data_type, sval)
void Init_fiddle_closure(void)
VALUE rb_define_module(const char *name)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)