Use common pattern for function-like macro (#4625)
This commit is contained in:
committed by
Nikolay Krasko
parent
32e3deace1
commit
adf80418af
@@ -25,6 +25,13 @@
|
||||
#define STRINGIFY(x) #x
|
||||
#define TOSTRING(x) STRINGIFY(x)
|
||||
|
||||
#if KONAN_ENABLE_ASSERT
|
||||
#define CURRENT_SOURCE_LOCATION __FILE__ ":" TOSTRING(__LINE__)
|
||||
#else
|
||||
// Do not generate location strings, when asserts are disabled to reduce code size.
|
||||
#define CURRENT_SOURCE_LOCATION nullptr
|
||||
#endif
|
||||
|
||||
RUNTIME_NORETURN void RuntimeAssertFailed(const char* location, const char* message, ...);
|
||||
|
||||
namespace internal {
|
||||
@@ -46,24 +53,31 @@ extern "C" const int KonanNeedDebugInfo;
|
||||
|
||||
#if KONAN_ENABLE_ASSERT
|
||||
// Use RuntimeAssert() in internal state checks, which could be ignored in production.
|
||||
#define RuntimeAssert(condition, format, ...) \
|
||||
if (KonanNeedDebugInfo && (!(condition))) { \
|
||||
RuntimeAssertFailed( __FILE__ ":" TOSTRING(__LINE__), format, ##__VA_ARGS__); \
|
||||
}
|
||||
#define RuntimeAssert(condition, format, ...) \
|
||||
do { \
|
||||
if (KonanNeedDebugInfo && (!(condition))) { \
|
||||
RuntimeAssertFailed(CURRENT_SOURCE_LOCATION, format, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while (false)
|
||||
#else
|
||||
#define RuntimeAssert(condition, message)
|
||||
#define RuntimeAssert(condition, format, ...) \
|
||||
do { \
|
||||
} while (false)
|
||||
#endif
|
||||
|
||||
// Use RuntimeCheck() in runtime checks that could fail due to external condition and shall lead
|
||||
// to program termination. Never compiled out.
|
||||
#define RuntimeCheck(condition, format, ...) \
|
||||
if (!(condition)) { \
|
||||
RuntimeAssertFailed(nullptr, format, ##__VA_ARGS__); \
|
||||
}
|
||||
// TODO: Consider using `CURRENT_SOURCE_LOCATION` when `KonanNeedDebugInfo` is `true`.
|
||||
#define RuntimeCheck(condition, format, ...) \
|
||||
do { \
|
||||
if (!(condition)) { \
|
||||
RuntimeAssertFailed(nullptr, format, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#define TODO(...) \
|
||||
do { \
|
||||
::internal::TODOImpl(__FILE__ ":" TOSTRING(__LINE__), ##__VA_ARGS__); \
|
||||
::internal::TODOImpl(CURRENT_SOURCE_LOCATION, ##__VA_ARGS__); \
|
||||
} while (false)
|
||||
|
||||
#endif // RUNTIME_ASSERT_H
|
||||
|
||||
@@ -177,7 +177,7 @@ void BackRefFromAssociatedObject::releaseRef() {
|
||||
}
|
||||
|
||||
void BackRefFromAssociatedObject::detach() {
|
||||
RuntimeAssert(atomicGet(&refCount) == 0, "unexpected refCount")
|
||||
RuntimeAssert(atomicGet(&refCount) == 0, "unexpected refCount");
|
||||
obj_ = nullptr; // Handled in addRef/tryAddRef/releaseRef/ref.
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user