Ruby: prism/defines.h Source File

Ruby 3.4.6p54 (2025-09-16 revision dbd83256b1cec76c69756ecb8758b9e1079833de)

defines.h
Go to the documentation of this file.
1
9#ifndef PRISM_DEFINES_H
10#define PRISM_DEFINES_H
11
12#include <ctype.h>
13#include <limits.h>
14#include <math.h>
15#include <stdarg.h>
16#include <stddef.h>
17#include <stdint.h>
18#include <stdio.h>
19#include <string.h>
20
25#define __STDC_FORMAT_MACROS
26// Include sys/types.h before inttypes.h to work around issue with
27// certain versions of GCC and newlib which causes omission of PRIx64
28#include <sys/types.h>
29#include <inttypes.h>
30
36#ifndef PRISM_DEPTH_MAXIMUM
37 #define PRISM_DEPTH_MAXIMUM 10000
38#endif
39
45#ifndef PRISM_EXPORTED_FUNCTION
46# ifdef PRISM_EXPORT_SYMBOLS
47# ifdef _WIN32
48# define PRISM_EXPORTED_FUNCTION __declspec(dllexport) extern
49# else
50# define PRISM_EXPORTED_FUNCTION __attribute__((__visibility__("default"))) extern
51# endif
52# else
53# define PRISM_EXPORTED_FUNCTION
54# endif
55#endif
56
63#if defined(__GNUC__)
64# if defined(__MINGW_PRINTF_FORMAT)
65# define PRISM_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(__MINGW_PRINTF_FORMAT, string_index, argument_index)))
66# else
67# define PRISM_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(printf, string_index, argument_index)))
68# endif
69#elif defined(__clang__)
70# define PRISM_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((__format__(__printf__, string_index, argument_index)))
71#else
72# define PRISM_ATTRIBUTE_FORMAT(string_index, argument_index)
73#endif
74
80#if defined(__GNUC__)
81# define PRISM_ATTRIBUTE_UNUSED __attribute__((unused))
82#else
83# define PRISM_ATTRIBUTE_UNUSED
84#endif
85
90#if defined(_MSC_VER) && !defined(inline)
91# define inline __inline
92#endif
93
98#if !defined(snprintf) && defined(_MSC_VER) && (_MSC_VER < 1900)
99# define snprintf _snprintf
100#endif
101
106#define PM_CONCATENATE(left, right) left ## right
107
113#if defined(_Static_assert)
114# define PM_STATIC_ASSERT(line, condition, message) _Static_assert(condition, message)
115#else
116# define PM_STATIC_ASSERT(line, condition, message) typedef char PM_CONCATENATE(static_assert_, line)[(condition) ? 1 : -1]
117#endif
118
124#ifdef _WIN32
125# define PRISM_HAS_MMAP
126#else
127# include <unistd.h>
128# ifdef _POSIX_MAPPED_FILES
129# define PRISM_HAS_MMAP
130# endif
131#endif
132
138#ifndef PRISM_HAS_NO_FILESYSTEM
139# define PRISM_HAS_FILESYSTEM
140#endif
141
147#ifdef __MINGW64__
148 #include <float.h>
149 #define PRISM_ISINF(x) (!_finite(x))
150#else
151 #define PRISM_ISINF(x) isinf(x)
152#endif
153
171#ifdef PRISM_XALLOCATOR
172 #include "prism_xallocator.h"
173#else
174 #ifndef xmalloc
179 #define xmalloc malloc
180 #endif
181
182 #ifndef xrealloc
187 #define xrealloc realloc
188 #endif
189
190 #ifndef xcalloc
195 #define xcalloc calloc
196 #endif
197
198 #ifndef xfree
203 #define xfree free
204 #endif
205#endif
206
211#ifdef PRISM_BUILD_MINIMAL
213 #define PRISM_EXCLUDE_SERIALIZATION
214
216 #define PRISM_EXCLUDE_JSON
217
219 #define PRISM_EXCLUDE_PACK
220
222 #define PRISM_EXCLUDE_PRETTYPRINT
223
225 #define PRISM_ENCODING_EXCLUDE_FULL
226#endif
227
232#if defined(__GNUC__) || defined(__clang__)
234 #define PRISM_LIKELY(x) __builtin_expect(!!(x), 1)
235
237 #define PRISM_UNLIKELY(x) __builtin_expect(!!(x), 0)
238#else
240 #define PRISM_LIKELY(x) (x)
241
243 #define PRISM_UNLIKELY(x) (x)
244#endif
245
250#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L // C23 or later
251 #define PRISM_FALLTHROUGH [[fallthrough]];
252#elif defined(__GNUC__) || defined(__clang__)
253 #define PRISM_FALLTHROUGH __attribute__((fallthrough));
254#elif defined(_MSC_VER)
255 #define PRISM_FALLTHROUGH __fallthrough;
256#else
257 #define PRISM_FALLTHROUGH
258#endif
259
260#endif
stdarg.h
Defines old _.