Skip to content

fix: don't declare bswap32/bswap64 function if macros are defined#419

Closed
botantony wants to merge 1 commit intomaxmind:mainfrom
botantony:macos-compilation-failure
Closed

fix: don't declare bswap32/bswap64 function if macros are defined#419
botantony wants to merge 1 commit intomaxmind:mainfrom
botantony:macos-compilation-failure

Conversation

@botantony
Copy link

Declaring these functions causes compilation failure on macOS because sys/endian.h header already defined macros with the same name

Related to Homebrew/homebrew-core#269271

@gemini-code-assist
Copy link

Summary of Changes

Hello @botantony, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a specific compilation issue encountered on macOS systems. By introducing conditional compilation directives, it ensures that custom bswap32 and bswap64 functions are only declared if they are not already defined as macros by the system's sys/endian.h header, thereby preventing conflicts and build failures.

Highlights

  • macOS Compilation Fix: Resolved a compilation failure on macOS by preventing the re-declaration of bswap32 and bswap64 functions when sys/endian.h already defines them as macros.
Changelog
  • src/maxminddb.c
    • Added conditional compilation (#ifndef bswap32 and #ifndef bswap64) around the declarations of bswap32 and bswap64 functions.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a compilation failure on macOS where bswap32 and bswap64 can be defined as macros. The change correctly wraps the inline function definitions of bswap32 and bswap64 with #ifndef preprocessor guards to avoid redefinition. This is a standard and effective way to handle such portability issues. The changes are correct and I have no further suggestions.

@botantony botantony force-pushed the macos-compilation-failure branch from 45fd484 to f8cb24f Compare February 25, 2026 09:38
Declaring these functions causes compilation failure on macOS because
`sys/endian.h` header already defined macros with the same name

Signed-off-by: botantony <antonsm21@gmail.com>
@botantony botantony force-pushed the macos-compilation-failure branch from f8cb24f to 0138e84 Compare February 25, 2026 09:38
@oschwald
Copy link
Member

Thanks for reporting this! We do have macOS builds in our CI, but I think the -std=c99 CFLAG must be masking this failure. I'll look into solving that first.

Rather than doing the ifdef, we may just rename our internal functions to ensure that we have more control over the implementation.

oschwald added a commit that referenced this pull request Feb 25, 2026
Our CI was using -std=c99 for all builds, which causes Darwin headers
to hide BSD extension symbols. This masked the bswap32/bswap64 macro
collision reported in #419, since real-world users (e.g. Homebrew) build
without -std=c99 and see the conflict.

Remove -std=c99 from the default CFLAGS so the main CI matrix matches
what downstream consumers build with. Add a dedicated strict-C99 matrix
entry (ubuntu/gcc) to preserve language compliance checking.

Also change CMAKE_C_EXTENSIONS from OFF to ON to match default CMake
behavior and what users get when building with cmake.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
oschwald added a commit that referenced this pull request Feb 25, 2026
Our CI was using -std=c99 for all builds, which causes Darwin headers
to hide BSD extension symbols. This masked the bswap32/bswap64 macro
collision reported in #419, since real-world users (e.g. Homebrew) build
without -std=c99 and see the conflict.

Remove -std=c99 from the default CFLAGS so the main CI matrix matches
what downstream consumers build with. Add a dedicated strict-C99 matrix
entry (ubuntu/gcc) to preserve language compliance checking.

Also change CMAKE_C_EXTENSIONS from OFF to ON to match default CMake
behavior and what users get when building with cmake.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
oschwald added a commit that referenced this pull request Feb 25, 2026
Our CI was using -std=c99 for all builds, which causes Darwin headers
to hide BSD extension symbols. This masked the bswap32/bswap64 macro
collision reported in #419, since real-world users (e.g. Homebrew) build
without -std=c99 and see the conflict.

Remove -std=c99 from the default CFLAGS so the main CI matrix matches
what downstream consumers build with. Add a dedicated strict-C99 matrix
entry (ubuntu/gcc) to preserve language compliance checking.

Also change CMAKE_C_EXTENSIONS from OFF to ON to match default CMake
behavior and what users get when building with cmake.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
oschwald added a commit that referenced this pull request Feb 25, 2026
Our CI was using -std=c99 for all builds, which causes Darwin headers
to hide BSD extension symbols. This masked the bswap32/bswap64 macro
collision reported in #419, since real-world users (e.g. Homebrew) build
without -std=c99 and see the conflict.

Remove -std=c99 from the default CFLAGS so the main CI matrix matches
what downstream consumers build with. Add a dedicated strict-C99 matrix
entry (ubuntu/gcc) to preserve language compliance checking.

Also change CMAKE_C_EXTENSIONS from OFF to ON to match default CMake
behavior and what users get when building with cmake.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
oschwald added a commit that referenced this pull request Feb 25, 2026
Our CI was using -std=c99 for all builds, which causes Darwin headers
to hide BSD extension symbols. This masked the bswap32/bswap64 macro
collision reported in #419, since real-world users (e.g. Homebrew) build
without -std=c99 and see the conflict.

Remove -std=c99 from the default CFLAGS so the main CI matrix matches
what downstream consumers build with. Add -std=c99 as a separate matrix
entry to preserve language compliance checking.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
oschwald added a commit that referenced this pull request Feb 25, 2026
Our CI was using -std=c99 for all builds, which causes Darwin headers
to hide BSD extension symbols. This masked the bswap32/bswap64 macro
collision reported in #419, since real-world users (e.g. Homebrew) build
without -std=c99 and see the conflict.

Remove -std=c99 from the default CFLAGS and add it as a separate matrix
entry to preserve language compliance checking. Also add macos-26 to the
OS matrix since the bswap collision appears to be specific to macOS 26
(Tahoe), which is not covered by macos-latest (currently macOS 15).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@oschwald
Copy link
Member

oschwald commented Feb 25, 2026

I was able to reproduce this by switching our macos-latest image to macos-26.

oschwald added a commit that referenced this pull request Feb 25, 2026
On macOS 26, sys/endian.h defines bswap32 and bswap64 as macros.
Since maxminddb.h includes sys/endian.h when available, our static
inline function declarations collide with those macros, causing a
compilation failure.

Rename to mmdb_bswap32/mmdb_bswap64 to avoid the namespace collision
entirely. These are internal static functions so the rename is safe.

Fixes #419

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
oschwald added a commit that referenced this pull request Feb 25, 2026
On macOS 26, sys/endian.h defines bswap32 and bswap64 as macros.
Since maxminddb.h includes sys/endian.h when available, our static
inline function declarations collide with those macros, causing a
compilation failure.

Rename to mmdb_bswap32/mmdb_bswap64 to avoid the namespace collision
entirely. These are internal static functions so the rename is safe.

Fixes #419

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
oschwald added a commit that referenced this pull request Feb 25, 2026
On macOS 26, sys/endian.h defines bswap32 and bswap64 as macros.
Since maxminddb.h includes sys/endian.h when available, our static
inline function declarations collide with those macros, causing a
compilation failure.

Rename to mmdb_bswap32/mmdb_bswap64 to avoid the namespace collision
entirely. These are internal static functions so the rename is safe.

Fixes #419

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@horgh horgh closed this in #420 Feb 25, 2026
@botantony botantony deleted the macos-compilation-failure branch February 25, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants