Suppress -Wundef warnings on arm64 macOS and Windows#134
Merged
Conversation
```
In file included from ../../../../ext/fiddle/fiddle.h:46:
/opt/local/include/ffi.h:477:5: warning: 'FFI_GO_CLOSURES' is not defined, evaluates to 0 [-Wundef]
^
```
c.f. libffi/libffi#796
nobu
added a commit
to nobu/ruby
that referenced
this pull request
Sep 17, 2023
(ruby/fiddle#134) ``` In file included from ../../../../ext/fiddle/fiddle.h:46: /opt/local/include/ffi.h:477:5: warning: 'FFI_GO_CLOSURES' is not defined, evaluates to 0 [-Wundef] ^ ``` c.f. libffi/libffi#796 ruby/fiddle@d4feb57098
kou
pushed a commit
that referenced
this pull request
Jul 17, 2026
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](https://claude.com/claude-code) Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
c.f. libffi/libffi#796