History log of /libuv/test/test-test-macros.c (Results 1 – 1 of 1)
Revision Date Author Comments
# 904b1c9b 12-Aug-2020 tjarlama <59913901+tjarlama@users.noreply.github.com>

test: avoid double evaluation in ASSERT_BASE macro

Passing expression as an argument to a function-like macro will replace
all occurrence of the arguments with expressions during preproc

test: avoid double evaluation in ASSERT_BASE macro

Passing expression as an argument to a function-like macro will replace
all occurrence of the arguments with expressions during preprocessing.
This result in multiple evaluation of the same expression and can
slow-down the program or even change program state. Here ASSERT_BASE
macro gets an expression involving a and b as first argument and macro
definition has a print statement with a and b, which means there is
double evaluation of a and b when the expression evaluates to false. To
avoid double evaluation temporary variables are created to store results
of a and b.

Since the expression argument is dropped from ASSERT_BASE, the macro no
longer works for string assertions. So a new macro, ASSERT_BASE_STR, is
introduced to deal with strings. ASSERT_BASE can still work with
pointers.

Fixes: https://github.com/libuv/libuv/issues/2916
PR-URL: https://github.com/libuv/libuv/pull/2926
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>

show more ...