Repository navigation
ape: guard MIN/MAX in <sys/param.h>, as glibc and the BSDs do - #725
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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