Skip to content

Document assert_(), combine with __ASSERT_; fixup Perl_assert() #23543

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 8 commits into from

Conversation

khwilliamson
Copy link
Contributor

@khwilliamson khwilliamson commented Aug 6, 2025

The combined documentation now cautions about macro parameters being evaluated more than once.

Perl_assert now works correctly on platforms where LINE is not an int., and expands to a no-op under Coverity, or on systems without adequate macro buffer space.

  • This set of changes does not require a perldelta entry.

@tonycoz
Copy link
Contributor

tonycoz commented Aug 7, 2025

Some assertions have caused Coverity to complain in the past

when was this?

I do the Coverity builds with -DDEBUGGING specifically to enable asserts since for Coverity they can act like ASSUME()s (if the assert fails some non-returning function would be called so the analysis of the following code can assume the assertion is true).

@tonycoz
Copy link
Contributor

tonycoz commented Aug 7, 2025

Perl_croak now works correctly on platforms where LINE is not an int., and expands to a no-op under Coverity, or on systems without adequate macro buffer space.

Presumably you meant Perl_assert there.

@khwilliamson
Copy link
Contributor Author

I wondered if Coverity was smart enough to know about assert(), but not smart enough to deal with _ASSERT. My claim stems from 7e75d1a which caused _ASSERT to be a no-op under Coverity. That commit mentioned several Coverity ids, and a similar one 3e94db2

This comment is not true; it may have been true once.  assert.h
is always included, and assert() is always supposed to be defined, since
at least C89.  But the code acts like it is possible to not be defined;
it's not a big deal to retain that check, so I'm leaving it in.
PERL_DEB2 is too obscure for me.  Simply use #ifdef DEBUGGING
This changes the white space in preparation for the next commit
Source code line numbers now have a typedef and format so that they work
on a variety of platforms.
This makes the next commits smaller.
They have the same conditional, and the next commit will change that
conditional and want it to apply to both.
Some assertions have caused Coverity to complain in the past, or
overflowed for some platforms, so the definition of __ASSERT_ in handy.h
expands to a no-op if under Coverity or the system doesn't have a normal
sized macro buffer.  Bring that definition here to also be the same for
Perl_assert().
And fix up the documentation, adding a caution that their use can easily
lead to differing behavior in DEBUGGING vs non-DEBUGGING builds.

These two macros are synonymous.  This documents assert_() for the first
time and clarifies their usage.

Thanks to Tony Cook for clarifying this for me.
@khwilliamson khwilliamson added the Use merge commit Don't merge this p.r. from github It contains multiple related commits. Instructions in perlgit label Aug 14, 2025
@khwilliamson
Copy link
Contributor Author

Fixed via a285955

@khwilliamson khwilliamson deleted the ASSERT_ branch August 14, 2025 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Use merge commit Don't merge this p.r. from github It contains multiple related commits. Instructions in perlgit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants