Skip to content

Avoid redefining FFI_GO_CLOSURES defined by libffi headers#206

Merged
kou merged 1 commit into
masterfrom
ffi-go-closures-redefinition
Jul 17, 2026
Merged

Avoid redefining FFI_GO_CLOSURES defined by libffi headers#206
kou merged 1 commit into
masterfrom
ffi-go-closures-redefinition

Conversation

@hsbt

@hsbt hsbt commented Jul 17, 2026

Copy link
Copy Markdown
Member

Building fiddle with MSVC against libffi whose ffitarget.h defines FFI_GO_CLOSURES unconditionally, for example vcpkg libffi 3.5.2 in a ruby/ruby mswin build, reports warning C4005: 'FFI_GO_CLOSURES': macro redefinition in every compilation unit. The pre-definition in fiddle.h added by #157 collides with libffi's own definition. GCC and clang hide the same redefinition because it happens in a system header there.

The pre-definition only exists to silence -Wundef warnings from old ffi.h that tests #if FFI_GO_CLOSURES without the target defining it, and libffi switched that test to #ifdef in 3.4.5 (libffi/libffi#796). This restores the conditional approach of #134, but detects whether the libffi headers define the macro with macro_defined? at extconf.rb time instead of matching compiler-specific warning text, and defines FFI_GO_CLOSURES=0 only when they do not. Fiddle itself does not use Go closures, so the macro only affects which declarations ffi.h exposes.

I verified on Windows with MSVC that the eight C4005 warnings disappear with vcpkg libffi 3.5.2, and that a simulated old libffi header set with no FFI_GO_CLOSURES definition and an #if FFI_GO_CLOSURES test still gets -DFFI_GO_CLOSURES=0 from extconf.rb. rake test passes on x64-mswin64_140.

Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings July 17, 2026 04:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@kou
kou merged commit d389bbf into master Jul 17, 2026
134 checks passed
@kou
kou deleted the ffi-go-closures-redefinition branch July 17, 2026 21:08
@kou

kou commented Jul 17, 2026

Copy link
Copy Markdown
Member

Should we release a new version soon?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants