Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(777)

Side by Side Diff: include/core/SkTypes.h

Issue 2161103002: Improve assert reporting. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkPostConfig.h ('k') | src/ports/SkMemory_malloc.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkTypes_DEFINED 8 #ifndef SkTypes_DEFINED
9 #define SkTypes_DEFINED 9 #define SkTypes_DEFINED
10 10
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 #endif 132 #endif
133 133
134 /////////////////////////////////////////////////////////////////////////////// 134 ///////////////////////////////////////////////////////////////////////////////
135 135
136 #define SK_INIT_TO_AVOID_WARNING = 0 136 #define SK_INIT_TO_AVOID_WARNING = 0
137 137
138 #ifndef SkDebugf 138 #ifndef SkDebugf
139 SK_API void SkDebugf(const char format[], ...); 139 SK_API void SkDebugf(const char format[], ...);
140 #endif 140 #endif
141 141
142 #define SkASSERT_RELEASE(cond) if(!(cond)) { SK_ABORT(#cond); } 142 #define SkASSERT_RELEASE(cond) if (!(cond)) { SK_ABORT(#cond); }
143 143
144 #ifdef SK_DEBUG 144 #ifdef SK_DEBUG
145 #if defined SK_BUILD_FOR_WIN 145 #define SkASSERT(cond) if (!(cond)) { SK_ABORT("assert(" #cond ")"); }
146 #define SkASSERT(cond) if(!(cond)) { __debugbreak(); } 146 #define SkASSERTF(cond, fmt, ...) if (!(cond)) { \
147 #else 147 SkDebugf(fmt"\n", __VA_ARGS__); \
148 #define SkASSERT(cond) SkASSERT_RELEASE(cond) 148 SK_ABORT("assert(" #cond ")"); \
149 #endif 149 }
150 #define SkDEBUGFAIL(message) SkASSERT(false && message) 150 #define SkDEBUGFAIL(message) SK_ABORT(message)
151 #define SkDEBUGFAILF(fmt, ...) SkASSERTF(false, fmt, ##__VA_ARGS__) 151 #define SkDEBUGFAILF(fmt, ...) SkASSERTF(false, fmt, ##__VA_ARGS__)
152 #define SkDEBUGCODE(code) code 152 #define SkDEBUGCODE(code) code
153 #define SkDECLAREPARAM(type, var) , type var 153 #define SkDECLAREPARAM(type, var) , type var
154 #define SkPARAM(var) , var 154 #define SkPARAM(var) , var
155 // #define SkDEBUGF(args ) SkDebugf##args
156 #define SkDEBUGF(args ) SkDebugf args 155 #define SkDEBUGF(args ) SkDebugf args
157 #define SkAssertResult(cond) SkASSERT(cond) 156 #define SkAssertResult(cond) SkASSERT(cond)
158 #else 157 #else
159 #define SkASSERT(cond) 158 #define SkASSERT(cond)
159 #define SkASSERTF(cond, fmt, ...)
160 #define SkDEBUGFAIL(message) 160 #define SkDEBUGFAIL(message)
161 #define SkDEBUGCODE(code) 161 #define SkDEBUGCODE(code)
162 #define SkDEBUGF(args) 162 #define SkDEBUGF(args)
163 #define SkDECLAREPARAM(type, var) 163 #define SkDECLAREPARAM(type, var)
164 #define SkPARAM(var) 164 #define SkPARAM(var)
165 165
166 // unlike SkASSERT, this guy executes its condition in the non-debug build. 166 // unlike SkASSERT, this guy executes its condition in the non-debug build.
167 // The if is present so that this can be used with functions marked SK_WARN_ UNUSED_RESULT. 167 // The if is present so that this can be used with functions marked SK_WARN_ UNUSED_RESULT.
168 #define SkAssertResult(cond) if (cond) {} do {} while(false) 168 #define SkAssertResult(cond) if (cond) {} do {} while(false)
169 #endif 169 #endif
170 170
171 // Legacy macro names for SK_ABORT 171 // Legacy macro names for SK_ABORT
172 #define SkFAIL(message) SK_ABORT(message) 172 #define SkFAIL(message) SK_ABORT(message)
173 #define sk_throw() SK_ABORT("sk_throw") 173 #define sk_throw() SK_ABORT("sk_throw")
174 174
175 // We want to evaluate cond only once, and inside the SkASSERT somewhere so we s ee its string form.
176 // So we use the comma operator to make an SkDebugf that always returns false: w e'll evaluate cond,
177 // and if it's true the assert passes; if it's false, we'll print the message an d the assert fails.
178 #define SkASSERTF(cond, fmt, ...) SkASSERT((cond) || (SkDebugf(fmt"\n", __ VA_ARGS__), false))
179
180 #ifdef SK_IGNORE_TO_STRING 175 #ifdef SK_IGNORE_TO_STRING
181 #define SK_TO_STRING_NONVIRT() 176 #define SK_TO_STRING_NONVIRT()
182 #define SK_TO_STRING_VIRT() 177 #define SK_TO_STRING_VIRT()
183 #define SK_TO_STRING_PUREVIRT() 178 #define SK_TO_STRING_PUREVIRT()
184 #define SK_TO_STRING_OVERRIDE() 179 #define SK_TO_STRING_OVERRIDE()
185 #else 180 #else
186 class SkString; 181 class SkString;
187 // the 'toString' helper functions convert Sk* objects to human-readable 182 // the 'toString' helper functions convert Sk* objects to human-readable
188 // form in developer mode 183 // form in developer mode
189 #define SK_TO_STRING_NONVIRT() void toString(SkString* str) const; 184 #define SK_TO_STRING_NONVIRT() void toString(SkString* str) const;
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 711
717 void* fPtr; 712 void* fPtr;
718 size_t fSize; // can be larger than the requested size (see kReuse) 713 size_t fSize; // can be larger than the requested size (see kReuse)
719 uint32_t fStorage[kSize >> 2]; 714 uint32_t fStorage[kSize >> 2];
720 }; 715 };
721 // Can't guard the constructor because it's a template class. 716 // Can't guard the constructor because it's a template class.
722 717
723 #endif /* C++ */ 718 #endif /* C++ */
724 719
725 #endif 720 #endif
OLDNEW
« no previous file with comments | « include/core/SkPostConfig.h ('k') | src/ports/SkMemory_malloc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698