diff options
Diffstat (limited to 'ext/fiddle/closure.c')
-rw-r--r-- | ext/fiddle/closure.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/ext/fiddle/closure.c b/ext/fiddle/closure.c index d064f11991..1aab631aad 100644 --- a/ext/fiddle/closure.c +++ b/ext/fiddle/closure.c @@ -10,15 +10,21 @@ typedef struct { ffi_type **argv; } fiddle_closure; -#if defined(MACOSX) || defined(__linux__) || defined(__OpenBSD__) -#define DONT_USE_FFI_CLOSURE_ALLOC +#if defined(USE_FFI_CLOSURE_ALLOC) +#elif defined(__OpenBSD__) +# define USE_FFI_CLOSURE_ALLOC 0 +#elif RUBY_LIBFFI_MODVERSION < 3000005 && \ + (defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_AMD64)) +# define USE_FFI_CLOSURE_ALLOC 0 +#else +# define USE_FFI_CLOSURE_ALLOC 1 #endif static void dealloc(void * ptr) { fiddle_closure * cls = (fiddle_closure *)ptr; -#ifndef DONT_USE_FFI_CLOSURE_ALLOC +#if USE_FFI_CLOSURE_ALLOC ffi_closure_free(cls->pcl); #else munmap(cls->pcl, sizeof(cls->pcl)); @@ -170,7 +176,7 @@ allocate(VALUE klass) VALUE i = TypedData_Make_Struct(klass, fiddle_closure, &closure_data_type, closure); -#ifndef DONT_USE_FFI_CLOSURE_ALLOC +#if USE_FFI_CLOSURE_ALLOC closure->pcl = ffi_closure_alloc(sizeof(ffi_closure), &closure->code); #else closure->pcl = mmap(NULL, sizeof(ffi_closure), PROT_READ | PROT_WRITE, @@ -222,7 +228,7 @@ initialize(int rbargc, VALUE argv[], VALUE self) if (FFI_OK != result) rb_raise(rb_eRuntimeError, "error prepping CIF %d", result); -#ifndef DONT_USE_FFI_CLOSURE_ALLOC +#if USE_FFI_CLOSURE_ALLOC result = ffi_prep_closure_loc(pcl, cif, callback, (void *)self, cl->code); #else |