* ext/fiddle/extconf.rb: define RUBY_LIBFFI_MODVERSION macro.
* ext/fiddle/closure.c (USE_FFI_CLOSURE_ALLOC): define 0 or 1 with platform and libffi's version. [Bug #3371] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40219 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c607493e48
commit
a0f7f29215
@ -1,3 +1,10 @@
|
|||||||
|
Thu Apr 11 06:09:57 2013 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/fiddle/extconf.rb: define RUBY_LIBFFI_MODVERSION macro.
|
||||||
|
|
||||||
|
* ext/fiddle/closure.c (USE_FFI_CLOSURE_ALLOC): define 0 or 1
|
||||||
|
with platform and libffi's version. [Bug #3371]
|
||||||
|
|
||||||
Thu Apr 11 05:30:43 2013 NARUSE, Yui <naruse@ruby-lang.org>
|
Thu Apr 11 05:30:43 2013 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* lib/mkmf.rb (pkg_config): Add optional argument "option".
|
* lib/mkmf.rb (pkg_config): Add optional argument "option".
|
||||||
|
@ -10,15 +10,21 @@ typedef struct {
|
|||||||
ffi_type **argv;
|
ffi_type **argv;
|
||||||
} fiddle_closure;
|
} fiddle_closure;
|
||||||
|
|
||||||
#if defined(MACOSX) || defined(__linux__) || defined(__OpenBSD__)
|
#if defined(USE_FFI_CLOSURE_ALLOC)
|
||||||
#define DONT_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
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dealloc(void * ptr)
|
dealloc(void * ptr)
|
||||||
{
|
{
|
||||||
fiddle_closure * cls = (fiddle_closure *)ptr;
|
fiddle_closure * cls = (fiddle_closure *)ptr;
|
||||||
#ifndef DONT_USE_FFI_CLOSURE_ALLOC
|
#if USE_FFI_CLOSURE_ALLOC
|
||||||
ffi_closure_free(cls->pcl);
|
ffi_closure_free(cls->pcl);
|
||||||
#else
|
#else
|
||||||
munmap(cls->pcl, sizeof(cls->pcl));
|
munmap(cls->pcl, sizeof(cls->pcl));
|
||||||
@ -170,7 +176,7 @@ allocate(VALUE klass)
|
|||||||
VALUE i = TypedData_Make_Struct(klass, fiddle_closure,
|
VALUE i = TypedData_Make_Struct(klass, fiddle_closure,
|
||||||
&closure_data_type, 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);
|
closure->pcl = ffi_closure_alloc(sizeof(ffi_closure), &closure->code);
|
||||||
#else
|
#else
|
||||||
closure->pcl = mmap(NULL, sizeof(ffi_closure), PROT_READ | PROT_WRITE,
|
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)
|
if (FFI_OK != result)
|
||||||
rb_raise(rb_eRuntimeError, "error prepping CIF %d", 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,
|
result = ffi_prep_closure_loc(pcl, cif, callback,
|
||||||
(void *)self, cl->code);
|
(void *)self, cl->code);
|
||||||
#else
|
#else
|
||||||
|
@ -5,6 +5,10 @@ require 'mkmf'
|
|||||||
dir_config 'libffi'
|
dir_config 'libffi'
|
||||||
|
|
||||||
pkg_config("libffi")
|
pkg_config("libffi")
|
||||||
|
if ver = pkg_config("libffi", "modversion")
|
||||||
|
$defs.push(%{-DRUBY_LIBFFI_MODVERSION=#{ '%d%03d%03d' % ver.split('.') }})
|
||||||
|
end
|
||||||
|
|
||||||
unless have_header('ffi.h')
|
unless have_header('ffi.h')
|
||||||
if have_header('ffi/ffi.h')
|
if have_header('ffi/ffi.h')
|
||||||
$defs.push(format('-DUSE_HEADER_HACKS'))
|
$defs.push(format('-DUSE_HEADER_HACKS'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user