]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/PyMod-2.7.2/Include/pyport.h
StdLib: Improve robustness of stat() and make basename() a public function.
[mirror_edk2.git] / AppPkg / Applications / Python / PyMod-2.7.2 / Include / pyport.h
CommitLineData
41b152c5 1/** @file\r
2 Symbols and macros to supply platform-independent interfaces to basic\r
3 C language & library operations whose spellings vary across platforms.\r
4\r
5 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
6 This program and the accompanying materials are licensed and made available under\r
7 the terms and conditions of the BSD License that accompanies this distribution.\r
8 The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13**/\r
6c0ebd5f 14#ifndef Py_PYPORT_H\r
15#define Py_PYPORT_H\r
16\r
17#include "pyconfig.h" /* include for defines */\r
18\r
19/* Some versions of HP-UX & Solaris need inttypes.h for int32_t,\r
20 INT32_MAX, etc. */\r
21#ifdef HAVE_INTTYPES_H\r
22#include <inttypes.h>\r
23#endif\r
24\r
25#ifdef HAVE_STDINT_H\r
26#include <stdint.h>\r
27#endif\r
28\r
29/**************************************************************************\r
30Symbols and macros to supply platform-independent interfaces to basic\r
31C language & library operations whose spellings vary across platforms.\r
32\r
33Please try to make documentation here as clear as possible: by definition,\r
34the stuff here is trying to illuminate C's darkest corners.\r
35\r
36Config #defines referenced here:\r
37\r
38SIGNED_RIGHT_SHIFT_ZERO_FILLS\r
39Meaning: To be defined iff i>>j does not extend the sign bit when i is a\r
40 signed integral type and i < 0.\r
41Used in: Py_ARITHMETIC_RIGHT_SHIFT\r
42\r
43Py_DEBUG\r
44Meaning: Extra checks compiled in for debug mode.\r
45Used in: Py_SAFE_DOWNCAST\r
46\r
47HAVE_UINTPTR_T\r
48Meaning: The C9X type uintptr_t is supported by the compiler\r
49Used in: Py_uintptr_t\r
50\r
51HAVE_LONG_LONG\r
52Meaning: The compiler supports the C type "long long"\r
53Used in: PY_LONG_LONG\r
54\r
55**************************************************************************/\r
56\r
57\r
58/* For backward compatibility only. Obsolete, do not use. */\r
59#ifdef HAVE_PROTOTYPES\r
60#define Py_PROTO(x) x\r
61#else\r
62#define Py_PROTO(x) ()\r
63#endif\r
64#ifndef Py_FPROTO\r
65#define Py_FPROTO(x) Py_PROTO(x)\r
66#endif\r
67\r
68/* typedefs for some C9X-defined synonyms for integral types.\r
69 *\r
70 * The names in Python are exactly the same as the C9X names, except with a\r
71 * Py_ prefix. Until C9X is universally implemented, this is the only way\r
72 * to ensure that Python gets reliable names that don't conflict with names\r
73 * in non-Python code that are playing their own tricks to define the C9X\r
74 * names.\r
75 *\r
76 * NOTE: don't go nuts here! Python has no use for *most* of the C9X\r
77 * integral synonyms. Only define the ones we actually need.\r
78 */\r
79\r
80#ifdef HAVE_LONG_LONG\r
81#ifndef PY_LONG_LONG\r
82#define PY_LONG_LONG long long\r
83#if defined(LLONG_MAX)\r
84/* If LLONG_MAX is defined in limits.h, use that. */\r
85#define PY_LLONG_MIN LLONG_MIN\r
86#define PY_LLONG_MAX LLONG_MAX\r
87#define PY_ULLONG_MAX ULLONG_MAX\r
88#elif defined(__LONG_LONG_MAX__)\r
89/* Otherwise, if GCC has a builtin define, use that. */\r
90#define PY_LLONG_MAX __LONG_LONG_MAX__\r
91#define PY_LLONG_MIN (-PY_LLONG_MAX-1)\r
92#define PY_ULLONG_MAX (__LONG_LONG_MAX__*2ULL + 1ULL)\r
93#else\r
94/* Otherwise, rely on two's complement. */\r
95#define PY_ULLONG_MAX (~0ULL)\r
96#define PY_LLONG_MAX ((long long)(PY_ULLONG_MAX>>1))\r
97#define PY_LLONG_MIN (-PY_LLONG_MAX-1)\r
98#endif /* LLONG_MAX */\r
99#endif\r
100#endif /* HAVE_LONG_LONG */\r
101\r
102/* a build with 30-bit digits for Python long integers needs an exact-width\r
103 * 32-bit unsigned integer type to store those digits. (We could just use\r
104 * type 'unsigned long', but that would be wasteful on a system where longs\r
105 * are 64-bits.) On Unix systems, the autoconf macro AC_TYPE_UINT32_T defines\r
106 * uint32_t to be such a type unless stdint.h or inttypes.h defines uint32_t.\r
107 * However, it doesn't set HAVE_UINT32_T, so we do that here.\r
108 */\r
109#if (defined UINT32_MAX || defined uint32_t)\r
110#ifndef PY_UINT32_T\r
111#define HAVE_UINT32_T 1\r
112#define PY_UINT32_T uint32_t\r
113#endif\r
114#endif\r
115\r
116/* Macros for a 64-bit unsigned integer type; used for type 'twodigits' in the\r
117 * long integer implementation, when 30-bit digits are enabled.\r
118 */\r
119#if (defined UINT64_MAX || defined uint64_t)\r
120#ifndef PY_UINT64_T\r
121#define HAVE_UINT64_T 1\r
122#define PY_UINT64_T uint64_t\r
123#endif\r
124#endif\r
125\r
126/* Signed variants of the above */\r
127#if (defined INT32_MAX || defined int32_t)\r
128#ifndef PY_INT32_T\r
129#define HAVE_INT32_T 1\r
130#define PY_INT32_T int32_t\r
131#endif\r
132#endif\r
133#if (defined INT64_MAX || defined int64_t)\r
134#ifndef PY_INT64_T\r
135#define HAVE_INT64_T 1\r
136#define PY_INT64_T int64_t\r
137#endif\r
138#endif\r
139\r
140/* If PYLONG_BITS_IN_DIGIT is not defined then we'll use 30-bit digits if all\r
141 the necessary integer types are available, and we're on a 64-bit platform\r
142 (as determined by SIZEOF_VOID_P); otherwise we use 15-bit digits. */\r
143\r
144#ifndef PYLONG_BITS_IN_DIGIT\r
145#if (defined HAVE_UINT64_T && defined HAVE_INT64_T && \\r
146 defined HAVE_UINT32_T && defined HAVE_INT32_T && SIZEOF_VOID_P >= 8)\r
147#define PYLONG_BITS_IN_DIGIT 30\r
148#else\r
149#define PYLONG_BITS_IN_DIGIT 15\r
150#endif\r
151#endif\r
152\r
153/* uintptr_t is the C9X name for an unsigned integral type such that a\r
154 * legitimate void* can be cast to uintptr_t and then back to void* again\r
155 * without loss of information. Similarly for intptr_t, wrt a signed\r
156 * integral type.\r
157 */\r
158#ifdef HAVE_UINTPTR_T\r
159typedef uintptr_t Py_uintptr_t;\r
160typedef intptr_t Py_intptr_t;\r
161\r
162#elif SIZEOF_VOID_P <= SIZEOF_INT\r
163typedef unsigned int Py_uintptr_t;\r
164typedef int Py_intptr_t;\r
165\r
166#elif SIZEOF_VOID_P <= SIZEOF_LONG\r
167typedef unsigned long Py_uintptr_t;\r
168typedef long Py_intptr_t;\r
169\r
170#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)\r
171typedef unsigned PY_LONG_LONG Py_uintptr_t;\r
172typedef PY_LONG_LONG Py_intptr_t;\r
173\r
174#else\r
175# error "Python needs a typedef for Py_uintptr_t in pyport.h."\r
176#endif /* HAVE_UINTPTR_T */\r
177\r
178/* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==\r
179 * sizeof(size_t). C99 doesn't define such a thing directly (size_t is an\r
180 * unsigned integral type). See PEP 353 for details.\r
181 */\r
182#ifdef HAVE_SSIZE_T\r
183typedef ssize_t Py_ssize_t;\r
184#elif SIZEOF_VOID_P == SIZEOF_SIZE_T\r
185typedef Py_intptr_t Py_ssize_t;\r
186#else\r
187# error "Python needs a typedef for Py_ssize_t in pyport.h."\r
188#endif\r
189\r
190/* Largest possible value of size_t.\r
191 SIZE_MAX is part of C99, so it might be defined on some\r
192 platforms. If it is not defined, (size_t)-1 is a portable\r
193 definition for C89, due to the way signed->unsigned\r
194 conversion is defined. */\r
195#ifdef SIZE_MAX\r
196#define PY_SIZE_MAX SIZE_MAX\r
197#else\r
198#define PY_SIZE_MAX ((size_t)-1)\r
199#endif\r
200\r
201/* Largest positive value of type Py_ssize_t. */\r
202#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))\r
203/* Smallest negative value of type Py_ssize_t. */\r
204#define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)\r
205\r
206#if SIZEOF_PID_T > SIZEOF_LONG\r
207# error "Python doesn't support sizeof(pid_t) > sizeof(long)"\r
208#endif\r
209\r
210/* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf\r
211 * format to convert an argument with the width of a size_t or Py_ssize_t.\r
212 * C99 introduced "z" for this purpose, but not all platforms support that;\r
213 * e.g., MS compilers use "I" instead.\r
214 *\r
215 * These "high level" Python format functions interpret "z" correctly on\r
216 * all platforms (Python interprets the format string itself, and does whatever\r
217 * the platform C requires to convert a size_t/Py_ssize_t argument):\r
218 *\r
219 * PyString_FromFormat\r
220 * PyErr_Format\r
221 * PyString_FromFormatV\r
222 *\r
223 * Lower-level uses require that you interpolate the correct format modifier\r
224 * yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for\r
225 * example,\r
226 *\r
227 * Py_ssize_t index;\r
228 * fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index);\r
229 *\r
230 * That will expand to %ld, or %Id, or to something else correct for a\r
231 * Py_ssize_t on the platform.\r
232 */\r
233#ifndef PY_FORMAT_SIZE_T\r
234# if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__)\r
235# define PY_FORMAT_SIZE_T ""\r
236# elif SIZEOF_SIZE_T == SIZEOF_LONG\r
237# define PY_FORMAT_SIZE_T "l"\r
238# elif defined(MS_WINDOWS)\r
239# define PY_FORMAT_SIZE_T "I"\r
240# else\r
241# error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T"\r
242# endif\r
243#endif\r
244\r
245/* PY_FORMAT_LONG_LONG is analogous to PY_FORMAT_SIZE_T above, but for\r
246 * the long long type instead of the size_t type. It's only available\r
247 * when HAVE_LONG_LONG is defined. The "high level" Python format\r
248 * functions listed above will interpret "lld" or "llu" correctly on\r
249 * all platforms.\r
250 */\r
251#ifdef HAVE_LONG_LONG\r
252# ifndef PY_FORMAT_LONG_LONG\r
253# if defined(MS_WIN64) || defined(MS_WINDOWS)\r
254# define PY_FORMAT_LONG_LONG "I64"\r
255# else\r
256# error "This platform's pyconfig.h needs to define PY_FORMAT_LONG_LONG"\r
257# endif\r
258# endif\r
259#endif\r
260\r
261/* Py_LOCAL can be used instead of static to get the fastest possible calling\r
262 * convention for functions that are local to a given module.\r
263 *\r
264 * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining,\r
265 * for platforms that support that.\r
266 *\r
267 * If PY_LOCAL_AGGRESSIVE is defined before python.h is included, more\r
268 * "aggressive" inlining/optimizaion is enabled for the entire module. This\r
269 * may lead to code bloat, and may slow things down for those reasons. It may\r
270 * also lead to errors, if the code relies on pointer aliasing. Use with\r
271 * care.\r
272 *\r
273 * NOTE: You can only use this for functions that are entirely local to a\r
274 * module; functions that are exported via method tables, callbacks, etc,\r
275 * should keep using static.\r
276 */\r
277\r
278#undef USE_INLINE /* XXX - set via configure? */\r
279\r
280#if defined(_MSC_VER)\r
281#if defined(PY_LOCAL_AGGRESSIVE)\r
282/* enable more aggressive optimization for visual studio */\r
283//#pragma optimize("agtw", on)\r
284#pragma optimize("gt", on) // a and w are not legal for VS2005\r
285#endif\r
286/* ignore warnings if the compiler decides not to inline a function */\r
287#pragma warning(disable: 4710)\r
288/* fastest possible local call under MSVC */\r
289#define Py_LOCAL(type) static type __fastcall\r
290#define Py_LOCAL_INLINE(type) static __inline type __fastcall\r
291#elif defined(USE_INLINE)\r
292#define Py_LOCAL(type) static type\r
293#define Py_LOCAL_INLINE(type) static inline type\r
294#else\r
295#define Py_LOCAL(type) static type\r
296#define Py_LOCAL_INLINE(type) static type\r
297#endif\r
298\r
299/* Py_MEMCPY can be used instead of memcpy in cases where the copied blocks\r
300 * are often very short. While most platforms have highly optimized code for\r
301 * large transfers, the setup costs for memcpy are often quite high. MEMCPY\r
302 * solves this by doing short copies "in line".\r
303 */\r
304\r
305#if defined(_MSC_VER)\r
306#define Py_MEMCPY(target, source, length) do { \\r
307 size_t i_, n_ = (length); \\r
308 char *t_ = (void*) (target); \\r
309 const char *s_ = (void*) (source); \\r
310 if (n_ >= 16) \\r
311 memcpy(t_, s_, n_); \\r
312 else \\r
313 for (i_ = 0; i_ < n_; i_++) \\r
314 t_[i_] = s_[i_]; \\r
315 } while (0)\r
316#else\r
317#define Py_MEMCPY memcpy\r
318#endif\r
319\r
320#include <stdlib.h>\r
321\r
322#ifdef HAVE_IEEEFP_H\r
323#include <ieeefp.h> /* needed for 'finite' declaration on some platforms */\r
324#endif\r
325\r
326#include <math.h> /* Moved here from the math section, before extern "C" */\r
327\r
328/********************************************\r
329 * WRAPPER FOR <time.h> and/or <sys/time.h> *\r
330 ********************************************/\r
331\r
332#ifdef TIME_WITH_SYS_TIME\r
333#include <sys/time.h>\r
334#include <time.h>\r
335#else /* !TIME_WITH_SYS_TIME */\r
336#ifdef HAVE_SYS_TIME_H\r
337#include <sys/time.h>\r
338#else /* !HAVE_SYS_TIME_H */\r
339#include <time.h>\r
340#endif /* !HAVE_SYS_TIME_H */\r
341#endif /* !TIME_WITH_SYS_TIME */\r
342\r
343\r
344/******************************\r
345 * WRAPPER FOR <sys/select.h> *\r
346 ******************************/\r
347\r
348/* NB caller must include <sys/types.h> */\r
349\r
350#ifdef HAVE_SYS_SELECT_H\r
351\r
352#include <sys/select.h>\r
353\r
354#endif /* !HAVE_SYS_SELECT_H */\r
355\r
356/*******************************\r
357 * stat() and fstat() fiddling *\r
358 *******************************/\r
359\r
360/* We expect that stat and fstat exist on most systems.\r
361 * It's confirmed on Unix, Mac and Windows.\r
362 * If you don't have them, add\r
363 * #define DONT_HAVE_STAT\r
364 * and/or\r
365 * #define DONT_HAVE_FSTAT\r
366 * to your pyconfig.h. Python code beyond this should check HAVE_STAT and\r
367 * HAVE_FSTAT instead.\r
368 * Also\r
369 * #define HAVE_SYS_STAT_H\r
370 * if <sys/stat.h> exists on your platform, and\r
371 * #define HAVE_STAT_H\r
372 * if <stat.h> does.\r
373 */\r
374#ifndef DONT_HAVE_STAT\r
375#define HAVE_STAT\r
376#endif\r
377\r
378#ifndef DONT_HAVE_FSTAT\r
379#define HAVE_FSTAT\r
380#endif\r
381\r
382#ifdef RISCOS\r
383#include <sys/types.h>\r
384#include "unixstuff.h"\r
385#endif\r
386\r
387#ifdef HAVE_SYS_STAT_H\r
388#if defined(PYOS_OS2) && defined(PYCC_GCC)\r
389#include <sys/types.h>\r
390#endif\r
391#include <sys/stat.h>\r
392#elif defined(HAVE_STAT_H)\r
393#include <stat.h>\r
394#endif\r
395\r
396#if defined(PYCC_VACPP)\r
397/* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */\r
398#define S_IFMT (S_IFDIR|S_IFCHR|S_IFREG)\r
399#endif\r
400\r
401#ifndef S_ISREG\r
402#define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)\r
403#endif\r
404\r
405#ifndef S_ISDIR\r
406#define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)\r
407#endif\r
408\r
409\r
410#ifdef __cplusplus\r
411/* Move this down here since some C++ #include's don't like to be included\r
412 inside an extern "C" */\r
413extern "C" {\r
414#endif\r
415\r
416\r
417/* Py_ARITHMETIC_RIGHT_SHIFT\r
418 * C doesn't define whether a right-shift of a signed integer sign-extends\r
419 * or zero-fills. Here a macro to force sign extension:\r
420 * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)\r
421 * Return I >> J, forcing sign extension. Arithmetically, return the\r
422 * floor of I/2**J.\r
423 * Requirements:\r
424 * I should have signed integer type. In the terminology of C99, this can\r
425 * be either one of the five standard signed integer types (signed char,\r
426 * short, int, long, long long) or an extended signed integer type.\r
427 * J is an integer >= 0 and strictly less than the number of bits in the\r
428 * type of I (because C doesn't define what happens for J outside that\r
429 * range either).\r
430 * TYPE used to specify the type of I, but is now ignored. It's been left\r
431 * in for backwards compatibility with versions <= 2.6 or 3.0.\r
432 * Caution:\r
433 * I may be evaluated more than once.\r
434 */\r
435#ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS\r
436#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \\r
437 ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))\r
438#else\r
439#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))\r
440#endif\r
441\r
442/* Py_FORCE_EXPANSION(X)\r
443 * "Simply" returns its argument. However, macro expansions within the\r
444 * argument are evaluated. This unfortunate trickery is needed to get\r
445 * token-pasting to work as desired in some cases.\r
446 */\r
447#define Py_FORCE_EXPANSION(X) X\r
448\r
449/* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW)\r
450 * Cast VALUE to type NARROW from type WIDE. In Py_DEBUG mode, this\r
451 * assert-fails if any information is lost.\r
452 * Caution:\r
453 * VALUE may be evaluated more than once.\r
454 */\r
455#ifdef Py_DEBUG\r
456#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \\r
457 (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE))\r
458#else\r
459#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)\r
460#endif\r
461\r
462/* Py_SET_ERRNO_ON_MATH_ERROR(x)\r
463 * If a libm function did not set errno, but it looks like the result\r
464 * overflowed or not-a-number, set errno to ERANGE or EDOM. Set errno\r
465 * to 0 before calling a libm function, and invoke this macro after,\r
466 * passing the function result.\r
467 * Caution:\r
468 * This isn't reliable. See Py_OVERFLOWED comments.\r
469 * X is evaluated more than once.\r
470 */\r
471#if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64))\r
472#define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM;\r
473#else\r
474#define _Py_SET_EDOM_FOR_NAN(X) ;\r
475#endif\r
476#define Py_SET_ERRNO_ON_MATH_ERROR(X) \\r
477 do { \\r
478 if (errno == 0) { \\r
479 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \\r
480 errno = ERANGE; \\r
481 else _Py_SET_EDOM_FOR_NAN(X) \\r
482 } \\r
483 } while(0)\r
484\r
485/* Py_SET_ERANGE_ON_OVERFLOW(x)\r
486 * An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility.\r
487 */\r
488#define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X)\r
489\r
490/* Py_ADJUST_ERANGE1(x)\r
491 * Py_ADJUST_ERANGE2(x, y)\r
492 * Set errno to 0 before calling a libm function, and invoke one of these\r
493 * macros after, passing the function result(s) (Py_ADJUST_ERANGE2 is useful\r
494 * for functions returning complex results). This makes two kinds of\r
495 * adjustments to errno: (A) If it looks like the platform libm set\r
496 * errno=ERANGE due to underflow, clear errno. (B) If it looks like the\r
497 * platform libm overflowed but didn't set errno, force errno to ERANGE. In\r
498 * effect, we're trying to force a useful implementation of C89 errno\r
499 * behavior.\r
500 * Caution:\r
501 * This isn't reliable. See Py_OVERFLOWED comments.\r
502 * X and Y may be evaluated more than once.\r
503 */\r
504#define Py_ADJUST_ERANGE1(X) \\r
505 do { \\r
506 if (errno == 0) { \\r
507 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \\r
508 errno = ERANGE; \\r
509 } \\r
510 else if (errno == ERANGE && (X) == 0.0) \\r
511 errno = 0; \\r
512 } while(0)\r
513\r
514#define Py_ADJUST_ERANGE2(X, Y) \\r
515 do { \\r
516 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL || \\r
517 (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) { \\r
518 if (errno == 0) \\r
519 errno = ERANGE; \\r
520 } \\r
521 else if (errno == ERANGE) \\r
522 errno = 0; \\r
523 } while(0)\r
524\r
525/* The functions _Py_dg_strtod and _Py_dg_dtoa in Python/dtoa.c (which are\r
526 * required to support the short float repr introduced in Python 3.1) require\r
527 * that the floating-point unit that's being used for arithmetic operations\r
528 * on C doubles is set to use 53-bit precision. It also requires that the\r
529 * FPU rounding mode is round-half-to-even, but that's less often an issue.\r
530 *\r
531 * If your FPU isn't already set to 53-bit precision/round-half-to-even, and\r
532 * you want to make use of _Py_dg_strtod and _Py_dg_dtoa, then you should\r
533 *\r
534 * #define HAVE_PY_SET_53BIT_PRECISION 1\r
535 *\r
536 * and also give appropriate definitions for the following three macros:\r
537 *\r
538 * _PY_SET_53BIT_PRECISION_START : store original FPU settings, and\r
539 * set FPU to 53-bit precision/round-half-to-even\r
540 * _PY_SET_53BIT_PRECISION_END : restore original FPU settings\r
541 * _PY_SET_53BIT_PRECISION_HEADER : any variable declarations needed to\r
542 * use the two macros above.\r
543 *\r
544 * The macros are designed to be used within a single C function: see\r
545 * Python/pystrtod.c for an example of their use.\r
546 */\r
547\r
548/* get and set x87 control word for gcc/x86 */\r
549#ifdef HAVE_GCC_ASM_FOR_X87\r
550#define HAVE_PY_SET_53BIT_PRECISION 1\r
551/* _Py_get/set_387controlword functions are defined in Python/pymath.c */\r
552#define _Py_SET_53BIT_PRECISION_HEADER \\r
553 unsigned short old_387controlword, new_387controlword\r
554#define _Py_SET_53BIT_PRECISION_START \\r
555 do { \\r
556 old_387controlword = _Py_get_387controlword(); \\r
557 new_387controlword = (old_387controlword & ~0x0f00) | 0x0200; \\r
558 if (new_387controlword != old_387controlword) \\r
559 _Py_set_387controlword(new_387controlword); \\r
560 } while (0)\r
561#define _Py_SET_53BIT_PRECISION_END \\r
562 if (new_387controlword != old_387controlword) \\r
563 _Py_set_387controlword(old_387controlword)\r
564#endif\r
565\r
566/* default definitions are empty */\r
567#ifndef HAVE_PY_SET_53BIT_PRECISION\r
568#define _Py_SET_53BIT_PRECISION_HEADER\r
569#define _Py_SET_53BIT_PRECISION_START\r
570#define _Py_SET_53BIT_PRECISION_END\r
571#endif\r
572\r
573/* If we can't guarantee 53-bit precision, don't use the code\r
574 in Python/dtoa.c, but fall back to standard code. This\r
575 means that repr of a float will be long (17 sig digits).\r
576\r
577 Realistically, there are two things that could go wrong:\r
578\r
579 (1) doubles aren't IEEE 754 doubles, or\r
580 (2) we're on x86 with the rounding precision set to 64-bits\r
581 (extended precision), and we don't know how to change\r
582 the rounding precision.\r
583 */\r
584\r
585#if !defined(DOUBLE_IS_LITTLE_ENDIAN_IEEE754) && \\r
586 !defined(DOUBLE_IS_BIG_ENDIAN_IEEE754) && \\r
587 !defined(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754)\r
588#define PY_NO_SHORT_FLOAT_REPR\r
589#endif\r
590\r
591/* double rounding is symptomatic of use of extended precision on x86. If\r
592 we're seeing double rounding, and we don't have any mechanism available for\r
593 changing the FPU rounding precision, then don't use Python/dtoa.c. */\r
594#if defined(X87_DOUBLE_ROUNDING) && !defined(HAVE_PY_SET_53BIT_PRECISION)\r
595#define PY_NO_SHORT_FLOAT_REPR\r
596#endif\r
597\r
598/* Py_DEPRECATED(version)\r
599 * Declare a variable, type, or function deprecated.\r
600 * Usage:\r
601 * extern int old_var Py_DEPRECATED(2.3);\r
602 * typedef int T1 Py_DEPRECATED(2.4);\r
603 * extern int x() Py_DEPRECATED(2.5);\r
604 */\r
605#if defined(__GNUC__) && ((__GNUC__ >= 4) || \\r
606 (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))\r
607#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))\r
608#else\r
609#define Py_DEPRECATED(VERSION_UNUSED)\r
610#endif\r
611\r
612/**************************************************************************\r
613Prototypes that are missing from the standard include files on some systems\r
614(and possibly only some versions of such systems.)\r
615\r
616Please be conservative with adding new ones, document them and enclose them\r
617in platform-specific #ifdefs.\r
618**************************************************************************/\r
619\r
620#ifdef SOLARIS\r
621/* Unchecked */\r
622extern int gethostname(char *, int);\r
623#endif\r
624\r
625#ifdef __BEOS__\r
626/* Unchecked */\r
627/* It's in the libs, but not the headers... - [cjh] */\r
628int shutdown( int, int );\r
629#endif\r
630\r
631#ifdef HAVE__GETPTY\r
632#include <sys/types.h> /* we need to import mode_t */\r
633extern char * _getpty(int *, int, mode_t, int);\r
634#endif\r
635\r
636/* On QNX 6, struct termio must be declared by including sys/termio.h\r
637 if TCGETA, TCSETA, TCSETAW, or TCSETAF are used. sys/termio.h must\r
638 be included before termios.h or it will generate an error. */\r
639#ifdef HAVE_SYS_TERMIO_H\r
640#include <sys/termio.h>\r
641#endif\r
642\r
643#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)\r
644#if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) && !defined(HAVE_UTIL_H)\r
645/* BSDI does not supply a prototype for the 'openpty' and 'forkpty'\r
646 functions, even though they are included in libutil. */\r
647#include <termios.h>\r
648extern int openpty(int *, int *, char *, struct termios *, struct winsize *);\r
649extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);\r
650#endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */\r
651#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */\r
652\r
653\r
654/* These are pulled from various places. It isn't obvious on what platforms\r
655 they are necessary, nor what the exact prototype should look like (which\r
656 is likely to vary between platforms!) If you find you need one of these\r
657 declarations, please move them to a platform-specific block and include\r
658 proper prototypes. */\r
659#if 0\r
660\r
661/* From Modules/resource.c */\r
662extern int getrusage();\r
663extern int getpagesize();\r
664\r
665/* From Python/sysmodule.c and Modules/posixmodule.c */\r
666extern int fclose(FILE *);\r
667\r
668/* From Modules/posixmodule.c */\r
669extern int fdatasync(int);\r
670#endif /* 0 */\r
671\r
672\r
673/* On 4.4BSD-descendants, ctype functions serves the whole range of\r
674 * wchar_t character set rather than single byte code points only.\r
675 * This characteristic can break some operations of string object\r
676 * including str.upper() and str.split() on UTF-8 locales. This\r
677 * workaround was provided by Tim Robbins of FreeBSD project.\r
678 */\r
679\r
680#ifdef __FreeBSD__\r
681#include <osreldate.h>\r
682#if __FreeBSD_version > 500039\r
683# define _PY_PORT_CTYPE_UTF8_ISSUE\r
684#endif\r
685#endif\r
686\r
687\r
688#if defined(__APPLE__)\r
689# define _PY_PORT_CTYPE_UTF8_ISSUE\r
690#endif\r
691\r
692#ifdef _PY_PORT_CTYPE_UTF8_ISSUE\r
693#include <ctype.h>\r
694#include <wctype.h>\r
695#undef isalnum\r
696#define isalnum(c) iswalnum(btowc(c))\r
697#undef isalpha\r
698#define isalpha(c) iswalpha(btowc(c))\r
699#undef islower\r
700#define islower(c) iswlower(btowc(c))\r
701#undef isspace\r
702#define isspace(c) iswspace(btowc(c))\r
703#undef isupper\r
704#define isupper(c) iswupper(btowc(c))\r
705#undef tolower\r
706#define tolower(c) towlower(btowc(c))\r
707#undef toupper\r
708#define toupper(c) towupper(btowc(c))\r
709#endif\r
710\r
711\r
712/* Declarations for symbol visibility.\r
713\r
714 PyAPI_FUNC(type): Declares a public Python API function and return type\r
715 PyAPI_DATA(type): Declares public Python data and its type\r
716 PyMODINIT_FUNC: A Python module init function. If these functions are\r
717 inside the Python core, they are private to the core.\r
718 If in an extension module, it may be declared with\r
719 external linkage depending on the platform.\r
720\r
721 As a number of platforms support/require "__declspec(dllimport/dllexport)",\r
722 we support a HAVE_DECLSPEC_DLL macro to save duplication.\r
723*/\r
724\r
725/*\r
726 All windows ports, except cygwin, are handled in PC/pyconfig.h.\r
727\r
728 BeOS and cygwin are the only other autoconf platform requiring special\r
729 linkage handling and both of these use __declspec().\r
730*/\r
731#if defined(__CYGWIN__) || defined(__BEOS__)\r
732# define HAVE_DECLSPEC_DLL\r
733#endif\r
734\r
735/* only get special linkage if built as shared or platform is Cygwin */\r
736#if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)\r
737# if defined(HAVE_DECLSPEC_DLL)\r
738# ifdef Py_BUILD_CORE\r
739# define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE\r
740# define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE\r
741 /* module init functions inside the core need no external linkage */\r
742 /* except for Cygwin to handle embedding (FIXME: BeOS too?) */\r
743# if defined(__CYGWIN__)\r
744# define PyMODINIT_FUNC __declspec(dllexport) void\r
745# else /* __CYGWIN__ */\r
746# define PyMODINIT_FUNC void\r
747# endif /* __CYGWIN__ */\r
748# else /* Py_BUILD_CORE */\r
749 /* Building an extension module, or an embedded situation */\r
750 /* public Python functions and data are imported */\r
751 /* Under Cygwin, auto-import functions to prevent compilation */\r
752 /* failures similar to those described at the bottom of 4.1: */\r
753 /* http://docs.python.org/extending/windows.html#a-cookbook-approach */\r
754# if !defined(__CYGWIN__)\r
755# define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE\r
756# endif /* !__CYGWIN__ */\r
757# define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE\r
758 /* module init functions outside the core must be exported */\r
759# if defined(__cplusplus)\r
760# define PyMODINIT_FUNC extern "C" __declspec(dllexport) void\r
761# else /* __cplusplus */\r
762# define PyMODINIT_FUNC __declspec(dllexport) void\r
763# endif /* __cplusplus */\r
764# endif /* Py_BUILD_CORE */\r
765# endif /* HAVE_DECLSPEC */\r
766#endif /* Py_ENABLE_SHARED */\r
767\r
768/* If no external linkage macros defined by now, create defaults */\r
769#ifndef PyAPI_FUNC\r
770# define PyAPI_FUNC(RTYPE) RTYPE\r
771#endif\r
772#ifndef PyAPI_DATA\r
773# define PyAPI_DATA(RTYPE) extern RTYPE\r
774#endif\r
775#ifndef PyMODINIT_FUNC\r
776# if defined(__cplusplus)\r
777# define PyMODINIT_FUNC extern "C" void\r
778# else /* __cplusplus */\r
779# define PyMODINIT_FUNC void\r
780# endif /* __cplusplus */\r
781#endif\r
782\r
783/* Deprecated DL_IMPORT and DL_EXPORT macros */\r
784#if defined(Py_ENABLE_SHARED) && defined (HAVE_DECLSPEC_DLL)\r
785# if defined(Py_BUILD_CORE)\r
786# define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE\r
787# define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE\r
788# else\r
789# define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE\r
790# define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE\r
791# endif\r
792#endif\r
793#ifndef DL_EXPORT\r
794# define DL_EXPORT(RTYPE) RTYPE\r
795#endif\r
796#ifndef DL_IMPORT\r
797# define DL_IMPORT(RTYPE) RTYPE\r
798#endif\r
799/* End of deprecated DL_* macros */\r
800\r
801/* If the fd manipulation macros aren't defined,\r
802 here is a set that should do the job */\r
803\r
804#if 0 /* disabled and probably obsolete */\r
805\r
806#ifndef FD_SETSIZE\r
807#define FD_SETSIZE 256\r
808#endif\r
809\r
810#ifndef FD_SET\r
811\r
812typedef long fd_mask;\r
813\r
814#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */\r
815#ifndef howmany\r
816#define howmany(x, y) (((x)+((y)-1))/(y))\r
817#endif /* howmany */\r
818\r
819typedef struct fd_set {\r
820 fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];\r
821} fd_set;\r
822\r
823#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))\r
824#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))\r
825#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))\r
826#define FD_ZERO(p) memset((char *)(p), '\0', sizeof(*(p)))\r
827\r
828#endif /* FD_SET */\r
829\r
830#endif /* fd manipulation macros */\r
831\r
832\r
833/* limits.h constants that may be missing */\r
834\r
835#ifndef INT_MAX\r
836#define INT_MAX 2147483647\r
837#endif\r
838\r
839#ifndef LONG_MAX\r
840#if SIZEOF_LONG == 4\r
841#define LONG_MAX 0X7FFFFFFFL\r
842#elif SIZEOF_LONG == 8\r
843#define LONG_MAX 0X7FFFFFFFFFFFFFFFL\r
844#else\r
845#error "could not set LONG_MAX in pyport.h"\r
846#endif\r
847#endif\r
848\r
849#ifndef LONG_MIN\r
850#define LONG_MIN (-LONG_MAX-1)\r
851#endif\r
852\r
853#ifndef LONG_BIT\r
854#define LONG_BIT (8 * SIZEOF_LONG)\r
855#endif\r
856\r
857#if LONG_BIT != 8 * SIZEOF_LONG\r
858/* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent\r
859 * 32-bit platforms using gcc. We try to catch that here at compile-time\r
860 * rather than waiting for integer multiplication to trigger bogus\r
861 * overflows.\r
862 */\r
863#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."\r
864#endif\r
865\r
866#ifdef __cplusplus\r
867}\r
868#endif\r
869\r
870/*\r
871 * Hide GCC attributes from compilers that don't support them.\r
872 */\r
873#if (!defined(__GNUC__) || __GNUC__ < 2 || \\r
874 (__GNUC__ == 2 && __GNUC_MINOR__ < 7) ) && \\r
875 !defined(RISCOS)\r
876#define Py_GCC_ATTRIBUTE(x)\r
877#else\r
878#define Py_GCC_ATTRIBUTE(x) __attribute__(x)\r
879#endif\r
880\r
881/*\r
882 * Add PyArg_ParseTuple format where available.\r
883 */\r
884#ifdef HAVE_ATTRIBUTE_FORMAT_PARSETUPLE\r
885#define Py_FORMAT_PARSETUPLE(func,p1,p2) __attribute__((format(func,p1,p2)))\r
886#else\r
887#define Py_FORMAT_PARSETUPLE(func,p1,p2)\r
888#endif\r
889\r
890/*\r
891 * Specify alignment on compilers that support it.\r
892 */\r
893#if defined(__GNUC__) && __GNUC__ >= 3\r
894#define Py_ALIGNED(x) __attribute__((aligned(x)))\r
895#else\r
896#define Py_ALIGNED(x)\r
897#endif\r
898\r
899/* Eliminate end-of-loop code not reached warnings from SunPro C\r
900 * when using do{...}while(0) macros\r
901 */\r
902#ifdef __SUNPRO_C\r
903#pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)\r
904#endif\r
905\r
906/*\r
907 * Older Microsoft compilers don't support the C99 long long literal suffixes,\r
908 * so these will be defined in PC/pyconfig.h for those compilers.\r
909 */\r
910#ifndef Py_LL\r
911#define Py_LL(x) x##LL\r
912#endif\r
913\r
914#ifndef Py_ULL\r
915#define Py_ULL(x) Py_LL(x##U)\r
916#endif\r
917\r
918#endif /* Py_PYPORT_H */\r