1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/fiddle] Use ffi_closure_free if available

This commit is contained in:
Nobuyoshi Nakada 2020-03-04 18:13:03 +09:00
parent d732bc51bd
commit 633a1f15d8
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
2 changed files with 4 additions and 6 deletions

View file

@ -14,10 +14,7 @@ typedef struct {
} fiddle_closure; } fiddle_closure;
#if defined(USE_FFI_CLOSURE_ALLOC) #if defined(USE_FFI_CLOSURE_ALLOC)
#elif defined(__OpenBSD__) || defined(__APPLE__) || defined(__linux__) #elif !defined(HAVE_FFI_CLOSURE_ALLOC)
# define USE_FFI_CLOSURE_ALLOC 0
#elif defined(RUBY_LIBFFI_MODVERSION) && RUBY_LIBFFI_MODVERSION < 3000005 && \
(defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_AMD64))
# define USE_FFI_CLOSURE_ALLOC 0 # define USE_FFI_CLOSURE_ALLOC 0
#else #else
# define USE_FFI_CLOSURE_ALLOC 1 # define USE_FFI_CLOSURE_ALLOC 1

View file

@ -13,7 +13,7 @@ if ! bundle
if have_header(ffi_header = 'ffi.h') if have_header(ffi_header = 'ffi.h')
true true
elsif have_header(ffi_header = 'ffi/ffi.h') elsif have_header(ffi_header = 'ffi/ffi.h')
$defs.push(format('-DUSE_HEADER_HACKS')) $defs.push('-DUSE_HEADER_HACKS')
true true
end and (have_library('ffi') || have_library('libffi')) end and (have_library('ffi') || have_library('libffi'))
end or end or
@ -135,6 +135,7 @@ elsif have_header "windows.h"
end end
have_const('FFI_STDCALL', ffi_header) have_const('FFI_STDCALL', ffi_header)
have_func('ffi_closure_alloc', ffi_header)
config = File.read(RbConfig.expand(File.join($arch_hdrdir, "ruby/config.h"))) config = File.read(RbConfig.expand(File.join($arch_hdrdir, "ruby/config.h")))
types = {"SIZE_T"=>"SSIZE_T", "PTRDIFF_T"=>nil, "INTPTR_T"=>nil} types = {"SIZE_T"=>"SSIZE_T", "PTRDIFF_T"=>nil, "INTPTR_T"=>nil}
@ -142,7 +143,7 @@ types.each do |type, signed|
if /^\#define\s+SIZEOF_#{type}\s+(SIZEOF_(.+)|\d+)/ =~ config if /^\#define\s+SIZEOF_#{type}\s+(SIZEOF_(.+)|\d+)/ =~ config
if size = $2 and size != 'VOIDP' if size = $2 and size != 'VOIDP'
size = types.fetch(size) {size} size = types.fetch(size) {size}
$defs << format("-DTYPE_%s=TYPE_%s", signed||type, size) $defs << "-DTYPE_#{signed||type}=TYPE_#{size}"
end end
if signed if signed
check_signedness(type.downcase, "stddef.h") check_signedness(type.downcase, "stddef.h")