Skip to content

Commit

Permalink
Fix failures on MacOS (#617)
Browse files Browse the repository at this point in the history
* Fix detection of system ffi

We need ffi_closure_alloc() since commit cf10854 but
don't use ffi_prep_closure() any longer.

* Prepend include path for bundled libffi to make sure it is preferred

When have_header('ffi.h') was successful the system libffi include
path is added to INCFLAGS. But when have_func() fails later on
the bundled libffi which should be used instead.

Using the wrong ffi.h resulted in compiler warnings about undefined
functions and leaded to segfaults on MacOS.
  • Loading branch information
larskanis authored and tduehr committed Feb 21, 2018
1 parent cf10854 commit 0fef6d4
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions ext/ffi_c/extconf.rb
Expand Up @@ -11,15 +11,15 @@
$CFLAGS.gsub!(/[\s+]-std=[^\s]+/, '')
# solaris 10 needs -c99 for <stdbool.h>
$CFLAGS << " -std=c99" if RbConfig::CONFIG['host_os'] =~ /solaris(!?2\.11)/

if ENV['RUBY_CC_VERSION'].nil? && (pkg_config("libffi") ||
have_header("ffi.h") ||
find_header("ffi.h", "/usr/local/include", "/usr/include/ffi"))

# We need at least ffi_call and ffi_prep_closure
# We need at least ffi_call and ffi_closure_alloc
libffi_ok = have_library("ffi", "ffi_call", [ "ffi.h" ]) ||
have_library("libffi", "ffi_call", [ "ffi.h" ])
libffi_ok &&= have_func("ffi_prep_closure")
libffi_ok &&= have_func("ffi_closure_alloc")

# Check if the raw api is available.
$defs << "-DHAVE_RAW_API" if have_func("ffi_raw_call") && have_func("ffi_prep_raw_closure")
Expand Down
2 changes: 1 addition & 1 deletion ext/ffi_c/libffi.bsd.mk
Expand Up @@ -3,11 +3,11 @@
# Makefile for BSD systems
#

INCFLAGS += -I${LIBFFI_BUILD_DIR}/include
LOCAL_LIBS += ${LIBFFI} -lpthread

LIBFFI_CFLAGS = ${FFI_MMAP_EXEC} -pthread
LIBFFI_BUILD_DIR = ${.CURDIR}/libffi-${arch}
INCFLAGS := -I${LIBFFI_BUILD_DIR}/include -I${INCFLAGS}

.if ${srcdir} == "."
LIBFFI_SRC_DIR := ${.CURDIR}/libffi
Expand Down
2 changes: 1 addition & 1 deletion ext/ffi_c/libffi.gnu.mk
Expand Up @@ -5,11 +5,11 @@


# Tack the extra deps onto the autogenerated variables
INCFLAGS += -I"$(LIBFFI_BUILD_DIR)"/include
LOCAL_LIBS += $(LIBFFI)
BUILD_DIR = $(shell pwd)
LIBFFI_CFLAGS = $(FFI_MMAP_EXEC)
LIBFFI_BUILD_DIR = $(BUILD_DIR)/libffi-$(arch)
INCFLAGS := -I"$(LIBFFI_BUILD_DIR)"/include $(INCFLAGS)

ifeq ($(srcdir),.)
LIBFFI_SRC_DIR := $(shell pwd)/libffi
Expand Down
2 changes: 1 addition & 1 deletion ext/ffi_c/libffi.vc.mk
Expand Up @@ -4,7 +4,7 @@
#

# Tack the extra deps onto the autogenerated variables
INCFLAGS = $(INCFLAGS) -I$(LIBFFI_BUILD_DIR)/include -I$(LIBFFI_BUILD_DIR)/src/x86
INCFLAGS = -I$(LIBFFI_BUILD_DIR)/include -I$(LIBFFI_BUILD_DIR)/src/x86 $(INCFLAGS)
LOCAL_LIBS = $(LOCAL_LIBS) $(LIBFFI)
BUILD_DIR = $(MAKEDIR)
LIBFFI_BUILD_DIR = $(BUILD_DIR)/libffi
Expand Down
2 changes: 1 addition & 1 deletion ext/ffi_c/libffi.vc64.mk
Expand Up @@ -4,7 +4,7 @@
#

# Tack the extra deps onto the autogenerated variables
INCFLAGS = $(INCFLAGS) -I$(LIBFFI_BUILD_DIR)/include -I$(LIBFFI_BUILD_DIR)/src/x86
INCFLAGS = -I$(LIBFFI_BUILD_DIR)/include -I$(LIBFFI_BUILD_DIR)/src/x86 $(INCFLAGS)
LOCAL_LIBS = $(LOCAL_LIBS) $(LIBFFI)
BUILD_DIR = $(MAKEDIR)
LIBFFI_BUILD_DIR = $(BUILD_DIR)/libffi
Expand Down

2 comments on commit 0fef6d4

@larskanis
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The segfault mentioned in the commit description was here: https://travis-ci.org/larskanis/ffi/jobs/344203027

@baburdick
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to this issue?: #626

Please sign in to comment.