Skip to content

ape: guard MIN/MAX in <sys/param.h>, as glibc and the BSDs do - #725

Merged
staalmannen merged 1 commit into
mainfrom
claude/upgrade-ape-c-library-mmZGd
Nov 5, 2026
Merged

staalmannen merged 1 commit into
mainfrom
claude/upgrade-ape-c-library-mmZGd

Conversation

@staalmannen

Copy link
Copy Markdown
Owner

zend_optimizer.c stopped on /sys/include/ape/sys/param.h:36 ... Macro redefinition of MIN'. php is careful: zend_portability.h:479 is #undef MIN' / `#undef MAX' followed by its own spelling, and main/php.h:215 then includes <sys/param.h>, which redefined them with a different token sequence. This tree's own rule that a macro's identity includes whether there is white space, arriving from the other side.

The fault is ours rather than php's. MIN and MAX are not POSIX, so a program that wants them defines its own, and glibc and the BSDs both wrap theirs in #ifndef for that reason; APE's copy came from musl, which is the odd one out. The guard can only turn an error into a success, since it changes nothing unless the name is already defined and that case is a diagnostic today. A grep for every other definition of these names in the APE headers found none, and apehdr-sweep is unchanged at 152 headers, 0 findings, the same 8 pre-existing TOGETHER errors.

Also records the answer to whether the missing atomics are worth implementing: no, for this configuration, with the reasoning in docs/notes/php.md. Across everything this port compiles they guard exactly two flags, EG(vm_interrupt) and EG(timed_out), written from a handler and read by the VM loop -- the sig_atomic_t case rather than the shared-memory one -- and the build is non-ZTS, so the only asynchrony is a Plan 9 note and an aligned load or store on x86-64 is already indivisible. The one genuine gap is the read-modify-write in zend_atomic_bool_exchange_ex, a two-instruction window that CLI does not reach because max_execution_time is 0 by default. Real atomics would be per-architecture assembly, the same shape as ucontext, and would not change this build.

Claude-Session: https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs

zend_optimizer.c stopped on `/sys/include/ape/sys/param.h:36 ...
Macro redefinition of MIN'.  php is careful: zend_portability.h:479
is `#undef MIN' / `#undef MAX' followed by its own spelling, and
main/php.h:215 then includes <sys/param.h>, which redefined them with
a different token sequence.  This tree's own rule that a macro's
identity includes whether there is white space, arriving from the
other side.

The fault is ours rather than php's.  MIN and MAX are not POSIX, so a
program that wants them defines its own, and glibc and the BSDs both
wrap theirs in #ifndef for that reason; APE's copy came from musl,
which is the odd one out.  The guard can only turn an error into a
success, since it changes nothing unless the name is already defined
and that case is a diagnostic today.  A grep for every other
definition of these names in the APE headers found none, and
apehdr-sweep is unchanged at 152 headers, 0 findings, the same 8
pre-existing TOGETHER errors.

Also records the answer to whether the missing atomics are worth
implementing: no, for this configuration, with the reasoning in
docs/notes/php.md.  Across everything this port compiles they guard
exactly two flags, EG(vm_interrupt) and EG(timed_out), written from a
handler and read by the VM loop -- the sig_atomic_t case rather than
the shared-memory one -- and the build is non-ZTS, so the only
asynchrony is a Plan 9 note and an aligned load or store on x86-64 is
already indivisible.  The one genuine gap is the read-modify-write in
zend_atomic_bool_exchange_ex, a two-instruction window that CLI does
not reach because max_execution_time is 0 by default.  Real atomics
would be per-architecture assembly, the same shape as ucontext, and
would not change this build.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
@staalmannen
staalmannen merged commit 28d270d into main Nov 5, 2026
1 check 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