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

Open
wants to merge 8 commits into
base: blead
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions perl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5101,8 +5101,8 @@ Gid_t getegid (void);
((what) \
? ((void) 0) \
: Perl_croak_nocontext("Assertion %s failed:" \
" file \"" __FILE__ "\", line %d", \
STRINGIFY(what), __LINE__))
" file \"" __FILE__ "\", line %" LINE_Tf, \
STRINGIFY(what), (line_t) __LINE__))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, though line_t is for line numbers stored in COPs (line numbers in perl code) rather than C source.

I doubt it makes a difference unless someone puts #line 4294967296 (__LINE__ is now a long) which changes the code from UB to incorrect output.

(doesn't require a change)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C99 says #line is UB above 31 bits. Does that affect this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does and I missed that.

Its actually a "shall not" so it's a diagnosable error rather than UB.

But that doesn't entirely prevent __LINE__ from being a long:

tony@venus:.../perl/git$ cat longline.c
#include <stdio.h>

#line 2147483646

int main() {
  printf("Line %d\n", __LINE__);
}
tony@venus:.../perl/git$ cc -Wall -Wextra -olongline longline.c 
longline.c: In function ‘main’:
longline.c:-2147483648:10: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=]
tony@venus:.../perl/git$ ./longline 
Line -2147483648

But like I said, I don't think this requires a change.

#else
# define Perl_assert(what) ((void) 0)
#endif
Expand Down