Ruby  3.4.0dev (2024-11-05 revision 348a53415339076afc4a02fcd09f3ae36e9c4c61)
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 <inttypes.h>
27 
33 #ifndef PRISM_DEPTH_MAXIMUM
34  #define PRISM_DEPTH_MAXIMUM 1000
35 #endif
36 
42 #ifndef PRISM_EXPORTED_FUNCTION
43 # ifdef PRISM_EXPORT_SYMBOLS
44 # ifdef _WIN32
45 # define PRISM_EXPORTED_FUNCTION __declspec(dllexport) extern
46 # else
47 # define PRISM_EXPORTED_FUNCTION __attribute__((__visibility__("default"))) extern
48 # endif
49 # else
50 # define PRISM_EXPORTED_FUNCTION
51 # endif
52 #endif
53 
60 #if defined(__GNUC__)
61 # if defined(__MINGW_PRINTF_FORMAT)
62 # define PRISM_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(__MINGW_PRINTF_FORMAT, string_index, argument_index)))
63 # else
64 # define PRISM_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(printf, string_index, argument_index)))
65 # endif
66 #elif defined(__clang__)
67 # define PRISM_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((__format__(__printf__, string_index, argument_index)))
68 #else
69 # define PRISM_ATTRIBUTE_FORMAT(string_index, argument_index)
70 #endif
71 
77 #if defined(__GNUC__)
78 # define PRISM_ATTRIBUTE_UNUSED __attribute__((unused))
79 #else
80 # define PRISM_ATTRIBUTE_UNUSED
81 #endif
82 
87 #if defined(_MSC_VER) && !defined(inline)
88 # define inline __inline
89 #endif
90 
95 #if !defined(snprintf) && defined(_MSC_VER) && (_MSC_VER < 1900)
96 # define snprintf _snprintf
97 #endif
98 
103 #define PM_CONCATENATE(left, right) left ## right
104 
110 #if defined(_Static_assert)
111 # define PM_STATIC_ASSERT(line, condition, message) _Static_assert(condition, message)
112 #else
113 # define PM_STATIC_ASSERT(line, condition, message) typedef char PM_CONCATENATE(static_assert_, line)[(condition) ? 1 : -1]
114 #endif
115 
121 #ifdef _WIN32
122 # define PRISM_HAS_MMAP
123 #else
124 # include <unistd.h>
125 # ifdef _POSIX_MAPPED_FILES
126 # define PRISM_HAS_MMAP
127 # endif
128 #endif
129 
135 #ifndef PRISM_HAS_NO_FILESYSTEM
136 # define PRISM_HAS_FILESYSTEM
137 #endif
138 
144 #ifdef _WIN32
145 # include <float.h>
146 # undef isinf
147 # define isinf(x) (sizeof(x) == sizeof(float) ? !_finitef(x) : !_finite(x))
148 #endif
149 
167 #ifdef PRISM_XALLOCATOR
168  #include "prism_xallocator.h"
169 #else
170  #ifndef xmalloc
175  #define xmalloc malloc
176  #endif
177 
178  #ifndef xrealloc
183  #define xrealloc realloc
184  #endif
185 
186  #ifndef xcalloc
191  #define xcalloc calloc
192  #endif
193 
194  #ifndef xfree
199  #define xfree free
200  #endif
201 #endif
202 
207 #ifdef PRISM_BUILD_MINIMAL
209  #define PRISM_EXCLUDE_SERIALIZATION
210 
212  #define PRISM_EXCLUDE_JSON
213 
215  #define PRISM_EXCLUDE_PACK
216 
218  #define PRISM_EXCLUDE_PRETTYPRINT
219 
221  #define PRISM_ENCODING_EXCLUDE_FULL
222 #endif
223 
228 #if defined(__GNUC__) || defined(__clang__)
230  #define PRISM_LIKELY(x) __builtin_expect(!!(x), 1)
231 
233  #define PRISM_UNLIKELY(x) __builtin_expect(!!(x), 0)
234 #else
236  #define PRISM_LIKELY(x) (x)
237 
239  #define PRISM_UNLIKELY(x) (x)
240 #endif
241 
242 #endif
Defines old _.