Skip to content

Commit 6889890

Browse files
hsbtclaude
andcommitted
Avoid redefining FFI_GO_CLOSURES defined by libffi headers
libffi defines FFI_GO_CLOSURES unconditionally in ffitarget.h on most targets, so pre-defining it in fiddle.h is a macro redefinition there, which MSVC reports as warning C4005 in every compilation unit, e.g. with vcpkg libffi. Restore the conditional definition of GH-134 in extconf.rb, but with macro_defined? instead of the fragile warning text matching that GH-157 removed. FFI_GO_CLOSURES=0 is only needed for old ffi.h that tests `#if FFI_GO_CLOSURES` and warns with -Wundef when the target's ffitarget.h does not define it. #134 #157 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 865d764 commit 6889890

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎ext/fiddle/extconf.rb‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ def enable_debug_build_flag(flags)
162162
$INCFLAGS << " -I" << libffi.include
163163
end
164164

165+
unless macro_defined?("FFI_GO_CLOSURES", cpp_include(ffi_header || 'ffi.h'))
166+
# ffi.h in libffi 3.4.4 or earlier and the macOS SDK uses
167+
# `#if FFI_GO_CLOSURES`, which warns with -Wundef on targets whose
168+
# ffitarget.h does not define it. Newer libffi defines it in
169+
# ffitarget.h unconditionally, where defining it on our side would be
170+
# a macro redefinition (e.g. warning C4005 with MSVC). Fiddle does
171+
# not use Go closures.
172+
$defs.push('-DFFI_GO_CLOSURES=0')
173+
end
174+
165175
if libffi_version
166176
# If libffi_version contains rc version, just ignored.
167177
libffi_version = libffi_version.gsub(/-rc\d+/, '')

‎ext/fiddle/fiddle.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
# endif
4141
#endif
4242

43-
#define FFI_GO_CLOSURES 0 /* fiddle does not use go closures */
4443
#ifdef USE_HEADER_HACKS
4544
#include <ffi/ffi.h>
4645
#else

0 commit comments

Comments
 (0)