|
|
0fce6c |
diff --git a/ext/fiddle/closure.c b/ext/fiddle/closure.c
|
|
|
0fce6c |
index 1a80b2b..b997e23 100644
|
|
|
0fce6c |
--- a/ext/fiddle/closure.c
|
|
|
0fce6c |
+++ b/ext/fiddle/closure.c
|
|
|
07f2a6 |
@@ -13,22 +13,11 @@ typedef struct {
|
|
|
0fce6c |
ffi_type **argv;
|
|
|
0fce6c |
} fiddle_closure;
|
|
|
0fce6c |
|
|
|
0fce6c |
-#if defined(USE_FFI_CLOSURE_ALLOC)
|
|
|
07f2a6 |
-#elif !defined(HAVE_FFI_CLOSURE_ALLOC)
|
|
|
0fce6c |
-# define USE_FFI_CLOSURE_ALLOC 0
|
|
|
0fce6c |
-#else
|
|
|
0fce6c |
-# define USE_FFI_CLOSURE_ALLOC 1
|
|
|
0fce6c |
-#endif
|
|
|
0fce6c |
-
|
|
|
0fce6c |
static void
|
|
|
0fce6c |
dealloc(void * ptr)
|
|
|
0fce6c |
{
|
|
|
0fce6c |
fiddle_closure * cls = (fiddle_closure *)ptr;
|
|
|
0fce6c |
-#if USE_FFI_CLOSURE_ALLOC
|
|
|
0fce6c |
ffi_closure_free(cls->pcl);
|
|
|
0fce6c |
-#else
|
|
|
0fce6c |
- munmap(cls->pcl, sizeof(*cls->pcl));
|
|
|
0fce6c |
-#endif
|
|
|
0fce6c |
if (cls->argv) xfree(cls->argv);
|
|
|
0fce6c |
xfree(cls);
|
|
|
0fce6c |
}
|
|
|
07f2a6 |
@@ -202,12 +188,7 @@ allocate(VALUE klass)
|
|
|
0fce6c |
VALUE i = TypedData_Make_Struct(klass, fiddle_closure,
|
|
|
0fce6c |
&closure_data_type, closure);
|
|
|
0fce6c |
|
|
|
0fce6c |
-#if USE_FFI_CLOSURE_ALLOC
|
|
|
0fce6c |
closure->pcl = ffi_closure_alloc(sizeof(ffi_closure), &closure->code);
|
|
|
0fce6c |
-#else
|
|
|
0fce6c |
- closure->pcl = mmap(NULL, sizeof(ffi_closure), PROT_READ | PROT_WRITE,
|
|
|
0fce6c |
- MAP_ANON | MAP_PRIVATE, -1, 0);
|
|
|
0fce6c |
-#endif
|
|
|
0fce6c |
|
|
|
0fce6c |
return i;
|
|
|
0fce6c |
}
|
|
|
07f2a6 |
@@ -254,17 +238,8 @@ initialize(int rbargc, VALUE argv[], VALUE self)
|
|
|
0fce6c |
if (FFI_OK != result)
|
|
|
0fce6c |
rb_raise(rb_eRuntimeError, "error prepping CIF %d", result);
|
|
|
0fce6c |
|
|
|
0fce6c |
-#if USE_FFI_CLOSURE_ALLOC
|
|
|
0fce6c |
result = ffi_prep_closure_loc(pcl, cif, callback,
|
|
|
0fce6c |
(void *)self, cl->code);
|
|
|
0fce6c |
-#else
|
|
|
0fce6c |
- result = ffi_prep_closure(pcl, cif, callback, (void *)self);
|
|
|
0fce6c |
- cl->code = (void *)pcl;
|
|
|
0fce6c |
- i = mprotect(pcl, sizeof(*pcl), PROT_READ | PROT_EXEC);
|
|
|
0fce6c |
- if (i) {
|
|
|
0fce6c |
- rb_sys_fail("mprotect");
|
|
|
0fce6c |
- }
|
|
|
0fce6c |
-#endif
|
|
|
0fce6c |
|
|
|
0fce6c |
if (FFI_OK != result)
|
|
|
0fce6c |
rb_raise(rb_eRuntimeError, "error prepping closure %d", result);
|