Skip to content

Commit 0cb8b4a

Browse files
committed
Use ffi_closure_free unconditionally.
The current conditionals reflect historic heritage of FFI. Usage of ffi_closure_free should be better default nowadays, because libffi 3.0.5 fixing issues of ffi_closure_free should be widely available.
1 parent ea06b28 commit 0cb8b4a

File tree

1 file changed

+0
-28
lines changed

1 file changed

+0
-28
lines changed

ext/fiddle/closure.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,11 @@ typedef struct {
1313
ffi_type **argv;
1414
} fiddle_closure;
1515

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
22-
#else
23-
# define USE_FFI_CLOSURE_ALLOC 1
24-
#endif
25-
2616
static void
2717
dealloc(void * ptr)
2818
{
2919
fiddle_closure * cls = (fiddle_closure *)ptr;
30-
#if USE_FFI_CLOSURE_ALLOC
3120
ffi_closure_free(cls->pcl);
32-
#else
33-
munmap(cls->pcl, sizeof(*cls->pcl));
34-
#endif
3521
if (cls->argv) xfree(cls->argv);
3622
xfree(cls);
3723
}
@@ -205,12 +191,7 @@ allocate(VALUE klass)
205191
VALUE i = TypedData_Make_Struct(klass, fiddle_closure,
206192
&closure_data_type, closure);
207193

208-
#if USE_FFI_CLOSURE_ALLOC
209194
closure->pcl = ffi_closure_alloc(sizeof(ffi_closure), &closure->code);
210-
#else
211-
closure->pcl = mmap(NULL, sizeof(ffi_closure), PROT_READ | PROT_WRITE,
212-
MAP_ANON | MAP_PRIVATE, -1, 0);
213-
#endif
214195

215196
return i;
216197
}
@@ -257,17 +238,8 @@ initialize(int rbargc, VALUE argv[], VALUE self)
257238
if (FFI_OK != result)
258239
rb_raise(rb_eRuntimeError, "error prepping CIF %d", result);
259240

260-
#if USE_FFI_CLOSURE_ALLOC
261241
result = ffi_prep_closure_loc(pcl, cif, callback,
262242
(void *)self, cl->code);
263-
#else
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);
267-
if (i) {
268-
rb_sys_fail("mprotect");
269-
}
270-
#endif
271243

272244
if (FFI_OK != result)
273245
rb_raise(rb_eRuntimeError, "error prepping closure %d", result);

0 commit comments

Comments
 (0)