Etterna 0.74.4
Loading...
Searching...
No Matches
global.h
1#ifndef GLOBAL_H
2#define GLOBAL_H
3
4#include "config.hpp"
5
6#if _MSC_VER >= 1000
7#pragma once
8#endif // _MSC_VER >= 1000
9#pragma warning(disable : 4251)
10#pragma warning(disable : 4275)
11#pragma warning(disable : 4996)
12#pragma warning(disable : 4267)
13#pragma warning(disable : 4244)
15#define __STDC_LIMIT_MACROS
17#define __STDC_CONSTANT_MACROS
18
19/* Platform-specific fixes. */
20#ifdef _WIN32
21#include "archutils/Win32/arch_setup.h"
22#elif defined(__APPLE__)
23#include "archutils/Darwin/arch_setup.h"
24#elif defined(__unix__)
25#include "archutils/Unix/arch_setup.h"
26#endif
27
28#if defined(HAVE_STDINT_H) /* need to define int64_t if so */
29#include <cstdint>
30#endif
31#if defined(HAVE_INTTYPES_H)
32#include <cinttypes>
33#endif
34
35/* Branch optimizations: */
36#if defined(__GNUC__)
37#define likely(x) (__builtin_expect(!!(x), 1))
38#define unlikely(x) (__builtin_expect(!!(x), 0))
39#else
40#define likely(x) (x)
41#define unlikely(x) (x)
42#endif
43
44#if defined(NEED_CSTDLIB_WORKAROUND)
45#define llabs ::llabs
46#endif
47
48#ifdef ASSERT
49#undef ASSERT
50#endif
51
58#if defined(_MSC_VER)
59#define NORETURN __declspec(noreturn)
60#elif defined(__GNUC__) && \
61 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
62#define NORETURN __attribute__((__noreturn__))
63#else
64#define NORETURN
65#endif
66
76void NORETURN
77sm_crash(const char* reason = "Internal error");
78
86#define FAIL_M(MESSAGE) \
87 do { \
88 sm_crash(std::string(MESSAGE).c_str()); \
89 } while (0)
90#define ASSERT_M(COND, MESSAGE) \
91 do { \
92 if (unlikely(!(COND))) { \
93 FAIL_M(std::string(MESSAGE).c_str()); \
94 } \
95 } while (0)
96
97#if !defined(CO_EXIST_WITH_MFC)
98#define ASSERT(COND) ASSERT_M((COND), "Assertion '" #COND "' failed")
99#endif
100
102#define DEFAULT_FAIL(i) \
103 default: \
104 FAIL_M(ssprintf("%s = %i", #i, (i)))
105
106void
107ShowWarningOrTrace(const char* file,
108 int line,
109 const char* message,
110 bool bWarning); // don't pull in LOG here
111
112#ifdef DEBUG
113// No reason to kill the program. A lot of these don't produce a crash in NDEBUG
114// so why stop?
115// TODO: These should have something you can hook a breakpoint on.
116#define DEBUG_ASSERT_M(COND, MESSAGE) \
117 if (unlikely(!(COND))) \
118 WARN(MESSAGE)
119#define DEBUG_ASSERT(COND) DEBUG_ASSERT_M(COND, "Debug assert failed")
120#else
122#define DEBUG_ASSERT(x)
124#define DEBUG_ASSERT_M(x, y)
125#endif
126
127/* Use SM_UNIQUE_NAME to get the line number concatenated to x. This is useful
128 * for generating unique identifiers in other macros. */
129#define SM_UNIQUE_NAME3(x, line) x##line
130#define SM_UNIQUE_NAME2(x, line) SM_UNIQUE_NAME3(x, line)
131#define SM_UNIQUE_NAME(x) SM_UNIQUE_NAME2(x, __LINE__)
132
133#include "RageUtil/Misc/RageException.h"
134/* Don't include our own headers here, since they tend to change often. */
135
136#endif