Skip to content
Open
Changes from all commits
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
6 changes: 6 additions & 0 deletions include/replayio-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
recordreplay::Assert(format, ##__VA_ARGS__); \
static_assert(true, "require semicolon")

// Same as |REPLAY_ASSERT| but won't Assert if the given condition is not true.
#define REPLAY_ASSERT_IF(cond, format, ...) \
Copy link

@toshok toshok Jul 10, 2024

Choose a reason for hiding this comment

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

Can these be defined in terms of one another?

e.g. REPLAY_ASSERT_IF could be:

#define REPLAY_ASSERT_IF(cond, format, ...) \
  if (cond) REPLAY_ASSERT(format, ##__VA_ARGS__)

and REPLAY_ASSERT_MAYBE_EVENTS_DISALLOWED could be:

#define REPLAY_ASSERT_MAYBE_EVENTS_DISALLOWED(format, ...) \
  REPLAY_ASSERT_IF(!recordreplay::AreEventsDisallowed(), format, ##__VA_ARGS__);

or REPLAY_ASSERT_IF could be the one that's ultimately evaluated with REPLAY_ASSERT being defined as:

#define REPLAY_ASSERT(format, ...) \
  REPLAY_ASSERT_IF(true, format, ## __VA_ARGS__)

otherwise I'd be concerned about things diverging between the macros.

Copy link
Author

Choose a reason for hiding this comment

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

  1. ❌Your first suggestion is a no-go, because suddenly you are evaluating cond even when things are enabled.
  2. 🤷‍♀️ I don't like the unnecessary if (true) in your third suggestion.
  3. ✅ I'm not concerned at all, since this is is going to be a very small set of often-used macros.

if (recordreplay::HasAsserts() && (cond)) \
recordreplay::Assert(format, ##__VA_ARGS__); \
static_assert(true, "require semicolon")

// Same as |REPLAY_ASSERT| but won't Assert when Events are disallowed.
#define REPLAY_ASSERT_MAYBE_EVENTS_DISALLOWED(format, ...) \
if (recordreplay::HasAsserts() && !recordreplay::AreEventsDisallowed()) \
Expand Down