Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright 2019 Google LLC.
- // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
- #ifndef SkAssertMacros_DEFINED
- #define SkAssertMacros_DEFINED
- ////////////////////////////////////////////////////////////////////////////////
- // This file assumes that SkDebugf and SK_ABORT exist and that SK_DEBUG is set
- // appropriately. Non-Skia users of this file can do something like this:
- // #include <cstdio>
- // #include <cstdlib>
- // #ifndef NDEBUG
- // #define SK_DEBUG
- // #endif
- // #define SkDebugf(...) std::printf(stderr, __VA_ARGS__)
- // #define SK_ABORT(M) \
- // do { SkDebugf("%s:%d: ABORT: '%s'\n", __FILE__, __LINE__, M); \
- // std::abort(); } while(false)
- // #include ".../SkAssertMacros.h"
- ////////////////////////////////////////////////////////////////////////////////
- // SkASSERT, SkASSERTF and SkASSERT_RELEASE can be used as stand alone assertion expressions, e.g.
- // uint32_t foo(int x) {
- // SkASSERT(x > 4);
- // return x - 4;
- // }
- // and are also written to be compatible with constexpr functions:
- // constexpr uint32_t foo(int x) {
- // return SkASSERT(x > 4),
- // x - 4;
- // }
- #define SkASSERT_RELEASE(cond) \
- static_cast<void>( (cond) ? (void)0 : []{ SK_ABORT("assert(" #cond ")"); }() )
- #ifdef SK_DEBUG
- #define SkASSERT(cond) SkASSERT_RELEASE(cond)
- #define SkASSERTF(cond, fmt, ...) static_cast<void>( (cond) ? (void)0 : [&]{ \
- 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(...) __VA_ARGS__
- #define SkDEBUGF(...) SkDebugf(__VA_ARGS__)
- #define SkAssertResult(cond) SkASSERT(cond)
- #else
- #define SkASSERT(cond) static_cast<void>(0)
- #define SkASSERTF(cond, fmt, ...) static_cast<void>(0)
- #define SkDEBUGFAIL(message)
- #define SkDEBUGFAILF(fmt, ...)
- #define SkDEBUGCODE(...)
- #define SkDEBUGF(...)
- // unlike SkASSERT, this macro executes its condition in the non-debug build.
- // The if is present so that this can be used with functions marked SK_WARN_UNUSED_RESULT.
- #define SkAssertResult(cond) if (cond) {} do {} while(false)
- #endif
- #endif // SkAssertMacros_DEFINED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement