13ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/** @file
23ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  Symbols and macros to supply platform-independent interfaces to basic
33ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  C language & library operations whose spellings vary across platforms.
43ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
53ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  Copyright (c) 2015, Daryl McDaniel. All rights reserved.<BR>
63ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
73ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  This program and the accompanying materials are licensed and made available under
83ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  the terms and conditions of the BSD License that accompanies this distribution.
93ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  The full text of the license may be found at
103ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  http://opensource.org/licenses/bsd-license.
113ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
123ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
133ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
143ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel**/
153ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
163ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef Py_PYPORT_H
173ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_PYPORT_H
183ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
193ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include "pyconfig.h" /* include for defines */
203ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
213ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Some versions of HP-UX & Solaris need inttypes.h for int32_t,
223ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   INT32_MAX, etc. */
233ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE_INTTYPES_H
243ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <inttypes.h>
253ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
263ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
273ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE_STDINT_H
283ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <stdint.h>
293ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
303ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
313ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/**************************************************************************
323ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielSymbols and macros to supply platform-independent interfaces to basic
333ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielC language & library operations whose spellings vary across platforms.
343ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
353ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielPlease try to make documentation here as clear as possible:  by definition,
363ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielthe stuff here is trying to illuminate C's darkest corners.
373ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
383ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielConfig #defines referenced here:
393ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
403ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielSIGNED_RIGHT_SHIFT_ZERO_FILLS
413ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielMeaning:  To be defined iff i>>j does not extend the sign bit when i is a
423ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel          signed integral type and i < 0.
433ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielUsed in:  Py_ARITHMETIC_RIGHT_SHIFT
443ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
453ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielPy_DEBUG
463ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielMeaning:  Extra checks compiled in for debug mode.
473ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielUsed in:  Py_SAFE_DOWNCAST
483ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
493ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielHAVE_UINTPTR_T
503ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielMeaning:  The C9X type uintptr_t is supported by the compiler
513ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielUsed in:  Py_uintptr_t
523ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
533ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielHAVE_LONG_LONG
543ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielMeaning:  The compiler supports the C type "long long"
553ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielUsed in:  PY_LONG_LONG
563ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
573ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel**************************************************************************/
583ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
593ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
603ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* For backward compatibility only. Obsolete, do not use. */
613ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE_PROTOTYPES
623ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_PROTO(x) x
633ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else
643ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_PROTO(x) ()
653ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
663ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef Py_FPROTO
673ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_FPROTO(x) Py_PROTO(x)
683ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
693ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
703ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* typedefs for some C9X-defined synonyms for integral types.
713ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *
723ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * The names in Python are exactly the same as the C9X names, except with a
733ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Py_ prefix.  Until C9X is universally implemented, this is the only way
743ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * to ensure that Python gets reliable names that don't conflict with names
753ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * in non-Python code that are playing their own tricks to define the C9X
763ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * names.
773ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *
783ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * NOTE: don't go nuts here!  Python has no use for *most* of the C9X
793ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * integral synonyms.  Only define the ones we actually need.
803ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
813ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
823ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE_LONG_LONG
833ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef PY_LONG_LONG
843ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_LONG_LONG long long
853ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if defined(LLONG_MAX)
863ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* If LLONG_MAX is defined in limits.h, use that. */
873ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_LLONG_MIN LLONG_MIN
883ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_LLONG_MAX LLONG_MAX
893ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_ULLONG_MAX ULLONG_MAX
903ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#elif defined(__LONG_LONG_MAX__)
913ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Otherwise, if GCC has a builtin define, use that. */
923ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_LLONG_MAX __LONG_LONG_MAX__
933ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_LLONG_MIN (-PY_LLONG_MAX-1)
943ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_ULLONG_MAX (__LONG_LONG_MAX__*2ULL + 1ULL)
953ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else
963ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Otherwise, rely on two's complement. */
973ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_ULLONG_MAX (~0ULL)
983ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_LLONG_MAX  ((long long)(PY_ULLONG_MAX>>1))
993ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_LLONG_MIN (-PY_LLONG_MAX-1)
1003ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif /* LLONG_MAX */
1013ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
1023ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif /* HAVE_LONG_LONG */
1033ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
1043ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* a build with 30-bit digits for Python long integers needs an exact-width
1053ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * 32-bit unsigned integer type to store those digits.  (We could just use
1063ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * type 'unsigned long', but that would be wasteful on a system where longs
1073ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * are 64-bits.)  On Unix systems, the autoconf macro AC_TYPE_UINT32_T defines
1083ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * uint32_t to be such a type unless stdint.h or inttypes.h defines uint32_t.
1093ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * However, it doesn't set HAVE_UINT32_T, so we do that here.
1103ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
1113ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef uint32_t
1123ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define HAVE_UINT32_T 1
1133ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
1143ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
1153ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE_UINT32_T
1163ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef PY_UINT32_T
1173ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_UINT32_T uint32_t
1183ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
1193ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
1203ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
1213ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Macros for a 64-bit unsigned integer type; used for type 'twodigits' in the
1223ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * long integer implementation, when 30-bit digits are enabled.
1233ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
1243ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef uint64_t
1253ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define HAVE_UINT64_T 1
1263ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
1273ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
1283ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE_UINT64_T
1293ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef PY_UINT64_T
1303ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_UINT64_T uint64_t
1313ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
1323ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
1333ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
1343ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Signed variants of the above */
1353ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef int32_t
1363ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define HAVE_INT32_T 1
1373ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
1383ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
1393ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE_INT32_T
1403ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef PY_INT32_T
1413ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_INT32_T int32_t
1423ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
1433ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
1443ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
1453ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef int64_t
1463ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define HAVE_INT64_T 1
1473ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
1483ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
1493ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE_INT64_T
1503ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef PY_INT64_T
1513ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_INT64_T int64_t
1523ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
1533ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
1543ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
1553ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* If PYLONG_BITS_IN_DIGIT is not defined then we'll use 30-bit digits if all
1563ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   the necessary integer types are available, and we're on a 64-bit platform
1573ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   (as determined by SIZEOF_VOID_P); otherwise we use 15-bit digits. */
1583ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
1593ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef PYLONG_BITS_IN_DIGIT
1603ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if (defined HAVE_UINT64_T && defined HAVE_INT64_T && \
1613ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel     defined HAVE_UINT32_T && defined HAVE_INT32_T && SIZEOF_VOID_P >= 8)
1623ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PYLONG_BITS_IN_DIGIT 30
1633ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else
1643ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PYLONG_BITS_IN_DIGIT 15
1653ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
1663ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
1673ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
1683ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* uintptr_t is the C9X name for an unsigned integral type such that a
1693ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * legitimate void* can be cast to uintptr_t and then back to void* again
1703ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * without loss of information.  Similarly for intptr_t, wrt a signed
1713ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * integral type.
1723ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
1733ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE_UINTPTR_T
1743ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanieltypedef uintptr_t       Py_uintptr_t;
1753ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanieltypedef intptr_t        Py_intptr_t;
1763ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
1773ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#elif SIZEOF_VOID_P <= SIZEOF_INT
1783ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanieltypedef unsigned int    Py_uintptr_t;
1793ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanieltypedef int             Py_intptr_t;
1803ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
1813ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#elif SIZEOF_VOID_P <= SIZEOF_LONG
1823ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanieltypedef unsigned long   Py_uintptr_t;
1833ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanieltypedef long            Py_intptr_t;
1843ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
1853ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)
1863ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanieltypedef unsigned PY_LONG_LONG   Py_uintptr_t;
1873ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanieltypedef PY_LONG_LONG            Py_intptr_t;
1883ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
1893ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else
1903ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#   error "Python needs a typedef for Py_uintptr_t in pyport.h."
1913ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif /* HAVE_UINTPTR_T */
1923ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
1933ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==
1943ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * sizeof(size_t).  C99 doesn't define such a thing directly (size_t is an
1953ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * unsigned integral type).  See PEP 353 for details.
1963ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
1973ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE_SSIZE_T
1983ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanieltypedef ssize_t         Py_ssize_t;
1993ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#elif SIZEOF_VOID_P == SIZEOF_SIZE_T
2003ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanieltypedef Py_intptr_t     Py_ssize_t;
2013ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else
2023ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#   error "Python needs a typedef for Py_ssize_t in pyport.h."
2033ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
2043ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
2053ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Largest possible value of size_t.
2063ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   SIZE_MAX is part of C99, so it might be defined on some
2073ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   platforms. If it is not defined, (size_t)-1 is a portable
2083ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   definition for C89, due to the way signed->unsigned
2093ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   conversion is defined. */
2103ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef SIZE_MAX
2113ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_SIZE_MAX SIZE_MAX
2123ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else
2133ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_SIZE_MAX ((size_t)-1)
2143ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
2153ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
2163ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Largest positive value of type Py_ssize_t. */
2173ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
2183ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Smallest negative value of type Py_ssize_t. */
2193ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
2203ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
2213ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if SIZEOF_PID_T > SIZEOF_LONG
2223ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#   error "Python doesn't support sizeof(pid_t) > sizeof(long)"
2233ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
2243ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
2253ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf
2263ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * format to convert an argument with the width of a size_t or Py_ssize_t.
2273ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * C99 introduced "z" for this purpose, but not all platforms support that;
2283ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * e.g., MS compilers use "I" instead.
2293ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *
2303ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * These "high level" Python format functions interpret "z" correctly on
2313ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * all platforms (Python interprets the format string itself, and does whatever
2323ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * the platform C requires to convert a size_t/Py_ssize_t argument):
2333ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *
2343ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *     PyString_FromFormat
2353ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *     PyErr_Format
2363ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *     PyString_FromFormatV
2373ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *
2383ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Lower-level uses require that you interpolate the correct format modifier
2393ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for
2403ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * example,
2413ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *
2423ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *     Py_ssize_t index;
2433ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *     fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index);
2443ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *
2453ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * That will expand to %ld, or %Id, or to something else correct for a
2463ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Py_ssize_t on the platform.
2473ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
2483ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef PY_FORMAT_SIZE_T
2493ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#   if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__)
2503ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       define PY_FORMAT_SIZE_T ""
2513ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#   elif SIZEOF_SIZE_T == SIZEOF_LONG
2523ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       define PY_FORMAT_SIZE_T "l"
2533ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#   elif defined(MS_WINDOWS)
2543ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       define PY_FORMAT_SIZE_T "I"
2553ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#   else
2563ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T"
2573ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#   endif
2583ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
2593ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
2603ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* PY_FORMAT_LONG_LONG is analogous to PY_FORMAT_SIZE_T above, but for
2613ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * the long long type instead of the size_t type.  It's only available
2623ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * when HAVE_LONG_LONG is defined. The "high level" Python format
2633ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * functions listed above will interpret "lld" or "llu" correctly on
2643ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * all platforms.
2653ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
2663ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE_LONG_LONG
2673ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#   ifndef PY_FORMAT_LONG_LONG
2683ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       if defined(MS_WIN64) || defined(MS_WINDOWS)
2693ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#           define PY_FORMAT_LONG_LONG "I64"
2703ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       else
2713ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#           error "This platform's pyconfig.h needs to define PY_FORMAT_LONG_LONG"
2723ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       endif
2733ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#   endif
2743ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
2753ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
2763ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Py_LOCAL can be used instead of static to get the fastest possible calling
2773ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * convention for functions that are local to a given module.
2783ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *
2793ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining,
2803ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * for platforms that support that.
2813ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *
2823ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * If PY_LOCAL_AGGRESSIVE is defined before python.h is included, more
2833ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * "aggressive" inlining/optimizaion is enabled for the entire module.  This
2843ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * may lead to code bloat, and may slow things down for those reasons.  It may
2853ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * also lead to errors, if the code relies on pointer aliasing.  Use with
2863ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * care.
2873ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *
2883ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * NOTE: You can only use this for functions that are entirely local to a
2893ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * module; functions that are exported via method tables, callbacks, etc,
2903ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * should keep using static.
2913ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
2923ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
2933ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#undef USE_INLINE /* XXX - set via configure? */
2943ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
2953ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if defined(_MSC_VER)
2963ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if defined(PY_LOCAL_AGGRESSIVE)
2973ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* enable more aggressive optimization for visual studio */
2983ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel//#pragma optimize("agtw", on)
2993ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#pragma optimize("gt", on)    // a and w are not legal for VS2005
3003ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
3013ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* ignore warnings if the compiler decides not to inline a function */
3023ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#pragma warning(disable: 4710)
3033ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* fastest possible local call under MSVC */
3043ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_LOCAL(type) static type __fastcall
3053ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_LOCAL_INLINE(type) static __inline type __fastcall
3063ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#elif defined(USE_INLINE)
3073ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_LOCAL(type) static type
3083ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_LOCAL_INLINE(type) static inline type
3093ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else
3103ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_LOCAL(type) static type
3113ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_LOCAL_INLINE(type) static type
3123ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
3133ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
3143ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Py_MEMCPY can be used instead of memcpy in cases where the copied blocks
3153ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * are often very short.  While most platforms have highly optimized code for
3163ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * large transfers, the setup costs for memcpy are often quite high.  MEMCPY
3173ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * solves this by doing short copies "in line".
3183ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
3193ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
3203ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if defined(_MSC_VER)
3213ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_MEMCPY(target, source, length) do {                          \
3223ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        size_t i_, n_ = (length);                                       \
3233ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        char *t_ = (void*) (target);                                    \
3243ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        const char *s_ = (void*) (source);                              \
3253ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        if (n_ >= 16)                                                   \
3263ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel            memcpy(t_, s_, n_);                                         \
3273ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        else                                                            \
3283ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel            for (i_ = 0; i_ < n_; i_++)                                 \
3293ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel                t_[i_] = s_[i_];                                        \
3303ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    } while (0)
3313ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else
3323ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_MEMCPY memcpy
3333ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
3343ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
3353ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <stdlib.h>
3363ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
3373ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE_IEEEFP_H
3383ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <ieeefp.h>  /* needed for 'finite' declaration on some platforms */
3393ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
3403ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
3413ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <math.h> /* Moved here from the math section, before extern "C" */
3423ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
3433ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/********************************************
3443ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * WRAPPER FOR <time.h> and/or <sys/time.h> *
3453ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel ********************************************/
3463ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
3473ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef TIME_WITH_SYS_TIME
3483ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <sys/time.h>
3493ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <time.h>
3503ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else /* !TIME_WITH_SYS_TIME */
3513ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE_SYS_TIME_H
3523ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <sys/time.h>
3533ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else /* !HAVE_SYS_TIME_H */
3543ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <time.h>
3553ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif /* !HAVE_SYS_TIME_H */
3563ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif /* !TIME_WITH_SYS_TIME */
3573ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
3583ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
3593ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/******************************
3603ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * WRAPPER FOR <sys/select.h> *
3613ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel ******************************/
3623ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
3633ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* NB caller must include <sys/types.h> */
3643ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
3653ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE_SYS_SELECT_H
3663ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
3673ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <sys/select.h>
3683ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
3693ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif /* !HAVE_SYS_SELECT_H */
3703ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
3713ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/*******************************
3723ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * stat() and fstat() fiddling *
3733ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *******************************/
3743ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
3753ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* We expect that stat and fstat exist on most systems.
3763ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *  It's confirmed on Unix, Mac and Windows.
3773ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *  If you don't have them, add
3783ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *      #define DONT_HAVE_STAT
3793ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * and/or
3803ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *      #define DONT_HAVE_FSTAT
3813ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * to your pyconfig.h. Python code beyond this should check HAVE_STAT and
3823ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * HAVE_FSTAT instead.
3833ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Also
3843ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *      #define HAVE_SYS_STAT_H
3853ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * if <sys/stat.h> exists on your platform, and
3863ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *      #define HAVE_STAT_H
3873ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * if <stat.h> does.
3883ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
3893ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef DONT_HAVE_STAT
3903ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define HAVE_STAT
3913ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
3923ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
3933ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef DONT_HAVE_FSTAT
3943ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define HAVE_FSTAT
3953ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
3963ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
3973ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef RISCOS
3983ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <sys/types.h>
3993ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include "unixstuff.h"
4003ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
4013ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
4023ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE_SYS_STAT_H
4033ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if defined(PYOS_OS2) && defined(PYCC_GCC)
4043ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <sys/types.h>
4053ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
4063ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <sys/stat.h>
4073ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#elif defined(HAVE_STAT_H)
4083ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <stat.h>
4093ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
4103ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
4113ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if defined(PYCC_VACPP)
4123ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */
4133ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define S_IFMT (S_IFDIR|S_IFCHR|S_IFREG)
4143ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
4153ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
4163ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef S_ISREG
4173ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
4183ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
4193ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
4203ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef S_ISDIR
4213ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
4223ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
4233ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
4243ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
4253ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef __cplusplus
4263ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Move this down here since some C++ #include's don't like to be included
4273ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   inside an extern "C" */
4283ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielextern "C" {
4293ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
4303ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
4313ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
4323ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Py_ARITHMETIC_RIGHT_SHIFT
4333ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * C doesn't define whether a right-shift of a signed integer sign-extends
4343ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * or zero-fills.  Here a macro to force sign extension:
4353ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
4363ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    Return I >> J, forcing sign extension.  Arithmetically, return the
4373ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    floor of I/2**J.
4383ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Requirements:
4393ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    I should have signed integer type.  In the terminology of C99, this can
4403ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    be either one of the five standard signed integer types (signed char,
4413ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    short, int, long, long long) or an extended signed integer type.
4423ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    J is an integer >= 0 and strictly less than the number of bits in the
4433ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    type of I (because C doesn't define what happens for J outside that
4443ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    range either).
4453ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    TYPE used to specify the type of I, but is now ignored.  It's been left
4463ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    in for backwards compatibility with versions <= 2.6 or 3.0.
4473ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Caution:
4483ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    I may be evaluated more than once.
4493ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
4503ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
4513ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
4523ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))
4533ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else
4543ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
4553ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
4563ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
4573ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Py_FORCE_EXPANSION(X)
4583ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * "Simply" returns its argument.  However, macro expansions within the
4593ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * argument are evaluated.  This unfortunate trickery is needed to get
4603ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * token-pasting to work as desired in some cases.
4613ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
4623ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_FORCE_EXPANSION(X) X
4633ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
4643ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW)
4653ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Cast VALUE to type NARROW from type WIDE.  In Py_DEBUG mode, this
4663ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * assert-fails if any information is lost.
4673ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Caution:
4683ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    VALUE may be evaluated more than once.
4693ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
4703ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef Py_DEBUG
4713ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
4723ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE))
4733ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else
4743ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
4753ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
4763ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
4773ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Py_SET_ERRNO_ON_MATH_ERROR(x)
4783ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * If a libm function did not set errno, but it looks like the result
4793ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * overflowed or not-a-number, set errno to ERANGE or EDOM.  Set errno
4803ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * to 0 before calling a libm function, and invoke this macro after,
4813ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * passing the function result.
4823ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Caution:
4833ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    This isn't reliable.  See Py_OVERFLOWED comments.
4843ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    X is evaluated more than once.
4853ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
4863ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64))
4873ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM;
4883ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else
4893ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define _Py_SET_EDOM_FOR_NAN(X) ;
4903ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
4913ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_SET_ERRNO_ON_MATH_ERROR(X) \
4923ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    do { \
4933ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        if (errno == 0) { \
4943ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel            if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
4953ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel                errno = ERANGE; \
4963ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel            else _Py_SET_EDOM_FOR_NAN(X) \
4973ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        } \
4983ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    } while(0)
4993ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
5003ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Py_SET_ERANGE_ON_OVERFLOW(x)
5013ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility.
5023ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
5033ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X)
5043ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
5053ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Py_ADJUST_ERANGE1(x)
5063ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Py_ADJUST_ERANGE2(x, y)
5073ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Set errno to 0 before calling a libm function, and invoke one of these
5083ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * macros after, passing the function result(s) (Py_ADJUST_ERANGE2 is useful
5093ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * for functions returning complex results).  This makes two kinds of
5103ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * adjustments to errno:  (A) If it looks like the platform libm set
5113ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * errno=ERANGE due to underflow, clear errno. (B) If it looks like the
5123ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * platform libm overflowed but didn't set errno, force errno to ERANGE.  In
5133ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * effect, we're trying to force a useful implementation of C89 errno
5143ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * behavior.
5153ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Caution:
5163ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    This isn't reliable.  See Py_OVERFLOWED comments.
5173ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    X and Y may be evaluated more than once.
5183ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
5193ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_ADJUST_ERANGE1(X)                                            \
5203ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    do {                                                                \
5213ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        if (errno == 0) {                                               \
5223ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel            if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL)              \
5233ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel                errno = ERANGE;                                         \
5243ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        }                                                               \
5253ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        else if (errno == ERANGE && (X) == 0.0)                         \
5263ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel            errno = 0;                                                  \
5273ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    } while(0)
5283ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
5293ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_ADJUST_ERANGE2(X, Y)                                         \
5303ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    do {                                                                \
5313ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL ||                \
5323ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel            (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) {                \
5333ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel                        if (errno == 0)                                 \
5343ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel                                errno = ERANGE;                         \
5353ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        }                                                               \
5363ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        else if (errno == ERANGE)                                       \
5373ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel            errno = 0;                                                  \
5383ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    } while(0)
5393ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
5403ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/*  The functions _Py_dg_strtod and _Py_dg_dtoa in Python/dtoa.c (which are
5413ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *  required to support the short float repr introduced in Python 3.1) require
5423ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *  that the floating-point unit that's being used for arithmetic operations
5433ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *  on C doubles is set to use 53-bit precision.  It also requires that the
5443ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *  FPU rounding mode is round-half-to-even, but that's less often an issue.
5453ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *
5463ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *  If your FPU isn't already set to 53-bit precision/round-half-to-even, and
5473ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *  you want to make use of _Py_dg_strtod and _Py_dg_dtoa, then you should
5483ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *
5493ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *     #define HAVE_PY_SET_53BIT_PRECISION 1
5503ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *
5513ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *  and also give appropriate definitions for the following three macros:
5523ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *
5533ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    _PY_SET_53BIT_PRECISION_START : store original FPU settings, and
5543ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *        set FPU to 53-bit precision/round-half-to-even
5553ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    _PY_SET_53BIT_PRECISION_END : restore original FPU settings
5563ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    _PY_SET_53BIT_PRECISION_HEADER : any variable declarations needed to
5573ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *        use the two macros above.
5583ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *
5593ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * The macros are designed to be used within a single C function: see
5603ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Python/pystrtod.c for an example of their use.
5613ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
5623ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
5633ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* get and set x87 control word for gcc/x86 */
5643ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE_GCC_ASM_FOR_X87
5653ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define HAVE_PY_SET_53BIT_PRECISION 1
5663ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* _Py_get/set_387controlword functions are defined in Python/pymath.c */
5673ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define _Py_SET_53BIT_PRECISION_HEADER                          \
5683ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    unsigned short old_387controlword, new_387controlword
5693ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define _Py_SET_53BIT_PRECISION_START                                   \
5703ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    do {                                                                \
5713ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        old_387controlword = _Py_get_387controlword();                  \
5723ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        new_387controlword = (old_387controlword & ~0x0f00) | 0x0200; \
5733ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        if (new_387controlword != old_387controlword)                   \
5743ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel            _Py_set_387controlword(new_387controlword);                 \
5753ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    } while (0)
5763ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define _Py_SET_53BIT_PRECISION_END                             \
5773ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    if (new_387controlword != old_387controlword)               \
5783ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        _Py_set_387controlword(old_387controlword)
5793ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
5803ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
5813ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* get and set x87 control word for VisualStudio/x86 */
5823ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if defined(_MSC_VER) && !defined(_WIN64) && !defined(UEFI_C_SOURCE) /* x87 not supported in 64-bit */
5833ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define HAVE_PY_SET_53BIT_PRECISION 1
5843ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define _Py_SET_53BIT_PRECISION_HEADER \
5853ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    unsigned int old_387controlword, new_387controlword, out_387controlword
5863ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* We use the __control87_2 function to set only the x87 control word.
5873ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   The SSE control word is unaffected. */
5883ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define _Py_SET_53BIT_PRECISION_START                                   \
5893ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    do {                                                                \
5903ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        __control87_2(0, 0, &old_387controlword, NULL);                 \
5913ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        new_387controlword =                                            \
5923ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel          (old_387controlword & ~(_MCW_PC | _MCW_RC)) | (_PC_53 | _RC_NEAR); \
5933ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        if (new_387controlword != old_387controlword)                   \
5943ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel            __control87_2(new_387controlword, _MCW_PC | _MCW_RC,        \
5953ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel                          &out_387controlword, NULL);                   \
5963ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    } while (0)
5973ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define _Py_SET_53BIT_PRECISION_END                                     \
5983ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    do {                                                                \
5993ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        if (new_387controlword != old_387controlword)                   \
6003ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel            __control87_2(old_387controlword, _MCW_PC | _MCW_RC,        \
6013ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel                          &out_387controlword, NULL);                   \
6023ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    } while (0)
6033ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
6043ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
6053ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* default definitions are empty */
6063ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef HAVE_PY_SET_53BIT_PRECISION
6073ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define _Py_SET_53BIT_PRECISION_HEADER
6083ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define _Py_SET_53BIT_PRECISION_START
6093ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define _Py_SET_53BIT_PRECISION_END
6103ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
6113ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
6123ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* If we can't guarantee 53-bit precision, don't use the code
6133ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   in Python/dtoa.c, but fall back to standard code.  This
6143ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   means that repr of a float will be long (17 sig digits).
6153ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
6163ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   Realistically, there are two things that could go wrong:
6173ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
6183ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   (1) doubles aren't IEEE 754 doubles, or
6193ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   (2) we're on x86 with the rounding precision set to 64-bits
6203ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel       (extended precision), and we don't know how to change
6213ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel       the rounding precision.
6223ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
6233ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
6243ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if !defined(DOUBLE_IS_LITTLE_ENDIAN_IEEE754) && \
6253ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    !defined(DOUBLE_IS_BIG_ENDIAN_IEEE754) && \
6263ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    !defined(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754)
6273ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_NO_SHORT_FLOAT_REPR
6283ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
6293ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
6303ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* double rounding is symptomatic of use of extended precision on x86.  If
6313ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   we're seeing double rounding, and we don't have any mechanism available for
6323ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   changing the FPU rounding precision, then don't use Python/dtoa.c. */
6333ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if defined(X87_DOUBLE_ROUNDING) && !defined(HAVE_PY_SET_53BIT_PRECISION)
6343ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define PY_NO_SHORT_FLOAT_REPR
6353ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
6363ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
6373ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Py_DEPRECATED(version)
6383ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Declare a variable, type, or function deprecated.
6393ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Usage:
6403ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    extern int old_var Py_DEPRECATED(2.3);
6413ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    typedef int T1 Py_DEPRECATED(2.4);
6423ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel *    extern int x() Py_DEPRECATED(2.5);
6433ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
6443ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if defined(__GNUC__) && ((__GNUC__ >= 4) || \
6453ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel              (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
6463ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
6473ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else
6483ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_DEPRECATED(VERSION_UNUSED)
6493ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
6503ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
6513ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/**************************************************************************
6523ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielPrototypes that are missing from the standard include files on some systems
6533ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel(and possibly only some versions of such systems.)
6543ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
6553ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielPlease be conservative with adding new ones, document them and enclose them
6563ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielin platform-specific #ifdefs.
6573ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel**************************************************************************/
6583ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
6593ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef SOLARIS
6603ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Unchecked */
6613ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielextern int gethostname(char *, int);
6623ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
6633ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
6643ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef __BEOS__
6653ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Unchecked */
6663ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* It's in the libs, but not the headers... - [cjh] */
6673ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielint shutdown( int, int );
6683ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
6693ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
6703ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE__GETPTY
6713ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <sys/types.h>          /* we need to import mode_t */
6723ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielextern char * _getpty(int *, int, mode_t, int);
6733ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
6743ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
6753ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* On QNX 6, struct termio must be declared by including sys/termio.h
6763ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   if TCGETA, TCSETA, TCSETAW, or TCSETAF are used.  sys/termio.h must
6773ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   be included before termios.h or it will generate an error. */
6783ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if defined(HAVE_SYS_TERMIO_H) && !defined(__hpux)
6793ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <sys/termio.h>
6803ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
6813ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
6823ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)
6833ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) && !defined(HAVE_UTIL_H)
6843ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* BSDI does not supply a prototype for the 'openpty' and 'forkpty'
6853ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   functions, even though they are included in libutil. */
6863ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <termios.h>
6873ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielextern int openpty(int *, int *, char *, struct termios *, struct winsize *);
6883ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielextern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
6893ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */
6903ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */
6913ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
6923ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
6933ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* These are pulled from various places. It isn't obvious on what platforms
6943ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   they are necessary, nor what the exact prototype should look like (which
6953ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   is likely to vary between platforms!) If you find you need one of these
6963ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   declarations, please move them to a platform-specific block and include
6973ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   proper prototypes. */
6983ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if 0
6993ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
7003ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* From Modules/resource.c */
7013ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielextern int getrusage();
7023ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielextern int getpagesize();
7033ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
7043ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* From Python/sysmodule.c and Modules/posixmodule.c */
7053ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielextern int fclose(FILE *);
7063ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
7073ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* From Modules/posixmodule.c */
7083ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanielextern int fdatasync(int);
7093ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif /* 0 */
7103ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
7113ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
7123ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* On 4.4BSD-descendants, ctype functions serves the whole range of
7133ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * wchar_t character set rather than single byte code points only.
7143ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * This characteristic can break some operations of string object
7153ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * including str.upper() and str.split() on UTF-8 locales.  This
7163ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * workaround was provided by Tim Robbins of FreeBSD project.
7173ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
7183ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
7193ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef __FreeBSD__
7203ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <osreldate.h>
7213ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if __FreeBSD_version > 500039
7223ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel# define _PY_PORT_CTYPE_UTF8_ISSUE
7233ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
7243ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
7253ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
7263ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
7273ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if defined(__APPLE__)
7283ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel# define _PY_PORT_CTYPE_UTF8_ISSUE
7293ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
7303ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
7313ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef _PY_PORT_CTYPE_UTF8_ISSUE
7323ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <ctype.h>
7333ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#include <wctype.h>
7343ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#undef isalnum
7353ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define isalnum(c) iswalnum(btowc(c))
7363ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#undef isalpha
7373ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define isalpha(c) iswalpha(btowc(c))
7383ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#undef islower
7393ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define islower(c) iswlower(btowc(c))
7403ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#undef isspace
7413ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define isspace(c) iswspace(btowc(c))
7423ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#undef isupper
7433ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define isupper(c) iswupper(btowc(c))
7443ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#undef tolower
7453ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define tolower(c) towlower(btowc(c))
7463ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#undef toupper
7473ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define toupper(c) towupper(btowc(c))
7483ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
7493ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
7503ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
7513ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Declarations for symbol visibility.
7523ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
7533ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  PyAPI_FUNC(type): Declares a public Python API function and return type
7543ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  PyAPI_DATA(type): Declares public Python data and its type
7553ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  PyMODINIT_FUNC:   A Python module init function.  If these functions are
7563ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel                    inside the Python core, they are private to the core.
7573ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel                    If in an extension module, it may be declared with
7583ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel                    external linkage depending on the platform.
7593ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
7603ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  As a number of platforms support/require "__declspec(dllimport/dllexport)",
7613ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  we support a HAVE_DECLSPEC_DLL macro to save duplication.
7623ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel*/
7633ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
7643ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/*
7653ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  All windows ports, except cygwin, are handled in PC/pyconfig.h.
7663ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
7673ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  BeOS and cygwin are the only other autoconf platform requiring special
7683ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel  linkage handling and both of these use __declspec().
7693ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel*/
7703ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if defined(__CYGWIN__) || defined(__BEOS__)
7713ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       define HAVE_DECLSPEC_DLL
7723ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
7733ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
7743ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* only get special linkage if built as shared or platform is Cygwin */
7753ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
7763ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       if defined(HAVE_DECLSPEC_DLL)
7773ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#               ifdef Py_BUILD_CORE
7783ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#                       define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
7793ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#                       define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE
7803ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        /* module init functions inside the core need no external linkage */
7813ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        /* except for Cygwin to handle embedding (FIXME: BeOS too?) */
7823ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#                       if defined(__CYGWIN__)
7833ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#                               define PyMODINIT_FUNC __declspec(dllexport) void
7843ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#                       else /* __CYGWIN__ */
7853ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#                               define PyMODINIT_FUNC void
7863ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#                       endif /* __CYGWIN__ */
7873ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#               else /* Py_BUILD_CORE */
7883ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        /* Building an extension module, or an embedded situation */
7893ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        /* public Python functions and data are imported */
7903ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        /* Under Cygwin, auto-import functions to prevent compilation */
7913ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        /* failures similar to those described at the bottom of 4.1: */
7923ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        /* http://docs.python.org/extending/windows.html#a-cookbook-approach */
7933ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#                       if !defined(__CYGWIN__)
7943ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#                               define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
7953ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#                       endif /* !__CYGWIN__ */
7963ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#                       define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
7973ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel        /* module init functions outside the core must be exported */
7983ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#                       if defined(__cplusplus)
7993ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#                               define PyMODINIT_FUNC extern "C" __declspec(dllexport) void
8003ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#                       else /* __cplusplus */
8013ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#                               define PyMODINIT_FUNC __declspec(dllexport) void
8023ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#                       endif /* __cplusplus */
8033ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#               endif /* Py_BUILD_CORE */
8043ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       endif /* HAVE_DECLSPEC */
8053ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif /* Py_ENABLE_SHARED */
8063ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8073ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* If no external linkage macros defined by now, create defaults */
8083ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef PyAPI_FUNC
8093ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       define PyAPI_FUNC(RTYPE) RTYPE
8103ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
8113ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef PyAPI_DATA
8123ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       define PyAPI_DATA(RTYPE) extern RTYPE
8133ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
8143ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef PyMODINIT_FUNC
8153ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       if defined(__cplusplus)
8163ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#               define PyMODINIT_FUNC extern "C" void
8173ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       else /* __cplusplus */
8183ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#               define PyMODINIT_FUNC void
8193ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       endif /* __cplusplus */
8203ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
8213ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8223ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Deprecated DL_IMPORT and DL_EXPORT macros */
8233ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if defined(Py_ENABLE_SHARED) && defined (HAVE_DECLSPEC_DLL)
8243ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       if defined(Py_BUILD_CORE)
8253ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#               define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE
8263ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#               define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
8273ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       else
8283ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#               define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE
8293ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#               define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
8303ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       endif
8313ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
8323ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef DL_EXPORT
8333ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       define DL_EXPORT(RTYPE) RTYPE
8343ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
8353ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef DL_IMPORT
8363ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#       define DL_IMPORT(RTYPE) RTYPE
8373ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
8383ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* End of deprecated DL_* macros */
8393ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8403ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* If the fd manipulation macros aren't defined,
8413ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel   here is a set that should do the job */
8423ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8433ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if 0 /* disabled and probably obsolete */
8443ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8453ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef FD_SETSIZE
8463ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define FD_SETSIZE      256
8473ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
8483ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8493ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef FD_SET
8503ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8513ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanieltypedef long fd_mask;
8523ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8533ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define NFDBITS (sizeof(fd_mask) * NBBY)        /* bits per mask */
8543ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef howmany
8553ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define howmany(x, y)   (((x)+((y)-1))/(y))
8563ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif /* howmany */
8573ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8583ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDanieltypedef struct fd_set {
8593ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    fd_mask     fds_bits[howmany(FD_SETSIZE, NFDBITS)];
8603ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel} fd_set;
8613ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8623ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
8633ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
8643ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
8653ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define FD_ZERO(p)      memset((char *)(p), '\0', sizeof(*(p)))
8663ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8673ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif /* FD_SET */
8683ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8693ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif /* fd manipulation macros */
8703ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8713ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8723ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* limits.h constants that may be missing */
8733ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8743ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef INT_MAX
8753ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define INT_MAX 2147483647
8763ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
8773ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8783ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef LONG_MAX
8793ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if SIZEOF_LONG == 4
8803ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define LONG_MAX 0X7FFFFFFFL
8813ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#elif SIZEOF_LONG == 8
8823ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define LONG_MAX 0X7FFFFFFFFFFFFFFFL
8833ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else
8843ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#error "could not set LONG_MAX in pyport.h"
8853ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
8863ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
8873ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8883ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef LONG_MIN
8893ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define LONG_MIN (-LONG_MAX-1)
8903ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
8913ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8923ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef LONG_BIT
8933ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define LONG_BIT (8 * SIZEOF_LONG)
8943ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
8953ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
8963ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if LONG_BIT != 8 * SIZEOF_LONG
8973ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent
8983ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * 32-bit platforms using gcc.  We try to catch that here at compile-time
8993ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * rather than waiting for integer multiplication to trigger bogus
9003ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * overflows.
9013ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
9023ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
9033ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
9043ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
9053ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef __cplusplus
9063ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel}
9073ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
9083ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
9093ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/*
9103ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Hide GCC attributes from compilers that don't support them.
9113ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
9123ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if (!defined(__GNUC__) || __GNUC__ < 2 || \
9133ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel     (__GNUC__ == 2 && __GNUC_MINOR__ < 7) ) && \
9143ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel    !defined(RISCOS)
9153ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_GCC_ATTRIBUTE(x)
9163ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else
9173ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_GCC_ATTRIBUTE(x) __attribute__(x)
9183ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
9193ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
9203ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/*
9213ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Add PyArg_ParseTuple format where available.
9223ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
9233ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef HAVE_ATTRIBUTE_FORMAT_PARSETUPLE
9243ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_FORMAT_PARSETUPLE(func,p1,p2) __attribute__((format(func,p1,p2)))
9253ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else
9263ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_FORMAT_PARSETUPLE(func,p1,p2)
9273ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
9283ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
9293ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/*
9303ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Specify alignment on compilers that support it.
9313ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
9323ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#if defined(__GNUC__) && __GNUC__ >= 3
9333ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_ALIGNED(x) __attribute__((aligned(x)))
9343ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#else
9353ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_ALIGNED(x)
9363ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
9373ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
9383ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/* Eliminate end-of-loop code not reached warnings from SunPro C
9393ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * when using do{...}while(0) macros
9403ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
9413ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifdef __SUNPRO_C
9423ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)
9433ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
9443ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
9453ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel/*
9463ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * Older Microsoft compilers don't support the C99 long long literal suffixes,
9473ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel * so these will be defined in PC/pyconfig.h for those compilers.
9483ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel */
9493ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef Py_LL
9503ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_LL(x) x##LL
9513ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
9523ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
9533ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#ifndef Py_ULL
9543ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#define Py_ULL(x) Py_LL(x##U)
9553ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif
9563ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel
9573ec97ca490009ed5604ccd7f2653e5a9ecbf3474Daryl McDaniel#endif /* Py_PYPORT_H */
958