Add SkASSERTF.

Example failure:
fRefCnt was 3
../../../usr/local/google/home/mtklein/skia/include/core/SkRefCnt.h:40: failed assertion "(fRefCnt == 1) || (SkDebugf("fRefCnt was %d""\n", fRefCnt), false)"
Command terminated by signal 11

Not pretty, but everything's there.  Perhaps we'll think of ways to make it nicer later.

BUG=skia:
R=bsalomon@google.com, reed@google.com, mtklein@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/337243004
This commit is contained in:
mtklein 2014-06-18 07:54:47 -07:00 committed by Commit bot
parent 12c2198535
commit b59161f000
2 changed files with 6 additions and 1 deletions

View File

@ -37,7 +37,7 @@ public:
*/ */
virtual ~SkRefCntBase() { virtual ~SkRefCntBase() {
#ifdef SK_DEBUG #ifdef SK_DEBUG
SkASSERT(fRefCnt == 1); SkASSERTF(fRefCnt == 1, "fRefCnt was %d", fRefCnt);
fRefCnt = 0; // illegal value, to catch us if we reuse after delete fRefCnt = 0; // illegal value, to catch us if we reuse after delete
#endif #endif
} }

View File

@ -115,6 +115,11 @@ inline void operator delete(void* p) {
#define SkFAIL(message) SK_ALWAYSBREAK(false && message) #define SkFAIL(message) SK_ALWAYSBREAK(false && message)
// We want to evaluate cond only once, and inside the SkASSERT somewhere so we see its string form.
// So we use the comma operator to make an SkDebugf that always returns false: we'll evaluate cond,
// and if it's true the assert passes; if it's false, we'll print the message and the assert fails.
#define SkASSERTF(cond, fmt, ...) SkASSERT((cond) || (SkDebugf(fmt"\n", __VA_ARGS__), false))
#ifdef SK_DEVELOPER #ifdef SK_DEVELOPER
#define SkDEVCODE(code) code #define SkDEVCODE(code) code
#else #else