Commit d389bbf
Avoid redefining FFI_GO_CLOSURES defined by libffi headers (#206)
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>1 parent 865d764 commit d389bbf
2 files changed
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
165 | 175 | | |
166 | 176 | | |
167 | 177 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | 43 | | |
45 | 44 | | |
46 | 45 | | |
| |||
0 commit comments