jpayne@69
|
1 #ifndef Py_PYPORT_H
|
jpayne@69
|
2 #define Py_PYPORT_H
|
jpayne@69
|
3
|
jpayne@69
|
4 #include "pyconfig.h" /* include for defines */
|
jpayne@69
|
5
|
jpayne@69
|
6 #include <inttypes.h>
|
jpayne@69
|
7
|
jpayne@69
|
8
|
jpayne@69
|
9 /* Defines to build Python and its standard library:
|
jpayne@69
|
10 *
|
jpayne@69
|
11 * - Py_BUILD_CORE: Build Python core. Give access to Python internals, but
|
jpayne@69
|
12 * should not be used by third-party modules.
|
jpayne@69
|
13 * - Py_BUILD_CORE_BUILTIN: Build a Python stdlib module as a built-in module.
|
jpayne@69
|
14 * - Py_BUILD_CORE_MODULE: Build a Python stdlib module as a dynamic library.
|
jpayne@69
|
15 *
|
jpayne@69
|
16 * Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE imply Py_BUILD_CORE.
|
jpayne@69
|
17 *
|
jpayne@69
|
18 * On Windows, Py_BUILD_CORE_MODULE exports "PyInit_xxx" symbol, whereas
|
jpayne@69
|
19 * Py_BUILD_CORE_BUILTIN does not.
|
jpayne@69
|
20 */
|
jpayne@69
|
21 #if defined(Py_BUILD_CORE_BUILTIN) && !defined(Py_BUILD_CORE)
|
jpayne@69
|
22 # define Py_BUILD_CORE
|
jpayne@69
|
23 #endif
|
jpayne@69
|
24 #if defined(Py_BUILD_CORE_MODULE) && !defined(Py_BUILD_CORE)
|
jpayne@69
|
25 # define Py_BUILD_CORE
|
jpayne@69
|
26 #endif
|
jpayne@69
|
27
|
jpayne@69
|
28
|
jpayne@69
|
29 /**************************************************************************
|
jpayne@69
|
30 Symbols and macros to supply platform-independent interfaces to basic
|
jpayne@69
|
31 C language & library operations whose spellings vary across platforms.
|
jpayne@69
|
32
|
jpayne@69
|
33 Please try to make documentation here as clear as possible: by definition,
|
jpayne@69
|
34 the stuff here is trying to illuminate C's darkest corners.
|
jpayne@69
|
35
|
jpayne@69
|
36 Config #defines referenced here:
|
jpayne@69
|
37
|
jpayne@69
|
38 SIGNED_RIGHT_SHIFT_ZERO_FILLS
|
jpayne@69
|
39 Meaning: To be defined iff i>>j does not extend the sign bit when i is a
|
jpayne@69
|
40 signed integral type and i < 0.
|
jpayne@69
|
41 Used in: Py_ARITHMETIC_RIGHT_SHIFT
|
jpayne@69
|
42
|
jpayne@69
|
43 Py_DEBUG
|
jpayne@69
|
44 Meaning: Extra checks compiled in for debug mode.
|
jpayne@69
|
45 Used in: Py_SAFE_DOWNCAST
|
jpayne@69
|
46
|
jpayne@69
|
47 **************************************************************************/
|
jpayne@69
|
48
|
jpayne@69
|
49 /* typedefs for some C9X-defined synonyms for integral types.
|
jpayne@69
|
50 *
|
jpayne@69
|
51 * The names in Python are exactly the same as the C9X names, except with a
|
jpayne@69
|
52 * Py_ prefix. Until C9X is universally implemented, this is the only way
|
jpayne@69
|
53 * to ensure that Python gets reliable names that don't conflict with names
|
jpayne@69
|
54 * in non-Python code that are playing their own tricks to define the C9X
|
jpayne@69
|
55 * names.
|
jpayne@69
|
56 *
|
jpayne@69
|
57 * NOTE: don't go nuts here! Python has no use for *most* of the C9X
|
jpayne@69
|
58 * integral synonyms. Only define the ones we actually need.
|
jpayne@69
|
59 */
|
jpayne@69
|
60
|
jpayne@69
|
61 /* long long is required. Ensure HAVE_LONG_LONG is defined for compatibility. */
|
jpayne@69
|
62 #ifndef HAVE_LONG_LONG
|
jpayne@69
|
63 #define HAVE_LONG_LONG 1
|
jpayne@69
|
64 #endif
|
jpayne@69
|
65 #ifndef PY_LONG_LONG
|
jpayne@69
|
66 #define PY_LONG_LONG long long
|
jpayne@69
|
67 /* If LLONG_MAX is defined in limits.h, use that. */
|
jpayne@69
|
68 #define PY_LLONG_MIN LLONG_MIN
|
jpayne@69
|
69 #define PY_LLONG_MAX LLONG_MAX
|
jpayne@69
|
70 #define PY_ULLONG_MAX ULLONG_MAX
|
jpayne@69
|
71 #endif
|
jpayne@69
|
72
|
jpayne@69
|
73 #define PY_UINT32_T uint32_t
|
jpayne@69
|
74 #define PY_UINT64_T uint64_t
|
jpayne@69
|
75
|
jpayne@69
|
76 /* Signed variants of the above */
|
jpayne@69
|
77 #define PY_INT32_T int32_t
|
jpayne@69
|
78 #define PY_INT64_T int64_t
|
jpayne@69
|
79
|
jpayne@69
|
80 /* If PYLONG_BITS_IN_DIGIT is not defined then we'll use 30-bit digits if all
|
jpayne@69
|
81 the necessary integer types are available, and we're on a 64-bit platform
|
jpayne@69
|
82 (as determined by SIZEOF_VOID_P); otherwise we use 15-bit digits. */
|
jpayne@69
|
83
|
jpayne@69
|
84 #ifndef PYLONG_BITS_IN_DIGIT
|
jpayne@69
|
85 #if SIZEOF_VOID_P >= 8
|
jpayne@69
|
86 #define PYLONG_BITS_IN_DIGIT 30
|
jpayne@69
|
87 #else
|
jpayne@69
|
88 #define PYLONG_BITS_IN_DIGIT 15
|
jpayne@69
|
89 #endif
|
jpayne@69
|
90 #endif
|
jpayne@69
|
91
|
jpayne@69
|
92 /* uintptr_t is the C9X name for an unsigned integral type such that a
|
jpayne@69
|
93 * legitimate void* can be cast to uintptr_t and then back to void* again
|
jpayne@69
|
94 * without loss of information. Similarly for intptr_t, wrt a signed
|
jpayne@69
|
95 * integral type.
|
jpayne@69
|
96 */
|
jpayne@69
|
97 typedef uintptr_t Py_uintptr_t;
|
jpayne@69
|
98 typedef intptr_t Py_intptr_t;
|
jpayne@69
|
99
|
jpayne@69
|
100 /* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==
|
jpayne@69
|
101 * sizeof(size_t). C99 doesn't define such a thing directly (size_t is an
|
jpayne@69
|
102 * unsigned integral type). See PEP 353 for details.
|
jpayne@69
|
103 */
|
jpayne@69
|
104 #ifdef HAVE_SSIZE_T
|
jpayne@69
|
105 typedef ssize_t Py_ssize_t;
|
jpayne@69
|
106 #elif SIZEOF_VOID_P == SIZEOF_SIZE_T
|
jpayne@69
|
107 typedef Py_intptr_t Py_ssize_t;
|
jpayne@69
|
108 #else
|
jpayne@69
|
109 # error "Python needs a typedef for Py_ssize_t in pyport.h."
|
jpayne@69
|
110 #endif
|
jpayne@69
|
111
|
jpayne@69
|
112 /* Py_hash_t is the same size as a pointer. */
|
jpayne@69
|
113 #define SIZEOF_PY_HASH_T SIZEOF_SIZE_T
|
jpayne@69
|
114 typedef Py_ssize_t Py_hash_t;
|
jpayne@69
|
115 /* Py_uhash_t is the unsigned equivalent needed to calculate numeric hash. */
|
jpayne@69
|
116 #define SIZEOF_PY_UHASH_T SIZEOF_SIZE_T
|
jpayne@69
|
117 typedef size_t Py_uhash_t;
|
jpayne@69
|
118
|
jpayne@69
|
119 /* Only used for compatibility with code that may not be PY_SSIZE_T_CLEAN. */
|
jpayne@69
|
120 #ifdef PY_SSIZE_T_CLEAN
|
jpayne@69
|
121 typedef Py_ssize_t Py_ssize_clean_t;
|
jpayne@69
|
122 #else
|
jpayne@69
|
123 typedef int Py_ssize_clean_t;
|
jpayne@69
|
124 #endif
|
jpayne@69
|
125
|
jpayne@69
|
126 /* Largest possible value of size_t. */
|
jpayne@69
|
127 #define PY_SIZE_MAX SIZE_MAX
|
jpayne@69
|
128
|
jpayne@69
|
129 /* Largest positive value of type Py_ssize_t. */
|
jpayne@69
|
130 #define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
|
jpayne@69
|
131 /* Smallest negative value of type Py_ssize_t. */
|
jpayne@69
|
132 #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
|
jpayne@69
|
133
|
jpayne@69
|
134 /* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf
|
jpayne@69
|
135 * format to convert an argument with the width of a size_t or Py_ssize_t.
|
jpayne@69
|
136 * C99 introduced "z" for this purpose, but not all platforms support that;
|
jpayne@69
|
137 * e.g., MS compilers use "I" instead.
|
jpayne@69
|
138 *
|
jpayne@69
|
139 * These "high level" Python format functions interpret "z" correctly on
|
jpayne@69
|
140 * all platforms (Python interprets the format string itself, and does whatever
|
jpayne@69
|
141 * the platform C requires to convert a size_t/Py_ssize_t argument):
|
jpayne@69
|
142 *
|
jpayne@69
|
143 * PyBytes_FromFormat
|
jpayne@69
|
144 * PyErr_Format
|
jpayne@69
|
145 * PyBytes_FromFormatV
|
jpayne@69
|
146 * PyUnicode_FromFormatV
|
jpayne@69
|
147 *
|
jpayne@69
|
148 * Lower-level uses require that you interpolate the correct format modifier
|
jpayne@69
|
149 * yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for
|
jpayne@69
|
150 * example,
|
jpayne@69
|
151 *
|
jpayne@69
|
152 * Py_ssize_t index;
|
jpayne@69
|
153 * fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index);
|
jpayne@69
|
154 *
|
jpayne@69
|
155 * That will expand to %ld, or %Id, or to something else correct for a
|
jpayne@69
|
156 * Py_ssize_t on the platform.
|
jpayne@69
|
157 */
|
jpayne@69
|
158 #ifndef PY_FORMAT_SIZE_T
|
jpayne@69
|
159 # if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__)
|
jpayne@69
|
160 # define PY_FORMAT_SIZE_T ""
|
jpayne@69
|
161 # elif SIZEOF_SIZE_T == SIZEOF_LONG
|
jpayne@69
|
162 # define PY_FORMAT_SIZE_T "l"
|
jpayne@69
|
163 # elif defined(MS_WINDOWS)
|
jpayne@69
|
164 # define PY_FORMAT_SIZE_T "I"
|
jpayne@69
|
165 # else
|
jpayne@69
|
166 # error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T"
|
jpayne@69
|
167 # endif
|
jpayne@69
|
168 #endif
|
jpayne@69
|
169
|
jpayne@69
|
170 /* Py_LOCAL can be used instead of static to get the fastest possible calling
|
jpayne@69
|
171 * convention for functions that are local to a given module.
|
jpayne@69
|
172 *
|
jpayne@69
|
173 * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining,
|
jpayne@69
|
174 * for platforms that support that.
|
jpayne@69
|
175 *
|
jpayne@69
|
176 * If PY_LOCAL_AGGRESSIVE is defined before python.h is included, more
|
jpayne@69
|
177 * "aggressive" inlining/optimization is enabled for the entire module. This
|
jpayne@69
|
178 * may lead to code bloat, and may slow things down for those reasons. It may
|
jpayne@69
|
179 * also lead to errors, if the code relies on pointer aliasing. Use with
|
jpayne@69
|
180 * care.
|
jpayne@69
|
181 *
|
jpayne@69
|
182 * NOTE: You can only use this for functions that are entirely local to a
|
jpayne@69
|
183 * module; functions that are exported via method tables, callbacks, etc,
|
jpayne@69
|
184 * should keep using static.
|
jpayne@69
|
185 */
|
jpayne@69
|
186
|
jpayne@69
|
187 #if defined(_MSC_VER)
|
jpayne@69
|
188 # if defined(PY_LOCAL_AGGRESSIVE)
|
jpayne@69
|
189 /* enable more aggressive optimization for visual studio */
|
jpayne@69
|
190 # pragma optimize("agtw", on)
|
jpayne@69
|
191 #endif
|
jpayne@69
|
192 /* ignore warnings if the compiler decides not to inline a function */
|
jpayne@69
|
193 # pragma warning(disable: 4710)
|
jpayne@69
|
194 /* fastest possible local call under MSVC */
|
jpayne@69
|
195 # define Py_LOCAL(type) static type __fastcall
|
jpayne@69
|
196 # define Py_LOCAL_INLINE(type) static __inline type __fastcall
|
jpayne@69
|
197 #else
|
jpayne@69
|
198 # define Py_LOCAL(type) static type
|
jpayne@69
|
199 # define Py_LOCAL_INLINE(type) static inline type
|
jpayne@69
|
200 #endif
|
jpayne@69
|
201
|
jpayne@69
|
202 /* Py_MEMCPY is kept for backwards compatibility,
|
jpayne@69
|
203 * see https://bugs.python.org/issue28126 */
|
jpayne@69
|
204 #define Py_MEMCPY memcpy
|
jpayne@69
|
205
|
jpayne@69
|
206 #include <stdlib.h>
|
jpayne@69
|
207
|
jpayne@69
|
208 #ifdef HAVE_IEEEFP_H
|
jpayne@69
|
209 #include <ieeefp.h> /* needed for 'finite' declaration on some platforms */
|
jpayne@69
|
210 #endif
|
jpayne@69
|
211
|
jpayne@69
|
212 #include <math.h> /* Moved here from the math section, before extern "C" */
|
jpayne@69
|
213
|
jpayne@69
|
214 /********************************************
|
jpayne@69
|
215 * WRAPPER FOR <time.h> and/or <sys/time.h> *
|
jpayne@69
|
216 ********************************************/
|
jpayne@69
|
217
|
jpayne@69
|
218 #ifdef TIME_WITH_SYS_TIME
|
jpayne@69
|
219 #include <sys/time.h>
|
jpayne@69
|
220 #include <time.h>
|
jpayne@69
|
221 #else /* !TIME_WITH_SYS_TIME */
|
jpayne@69
|
222 #ifdef HAVE_SYS_TIME_H
|
jpayne@69
|
223 #include <sys/time.h>
|
jpayne@69
|
224 #else /* !HAVE_SYS_TIME_H */
|
jpayne@69
|
225 #include <time.h>
|
jpayne@69
|
226 #endif /* !HAVE_SYS_TIME_H */
|
jpayne@69
|
227 #endif /* !TIME_WITH_SYS_TIME */
|
jpayne@69
|
228
|
jpayne@69
|
229
|
jpayne@69
|
230 /******************************
|
jpayne@69
|
231 * WRAPPER FOR <sys/select.h> *
|
jpayne@69
|
232 ******************************/
|
jpayne@69
|
233
|
jpayne@69
|
234 /* NB caller must include <sys/types.h> */
|
jpayne@69
|
235
|
jpayne@69
|
236 #ifdef HAVE_SYS_SELECT_H
|
jpayne@69
|
237 #include <sys/select.h>
|
jpayne@69
|
238 #endif /* !HAVE_SYS_SELECT_H */
|
jpayne@69
|
239
|
jpayne@69
|
240 /*******************************
|
jpayne@69
|
241 * stat() and fstat() fiddling *
|
jpayne@69
|
242 *******************************/
|
jpayne@69
|
243
|
jpayne@69
|
244 #ifdef HAVE_SYS_STAT_H
|
jpayne@69
|
245 #include <sys/stat.h>
|
jpayne@69
|
246 #elif defined(HAVE_STAT_H)
|
jpayne@69
|
247 #include <stat.h>
|
jpayne@69
|
248 #endif
|
jpayne@69
|
249
|
jpayne@69
|
250 #ifndef S_IFMT
|
jpayne@69
|
251 /* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */
|
jpayne@69
|
252 #define S_IFMT 0170000
|
jpayne@69
|
253 #endif
|
jpayne@69
|
254
|
jpayne@69
|
255 #ifndef S_IFLNK
|
jpayne@69
|
256 /* Windows doesn't define S_IFLNK but posixmodule.c maps
|
jpayne@69
|
257 * IO_REPARSE_TAG_SYMLINK to S_IFLNK */
|
jpayne@69
|
258 # define S_IFLNK 0120000
|
jpayne@69
|
259 #endif
|
jpayne@69
|
260
|
jpayne@69
|
261 #ifndef S_ISREG
|
jpayne@69
|
262 #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
|
jpayne@69
|
263 #endif
|
jpayne@69
|
264
|
jpayne@69
|
265 #ifndef S_ISDIR
|
jpayne@69
|
266 #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
|
jpayne@69
|
267 #endif
|
jpayne@69
|
268
|
jpayne@69
|
269 #ifndef S_ISCHR
|
jpayne@69
|
270 #define S_ISCHR(x) (((x) & S_IFMT) == S_IFCHR)
|
jpayne@69
|
271 #endif
|
jpayne@69
|
272
|
jpayne@69
|
273 #ifdef __cplusplus
|
jpayne@69
|
274 /* Move this down here since some C++ #include's don't like to be included
|
jpayne@69
|
275 inside an extern "C" */
|
jpayne@69
|
276 extern "C" {
|
jpayne@69
|
277 #endif
|
jpayne@69
|
278
|
jpayne@69
|
279
|
jpayne@69
|
280 /* Py_ARITHMETIC_RIGHT_SHIFT
|
jpayne@69
|
281 * C doesn't define whether a right-shift of a signed integer sign-extends
|
jpayne@69
|
282 * or zero-fills. Here a macro to force sign extension:
|
jpayne@69
|
283 * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
|
jpayne@69
|
284 * Return I >> J, forcing sign extension. Arithmetically, return the
|
jpayne@69
|
285 * floor of I/2**J.
|
jpayne@69
|
286 * Requirements:
|
jpayne@69
|
287 * I should have signed integer type. In the terminology of C99, this can
|
jpayne@69
|
288 * be either one of the five standard signed integer types (signed char,
|
jpayne@69
|
289 * short, int, long, long long) or an extended signed integer type.
|
jpayne@69
|
290 * J is an integer >= 0 and strictly less than the number of bits in the
|
jpayne@69
|
291 * type of I (because C doesn't define what happens for J outside that
|
jpayne@69
|
292 * range either).
|
jpayne@69
|
293 * TYPE used to specify the type of I, but is now ignored. It's been left
|
jpayne@69
|
294 * in for backwards compatibility with versions <= 2.6 or 3.0.
|
jpayne@69
|
295 * Caution:
|
jpayne@69
|
296 * I may be evaluated more than once.
|
jpayne@69
|
297 */
|
jpayne@69
|
298 #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
|
jpayne@69
|
299 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
|
jpayne@69
|
300 ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))
|
jpayne@69
|
301 #else
|
jpayne@69
|
302 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
|
jpayne@69
|
303 #endif
|
jpayne@69
|
304
|
jpayne@69
|
305 /* Py_FORCE_EXPANSION(X)
|
jpayne@69
|
306 * "Simply" returns its argument. However, macro expansions within the
|
jpayne@69
|
307 * argument are evaluated. This unfortunate trickery is needed to get
|
jpayne@69
|
308 * token-pasting to work as desired in some cases.
|
jpayne@69
|
309 */
|
jpayne@69
|
310 #define Py_FORCE_EXPANSION(X) X
|
jpayne@69
|
311
|
jpayne@69
|
312 /* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW)
|
jpayne@69
|
313 * Cast VALUE to type NARROW from type WIDE. In Py_DEBUG mode, this
|
jpayne@69
|
314 * assert-fails if any information is lost.
|
jpayne@69
|
315 * Caution:
|
jpayne@69
|
316 * VALUE may be evaluated more than once.
|
jpayne@69
|
317 */
|
jpayne@69
|
318 #ifdef Py_DEBUG
|
jpayne@69
|
319 #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
|
jpayne@69
|
320 (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE))
|
jpayne@69
|
321 #else
|
jpayne@69
|
322 #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
|
jpayne@69
|
323 #endif
|
jpayne@69
|
324
|
jpayne@69
|
325 /* Py_SET_ERRNO_ON_MATH_ERROR(x)
|
jpayne@69
|
326 * If a libm function did not set errno, but it looks like the result
|
jpayne@69
|
327 * overflowed or not-a-number, set errno to ERANGE or EDOM. Set errno
|
jpayne@69
|
328 * to 0 before calling a libm function, and invoke this macro after,
|
jpayne@69
|
329 * passing the function result.
|
jpayne@69
|
330 * Caution:
|
jpayne@69
|
331 * This isn't reliable. See Py_OVERFLOWED comments.
|
jpayne@69
|
332 * X is evaluated more than once.
|
jpayne@69
|
333 */
|
jpayne@69
|
334 #if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64))
|
jpayne@69
|
335 #define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM;
|
jpayne@69
|
336 #else
|
jpayne@69
|
337 #define _Py_SET_EDOM_FOR_NAN(X) ;
|
jpayne@69
|
338 #endif
|
jpayne@69
|
339 #define Py_SET_ERRNO_ON_MATH_ERROR(X) \
|
jpayne@69
|
340 do { \
|
jpayne@69
|
341 if (errno == 0) { \
|
jpayne@69
|
342 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
|
jpayne@69
|
343 errno = ERANGE; \
|
jpayne@69
|
344 else _Py_SET_EDOM_FOR_NAN(X) \
|
jpayne@69
|
345 } \
|
jpayne@69
|
346 } while(0)
|
jpayne@69
|
347
|
jpayne@69
|
348 /* Py_SET_ERANGE_IF_OVERFLOW(x)
|
jpayne@69
|
349 * An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility.
|
jpayne@69
|
350 */
|
jpayne@69
|
351 #define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X)
|
jpayne@69
|
352
|
jpayne@69
|
353 /* Py_ADJUST_ERANGE1(x)
|
jpayne@69
|
354 * Py_ADJUST_ERANGE2(x, y)
|
jpayne@69
|
355 * Set errno to 0 before calling a libm function, and invoke one of these
|
jpayne@69
|
356 * macros after, passing the function result(s) (Py_ADJUST_ERANGE2 is useful
|
jpayne@69
|
357 * for functions returning complex results). This makes two kinds of
|
jpayne@69
|
358 * adjustments to errno: (A) If it looks like the platform libm set
|
jpayne@69
|
359 * errno=ERANGE due to underflow, clear errno. (B) If it looks like the
|
jpayne@69
|
360 * platform libm overflowed but didn't set errno, force errno to ERANGE. In
|
jpayne@69
|
361 * effect, we're trying to force a useful implementation of C89 errno
|
jpayne@69
|
362 * behavior.
|
jpayne@69
|
363 * Caution:
|
jpayne@69
|
364 * This isn't reliable. See Py_OVERFLOWED comments.
|
jpayne@69
|
365 * X and Y may be evaluated more than once.
|
jpayne@69
|
366 */
|
jpayne@69
|
367 #define Py_ADJUST_ERANGE1(X) \
|
jpayne@69
|
368 do { \
|
jpayne@69
|
369 if (errno == 0) { \
|
jpayne@69
|
370 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
|
jpayne@69
|
371 errno = ERANGE; \
|
jpayne@69
|
372 } \
|
jpayne@69
|
373 else if (errno == ERANGE && (X) == 0.0) \
|
jpayne@69
|
374 errno = 0; \
|
jpayne@69
|
375 } while(0)
|
jpayne@69
|
376
|
jpayne@69
|
377 #define Py_ADJUST_ERANGE2(X, Y) \
|
jpayne@69
|
378 do { \
|
jpayne@69
|
379 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL || \
|
jpayne@69
|
380 (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) { \
|
jpayne@69
|
381 if (errno == 0) \
|
jpayne@69
|
382 errno = ERANGE; \
|
jpayne@69
|
383 } \
|
jpayne@69
|
384 else if (errno == ERANGE) \
|
jpayne@69
|
385 errno = 0; \
|
jpayne@69
|
386 } while(0)
|
jpayne@69
|
387
|
jpayne@69
|
388 /* The functions _Py_dg_strtod and _Py_dg_dtoa in Python/dtoa.c (which are
|
jpayne@69
|
389 * required to support the short float repr introduced in Python 3.1) require
|
jpayne@69
|
390 * that the floating-point unit that's being used for arithmetic operations
|
jpayne@69
|
391 * on C doubles is set to use 53-bit precision. It also requires that the
|
jpayne@69
|
392 * FPU rounding mode is round-half-to-even, but that's less often an issue.
|
jpayne@69
|
393 *
|
jpayne@69
|
394 * If your FPU isn't already set to 53-bit precision/round-half-to-even, and
|
jpayne@69
|
395 * you want to make use of _Py_dg_strtod and _Py_dg_dtoa, then you should
|
jpayne@69
|
396 *
|
jpayne@69
|
397 * #define HAVE_PY_SET_53BIT_PRECISION 1
|
jpayne@69
|
398 *
|
jpayne@69
|
399 * and also give appropriate definitions for the following three macros:
|
jpayne@69
|
400 *
|
jpayne@69
|
401 * _PY_SET_53BIT_PRECISION_START : store original FPU settings, and
|
jpayne@69
|
402 * set FPU to 53-bit precision/round-half-to-even
|
jpayne@69
|
403 * _PY_SET_53BIT_PRECISION_END : restore original FPU settings
|
jpayne@69
|
404 * _PY_SET_53BIT_PRECISION_HEADER : any variable declarations needed to
|
jpayne@69
|
405 * use the two macros above.
|
jpayne@69
|
406 *
|
jpayne@69
|
407 * The macros are designed to be used within a single C function: see
|
jpayne@69
|
408 * Python/pystrtod.c for an example of their use.
|
jpayne@69
|
409 */
|
jpayne@69
|
410
|
jpayne@69
|
411 /* get and set x87 control word for gcc/x86 */
|
jpayne@69
|
412 #ifdef HAVE_GCC_ASM_FOR_X87
|
jpayne@69
|
413 #define HAVE_PY_SET_53BIT_PRECISION 1
|
jpayne@69
|
414 /* _Py_get/set_387controlword functions are defined in Python/pymath.c */
|
jpayne@69
|
415 #define _Py_SET_53BIT_PRECISION_HEADER \
|
jpayne@69
|
416 unsigned short old_387controlword, new_387controlword
|
jpayne@69
|
417 #define _Py_SET_53BIT_PRECISION_START \
|
jpayne@69
|
418 do { \
|
jpayne@69
|
419 old_387controlword = _Py_get_387controlword(); \
|
jpayne@69
|
420 new_387controlword = (old_387controlword & ~0x0f00) | 0x0200; \
|
jpayne@69
|
421 if (new_387controlword != old_387controlword) \
|
jpayne@69
|
422 _Py_set_387controlword(new_387controlword); \
|
jpayne@69
|
423 } while (0)
|
jpayne@69
|
424 #define _Py_SET_53BIT_PRECISION_END \
|
jpayne@69
|
425 if (new_387controlword != old_387controlword) \
|
jpayne@69
|
426 _Py_set_387controlword(old_387controlword)
|
jpayne@69
|
427 #endif
|
jpayne@69
|
428
|
jpayne@69
|
429 /* get and set x87 control word for VisualStudio/x86 */
|
jpayne@69
|
430 #if defined(_MSC_VER) && !defined(_WIN64) && !defined(_M_ARM) /* x87 not supported in 64-bit or ARM */
|
jpayne@69
|
431 #define HAVE_PY_SET_53BIT_PRECISION 1
|
jpayne@69
|
432 #define _Py_SET_53BIT_PRECISION_HEADER \
|
jpayne@69
|
433 unsigned int old_387controlword, new_387controlword, out_387controlword
|
jpayne@69
|
434 /* We use the __control87_2 function to set only the x87 control word.
|
jpayne@69
|
435 The SSE control word is unaffected. */
|
jpayne@69
|
436 #define _Py_SET_53BIT_PRECISION_START \
|
jpayne@69
|
437 do { \
|
jpayne@69
|
438 __control87_2(0, 0, &old_387controlword, NULL); \
|
jpayne@69
|
439 new_387controlword = \
|
jpayne@69
|
440 (old_387controlword & ~(_MCW_PC | _MCW_RC)) | (_PC_53 | _RC_NEAR); \
|
jpayne@69
|
441 if (new_387controlword != old_387controlword) \
|
jpayne@69
|
442 __control87_2(new_387controlword, _MCW_PC | _MCW_RC, \
|
jpayne@69
|
443 &out_387controlword, NULL); \
|
jpayne@69
|
444 } while (0)
|
jpayne@69
|
445 #define _Py_SET_53BIT_PRECISION_END \
|
jpayne@69
|
446 do { \
|
jpayne@69
|
447 if (new_387controlword != old_387controlword) \
|
jpayne@69
|
448 __control87_2(old_387controlword, _MCW_PC | _MCW_RC, \
|
jpayne@69
|
449 &out_387controlword, NULL); \
|
jpayne@69
|
450 } while (0)
|
jpayne@69
|
451 #endif
|
jpayne@69
|
452
|
jpayne@69
|
453 #ifdef HAVE_GCC_ASM_FOR_MC68881
|
jpayne@69
|
454 #define HAVE_PY_SET_53BIT_PRECISION 1
|
jpayne@69
|
455 #define _Py_SET_53BIT_PRECISION_HEADER \
|
jpayne@69
|
456 unsigned int old_fpcr, new_fpcr
|
jpayne@69
|
457 #define _Py_SET_53BIT_PRECISION_START \
|
jpayne@69
|
458 do { \
|
jpayne@69
|
459 __asm__ ("fmove.l %%fpcr,%0" : "=g" (old_fpcr)); \
|
jpayne@69
|
460 /* Set double precision / round to nearest. */ \
|
jpayne@69
|
461 new_fpcr = (old_fpcr & ~0xf0) | 0x80; \
|
jpayne@69
|
462 if (new_fpcr != old_fpcr) \
|
jpayne@69
|
463 __asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (new_fpcr)); \
|
jpayne@69
|
464 } while (0)
|
jpayne@69
|
465 #define _Py_SET_53BIT_PRECISION_END \
|
jpayne@69
|
466 do { \
|
jpayne@69
|
467 if (new_fpcr != old_fpcr) \
|
jpayne@69
|
468 __asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (old_fpcr)); \
|
jpayne@69
|
469 } while (0)
|
jpayne@69
|
470 #endif
|
jpayne@69
|
471
|
jpayne@69
|
472 /* default definitions are empty */
|
jpayne@69
|
473 #ifndef HAVE_PY_SET_53BIT_PRECISION
|
jpayne@69
|
474 #define _Py_SET_53BIT_PRECISION_HEADER
|
jpayne@69
|
475 #define _Py_SET_53BIT_PRECISION_START
|
jpayne@69
|
476 #define _Py_SET_53BIT_PRECISION_END
|
jpayne@69
|
477 #endif
|
jpayne@69
|
478
|
jpayne@69
|
479 /* If we can't guarantee 53-bit precision, don't use the code
|
jpayne@69
|
480 in Python/dtoa.c, but fall back to standard code. This
|
jpayne@69
|
481 means that repr of a float will be long (17 sig digits).
|
jpayne@69
|
482
|
jpayne@69
|
483 Realistically, there are two things that could go wrong:
|
jpayne@69
|
484
|
jpayne@69
|
485 (1) doubles aren't IEEE 754 doubles, or
|
jpayne@69
|
486 (2) we're on x86 with the rounding precision set to 64-bits
|
jpayne@69
|
487 (extended precision), and we don't know how to change
|
jpayne@69
|
488 the rounding precision.
|
jpayne@69
|
489 */
|
jpayne@69
|
490
|
jpayne@69
|
491 #if !defined(DOUBLE_IS_LITTLE_ENDIAN_IEEE754) && \
|
jpayne@69
|
492 !defined(DOUBLE_IS_BIG_ENDIAN_IEEE754) && \
|
jpayne@69
|
493 !defined(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754)
|
jpayne@69
|
494 #define PY_NO_SHORT_FLOAT_REPR
|
jpayne@69
|
495 #endif
|
jpayne@69
|
496
|
jpayne@69
|
497 /* double rounding is symptomatic of use of extended precision on x86. If
|
jpayne@69
|
498 we're seeing double rounding, and we don't have any mechanism available for
|
jpayne@69
|
499 changing the FPU rounding precision, then don't use Python/dtoa.c. */
|
jpayne@69
|
500 #if defined(X87_DOUBLE_ROUNDING) && !defined(HAVE_PY_SET_53BIT_PRECISION)
|
jpayne@69
|
501 #define PY_NO_SHORT_FLOAT_REPR
|
jpayne@69
|
502 #endif
|
jpayne@69
|
503
|
jpayne@69
|
504
|
jpayne@69
|
505 /* Py_DEPRECATED(version)
|
jpayne@69
|
506 * Declare a variable, type, or function deprecated.
|
jpayne@69
|
507 * The macro must be placed before the declaration.
|
jpayne@69
|
508 * Usage:
|
jpayne@69
|
509 * Py_DEPRECATED(3.3) extern int old_var;
|
jpayne@69
|
510 * Py_DEPRECATED(3.4) typedef int T1;
|
jpayne@69
|
511 * Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void);
|
jpayne@69
|
512 */
|
jpayne@69
|
513 #if defined(__GNUC__) \
|
jpayne@69
|
514 && ((__GNUC__ >= 4) || (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
|
jpayne@69
|
515 #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
|
jpayne@69
|
516 #elif defined(_MSC_VER)
|
jpayne@69
|
517 #define Py_DEPRECATED(VERSION) __declspec(deprecated( \
|
jpayne@69
|
518 "deprecated in " #VERSION))
|
jpayne@69
|
519 #else
|
jpayne@69
|
520 #define Py_DEPRECATED(VERSION_UNUSED)
|
jpayne@69
|
521 #endif
|
jpayne@69
|
522
|
jpayne@69
|
523
|
jpayne@69
|
524 /* _Py_HOT_FUNCTION
|
jpayne@69
|
525 * The hot attribute on a function is used to inform the compiler that the
|
jpayne@69
|
526 * function is a hot spot of the compiled program. The function is optimized
|
jpayne@69
|
527 * more aggressively and on many target it is placed into special subsection of
|
jpayne@69
|
528 * the text section so all hot functions appears close together improving
|
jpayne@69
|
529 * locality.
|
jpayne@69
|
530 *
|
jpayne@69
|
531 * Usage:
|
jpayne@69
|
532 * int _Py_HOT_FUNCTION x(void) { return 3; }
|
jpayne@69
|
533 *
|
jpayne@69
|
534 * Issue #28618: This attribute must not be abused, otherwise it can have a
|
jpayne@69
|
535 * negative effect on performance. Only the functions were Python spend most of
|
jpayne@69
|
536 * its time must use it. Use a profiler when running performance benchmark
|
jpayne@69
|
537 * suite to find these functions.
|
jpayne@69
|
538 */
|
jpayne@69
|
539 #if defined(__GNUC__) \
|
jpayne@69
|
540 && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))
|
jpayne@69
|
541 #define _Py_HOT_FUNCTION __attribute__((hot))
|
jpayne@69
|
542 #else
|
jpayne@69
|
543 #define _Py_HOT_FUNCTION
|
jpayne@69
|
544 #endif
|
jpayne@69
|
545
|
jpayne@69
|
546 /* _Py_NO_INLINE
|
jpayne@69
|
547 * Disable inlining on a function. For example, it helps to reduce the C stack
|
jpayne@69
|
548 * consumption.
|
jpayne@69
|
549 *
|
jpayne@69
|
550 * Usage:
|
jpayne@69
|
551 * int _Py_NO_INLINE x(void) { return 3; }
|
jpayne@69
|
552 */
|
jpayne@69
|
553 #if defined(_MSC_VER)
|
jpayne@69
|
554 # define _Py_NO_INLINE __declspec(noinline)
|
jpayne@69
|
555 #elif defined(__GNUC__) || defined(__clang__)
|
jpayne@69
|
556 # define _Py_NO_INLINE __attribute__ ((noinline))
|
jpayne@69
|
557 #else
|
jpayne@69
|
558 # define _Py_NO_INLINE
|
jpayne@69
|
559 #endif
|
jpayne@69
|
560
|
jpayne@69
|
561 /**************************************************************************
|
jpayne@69
|
562 Prototypes that are missing from the standard include files on some systems
|
jpayne@69
|
563 (and possibly only some versions of such systems.)
|
jpayne@69
|
564
|
jpayne@69
|
565 Please be conservative with adding new ones, document them and enclose them
|
jpayne@69
|
566 in platform-specific #ifdefs.
|
jpayne@69
|
567 **************************************************************************/
|
jpayne@69
|
568
|
jpayne@69
|
569 #ifdef SOLARIS
|
jpayne@69
|
570 /* Unchecked */
|
jpayne@69
|
571 extern int gethostname(char *, int);
|
jpayne@69
|
572 #endif
|
jpayne@69
|
573
|
jpayne@69
|
574 #ifdef HAVE__GETPTY
|
jpayne@69
|
575 #include <sys/types.h> /* we need to import mode_t */
|
jpayne@69
|
576 extern char * _getpty(int *, int, mode_t, int);
|
jpayne@69
|
577 #endif
|
jpayne@69
|
578
|
jpayne@69
|
579 /* On QNX 6, struct termio must be declared by including sys/termio.h
|
jpayne@69
|
580 if TCGETA, TCSETA, TCSETAW, or TCSETAF are used. sys/termio.h must
|
jpayne@69
|
581 be included before termios.h or it will generate an error. */
|
jpayne@69
|
582 #if defined(HAVE_SYS_TERMIO_H) && !defined(__hpux)
|
jpayne@69
|
583 #include <sys/termio.h>
|
jpayne@69
|
584 #endif
|
jpayne@69
|
585
|
jpayne@69
|
586
|
jpayne@69
|
587 /* On 4.4BSD-descendants, ctype functions serves the whole range of
|
jpayne@69
|
588 * wchar_t character set rather than single byte code points only.
|
jpayne@69
|
589 * This characteristic can break some operations of string object
|
jpayne@69
|
590 * including str.upper() and str.split() on UTF-8 locales. This
|
jpayne@69
|
591 * workaround was provided by Tim Robbins of FreeBSD project.
|
jpayne@69
|
592 */
|
jpayne@69
|
593
|
jpayne@69
|
594 #if defined(__APPLE__)
|
jpayne@69
|
595 # define _PY_PORT_CTYPE_UTF8_ISSUE
|
jpayne@69
|
596 #endif
|
jpayne@69
|
597
|
jpayne@69
|
598 #ifdef _PY_PORT_CTYPE_UTF8_ISSUE
|
jpayne@69
|
599 #ifndef __cplusplus
|
jpayne@69
|
600 /* The workaround below is unsafe in C++ because
|
jpayne@69
|
601 * the <locale> defines these symbols as real functions,
|
jpayne@69
|
602 * with a slightly different signature.
|
jpayne@69
|
603 * See issue #10910
|
jpayne@69
|
604 */
|
jpayne@69
|
605 #include <ctype.h>
|
jpayne@69
|
606 #include <wctype.h>
|
jpayne@69
|
607 #undef isalnum
|
jpayne@69
|
608 #define isalnum(c) iswalnum(btowc(c))
|
jpayne@69
|
609 #undef isalpha
|
jpayne@69
|
610 #define isalpha(c) iswalpha(btowc(c))
|
jpayne@69
|
611 #undef islower
|
jpayne@69
|
612 #define islower(c) iswlower(btowc(c))
|
jpayne@69
|
613 #undef isspace
|
jpayne@69
|
614 #define isspace(c) iswspace(btowc(c))
|
jpayne@69
|
615 #undef isupper
|
jpayne@69
|
616 #define isupper(c) iswupper(btowc(c))
|
jpayne@69
|
617 #undef tolower
|
jpayne@69
|
618 #define tolower(c) towlower(btowc(c))
|
jpayne@69
|
619 #undef toupper
|
jpayne@69
|
620 #define toupper(c) towupper(btowc(c))
|
jpayne@69
|
621 #endif
|
jpayne@69
|
622 #endif
|
jpayne@69
|
623
|
jpayne@69
|
624
|
jpayne@69
|
625 /* Declarations for symbol visibility.
|
jpayne@69
|
626
|
jpayne@69
|
627 PyAPI_FUNC(type): Declares a public Python API function and return type
|
jpayne@69
|
628 PyAPI_DATA(type): Declares public Python data and its type
|
jpayne@69
|
629 PyMODINIT_FUNC: A Python module init function. If these functions are
|
jpayne@69
|
630 inside the Python core, they are private to the core.
|
jpayne@69
|
631 If in an extension module, it may be declared with
|
jpayne@69
|
632 external linkage depending on the platform.
|
jpayne@69
|
633
|
jpayne@69
|
634 As a number of platforms support/require "__declspec(dllimport/dllexport)",
|
jpayne@69
|
635 we support a HAVE_DECLSPEC_DLL macro to save duplication.
|
jpayne@69
|
636 */
|
jpayne@69
|
637
|
jpayne@69
|
638 /*
|
jpayne@69
|
639 All windows ports, except cygwin, are handled in PC/pyconfig.h.
|
jpayne@69
|
640
|
jpayne@69
|
641 Cygwin is the only other autoconf platform requiring special
|
jpayne@69
|
642 linkage handling and it uses __declspec().
|
jpayne@69
|
643 */
|
jpayne@69
|
644 #if defined(__CYGWIN__)
|
jpayne@69
|
645 # define HAVE_DECLSPEC_DLL
|
jpayne@69
|
646 #endif
|
jpayne@69
|
647
|
jpayne@69
|
648 /* only get special linkage if built as shared or platform is Cygwin */
|
jpayne@69
|
649 #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
|
jpayne@69
|
650 # if defined(HAVE_DECLSPEC_DLL)
|
jpayne@69
|
651 # if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
jpayne@69
|
652 # define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
|
jpayne@69
|
653 # define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE
|
jpayne@69
|
654 /* module init functions inside the core need no external linkage */
|
jpayne@69
|
655 /* except for Cygwin to handle embedding */
|
jpayne@69
|
656 # if defined(__CYGWIN__)
|
jpayne@69
|
657 # define PyMODINIT_FUNC __declspec(dllexport) PyObject*
|
jpayne@69
|
658 # else /* __CYGWIN__ */
|
jpayne@69
|
659 # define PyMODINIT_FUNC PyObject*
|
jpayne@69
|
660 # endif /* __CYGWIN__ */
|
jpayne@69
|
661 # else /* Py_BUILD_CORE */
|
jpayne@69
|
662 /* Building an extension module, or an embedded situation */
|
jpayne@69
|
663 /* public Python functions and data are imported */
|
jpayne@69
|
664 /* Under Cygwin, auto-import functions to prevent compilation */
|
jpayne@69
|
665 /* failures similar to those described at the bottom of 4.1: */
|
jpayne@69
|
666 /* http://docs.python.org/extending/windows.html#a-cookbook-approach */
|
jpayne@69
|
667 # if !defined(__CYGWIN__)
|
jpayne@69
|
668 # define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
|
jpayne@69
|
669 # endif /* !__CYGWIN__ */
|
jpayne@69
|
670 # define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
|
jpayne@69
|
671 /* module init functions outside the core must be exported */
|
jpayne@69
|
672 # if defined(__cplusplus)
|
jpayne@69
|
673 # define PyMODINIT_FUNC extern "C" __declspec(dllexport) PyObject*
|
jpayne@69
|
674 # else /* __cplusplus */
|
jpayne@69
|
675 # define PyMODINIT_FUNC __declspec(dllexport) PyObject*
|
jpayne@69
|
676 # endif /* __cplusplus */
|
jpayne@69
|
677 # endif /* Py_BUILD_CORE */
|
jpayne@69
|
678 # endif /* HAVE_DECLSPEC_DLL */
|
jpayne@69
|
679 #endif /* Py_ENABLE_SHARED */
|
jpayne@69
|
680
|
jpayne@69
|
681 /* If no external linkage macros defined by now, create defaults */
|
jpayne@69
|
682 #ifndef PyAPI_FUNC
|
jpayne@69
|
683 # define PyAPI_FUNC(RTYPE) RTYPE
|
jpayne@69
|
684 #endif
|
jpayne@69
|
685 #ifndef PyAPI_DATA
|
jpayne@69
|
686 # define PyAPI_DATA(RTYPE) extern RTYPE
|
jpayne@69
|
687 #endif
|
jpayne@69
|
688 #ifndef PyMODINIT_FUNC
|
jpayne@69
|
689 # if defined(__cplusplus)
|
jpayne@69
|
690 # define PyMODINIT_FUNC extern "C" PyObject*
|
jpayne@69
|
691 # else /* __cplusplus */
|
jpayne@69
|
692 # define PyMODINIT_FUNC PyObject*
|
jpayne@69
|
693 # endif /* __cplusplus */
|
jpayne@69
|
694 #endif
|
jpayne@69
|
695
|
jpayne@69
|
696 /* limits.h constants that may be missing */
|
jpayne@69
|
697
|
jpayne@69
|
698 #ifndef INT_MAX
|
jpayne@69
|
699 #define INT_MAX 2147483647
|
jpayne@69
|
700 #endif
|
jpayne@69
|
701
|
jpayne@69
|
702 #ifndef LONG_MAX
|
jpayne@69
|
703 #if SIZEOF_LONG == 4
|
jpayne@69
|
704 #define LONG_MAX 0X7FFFFFFFL
|
jpayne@69
|
705 #elif SIZEOF_LONG == 8
|
jpayne@69
|
706 #define LONG_MAX 0X7FFFFFFFFFFFFFFFL
|
jpayne@69
|
707 #else
|
jpayne@69
|
708 #error "could not set LONG_MAX in pyport.h"
|
jpayne@69
|
709 #endif
|
jpayne@69
|
710 #endif
|
jpayne@69
|
711
|
jpayne@69
|
712 #ifndef LONG_MIN
|
jpayne@69
|
713 #define LONG_MIN (-LONG_MAX-1)
|
jpayne@69
|
714 #endif
|
jpayne@69
|
715
|
jpayne@69
|
716 #ifndef LONG_BIT
|
jpayne@69
|
717 #define LONG_BIT (8 * SIZEOF_LONG)
|
jpayne@69
|
718 #endif
|
jpayne@69
|
719
|
jpayne@69
|
720 #if LONG_BIT != 8 * SIZEOF_LONG
|
jpayne@69
|
721 /* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent
|
jpayne@69
|
722 * 32-bit platforms using gcc. We try to catch that here at compile-time
|
jpayne@69
|
723 * rather than waiting for integer multiplication to trigger bogus
|
jpayne@69
|
724 * overflows.
|
jpayne@69
|
725 */
|
jpayne@69
|
726 #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
|
jpayne@69
|
727 #endif
|
jpayne@69
|
728
|
jpayne@69
|
729 #ifdef __cplusplus
|
jpayne@69
|
730 }
|
jpayne@69
|
731 #endif
|
jpayne@69
|
732
|
jpayne@69
|
733 /*
|
jpayne@69
|
734 * Hide GCC attributes from compilers that don't support them.
|
jpayne@69
|
735 */
|
jpayne@69
|
736 #if (!defined(__GNUC__) || __GNUC__ < 2 || \
|
jpayne@69
|
737 (__GNUC__ == 2 && __GNUC_MINOR__ < 7) )
|
jpayne@69
|
738 #define Py_GCC_ATTRIBUTE(x)
|
jpayne@69
|
739 #else
|
jpayne@69
|
740 #define Py_GCC_ATTRIBUTE(x) __attribute__(x)
|
jpayne@69
|
741 #endif
|
jpayne@69
|
742
|
jpayne@69
|
743 /*
|
jpayne@69
|
744 * Specify alignment on compilers that support it.
|
jpayne@69
|
745 */
|
jpayne@69
|
746 #if defined(__GNUC__) && __GNUC__ >= 3
|
jpayne@69
|
747 #define Py_ALIGNED(x) __attribute__((aligned(x)))
|
jpayne@69
|
748 #else
|
jpayne@69
|
749 #define Py_ALIGNED(x)
|
jpayne@69
|
750 #endif
|
jpayne@69
|
751
|
jpayne@69
|
752 /* Eliminate end-of-loop code not reached warnings from SunPro C
|
jpayne@69
|
753 * when using do{...}while(0) macros
|
jpayne@69
|
754 */
|
jpayne@69
|
755 #ifdef __SUNPRO_C
|
jpayne@69
|
756 #pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)
|
jpayne@69
|
757 #endif
|
jpayne@69
|
758
|
jpayne@69
|
759 #ifndef Py_LL
|
jpayne@69
|
760 #define Py_LL(x) x##LL
|
jpayne@69
|
761 #endif
|
jpayne@69
|
762
|
jpayne@69
|
763 #ifndef Py_ULL
|
jpayne@69
|
764 #define Py_ULL(x) Py_LL(x##U)
|
jpayne@69
|
765 #endif
|
jpayne@69
|
766
|
jpayne@69
|
767 #define Py_VA_COPY va_copy
|
jpayne@69
|
768
|
jpayne@69
|
769 /*
|
jpayne@69
|
770 * Convenient macros to deal with endianness of the platform. WORDS_BIGENDIAN is
|
jpayne@69
|
771 * detected by configure and defined in pyconfig.h. The code in pyconfig.h
|
jpayne@69
|
772 * also takes care of Apple's universal builds.
|
jpayne@69
|
773 */
|
jpayne@69
|
774
|
jpayne@69
|
775 #ifdef WORDS_BIGENDIAN
|
jpayne@69
|
776 #define PY_BIG_ENDIAN 1
|
jpayne@69
|
777 #define PY_LITTLE_ENDIAN 0
|
jpayne@69
|
778 #else
|
jpayne@69
|
779 #define PY_BIG_ENDIAN 0
|
jpayne@69
|
780 #define PY_LITTLE_ENDIAN 1
|
jpayne@69
|
781 #endif
|
jpayne@69
|
782
|
jpayne@69
|
783 #ifdef Py_BUILD_CORE
|
jpayne@69
|
784 /*
|
jpayne@69
|
785 * Macros to protect CRT calls against instant termination when passed an
|
jpayne@69
|
786 * invalid parameter (issue23524).
|
jpayne@69
|
787 */
|
jpayne@69
|
788 #if defined _MSC_VER && _MSC_VER >= 1900
|
jpayne@69
|
789
|
jpayne@69
|
790 extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
|
jpayne@69
|
791 #define _Py_BEGIN_SUPPRESS_IPH { _invalid_parameter_handler _Py_old_handler = \
|
jpayne@69
|
792 _set_thread_local_invalid_parameter_handler(_Py_silent_invalid_parameter_handler);
|
jpayne@69
|
793 #define _Py_END_SUPPRESS_IPH _set_thread_local_invalid_parameter_handler(_Py_old_handler); }
|
jpayne@69
|
794
|
jpayne@69
|
795 #else
|
jpayne@69
|
796
|
jpayne@69
|
797 #define _Py_BEGIN_SUPPRESS_IPH
|
jpayne@69
|
798 #define _Py_END_SUPPRESS_IPH
|
jpayne@69
|
799
|
jpayne@69
|
800 #endif /* _MSC_VER >= 1900 */
|
jpayne@69
|
801 #endif /* Py_BUILD_CORE */
|
jpayne@69
|
802
|
jpayne@69
|
803 #ifdef __ANDROID__
|
jpayne@69
|
804 /* The Android langinfo.h header is not used. */
|
jpayne@69
|
805 # undef HAVE_LANGINFO_H
|
jpayne@69
|
806 # undef CODESET
|
jpayne@69
|
807 #endif
|
jpayne@69
|
808
|
jpayne@69
|
809 /* Maximum value of the Windows DWORD type */
|
jpayne@69
|
810 #define PY_DWORD_MAX 4294967295U
|
jpayne@69
|
811
|
jpayne@69
|
812 /* This macro used to tell whether Python was built with multithreading
|
jpayne@69
|
813 * enabled. Now multithreading is always enabled, but keep the macro
|
jpayne@69
|
814 * for compatibility.
|
jpayne@69
|
815 */
|
jpayne@69
|
816 #ifndef WITH_THREAD
|
jpayne@69
|
817 # define WITH_THREAD
|
jpayne@69
|
818 #endif
|
jpayne@69
|
819
|
jpayne@69
|
820 /* Check that ALT_SOABI is consistent with Py_TRACE_REFS:
|
jpayne@69
|
821 ./configure --with-trace-refs should must be used to define Py_TRACE_REFS */
|
jpayne@69
|
822 #if defined(ALT_SOABI) && defined(Py_TRACE_REFS)
|
jpayne@69
|
823 # error "Py_TRACE_REFS ABI is not compatible with release and debug ABI"
|
jpayne@69
|
824 #endif
|
jpayne@69
|
825
|
jpayne@69
|
826 #if defined(__ANDROID__) || defined(__VXWORKS__)
|
jpayne@69
|
827 /* Ignore the locale encoding: force UTF-8 */
|
jpayne@69
|
828 # define _Py_FORCE_UTF8_LOCALE
|
jpayne@69
|
829 #endif
|
jpayne@69
|
830
|
jpayne@69
|
831 #if defined(_Py_FORCE_UTF8_LOCALE) || defined(__APPLE__)
|
jpayne@69
|
832 /* Use UTF-8 as filesystem encoding */
|
jpayne@69
|
833 # define _Py_FORCE_UTF8_FS_ENCODING
|
jpayne@69
|
834 #endif
|
jpayne@69
|
835
|
jpayne@69
|
836 /* Mark a function which cannot return. Example:
|
jpayne@69
|
837
|
jpayne@69
|
838 PyAPI_FUNC(void) _Py_NO_RETURN PyThread_exit_thread(void); */
|
jpayne@69
|
839 #if defined(__clang__) || \
|
jpayne@69
|
840 (defined(__GNUC__) && \
|
jpayne@69
|
841 ((__GNUC__ >= 3) || \
|
jpayne@69
|
842 (__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)))
|
jpayne@69
|
843 # define _Py_NO_RETURN __attribute__((__noreturn__))
|
jpayne@69
|
844 #elif defined(_MSC_VER)
|
jpayne@69
|
845 # define _Py_NO_RETURN __declspec(noreturn)
|
jpayne@69
|
846 #else
|
jpayne@69
|
847 # define _Py_NO_RETURN
|
jpayne@69
|
848 #endif
|
jpayne@69
|
849
|
jpayne@69
|
850 #endif /* Py_PYPORT_H */
|