Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/pcre2/src/pcre2_util.h
9898 views
1
/*************************************************
2
* Perl-Compatible Regular Expressions *
3
*************************************************/
4
5
/* PCRE2 is a library of functions to support regular expressions whose syntax
6
and semantics are as close as possible to those of the Perl 5 language.
7
8
Written by Philip Hazel
9
Original API code Copyright (c) 1997-2012 University of Cambridge
10
New API code Copyright (c) 2016-2024 University of Cambridge
11
12
-----------------------------------------------------------------------------
13
Redistribution and use in source and binary forms, with or without
14
modification, are permitted provided that the following conditions are met:
15
16
* Redistributions of source code must retain the above copyright notice,
17
this list of conditions and the following disclaimer.
18
19
* Redistributions in binary form must reproduce the above copyright
20
notice, this list of conditions and the following disclaimer in the
21
documentation and/or other materials provided with the distribution.
22
23
* Neither the name of the University of Cambridge nor the names of its
24
contributors may be used to endorse or promote products derived from
25
this software without specific prior written permission.
26
27
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37
POSSIBILITY OF SUCH DAMAGE.
38
-----------------------------------------------------------------------------
39
*/
40
41
#ifndef PCRE2_UTIL_H_IDEMPOTENT_GUARD
42
#define PCRE2_UTIL_H_IDEMPOTENT_GUARD
43
44
/* Assertion macros */
45
46
#ifdef PCRE2_DEBUG
47
48
#if defined(HAVE_ASSERT_H) && !defined(NDEBUG)
49
#include <assert.h>
50
#endif
51
52
/* PCRE2_ASSERT(x) can be used to inject an assert() for conditions
53
that the code below doesn't support. It is a NOP for non debug builds
54
but in debug builds will print information about the location of the
55
code where it triggered and crash.
56
57
It is meant to work like assert(), and therefore the expression used
58
should indicate what the expected state is, and shouldn't have any
59
side-effects. */
60
61
#if defined(HAVE_ASSERT_H) && !defined(NDEBUG)
62
#define PCRE2_ASSERT(x) assert(x)
63
#else
64
#define PCRE2_ASSERT(x) do \
65
{ \
66
if (!(x)) \
67
{ \
68
fprintf(stderr, "Assertion failed at " __FILE__ ":%d\n", __LINE__); \
69
abort(); \
70
} \
71
} while(0)
72
#endif
73
74
/* PCRE2_UNREACHABLE() can be used to mark locations on the code that
75
shouldn't be reached. In non debug builds is defined as a hint for
76
the compiler to eliminate any code after it, so it is useful also for
77
performance reasons, but should be used with care because if it is
78
ever reached will trigger Undefined Behaviour and if you are lucky a
79
crash. In debug builds it will report the location where it was triggered
80
and crash. One important point to consider when using this macro, is
81
that it is only implemented for a few compilers, and therefore can't
82
be relied on to always be active either, so if it is followed by some
83
code it is important to make sure that the whole thing is safe to
84
use even if the macro is not there (ex: make sure there is a `break`
85
after it if used at the end of a `case`) and to test your code also
86
with a configuration where the macro will be a NOP. */
87
88
#if defined(HAVE_ASSERT_H) && !defined(NDEBUG)
89
#define PCRE2_UNREACHABLE() \
90
assert(((void)"Execution reached unexpected point", 0))
91
#else
92
#define PCRE2_UNREACHABLE() do \
93
{ \
94
fprintf(stderr, "Execution reached unexpected point at " __FILE__ \
95
":%d\n", __LINE__); \
96
abort(); \
97
} while(0)
98
#endif
99
100
/* PCRE2_DEBUG_UNREACHABLE() is a debug only version of the previous
101
macro. It is meant to be used in places where the code is handling
102
an error situation in code that shouldn't be reached, but that has
103
some sort of fallback code to normally handle the error. When in
104
doubt you should use this instead of the previous macro. Like in
105
the previous case, it is a good idea to document as much as possible
106
the reason and the actions that should be taken if it ever triggers. */
107
108
#define PCRE2_DEBUG_UNREACHABLE() PCRE2_UNREACHABLE()
109
110
#endif /* PCRE2_DEBUG */
111
112
#ifndef PCRE2_DEBUG_UNREACHABLE
113
#define PCRE2_DEBUG_UNREACHABLE() do {} while(0)
114
#endif
115
116
#ifndef PCRE2_UNREACHABLE
117
#ifdef HAVE_BUILTIN_UNREACHABLE
118
#define PCRE2_UNREACHABLE() __builtin_unreachable()
119
#elif defined(HAVE_BUILTIN_ASSUME)
120
#define PCRE2_UNREACHABLE() __assume(0)
121
#else
122
#define PCRE2_UNREACHABLE() do {} while(0)
123
#endif
124
#endif /* !PCRE2_UNREACHABLE */
125
126
#ifndef PCRE2_ASSERT
127
#define PCRE2_ASSERT(x) do {} while(0)
128
#endif
129
130
#endif /* PCRE2_UTIL_H_IDEMPOTENT_GUARD */
131
132
/* End of pcre2_util.h */
133
134