From: mtklein Date: Wed, 18 Jun 2014 14:54:47 +0000 (-0700) Subject: Add SkASSERTF. X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~7156 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b59161f0000eb4aca3dcef29f27ffd0fb5a568e5;p=platform%2Fupstream%2FlibSkiaSharp.git 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 --- diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h index 41c7829..1724c77 100644 --- a/include/core/SkRefCnt.h +++ b/include/core/SkRefCnt.h @@ -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 } diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h index 15de8a4..5ff57f8 100644 --- a/include/core/SkTypes.h +++ b/include/core/SkTypes.h @@ -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