SHARE
TWEET

Untitled

a guest Aug 25th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Copyright 2019 Google LLC.
  2. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
  3. #ifndef SkAssertMacros_DEFINED
  4. #define SkAssertMacros_DEFINED
  5.  
  6. ////////////////////////////////////////////////////////////////////////////////
  7. // This file assumes that SkDebugf and SK_ABORT exist and that SK_DEBUG is set
  8. // appropriately.  Non-Skia users of this file can do something like this:
  9. //     #include <cstdio>
  10. //     #include <cstdlib>
  11. //     #ifndef NDEBUG
  12. //     #define SK_DEBUG
  13. //     #endif
  14. //     #define SkDebugf(...) std::printf(stderr, __VA_ARGS__)
  15. //     #define SK_ABORT(M) \
  16. //         do { SkDebugf("%s:%d: ABORT: '%s'\n", __FILE__, __LINE__, M); \
  17. //              std::abort(); } while(false)
  18. //     #include ".../SkAssertMacros.h"
  19. ////////////////////////////////////////////////////////////////////////////////
  20.  
  21. // SkASSERT, SkASSERTF and SkASSERT_RELEASE can be used as stand alone assertion expressions, e.g.
  22. //    uint32_t foo(int x) {
  23. //        SkASSERT(x > 4);
  24. //        return x - 4;
  25. //    }
  26. // and are also written to be compatible with constexpr functions:
  27. //    constexpr uint32_t foo(int x) {
  28. //        return SkASSERT(x > 4),
  29. //               x - 4;
  30. //    }
  31. #define SkASSERT_RELEASE(cond) \
  32.         static_cast<void>( (cond) ? (void)0 : []{ SK_ABORT("assert(" #cond ")"); }() )
  33.  
  34. #ifdef SK_DEBUG
  35.     #define SkASSERT(cond) SkASSERT_RELEASE(cond)
  36.     #define SkASSERTF(cond, fmt, ...) static_cast<void>( (cond) ? (void)0 : [&]{ \
  37.                                           SkDebugf(fmt"\n", __VA_ARGS__);        \
  38.                                           SK_ABORT("assert(" #cond ")");         \
  39.                                       }() )
  40.     #define SkDEBUGFAIL(message)        SK_ABORT(message)
  41.     #define SkDEBUGFAILF(fmt, ...)      SkASSERTF(false, fmt, ##__VA_ARGS__)
  42.     #define SkDEBUGCODE(...)            __VA_ARGS__
  43.     #define SkDEBUGF(...)               SkDebugf(__VA_ARGS__)
  44.     #define SkAssertResult(cond)        SkASSERT(cond)
  45. #else
  46.     #define SkASSERT(cond)            static_cast<void>(0)
  47.     #define SkASSERTF(cond, fmt, ...) static_cast<void>(0)
  48.     #define SkDEBUGFAIL(message)
  49.     #define SkDEBUGFAILF(fmt, ...)
  50.     #define SkDEBUGCODE(...)
  51.     #define SkDEBUGF(...)
  52.  
  53.     // unlike SkASSERT, this macro executes its condition in the non-debug build.
  54.     // The if is present so that this can be used with functions marked SK_WARN_UNUSED_RESULT.
  55.     #define SkAssertResult(cond)         if (cond) {} do {} while(false)
  56. #endif
  57.  
  58. #endif  // SkAssertMacros_DEFINED
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top