Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/cfis/ffi into cfis-master
Browse files Browse the repository at this point in the history
  • Loading branch information
larskanis committed May 23, 2020
2 parents be38126 + 7bbbce2 commit de9dd38
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions ext/ffi_c/Buffer.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion ext/ffi_c/MemoryPointer.c
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions ext/ffi_c/MethodHandle.c
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ext/ffi_c/Pointer.c
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions ext/ffi_c/compat.h
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions ext/ffi_c/extconf.rb
Expand Up @@ -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")
Expand All @@ -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"
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions lib/ffi/platform.rb
Expand Up @@ -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"
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit de9dd38

Please sign in to comment.