Ruby  3.4.0dev (2024-12-06 revision 892c46283a5ea4179500d951c9d4866c0051f27b)
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 
143 #ifdef _WIN32
144 # include <float.h>
145 #endif
146 
164 #ifdef PRISM_XALLOCATOR
165  #include "prism_xallocator.h"
166 #else
167  #ifndef xmalloc
172  #define xmalloc malloc
173  #endif
174 
175  #ifndef xrealloc
180  #define xrealloc realloc
181  #endif
182 
183  #ifndef xcalloc
188  #define xcalloc calloc
189  #endif
190 
191  #ifndef xfree
196  #define xfree free
197  #endif
198 #endif
199 
204 #ifdef PRISM_BUILD_MINIMAL
206  #define PRISM_EXCLUDE_SERIALIZATION
207 
209  #define PRISM_EXCLUDE_JSON
210 
212  #define PRISM_EXCLUDE_PACK
213 
215  #define PRISM_EXCLUDE_PRETTYPRINT
216 
218  #define PRISM_ENCODING_EXCLUDE_FULL
219 #endif
220 
225 #if defined(__GNUC__) || defined(__clang__)
227  #define PRISM_LIKELY(x) __builtin_expect(!!(x), 1)
228 
230  #define PRISM_UNLIKELY(x) __builtin_expect(!!(x), 0)
231 #else
233  #define PRISM_LIKELY(x) (x)
234 
236  #define PRISM_UNLIKELY(x) (x)
237 #endif
238 
239 #endif
Defines old _.