1 #ifndef SIMDJSON_COMMON_DEFS_H
2 #define SIMDJSON_COMMON_DEFS_H
5 #include "simdjson/portability.h"
15 char *to_chars(
char *first,
const char *last,
double value);
21 double from_chars(
const char *first) noexcept;
22 double from_chars(
const char *first,
const char* end) noexcept;
26 #ifndef SIMDJSON_EXCEPTIONS
28 #define SIMDJSON_EXCEPTIONS 1
30 #define SIMDJSON_EXCEPTIONS 0
58 #define SIMDJSON_BEGIN_DEBUG_BLOCK(name) __asm volatile("# LLVM-MCA-BEGIN " #name);
59 #define SIMDJSON_END_DEBUG_BLOCK(name) __asm volatile("# LLVM-MCA-END " #name);
60 #define SIMDJSON_DEBUG_BLOCK(name, block) BEGIN_DEBUG_BLOCK(name); block; END_DEBUG_BLOCK(name);
62 #define SIMDJSON_BEGIN_DEBUG_BLOCK(name)
63 #define SIMDJSON_END_DEBUG_BLOCK(name)
64 #define SIMDJSON_DEBUG_BLOCK(name, block)
68 #define SIMDJSON_ROUNDUP_N(a, n) (((a) + ((n)-1)) & ~((n)-1))
69 #define SIMDJSON_ROUNDDOWN_N(a, n) ((a) & ~((n)-1))
71 #define SIMDJSON_ISALIGNED_N(ptr, n) (((uintptr_t)(ptr) & ((n)-1)) == 0)
73 #if SIMDJSON_REGULAR_VISUAL_STUDIO
75 #define simdjson_really_inline __forceinline
76 #define simdjson_never_inline __declspec(noinline)
78 #define simdjson_unused
79 #define simdjson_warn_unused
81 #ifndef simdjson_likely
82 #define simdjson_likely(x) x
84 #ifndef simdjson_unlikely
85 #define simdjson_unlikely(x) x
88 #define SIMDJSON_PUSH_DISABLE_WARNINGS __pragma(warning( push ))
89 #define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS __pragma(warning( push, 0 ))
90 #define SIMDJSON_DISABLE_VS_WARNING(WARNING_NUMBER) __pragma(warning( disable : WARNING_NUMBER ))
94 #if __has_include(<CppCoreCheck\Warnings.h>)
95 #include <CppCoreCheck\Warnings.h>
96 #define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_VS_WARNING(ALL_CPPCORECHECK_WARNINGS)
100 #ifndef SIMDJSON_DISABLE_UNDESIRED_WARNINGS
101 #define SIMDJSON_DISABLE_UNDESIRED_WARNINGS
104 #define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_VS_WARNING(4996)
105 #define SIMDJSON_DISABLE_STRICT_OVERFLOW_WARNING
106 #define SIMDJSON_POP_DISABLE_WARNINGS __pragma(warning( pop ))
110 #define simdjson_really_inline inline __attribute__((always_inline))
111 #define simdjson_never_inline inline __attribute__((noinline))
113 #define simdjson_unused __attribute__((unused))
114 #define simdjson_warn_unused __attribute__((warn_unused_result))
116 #ifndef simdjson_likely
117 #define simdjson_likely(x) __builtin_expect(!!(x), 1)
119 #ifndef simdjson_unlikely
120 #define simdjson_unlikely(x) __builtin_expect(!!(x), 0)
123 #define SIMDJSON_PUSH_DISABLE_WARNINGS _Pragma("GCC diagnostic push")
128 #define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS SIMDJSON_PUSH_DISABLE_WARNINGS \
129 SIMDJSON_DISABLE_GCC_WARNING(-Weffc++) \
130 SIMDJSON_DISABLE_GCC_WARNING(-Wall) \
131 SIMDJSON_DISABLE_GCC_WARNING(-Wconversion) \
132 SIMDJSON_DISABLE_GCC_WARNING(-Wextra) \
133 SIMDJSON_DISABLE_GCC_WARNING(-Wattributes) \
134 SIMDJSON_DISABLE_GCC_WARNING(-Wimplicit-fallthrough) \
135 SIMDJSON_DISABLE_GCC_WARNING(-Wnon-virtual-dtor) \
136 SIMDJSON_DISABLE_GCC_WARNING(-Wreturn-type) \
137 SIMDJSON_DISABLE_GCC_WARNING(-Wshadow) \
138 SIMDJSON_DISABLE_GCC_WARNING(-Wunused-parameter) \
139 SIMDJSON_DISABLE_GCC_WARNING(-Wunused-variable)
141 #define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS SIMDJSON_PUSH_DISABLE_WARNINGS \
142 SIMDJSON_DISABLE_GCC_WARNING(-Weffc++) \
143 SIMDJSON_DISABLE_GCC_WARNING(-Wall) \
144 SIMDJSON_DISABLE_GCC_WARNING(-Wconversion) \
145 SIMDJSON_DISABLE_GCC_WARNING(-Wextra) \
146 SIMDJSON_DISABLE_GCC_WARNING(-Wattributes) \
147 SIMDJSON_DISABLE_GCC_WARNING(-Wimplicit-fallthrough) \
148 SIMDJSON_DISABLE_GCC_WARNING(-Wnon-virtual-dtor) \
149 SIMDJSON_DISABLE_GCC_WARNING(-Wreturn-type) \
150 SIMDJSON_DISABLE_GCC_WARNING(-Wshadow) \
151 SIMDJSON_DISABLE_GCC_WARNING(-Wunused-parameter) \
152 SIMDJSON_DISABLE_GCC_WARNING(-Wunused-variable) \
153 SIMDJSON_DISABLE_GCC_WARNING(-Wmaybe-uninitialized)
156 #define SIMDJSON_PRAGMA(P) _Pragma(#P)
157 #define SIMDJSON_DISABLE_GCC_WARNING(WARNING) SIMDJSON_PRAGMA(GCC diagnostic ignored #WARNING)
158 #if SIMDJSON_CLANG_VISUAL_STUDIO
159 #define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_GCC_WARNING(-Wmicrosoft-include)
161 #define SIMDJSON_DISABLE_UNDESIRED_WARNINGS
163 #define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wdeprecated-declarations)
164 #define SIMDJSON_DISABLE_STRICT_OVERFLOW_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wstrict-overflow)
165 #define SIMDJSON_POP_DISABLE_WARNINGS _Pragma("GCC diagnostic pop")
171 #if defined(simdjson_inline)
173 #elif defined(__GNUC__) && !defined(__OPTIMIZE__)
177 #define simdjson_inline inline
180 #define simdjson_inline simdjson_really_inline
183 #if SIMDJSON_VISUAL_STUDIO
199 #if SIMDJSON_BUILDING_WINDOWS_DYNAMIC_LIBRARY
203 #define SIMDJSON_DLLIMPORTEXPORT __declspec(dllexport)
204 #elif SIMDJSON_USING_WINDOWS_DYNAMIC_LIBRARY
206 #define SIMDJSON_DLLIMPORTEXPORT __declspec(dllimport)
209 #define SIMDJSON_DLLIMPORTEXPORT
216 #if SIMDJSON_USING_LIBRARY
217 #define SIMDJSON_DLLIMPORTEXPORT __declspec(dllimport)
223 #define SIMDJSON_DLLIMPORTEXPORT
227 #if SIMDJSON_CPLUSPLUS17
228 #define SIMDJSON_HAS_STRING_VIEW
229 #include <string_view>
236 #ifdef __cpp_lib_string_view
237 #define SIMDJSON_HAS_STRING_VIEW
244 #ifndef SIMDJSON_HAS_STRING_VIEW
245 #if defined __has_include
247 #if __has_include (<string_view>)
249 #include <string_view>
250 #if defined(_LIBCPP_STRING_VIEW)
254 #define SIMDJSON_HAS_STRING_VIEW
267 #ifndef SIMDJSON_HAS_STRING_VIEW
268 SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
269 #include "simdjson/nonstd/string_view.hpp"
270 SIMDJSON_POP_DISABLE_WARNINGS
273 using string_view = nonstd::string_view;
276 #undef SIMDJSON_HAS_STRING_VIEW
279 #define SIMDJSON_TRY(EXPR) { auto _err = (EXPR); if (_err) { return _err; } }
291 #ifndef SIMDJSON_DEVELOPMENT_CHECKS
295 #define SIMDJSON_DEVELOPMENT_CHECKS 1
301 #define SIMDJSON_DEVELOPMENT_CHECKS 1
309 #if SIMDJSON_CPLUSPLUS17
311 # define simdjson_fallthrough [[fallthrough]]
313 #elif defined(__has_attribute)
315 #if __has_attribute(__fallthrough__)
317 # define simdjson_fallthrough __attribute__((__fallthrough__))
321 #ifndef simdjson_fallthrough
322 # define simdjson_fallthrough do {} while (0)
326 #if SIMDJSON_DEVELOPMENT_CHECKS
327 #define SIMDJSON_DEVELOPMENT_ASSERT(expr) do { assert ((expr)); } while (0)
329 #define SIMDJSON_DEVELOPMENT_ASSERT(expr) do { } while (0)
332 #ifndef SIMDJSON_UTF8VALIDATION
333 #define SIMDJSON_UTF8VALIDATION 1
We want to support argument-dependent lookup (ADL).
constexpr size_t DEFAULT_MAX_DEPTH
By default, simdjson supports this many nested objects and arrays.
constexpr size_t SIMDJSON_MAXSIZE_BYTES
The maximum document size supported by simdjson.
constexpr size_t SIMDJSON_PADDING
The amount of padding needed in a buffer to parse JSON.