Add SkASSERTF.
authormtklein <mtklein@chromium.org>
Wed, 18 Jun 2014 14:54:47 +0000 (07:54 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 18 Jun 2014 14:54:47 +0000 (07:54 -0700)
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

include/core/SkRefCnt.h
include/core/SkTypes.h

index 41c7829..1724c77 100644 (file)
@@ -37,7 +37,7 @@ public:
     */
     virtual ~SkRefCntBase() {
 #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
 #endif
     }
index 15de8a4..5ff57f8 100644 (file)
@@ -115,6 +115,11 @@ inline void operator delete(void* p) {
 
 #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
     #define SkDEVCODE(code)             code
 #else