Skip to content

Suppress -Wundef warnings on arm64 macOS and Windows#134

Merged
kou merged 1 commit into
ruby:masterfrom
nobu:undef-warnings
Sep 11, 2023
Merged

Suppress -Wundef warnings on arm64 macOS and Windows#134
kou merged 1 commit into
ruby:masterfrom
nobu:undef-warnings

Conversation

@nobu

@nobu nobu commented Sep 10, 2023

Copy link
Copy Markdown
Member
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

```
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
nobu requested a review from kou September 10, 2023 07:44

@kou kou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

@kou
kou merged commit d4feb57 into ruby:master Sep 11, 2023
@nobu
nobu deleted the undef-warnings branch September 12, 2023 05:57
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>
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.

2 participants