Skip to content

Push NDEBUG handling down to zend_portability.h #16366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Oct 11, 2024

As is, NEDBUG is set to match PHP_DEBUG (which matches ZEND_DEBUG) in php.h right before including assert.h; however, assert.h is already included at this point, so the NDEBUG handling is useless. We push it down to zend_portability.h, where it has effect.

The alternative would be to drop that code in php.h altogether, but that would make some test assumptions invalid. E.g. a build with CFLAGS=-DNDEBUG ./configure --enable-debug-assertions would fail internal_functions001.phpt, because the userland PHP_DEBUG is true, but assertions would not be evaluated.

As is, `NEDBUG` is set to match `PHP_DEBUG` (which matches `ZEND_DEBUG`)
in php.h right before including assert.h; however, assert.h is already
included at this point, so the `NDEBUG` handling is useless.  We push
it down to zend_portability.h, where it has effect.

The alternative would be to drop that code in php.h altogether, but
that would make some test assumptions invalid.   E.g. a build with
`CFLAGS=-DNDEBUG ./configure --enable-debug-assertions` would fail
internal_functions001.phpt, because the userland `PHP_DEBUG` is true,
but assertions would not be evaluated.
@arnaud-lb
Copy link
Member

arnaud-lb commented Oct 17, 2024

It seems that the most robust would be to define NDEBUG on the command line in non-debug builds, as there is always a possibility of including assert.h too early. For debug builds, we can automatically remove -DNDEBUG from CFLAGS (like we do for -O flags), or just fail at build time when defined(ZEND_DEBUG) && defined(NDEBUG).

@cmb69
Copy link
Member Author

cmb69 commented Oct 18, 2024

It seems that the most robust would be to define NDEBUG on the command line in non-debug builds, as there is always a possibility of including assert.h too early.

Makes sense. I'll try to come up with a solution soon.

@cmb69 cmb69 marked this pull request as draft October 18, 2024 15:25
@cmb69
Copy link
Member Author

cmb69 commented Oct 21, 2024

Closing in favor of #16511.

@cmb69 cmb69 closed this Oct 21, 2024
@cmb69 cmb69 deleted the cmb/ndebug branch October 21, 2024 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants