Ruby
3.1.0dev(2021-09-10revisionb76ad15ed0da636161de0243c547ee1e6fc95681)
|
Go to the documentation of this file.
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));
41 closure_memsize(
const void *
ptr)
47 #if !defined(FFI_NO_RAW_API) || !FFI_NO_RAW_API
48 size += ffi_raw_size(&cls->
cif);
51 size +=
sizeof(ffi_closure);
58 {0, dealloc, closure_memsize,},
69 with_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);
210 allocate(
VALUE klass)
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;
241 abi =
INT2NUM(FFI_DEFAULT_ABI);
252 for (i = 0; i <
argc; i++) {
261 rb_iv_set(
self,
"@args", normalized_args);
266 result = ffi_prep_cif(
cif,
272 if (FFI_OK != result)
275 #if USE_FFI_CLOSURE_ALLOC
276 result = ffi_prep_closure_loc(pcl,
cif, callback,
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)
VALUE rb_const_get(VALUE, ID)
VALUE rb_ary_new_capa(long capa)
void Init_fiddle_closure(void)
ID rb_intern(const char *)
VALUE rb_define_module(const char *name)
#define TypedData_Make_Struct(klass, type, data_type, sval)
VALUE rb_iv_get(VALUE, const char *)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_iv_set(VALUE, const char *, VALUE)
const rb_data_type_t closure_data_type
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE rb_cObject
Object class.
VALUE rb_ary_tmp_new(long capa)
VALUE rb_ary_push(VALUE ary, VALUE item)
void rb_sys_fail(const char *mesg)
ffi_type * rb_fiddle_int_to_ffi_type(int type)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
int ruby_thread_has_gvl_p(void)
#define RARRAY_CONST_PTR(a)
void * rb_thread_call_with_gvl(void *(*func)(void *), void *data1)
#define TypedData_Get_Struct(obj, type, data_type, sval)
#define RARRAY_AREF(a, i)
#define rb_str_new_cstr(str)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_fiddle_type_ensure(VALUE type)
#define StringValueCStr(v)
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define TYPE_CONST_STRING
VALUE type(ANYARGS)
ANYARGS-ed function type.