Skip to content

Stop ultralib's __assert declaration colliding with Darwin's macro - #419

Merged
Malkierian merged 1 commit into
HarbourMasters:develop-splitrockfrom
buddingmonkey:lh/darwin-assert-collision
Aug 8, 2026
Merged

Stop ultralib's __assert declaration colliding with Darwin's macro#419
Malkierian merged 1 commit into
HarbourMasters:develop-splitrockfrom
buddingmonkey:lh/darwin-assert-collision

Conversation

@buddingmonkey

Copy link
Copy Markdown

The problem

Apple's <assert.h> already provides __assert, but as a three-argument
function-like macro
, not a function:

#define __assert(e, file, line) __assert_rtn(..., file, line, e)

lib/ultralib/include/ultra_assert.h declares its own:

extern void __assert(const char *, const char *, int);

On Apple platforms the macro expands mid-declaration and the parse collapses,
taking the rest of the header down with it.

Why this hasn't been noticed

The declaration lives in the #else (i.e. !NDEBUG) branch of the header.
Release builds define NDEBUG, take the #define assert(EX) ((void)0) branch
above, and never reach the declaration. Only Debug builds break.

The fix

Declare __assert only where the platform has not already provided it:

#ifndef __assert
extern void __assert(const char *, const char *, int);
#endif

The macro's argument order (expression, file, line) matches the call sites
further down this same header, so where the platform supplies __assert we let
it handle the failure — on Apple platforms assert() now routes through
__assert_rtn. Behaviour on every other platform is unchanged: nothing else
defines __assert as a macro, so the declaration is emitted exactly as before.

One file, ten added lines (eight of which are the explanatory comment).

Notes

Not covered by run-clang-format.sh (which only formats src/port), so no
formatting gate applies here — confirmed by running the script and seeing the
tree stay clean apart from this change.


Prepared with AI assistance; the change and its rationale were verified by hand.

@buddingmonkey
buddingmonkey force-pushed the lh/darwin-assert-collision branch from 389aa94 to 6c0efc6 Compare August 6, 2026 15:57
Apple's <assert.h> defines __assert as a three-argument function-like macro, so
ultralib's own declaration of it expanded mid-declaration and the parse
collapsed. The declaration sits in the !NDEBUG branch, so Release builds never
reached it and only Debug broke -- which is what Xcode's default scheme builds.

This is not iOS-specific: a macOS Debug build fails the same way today.

Declare it only where the platform has not already provided it. The macro's
argument order matches the calls in the file, so on Apple platforms assert() now
routes through __assert_rtn.
@buddingmonkey
buddingmonkey force-pushed the lh/darwin-assert-collision branch from 6c0efc6 to bba1cab Compare August 6, 2026 16:24
@Malkierian
Malkierian merged commit ac4dcd8 into HarbourMasters:develop-splitrock Aug 8, 2026
6 checks passed
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