Revert "Remove declarations in VERIFY3_IMPL to save stack"
This reverts commit 421d95b3ea
.
Ricardo correctly pointed out that there is more going on here than
typecasting. By removing the locals we are actually causing LEFT and
RIGHT to be evaluated twice which can potentially lead to some
strange side effects as:
1) VERIFY3*() causing a panic but in the panic message the values
look correct such that the assertion shouldn't fail, or:
2) if LEFT or RIGHT are expressions with side-effects (e.g. a call
to a function which changes some state), then when we panic and
examine the crash dump, it may lead to an unexpected state because
we are not expecting certain things to change during the panic,
after the expressions inside VERIFY3*(...) have been evaluated.
3) Also, it may lead to double-panics or deadlocks during panics,
like for example, if the expressions inside VERIFY3*(...) only expect
to be called once (e.g. because they acquire a mutex).
This commit is contained in:
parent
0fd353341a
commit
615e289a57
|
@ -65,11 +65,13 @@ extern void __assert(const char *, const char *, int);
|
|||
|
||||
/* BEGIN CSTYLED */
|
||||
#define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \
|
||||
if (!((TYPE)(LEFT) OP (TYPE)(RIGHT))) { \
|
||||
const TYPE __left = (TYPE)(LEFT); \
|
||||
const TYPE __right = (TYPE)(RIGHT); \
|
||||
if (!(__left OP __right)) { \
|
||||
char *__buf = alloca(256); \
|
||||
(void) snprintf(__buf, 256, "%s %s %s (0x%llx %s 0x%llx)", \
|
||||
#LEFT, #OP, #RIGHT, \
|
||||
(u_longlong_t)(LEFT), #OP, (u_longlong_t)(RIGHT)); \
|
||||
(u_longlong_t)__left, #OP, (u_longlong_t)__right); \
|
||||
__assert(__buf, __FILE__, __LINE__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
|
Loading…
Reference in New Issue