-
Notifications
You must be signed in to change notification settings - Fork 37.7k
util/check: Add CHECK_NONFATAL identity function and NONFATAL_UNREACHABLE macro #24812
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
Conversation
70bff71
to
5eeb1e5
Compare
ebdd846
to
0661baf
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
0661baf
to
3665422
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I'm not a big fan of while(0)
in C++, maybe C in yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
3665422
to
1e4d382
Compare
I've addressed the nits, thanks for your reviews. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 1e4d382
Good job!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 1e4d382
Tested NONFATAL_UNREACHABLE
error code: -1
error message:
Internal bug detected: 'Unreachable code reached'
wallet/rpc/addresses.cpp:38 (operator())
Please report this issue here: https://github.com/bitcoin/bitcoin/issues
Tested UNREACHABLE
Internal bug detected: 'Unreachable code reached'
wallet/rpc/addresses.cpp:38 (operator())
Please report this issue here: https://github.com/bitcoin/bitcoin/issues
Aborted
If you retouch, it looks like #include <util/check.h>
ought to be added to /rpc/blockchain.cpp
and /rpc/util.cpp
as well here.
f9cffe2
to
63b7534
Compare
re-ACK 63b7534 |
Might be good to adjust the rpc linter as well for the new macros: #24856 Can be done in a follow-up to avoid a conflict for now. |
…E AND UNREACHABLE macros
63b7534
to
ee02c8b
Compare
ACK ee02c8b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this also fixes a warning with gcc-12.
ACK ee02c8b 🍨
Show signature
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
ACK ee02c8bd9aedad8cfd3c2618035fe275da025fb9 🍨
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUjsdwwArddL1iP4wywDs5YPWiBmm1hOzJSazUrpOb4gx4plkEEHXOXvGqIIwoRQ
IPnUtiwBnIfZ7UDTHRUCgY8jeLNmlfZAtKRqd8n9V7fat6Uarmubynkz66O4C/pH
lPV6WRkkcby+KDy01EJW10vGa0NqLg9VoxWiTIfb5LwoiyqcxnLYvJ6/Ir30GYsn
cgG9pOIRhyYPYJQp79Q2R1fZmNe1Vi53RfxCBBkNXJI+tlMeCT7N8A6IHh239Dak
KPQP43FDbgkhTuwDmf+RNipSqyvH0sWRTqNCei9Q6WWqwGiiRMH883GWtWO392bR
gvkf+TmQeVoWqELVi+fFk7d+14zLJnnIvouMESjacwCEbkL5j5OKSw8WW6g0Uffb
y5VyRSEFV02OrxMHmKFKn3UEAQm551gnILgu0ERvkKopedGXxttNdvsnj9nuYiMj
IyPjD7MVuu+Ri6IaFtJ7jxCUGm+cPgei79bOuumTrRt/6g/+QZZnniZyhNx5oVHz
CKvY4MQC
=l4Sj
-----END PGP SIGNATURE-----
@@ -793,7 +794,7 @@ void RPCResult::ToSections(Sections& sections, const OuterType outer_type, const | |||
return; | |||
} | |||
case Type::ANY: { | |||
CHECK_NONFATAL(false); // Only for testing | |||
NONFATAL_UNREACHABLE(); // Only for testing | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will also fix a warning on current master with gcc-12:
In file included from ./rpc/util.h:19,
from rpc/util.cpp:8:
rpc/util.cpp: In member function 'void RPCResult::ToSections(Sections&, OuterType, int) const':
./util/check.h:34:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
34 | if (!(condition)) { \
| ^~
rpc/util.cpp:796:9: note: in expansion of macro 'CHECK_NONFATAL'
796 | CHECK_NONFATAL(false); // Only for testing
| ^~~~~~~~~~~~~~
rpc/util.cpp:798:5: note: here
798 | case Type::NONE: {
| ^~~~
template <typename T> | ||
T&& inline_check_non_fatal(T&& val, const char* file, int line, const char* func, const char* assertion) | ||
{ | ||
if (!(val)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!(val)) { | |
if (!val) { |
nit: No need for ()
.
throw NonFatalCheckError( | ||
format_internal_error(assertion, file, line, func, PACKAGE_BUGREPORT)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no need for newline
…CHABLE macro Summary: This is a backport of [[bitcoin/bitcoin#24812 | core#24812]] Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, sdulfari Reviewed By: #bitcoin_abc, sdulfari Subscribers: sdulfari Differential Revision: https://reviews.bitcoinabc.org/D13096
This PR replaces the macro
CHECK_NONFATAL
with an identity function.I simplified the usage of
CHECK_NONFATAL
where applicable insrc/rpc
.This function is useful in sanity checks for RPC and command-line interfaces.
Context: #24804 (comment).
Also adds
UNREACHABLE_NONFATAL
macro.