Blender V5.0
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
9
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 <cstdio> /* For `printf()`. */
20#include <iostream>
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#ifndef NDEBUG
54# ifdef WITH_ASSERT_ABORT
55# include <cstdlib> /* For `abort()`. */
56# define GHOST_ASSERT(x, info) \
57 { \
58 if (!(x)) { \
59 fprintf(stderr, "GHOST_ASSERT failed: "); \
60 fprintf(stderr, info); \
61 fprintf(stderr, "\n"); \
62 abort(); \
63 } \
64 } \
65 ((void)0)
66/* Show the failure in non-release builds too. */
67# else
68# define GHOST_ASSERT(x, info) \
69 { \
70 if (!(x)) { \
71 GHOST_PRINT("GHOST_ASSERT failed: "); \
72 GHOST_PRINT(info); \
73 GHOST_PRINT("\n"); \
74 } \
75 } \
76 ((void)0)
77# endif
78#else /* `!defined(NDEBUG)` */
79# define GHOST_ASSERT(x, info) ((void)0)
80#endif /* `!defined(NDEBUG)` */