diff --git a/ext/ffi_c/Buffer.c b/ext/ffi_c/Buffer.c index faf4834d0..6863dda07 100644 --- a/ext/ffi_c/Buffer.c +++ b/ext/ffi_c/Buffer.c @@ -114,7 +114,7 @@ buffer_initialize(int argc, VALUE* argv, VALUE self) } /* ensure the memory is aligned on at least a 8 byte boundary */ - p->memory.address = (void *) (((uintptr_t) p->data.storage + 0x7) & (uintptr_t) ~0x7UL); + p->memory.address = (void *) (((uintptr_t) p->data.storage + 0x7) & (uintptr_t) ~0x7ULL); if (p->memory.size > 0 && (nargs < 3 || RTEST(rbClear))) { memset(p->memory.address, 0, p->memory.size); @@ -154,7 +154,7 @@ buffer_initialize_copy(VALUE self, VALUE other) return Qnil; } - dst->memory.address = (void *) (((uintptr_t) dst->data.storage + 0x7) & (uintptr_t) ~0x7UL); + dst->memory.address = (void *) (((uintptr_t) dst->data.storage + 0x7) & (uintptr_t) ~0x7ULL); dst->memory.size = src->size; dst->memory.typeSize = src->typeSize; diff --git a/ext/ffi_c/MemoryPointer.c b/ext/ffi_c/MemoryPointer.c index 0d91c35b7..9dc59bb57 100644 --- a/ext/ffi_c/MemoryPointer.c +++ b/ext/ffi_c/MemoryPointer.c @@ -112,7 +112,7 @@ memptr_malloc(VALUE self, long size, long count, bool clear) p->memory.typeSize = (int) size; p->memory.size = msize; /* ensure the memory is aligned on at least a 8 byte boundary */ - p->memory.address = (char *) (((uintptr_t) p->storage + 0x7) & (uintptr_t) ~0x7UL);; + p->memory.address = (char *) (((uintptr_t) p->storage + 0x7) & (uintptr_t) ~0x7ULL); p->allocated = true; if (clear && p->memory.size > 0) { diff --git a/ext/ffi_c/MethodHandle.c b/ext/ffi_c/MethodHandle.c index b266f995e..4dc85fbff 100644 --- a/ext/ffi_c/MethodHandle.c +++ b/ext/ffi_c/MethodHandle.c @@ -128,11 +128,7 @@ rbffi_function_anyargs rbffi_MethodHandle_CodeAddress(MethodHandle* handle) #ifndef CUSTOM_TRAMPOLINE static void attached_method_invoke(ffi_cif* cif, void* retval, METHOD_PARAMS parameters, void* user_data); -static ffi_type* methodHandleParamTypes[] = { - &ffi_type_sint, - &ffi_type_pointer, - &ffi_type_ulong, -}; +static ffi_type* methodHandleParamTypes[3]; static ffi_cif mh_cif; @@ -342,6 +338,10 @@ rbffi_MethodHandle_Init(VALUE module) rb_raise(rb_eFatal, "Could not locate offsets in trampoline code"); } #else + methodHandleParamTypes[0] = &ffi_type_sint; + methodHandleParamTypes[1] = &ffi_type_pointer; + methodHandleParamTypes[2] = &ffi_type_ulong; + ffiStatus = ffi_prep_cif(&mh_cif, FFI_DEFAULT_ABI, 3, &ffi_type_ulong, methodHandleParamTypes); if (ffiStatus != FFI_OK) { diff --git a/ext/ffi_c/Pointer.c b/ext/ffi_c/Pointer.c index 1eee790db..e5f24a4dc 100644 --- a/ext/ffi_c/Pointer.c +++ b/ext/ffi_c/Pointer.c @@ -183,7 +183,7 @@ ptr_initialize_copy(VALUE self, VALUE other) dst->allocated = true; dst->autorelease = true; - dst->memory.address = (void *) (((uintptr_t) dst->storage + 0x7) & (uintptr_t) ~0x7UL); + dst->memory.address = (void *) (((uintptr_t) dst->storage + 0x7) & (uintptr_t) ~0x7ULL); dst->memory.size = src->size; dst->memory.typeSize = src->typeSize; diff --git a/ext/ffi_c/compat.h b/ext/ffi_c/compat.h index a4dfc0851..3f7bbaed1 100644 --- a/ext/ffi_c/compat.h +++ b/ext/ffi_c/compat.h @@ -64,6 +64,10 @@ # define unlikely(x) (x) #endif +#ifdef _MSC_VER +#define ffi_type_longdouble ffi_type_double +#endif + #ifndef MAX # define MAX(a, b) ((a) < (b) ? (b) : (a)) #endif diff --git a/ext/ffi_c/extconf.rb b/ext/ffi_c/extconf.rb index 9bdb807a6..2e964c2e3 100644 --- a/ext/ffi_c/extconf.rb +++ b/ext/ffi_c/extconf.rb @@ -15,7 +15,13 @@ def system_libffi_usable? # Ensure we can link to ffi_call libffi_ok &&= have_library("ffi", "ffi_call", [ "ffi.h" ]) || - have_library("libffi", "ffi_call", [ "ffi.h" ]) + have_library("libffi", "ffi_call", [ "ffi.h" ]) || + have_library("libffi-8", "ffi_call", [ "ffi.h" ]) + + if RbConfig::CONFIG['host_os'] =~ /mswin/ + have_library('libffi_convenience') + have_library('shlwapi') + end # And we need a libffi version recent enough to provide ffi_closure_alloc libffi_ok &&= have_func("ffi_closure_alloc") @@ -39,7 +45,6 @@ def system_libffi_usable? abort "system libffi is not usable" unless system_libffi_usable? end - have_header('shlwapi.h') have_func('rb_thread_call_without_gvl') || abort("Ruby C-API function `rb_thread_call_without_gvl` is missing") have_func('ruby_native_thread_p') if RUBY_VERSION >= "2.3.0" @@ -56,13 +61,10 @@ def system_libffi_usable? end $defs << "-DHAVE_EXTCONF_H" if $defs.empty? # needed so create_header works - $defs << "-DFFI_BUILDING" if RbConfig::CONFIG['host_os'] =~ /mswin/ # for compatibility with newer libffi create_header - - $LOCAL_LIBS << " ./libffi/.libs/libffi_convenience.lib" if !system_libffi && RbConfig::CONFIG['host_os'] =~ /mswin/ - create_makefile("ffi_c") + unless system_libffi File.open("Makefile", "a") do |mf| mf.puts "LIBFFI_HOST=--host=#{RbConfig::CONFIG['host_alias']}" if RbConfig::CONFIG.has_key?("host_alias") diff --git a/lib/ffi/platform.rb b/lib/ffi/platform.rb index 3e0fc6059..959a72cff 100644 --- a/lib/ffi/platform.rb +++ b/lib/ffi/platform.rb @@ -61,7 +61,7 @@ module Platform CPU = RbConfig::CONFIG['host_cpu'] ARCH = case CPU.downcase - when /amd64|x86_64/ + when /amd64|x86_64|x64/ "x86_64" when /i?86|x86|i86pc/ "i386" @@ -129,7 +129,7 @@ def self.is_os(os) end LIBC = if IS_WINDOWS - RbConfig::CONFIG['RUBY_SO_NAME'].split('-')[-2] + '.dll' + "ucrtbase.dll" elsif IS_GNU GNU_LIBC elsif OS == 'cygwin'