Improve assert reporting.
Make SkASSERTF output readable.
Ensure the assert predicate is stringified once.
Make the abort code consistent.
TBR=reed
This doesn't change any public API, most of this should be privatized.
Review-Url: https://codereview.chromium.org/2161103002
diff --git a/include/core/SkPostConfig.h b/include/core/SkPostConfig.h
index b1965ba..e44c709 100644
--- a/include/core/SkPostConfig.h
+++ b/include/core/SkPostConfig.h
@@ -133,10 +133,10 @@
#endif
#ifndef SK_ABORT
-# define SK_ABORT(msg) \
+# define SK_ABORT(message) \
do { \
SkNO_RETURN_HINT(); \
- SkDebugf("%s:%d: fatal error: \"%s\"\n", __FILE__, __LINE__, #msg); \
+ SkDebugf("%s:%d: fatal error: \"%s\"\n", __FILE__, __LINE__, message); \
SK_DUMP_GOOGLE3_STACK(); \
sk_abort_no_print(); \
} while (false)
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h
index 1ac3efb..2795574 100644
--- a/include/core/SkTypes.h
+++ b/include/core/SkTypes.h
@@ -139,24 +139,24 @@
SK_API void SkDebugf(const char format[], ...);
#endif
-#define SkASSERT_RELEASE(cond) if(!(cond)) { SK_ABORT(#cond); }
+#define SkASSERT_RELEASE(cond) if (!(cond)) { SK_ABORT(#cond); }
#ifdef SK_DEBUG
- #if defined SK_BUILD_FOR_WIN
- #define SkASSERT(cond) if(!(cond)) { __debugbreak(); }
- #else
- #define SkASSERT(cond) SkASSERT_RELEASE(cond)
- #endif
- #define SkDEBUGFAIL(message) SkASSERT(false && message)
+ #define SkASSERT(cond) if (!(cond)) { SK_ABORT("assert(" #cond ")"); }
+ #define SkASSERTF(cond, fmt, ...) if (!(cond)) { \
+ SkDebugf(fmt"\n", __VA_ARGS__); \
+ SK_ABORT("assert(" #cond ")"); \
+ }
+ #define SkDEBUGFAIL(message) SK_ABORT(message)
#define SkDEBUGFAILF(fmt, ...) SkASSERTF(false, fmt, ##__VA_ARGS__)
#define SkDEBUGCODE(code) code
#define SkDECLAREPARAM(type, var) , type var
#define SkPARAM(var) , var
-// #define SkDEBUGF(args ) SkDebugf##args
#define SkDEBUGF(args ) SkDebugf args
#define SkAssertResult(cond) SkASSERT(cond)
#else
#define SkASSERT(cond)
+ #define SkASSERTF(cond, fmt, ...)
#define SkDEBUGFAIL(message)
#define SkDEBUGCODE(code)
#define SkDEBUGF(args)
@@ -172,11 +172,6 @@
#define SkFAIL(message) SK_ABORT(message)
#define sk_throw() SK_ABORT("sk_throw")
-// 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_IGNORE_TO_STRING
#define SK_TO_STRING_NONVIRT()
#define SK_TO_STRING_VIRT()
diff --git a/src/ports/SkMemory_malloc.cpp b/src/ports/SkMemory_malloc.cpp
index 2fc59f9..f06dc35 100644
--- a/src/ports/SkMemory_malloc.cpp
+++ b/src/ports/SkMemory_malloc.cpp
@@ -31,7 +31,11 @@
// do not display a system dialog before aborting the process
_set_abort_behavior(0, _WRITE_ABORT_MSG);
#endif
+#if defined(SK_DEBUG) && defined(SK_BUILD_FOR_WIN)
+ __debugbreak();
+#else
abort();
+#endif
}
void sk_out_of_memory(void) {