Blender V4.3
GHOST_Debug.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10#pragma once
11
12#ifdef _MSC_VER
13# ifdef _DEBUG
14/* Suppress STL-MSVC debug info warning. */
15# pragma warning(disable : 4786)
16# endif
17#endif
18
19#include <iostream>
20#include <stdio.h> /* For `printf()`. */
21
22#if defined(WITH_GHOST_DEBUG)
23# define GHOST_PRINT(x) \
24 { \
25 std::cout << x; \
26 } \
27 ((void)0)
28# define GHOST_PRINTF(x, ...) \
29 { \
30 printf(x, __VA_ARGS__); \
31 } \
32 ((void)0)
33#else
34/* Expand even when `WITH_GHOST_DEBUG` is disabled to prevent expressions
35 * becoming invalid even when the option is disable. */
36# define GHOST_PRINT(x) \
37 { \
38 if (false) { \
39 std::cout << x; \
40 } \
41 } \
42 ((void)0)
43# define GHOST_PRINTF(x, ...) \
44 { \
45 if (false) { \
46 printf(x, __VA_ARGS__); \
47 } \
48 } \
49 ((void)0)
50
51#endif /* `!defined(WITH_GHOST_DEBUG)` */
52
53#ifdef WITH_ASSERT_ABORT
54# include <stdlib.h> //for abort()
55# define GHOST_ASSERT(x, info) \
56 { \
57 if (!(x)) { \
58 fprintf(stderr, "GHOST_ASSERT failed: "); \
59 fprintf(stderr, info); \
60 fprintf(stderr, "\n"); \
61 abort(); \
62 } \
63 } \
64 ((void)0)
65/* Assert in non-release builds too. */
66#elif defined(WITH_GHOST_DEBUG) || (!defined(NDEBUG))
67# define GHOST_ASSERT(x, info) \
68 { \
69 if (!(x)) { \
70 GHOST_PRINT("GHOST_ASSERT failed: "); \
71 GHOST_PRINT(info); \
72 GHOST_PRINT("\n"); \
73 } \
74 } \
75 ((void)0)
76#else /* `defined(WITH_GHOST_DEBUG) || (!defined(NDEBUG))` */
77# define GHOST_ASSERT(x, info) ((void)0)
78#endif /* `defined(WITH_GHOST_DEBUG) || (!defined(NDEBUG))` */