8#ifndef SkAssert_DEFINED
9#define SkAssert_DEFINED
18#if defined(__clang__) && defined(__has_attribute)
19 #if __has_attribute(likely)
20 #define SK_LIKELY [[likely]]
21 #define SK_UNLIKELY [[unlikely]]
33 #define SK_ASSUME(cond) __builtin_assume(cond)
34#elif defined(__GNUC__)
36 #define SK_ASSUME(cond) __attribute__((assume(cond)))
39 #define SK_ASSUME(cond) ((cond) ? (void)0 : __builtin_unreachable())
41#elif defined(_MSC_VER)
42 #define SK_ASSUME(cond) __assume(cond)
44 #define SK_ASSUME(cond) ((void)0)
53#if defined(SK_BUILD_FOR_GOOGLE3)
54 void SkDebugfForDumpStackTrace(
const char* data,
void*
unused);
56 void DumpStackTrace(
int skip_count,
void w(
const char*,
void*),
void* arg);
58# define SK_DUMP_GOOGLE3_STACK() ::base::DumpStackTrace(0, SkDebugfForDumpStackTrace, nullptr)
60# define SK_DUMP_GOOGLE3_STACK()
64# if defined(SK_BUILD_FOR_WIN)
66# define SK_DUMP_LINE_FORMAT "%s(%d)"
68# define SK_DUMP_LINE_FORMAT "%s:%d"
70# define SK_ABORT(message, ...) \
72 SkDebugf(SK_DUMP_LINE_FORMAT ": fatal error: \"" message "\"\n", \
73 __FILE__, __LINE__, ##__VA_ARGS__); \
74 SK_DUMP_GOOGLE3_STACK(); \
75 sk_abort_no_print(); \
90#define SkASSERT_RELEASE(cond) \
91 static_cast<void>( __builtin_expect(static_cast<bool>(cond), 1) \
92 ? static_cast<void>(0) \
93 : []{ SK_ABORT("check(%s)", #cond); }() )
95#define SkASSERTF_RELEASE(cond, fmt, ...) \
96 static_cast<void>( __builtin_expect(static_cast<bool>(cond), 1) \
97 ? static_cast<void>(0) \
98 : [&]{ SK_ABORT("assertf(%s): " fmt, #cond, ##__VA_ARGS__); }() )
100#define SkASSERT_RELEASE(cond) \
101 static_cast<void>( (cond) ? static_cast<void>(0) : []{ SK_ABORT("check(%s)", #cond); }() )
103#define SkASSERTF_RELEASE(cond, fmt, ...) \
104 static_cast<void>( (cond) \
105 ? static_cast<void>(0) \
106 : [&]{ SK_ABORT("assertf(%s): " fmt, #cond, ##__VA_ARGS__); }() )
110 #define SkASSERT(cond) SkASSERT_RELEASE(cond)
111 #define SkASSERTF(cond, fmt, ...) SkASSERTF_RELEASE(cond, fmt, ##__VA_ARGS__)
112 #define SkDEBUGFAIL(message) SK_ABORT("%s", message)
113 #define SkDEBUGFAILF(fmt, ...) SK_ABORT(fmt, ##__VA_ARGS__)
114 #define SkAssertResult(cond) SkASSERT(cond)
116 #define SkASSERT(cond) static_cast<void>(0)
117 #define SkASSERTF(cond, fmt, ...) static_cast<void>(0)
118 #define SkDEBUGFAIL(message)
119 #define SkDEBUGFAILF(fmt, ...)
123 #define SkAssertResult(cond) if (cond) {} do {} while(false)
126#if !defined(SkUNREACHABLE)
127# if defined(_MSC_VER) && !defined(__clang__)
129# define FAST_FAIL_INVALID_ARG 5
132[[noreturn]]
static inline void sk_fast_fail() { __fastfail(FAST_FAIL_INVALID_ARG); }
133# define SkUNREACHABLE sk_fast_fail()
135# define SkUNREACHABLE __builtin_trap()
140 SK_ABORT(
"Index (%zu) out of bounds for size %zu.\n", i, size);
149 #if defined(SK_DEBUG)
158 SK_ABORT(
"Length (%zu) is too big for size %zu.\n", i, size);
167 #if defined(SK_DEBUG)
177 #if defined(SK_DEBUG)
186 SK_ABORT(
"Size (%zu) can't be represented in bytes. Max size is %zu.\n", size, maxSize);
191 const size_t kMaxSize = std::numeric_limits<size_t>::max() /
sizeof(
T);
192 if (size > kMaxSize) {
193 #if defined(SK_DEBUG)
SK_ALWAYS_INLINE size_t check_size_bytes_too_big(size_t size)
#define SK_ABORT(message,...)
SK_API void sk_collection_not_empty(bool empty)
SK_API void sk_print_size_too_big(size_t size, size_t maxSize)
SK_API void sk_abort_no_print(void)
SK_API T sk_collection_check_bounds(T i, T size)
SK_API void sk_print_length_too_big(size_t i, size_t size)
SK_API void sk_print_index_out_of_bounds(size_t i, size_t size)
SK_API T sk_collection_check_length(T i, T size)
EMSCRIPTEN_KEEPALIVE void empty()