16#if defined(__OpenBSD__)
17# define USE_FFI_CLOSURE_ALLOC 0
20#if defined(USE_FFI_CLOSURE_ALLOC)
21#elif !defined(HAVE_FFI_CLOSURE_ALLOC)
22# define USE_FFI_CLOSURE_ALLOC 0
24# define USE_FFI_CLOSURE_ALLOC 1
31#if USE_FFI_CLOSURE_ALLOC
32 ffi_closure_free(cls->
pcl);
34 munmap(cls->
pcl,
sizeof(*cls->
pcl));
41closure_memsize(
const void *
ptr)
47#if !defined(FFI_NO_RAW_API) || !FFI_NO_RAW_API
51 size +=
sizeof(ffi_closure);
58 {0, dealloc, closure_memsize,},
69with_gvl_callback(
void *
ptr)
76 int argc = RARRAY_LENINT(rbargs);
84 for (i = 0; i <
argc; i++) {
129 case -TYPE_LONG_LONG:
178 case -TYPE_LONG_LONG:
203 (void)with_gvl_callback(&x);
217#if USE_FFI_CLOSURE_ALLOC
218 closure->
pcl = ffi_closure_alloc(
sizeof(ffi_closure), &closure->
code);
220 closure->
pcl = mmap(
NULL,
sizeof(ffi_closure), PROT_READ | PROT_WRITE,
221 MAP_ANON | MAP_PRIVATE, -1, 0);
232 VALUE normalized_args;
252 for (i = 0; i <
argc; i++) {
261 rb_iv_set(self,
"@args", normalized_args);
272 if (FFI_OK != result)
275#if USE_FFI_CLOSURE_ALLOC
277 (
void *)self, cl->
code);
279 result = ffi_prep_closure(pcl,
cif, callback, (
void *)self);
280 cl->
code = (
void *)pcl;
281 i = mprotect(pcl,
sizeof(*pcl), PROT_READ | PROT_EXEC);
287 if (FFI_OK != result)
ffi_status ffi_prep_closure_loc(ffi_closure *closure, ffi_cif *cif, void(*fun)(ffi_cif *, void *, void **, void *), void *user_data, void *codeloc)
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_ary_new_capa(long capa)
VALUE rb_ary_tmp_new(long capa)
int ruby_thread_has_gvl_p(void)
const rb_data_type_t closure_data_type
void Init_fiddle_closure(void)
ffi_type * rb_fiddle_int_to_ffi_type(int type)
VALUE rb_fiddle_type_ensure(VALUE type)
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define TYPE_CONST_STRING
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_define_module(const char *name)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
void rb_raise(VALUE exc, const char *fmt,...)
void rb_sys_fail(const char *mesg)
VALUE rb_cObject
Object class.
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
#define rb_str_new_cstr(str)
VALUE rb_const_get(VALUE, ID)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
ID rb_intern(const char *)
VALUE rb_iv_set(VALUE, const char *, VALUE)
VALUE rb_iv_get(VALUE, const char *)
void * rb_thread_call_with_gvl(void *(*func)(void *), void *data1)
VALUE type(ANYARGS)
ANYARGS-ed function type.
ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs, ffi_type *rtype, ffi_type **atypes)
#define RARRAY_CONST_PTR(s)
#define RARRAY_AREF(a, i)
size_t ffi_raw_size(ffi_cif *cif)
#define StringValueCStr(v)
#define TypedData_Get_Struct(obj, type, data_type, sval)
#define TypedData_Make_Struct(klass, type, data_type, sval)