blob: df97b999ac5af2dad09b7bc6835920cf8fb707aa [file] [log] [blame]
Tim Peters7d3a5112000-07-08 04:17:21 +00001#ifndef Py_PYPORT_H
Vladimir Marangozov14a4d882000-07-10 04:59:49 +00002#define Py_PYPORT_H
Tim Peters7d3a5112000-07-08 04:17:21 +00003
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +00004#include "pyconfig.h" /* include for defines */
Peter Schneider-Kamp25f68942000-07-31 22:19:30 +00005
Tim Peters7d3a5112000-07-08 04:17:21 +00006/**************************************************************************
7Symbols and macros to supply platform-independent interfaces to basic
Tim Peters1be46842000-07-23 18:10:18 +00008C language & library operations whose spellings vary across platforms.
Tim Peters7d3a5112000-07-08 04:17:21 +00009
10Please try to make documentation here as clear as possible: by definition,
11the stuff here is trying to illuminate C's darkest corners.
12
13Config #defines referenced here:
14
15SIGNED_RIGHT_SHIFT_ZERO_FILLS
16Meaning: To be defined iff i>>j does not extend the sign bit when i is a
17 signed integral type and i < 0.
18Used in: Py_ARITHMETIC_RIGHT_SHIFT
Tim Peters1be46842000-07-23 18:10:18 +000019
Tim Peters8315ea52000-07-23 19:28:35 +000020Py_DEBUG
21Meaning: Extra checks compiled in for debug mode.
22Used in: Py_SAFE_DOWNCAST
Barry Warsawfd847b22000-08-18 04:48:18 +000023
24HAVE_UINTPTR_T
25Meaning: The C9X type uintptr_t is supported by the compiler
26Used in: Py_uintptr_t
27
28HAVE_LONG_LONG
29Meaning: The compiler supports the C type "long long"
Martin v. Löwisb9a0f912003-03-29 10:06:18 +000030Used in: PY_LONG_LONG
Barry Warsawfd847b22000-08-18 04:48:18 +000031
Tim Peters7d3a5112000-07-08 04:17:21 +000032**************************************************************************/
33
34
Vladimir Marangozove2bf7e62000-09-08 12:55:35 +000035/* For backward compatibility only. Obsolete, do not use. */
Vladimir Marangozove2bf7e62000-09-08 12:55:35 +000036#ifdef HAVE_PROTOTYPES
37#define Py_PROTO(x) x
38#else
39#define Py_PROTO(x) ()
40#endif
Marc-André Lemburg77317ca2000-10-05 17:25:45 +000041#ifndef Py_FPROTO
42#define Py_FPROTO(x) Py_PROTO(x)
43#endif
Peter Schneider-Kamp7e018902000-07-31 15:28:04 +000044
Barry Warsawfd847b22000-08-18 04:48:18 +000045/* typedefs for some C9X-defined synonyms for integral types.
46 *
47 * The names in Python are exactly the same as the C9X names, except with a
48 * Py_ prefix. Until C9X is universally implemented, this is the only way
49 * to ensure that Python gets reliable names that don't conflict with names
50 * in non-Python code that are playing their own tricks to define the C9X
51 * names.
52 *
53 * NOTE: don't go nuts here! Python has no use for *most* of the C9X
54 * integral synonyms. Only define the ones we actually need.
55 */
56
57#ifdef HAVE_LONG_LONG
Martin v. Löwisb9a0f912003-03-29 10:06:18 +000058#ifndef PY_LONG_LONG
59#define PY_LONG_LONG long long
Barry Warsawfd847b22000-08-18 04:48:18 +000060#endif
61#endif /* HAVE_LONG_LONG */
62
63/* uintptr_t is the C9X name for an unsigned integral type such that a
64 * legitimate void* can be cast to uintptr_t and then back to void* again
Tim Peters79248aa2001-08-29 21:37:10 +000065 * without loss of information. Similarly for intptr_t, wrt a signed
66 * integral type.
Barry Warsawfd847b22000-08-18 04:48:18 +000067 */
68#ifdef HAVE_UINTPTR_T
Tim Peters79248aa2001-08-29 21:37:10 +000069typedef uintptr_t Py_uintptr_t;
70typedef intptr_t Py_intptr_t;
71
Barry Warsawfd847b22000-08-18 04:48:18 +000072#elif SIZEOF_VOID_P <= SIZEOF_INT
Tim Peters79248aa2001-08-29 21:37:10 +000073typedef unsigned int Py_uintptr_t;
74typedef int Py_intptr_t;
75
Barry Warsawfd847b22000-08-18 04:48:18 +000076#elif SIZEOF_VOID_P <= SIZEOF_LONG
Tim Peters79248aa2001-08-29 21:37:10 +000077typedef unsigned long Py_uintptr_t;
78typedef long Py_intptr_t;
79
Barry Warsawfd847b22000-08-18 04:48:18 +000080#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)
Martin v. Löwisb9a0f912003-03-29 10:06:18 +000081typedef unsigned PY_LONG_LONG Py_uintptr_t;
82typedef PY_LONG_LONG Py_intptr_t;
Tim Peters79248aa2001-08-29 21:37:10 +000083
Barry Warsawfd847b22000-08-18 04:48:18 +000084#else
85# error "Python needs a typedef for Py_uintptr_t in pyport.h."
86#endif /* HAVE_UINTPTR_T */
87
Tim Petersae1d0c92006-03-17 03:29:34 +000088/* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==
89 * sizeof(size_t). C99 doesn't define such a thing directly (size_t is an
90 * unsigned integral type). See PEP 353 for details.
91 */
Martin v. Löwis18e16552006-02-15 17:27:45 +000092#ifdef HAVE_SSIZE_T
93typedef ssize_t Py_ssize_t;
94#elif SIZEOF_VOID_P == SIZEOF_SIZE_T
Martin v. Löwis2d65b552006-02-18 18:26:55 +000095typedef Py_intptr_t Py_ssize_t;
Martin v. Löwis18e16552006-02-15 17:27:45 +000096#else
97# error "Python needs a typedef for Py_ssize_t in pyport.h."
98#endif
Tim Petersae1d0c92006-03-17 03:29:34 +000099
100/* Largest positive value of type Py_ssize_t. */
Martin v. Löwis18e16552006-02-15 17:27:45 +0000101#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
102
Tim Petersae1d0c92006-03-17 03:29:34 +0000103/* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf
104 * format to convert an argument with the width of a size_t or Py_ssize_t.
105 * C99 introduced "z" for this purpose, but not all platforms support that;
106 * e.g., MS compilers use "I" instead.
107 *
108 * These "high level" Python format functions interpret "z" correctly on
109 * all platforms (Python interprets the format string itself, and does whatever
110 * the platform C requires to convert a size_t/Py_ssize_t argument):
111 *
112 * PyString_FromFormat
113 * PyErr_Format
114 * PyString_FromFormatV
115 *
116 * Lower-level uses require that you interpolate the correct format modifier
117 * yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for
118 * example,
119 *
120 * Py_ssize_t index;
121 * fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index);
122 *
123 * That will expand to %ld, or %Id, or to something else correct for a
124 * Py_ssize_t on the platform.
125 */
126#ifndef PY_FORMAT_SIZE_T
127# if SIZEOF_SIZE_T == SIZEOF_LONG
128# define PY_FORMAT_SIZE_T "l"
129# elif defined(MS_WINDOWS)
130# define PY_FORMAT_SIZE_T "I"
131# else
132# error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T"
133# endif
134#endif
135
Peter Schneider-Kamp7e018902000-07-31 15:28:04 +0000136#include <stdlib.h>
Peter Schneider-Kamp7e018902000-07-31 15:28:04 +0000137
Vladimir Marangozov2c57e072000-08-11 11:48:33 +0000138#include <math.h> /* Moved here from the math section, before extern "C" */
139
140/********************************************
141 * WRAPPER FOR <time.h> and/or <sys/time.h> *
142 ********************************************/
143
144#ifdef TIME_WITH_SYS_TIME
145#include <sys/time.h>
146#include <time.h>
147#else /* !TIME_WITH_SYS_TIME */
148#ifdef HAVE_SYS_TIME_H
149#include <sys/time.h>
150#else /* !HAVE_SYS_TIME_H */
151#include <time.h>
152#endif /* !HAVE_SYS_TIME_H */
153#endif /* !TIME_WITH_SYS_TIME */
154
155
156/******************************
157 * WRAPPER FOR <sys/select.h> *
158 ******************************/
159
160/* NB caller must include <sys/types.h> */
161
162#ifdef HAVE_SYS_SELECT_H
163
164#include <sys/select.h>
165
Vladimir Marangozov2c57e072000-08-11 11:48:33 +0000166#endif /* !HAVE_SYS_SELECT_H */
167
Tim Peters60f42b52001-01-18 03:03:16 +0000168/*******************************
169 * stat() and fstat() fiddling *
170 *******************************/
171
172/* We expect that stat and fstat exist on most systems.
173 * It's confirmed on Unix, Mac and Windows.
174 * If you don't have them, add
175 * #define DONT_HAVE_STAT
176 * and/or
177 * #define DONT_HAVE_FSTAT
Tim Peters76f373d2001-07-26 21:34:59 +0000178 * to your pyconfig.h. Python code beyond this should check HAVE_STAT and
Tim Peters60f42b52001-01-18 03:03:16 +0000179 * HAVE_FSTAT instead.
180 * Also
181 * #define DONT_HAVE_SYS_STAT_H
182 * if <sys/stat.h> doesn't exist on your platform, and
183 * #define HAVE_STAT_H
184 * if <stat.h> does (don't look at me -- ths mess is inherited).
185 */
186#ifndef DONT_HAVE_STAT
187#define HAVE_STAT
188#endif
189
190#ifndef DONT_HAVE_FSTAT
191#define HAVE_FSTAT
192#endif
193
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000194#ifdef RISCOS
195#include <sys/types.h>
Martin v. Löwisa94568a2003-05-10 07:36:56 +0000196#include "unixstuff.h"
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000197#endif
198
Tim Peters60f42b52001-01-18 03:03:16 +0000199#ifndef DONT_HAVE_SYS_STAT_H
Andrew MacIntyre5e090fc2002-02-26 11:20:01 +0000200#if defined(PYOS_OS2) && defined(PYCC_GCC)
201#include <sys/types.h>
202#endif
Tim Peters60f42b52001-01-18 03:03:16 +0000203#include <sys/stat.h>
204#elif defined(HAVE_STAT_H)
205#include <stat.h>
206#endif
207
Martin v. Löwisf9836ba2001-08-08 10:28:06 +0000208#if defined(PYCC_VACPP)
209/* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */
210#define S_IFMT (S_IFDIR|S_IFCHR|S_IFREG)
211#endif
212
213#ifndef S_ISREG
214#define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
215#endif
216
217#ifndef S_ISDIR
218#define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
219#endif
220
Vladimir Marangozov2c57e072000-08-11 11:48:33 +0000221
Tim Peters7d3a5112000-07-08 04:17:21 +0000222#ifdef __cplusplus
Peter Schneider-Kamp7e018902000-07-31 15:28:04 +0000223/* Move this down here since some C++ #include's don't like to be included
224 inside an extern "C" */
Tim Peters7d3a5112000-07-08 04:17:21 +0000225extern "C" {
226#endif
227
Vladimir Marangozov2c57e072000-08-11 11:48:33 +0000228
Tim Peters7d3a5112000-07-08 04:17:21 +0000229/* Py_ARITHMETIC_RIGHT_SHIFT
230 * C doesn't define whether a right-shift of a signed integer sign-extends
231 * or zero-fills. Here a macro to force sign extension:
232 * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
233 * Return I >> J, forcing sign extension.
234 * Requirements:
235 * I is of basic signed type TYPE (char, short, int, long, or long long).
236 * TYPE is one of char, short, int, long, or long long, although long long
237 * must not be used except on platforms that support it.
238 * J is an integer >= 0 and strictly less than the number of bits in TYPE
239 * (because C doesn't define what happens for J outside that range either).
240 * Caution:
241 * I may be evaluated more than once.
242 */
243#ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
244#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
245 ((I) < 0 ? ~((~(unsigned TYPE)(I)) >> (J)) : (I) >> (J))
246#else
247#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
248#endif
249
Tim Peters39dce292000-08-15 03:34:48 +0000250/* Py_FORCE_EXPANSION(X)
Tim Peters1be46842000-07-23 18:10:18 +0000251 * "Simply" returns its argument. However, macro expansions within the
252 * argument are evaluated. This unfortunate trickery is needed to get
253 * token-pasting to work as desired in some cases.
254 */
255#define Py_FORCE_EXPANSION(X) X
256
Tim Peters8315ea52000-07-23 19:28:35 +0000257/* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW)
258 * Cast VALUE to type NARROW from type WIDE. In Py_DEBUG mode, this
259 * assert-fails if any information is lost.
260 * Caution:
261 * VALUE may be evaluated more than once.
262 */
263#ifdef Py_DEBUG
264#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
265 (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE))
266#else
267#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
268#endif
269
Tim Peters862f0592004-09-23 19:11:32 +0000270/* Py_IS_NAN(X)
271 * Return 1 if float or double arg is a NaN, else 0.
272 * Caution:
273 * X is evaluated more than once.
274 * This may not work on all platforms. Each platform has *some*
275 * way to spell this, though -- override in pyconfig.h if you have
276 * a platform where it doesn't work.
277 */
278#ifndef Py_IS_NAN
279#define Py_IS_NAN(X) ((X) != (X))
280#endif
281
Tim Peters39dce292000-08-15 03:34:48 +0000282/* Py_IS_INFINITY(X)
283 * Return 1 if float or double arg is an infinity, else 0.
284 * Caution:
285 * X is evaluated more than once.
286 * This implementation may set the underflow flag if |X| is very small;
287 * it really can't be implemented correctly (& easily) before C99.
Tim Peters862f0592004-09-23 19:11:32 +0000288 * Override in pyconfig.h if you have a better spelling on your platform.
Tim Peters39dce292000-08-15 03:34:48 +0000289 */
Tim Peters862f0592004-09-23 19:11:32 +0000290#ifndef Py_IS_INFINITY
Tim Peters1a2eefd2000-09-08 15:45:34 +0000291#define Py_IS_INFINITY(X) ((X) && (X)*0.5 == (X))
Tim Peters862f0592004-09-23 19:11:32 +0000292#endif
Thomas Wouters1e0c2f42000-07-24 16:06:23 +0000293
Tim Peters1de41bf2002-07-03 03:31:20 +0000294/* HUGE_VAL is supposed to expand to a positive double infinity. Python
295 * uses Py_HUGE_VAL instead because some platforms are broken in this
296 * respect. We used to embed code in pyport.h to try to worm around that,
297 * but different platforms are broken in conflicting ways. If you're on
298 * a platform where HUGE_VAL is defined incorrectly, fiddle your Python
299 * config to #define Py_HUGE_VAL to something that works on your platform.
Tim Petersa40c7932001-09-05 22:36:56 +0000300 */
Tim Peters1de41bf2002-07-03 03:31:20 +0000301#ifndef Py_HUGE_VAL
Tim Petersa40c7932001-09-05 22:36:56 +0000302#define Py_HUGE_VAL HUGE_VAL
303#endif
304
Tim Peters57f282a2001-09-05 05:38:10 +0000305/* Py_OVERFLOWED(X)
306 * Return 1 iff a libm function overflowed. Set errno to 0 before calling
307 * a libm function, and invoke this macro after, passing the function
308 * result.
309 * Caution:
310 * This isn't reliable. C99 no longer requires libm to set errno under
Tim Petersd893fd62001-09-05 06:24:24 +0000311 * any exceptional condition, but does require +- HUGE_VAL return
312 * values on overflow. A 754 box *probably* maps HUGE_VAL to a
313 * double infinity, and we're cool if that's so, unless the input
314 * was an infinity and an infinity is the expected result. A C89
315 * system sets errno to ERANGE, so we check for that too. We're
Tim Peters57f282a2001-09-05 05:38:10 +0000316 * out of luck if a C99 754 box doesn't map HUGE_VAL to +Inf, or
317 * if the returned result is a NaN, or if a C89 box returns HUGE_VAL
318 * in non-overflow cases.
319 * X is evaluated more than once.
Tim Peters4643bd92002-12-28 21:56:08 +0000320 * Some platforms have better way to spell this, so expect some #ifdef'ery.
Anthony Baxter83dd43f2003-09-30 14:58:59 +0000321 *
322 * OpenBSD uses 'isinf()' because a compiler bug on that platform causes
Tim Peters862f0592004-09-23 19:11:32 +0000323 * the longer macro version to be mis-compiled. This isn't optimal, and
Anthony Baxter83dd43f2003-09-30 14:58:59 +0000324 * should be removed once a newer compiler is available on that platform.
325 * The system that had the failure was running OpenBSD 3.2 on Intel, with
326 * gcc 2.95.3.
327 *
Tim Peters862f0592004-09-23 19:11:32 +0000328 * According to Tim's checkin, the FreeBSD systems use isinf() to work
Anthony Baxter83dd43f2003-09-30 14:58:59 +0000329 * around a FPE bug on that platform.
Tim Peters57f282a2001-09-05 05:38:10 +0000330 */
Anthony Baxter83dd43f2003-09-30 14:58:59 +0000331#if defined(__FreeBSD__) || defined(__OpenBSD__)
Tim Peters4643bd92002-12-28 21:56:08 +0000332#define Py_OVERFLOWED(X) isinf(X)
333#else
Tim Petersa40c7932001-09-05 22:36:56 +0000334#define Py_OVERFLOWED(X) ((X) != 0.0 && (errno == ERANGE || \
335 (X) == Py_HUGE_VAL || \
336 (X) == -Py_HUGE_VAL))
Tim Peters4643bd92002-12-28 21:56:08 +0000337#endif
Tim Petersa40c7932001-09-05 22:36:56 +0000338
Hye-Shik Chang77d9a3e2004-03-22 08:43:55 +0000339/* Py_SET_ERRNO_ON_MATH_ERROR(x)
Tim Petersa40c7932001-09-05 22:36:56 +0000340 * If a libm function did not set errno, but it looks like the result
Hye-Shik Chang77d9a3e2004-03-22 08:43:55 +0000341 * overflowed or not-a-number, set errno to ERANGE or EDOM. Set errno
342 * to 0 before calling a libm function, and invoke this macro after,
343 * passing the function result.
Tim Petersa40c7932001-09-05 22:36:56 +0000344 * Caution:
345 * This isn't reliable. See Py_OVERFLOWED comments.
346 * X is evaluated more than once.
347 */
Guido van Rossum539c6622005-09-14 17:49:54 +0000348#if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64))
Hye-Shik Chang77d9a3e2004-03-22 08:43:55 +0000349#define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM;
350#else
351#define _Py_SET_EDOM_FOR_NAN(X) ;
352#endif
353#define Py_SET_ERRNO_ON_MATH_ERROR(X) \
Tim Petersa40c7932001-09-05 22:36:56 +0000354 do { \
Hye-Shik Chang77d9a3e2004-03-22 08:43:55 +0000355 if (errno == 0) { \
356 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
357 errno = ERANGE; \
358 else _Py_SET_EDOM_FOR_NAN(X) \
359 } \
Tim Petersa40c7932001-09-05 22:36:56 +0000360 } while(0)
Tim Peters57f282a2001-09-05 05:38:10 +0000361
Hye-Shik Chang77d9a3e2004-03-22 08:43:55 +0000362/* Py_SET_ERANGE_ON_OVERFLOW(x)
363 * An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility.
364 */
365#define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X)
366
Tim Petersdc5a5082002-03-09 04:58:24 +0000367/* Py_ADJUST_ERANGE1(x)
368 * Py_ADJUST_ERANGE2(x, y)
369 * Set errno to 0 before calling a libm function, and invoke one of these
370 * macros after, passing the function result(s) (Py_ADJUST_ERANGE2 is useful
371 * for functions returning complex results). This makes two kinds of
372 * adjustments to errno: (A) If it looks like the platform libm set
373 * errno=ERANGE due to underflow, clear errno. (B) If it looks like the
374 * platform libm overflowed but didn't set errno, force errno to ERANGE. In
375 * effect, we're trying to force a useful implementation of C89 errno
376 * behavior.
377 * Caution:
378 * This isn't reliable. See Py_OVERFLOWED comments.
379 * X and Y may be evaluated more than once.
380 */
381#define Py_ADJUST_ERANGE1(X) \
382 do { \
383 if (errno == 0) { \
384 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
385 errno = ERANGE; \
386 } \
387 else if (errno == ERANGE && (X) == 0.0) \
388 errno = 0; \
389 } while(0)
390
391#define Py_ADJUST_ERANGE2(X, Y) \
392 do { \
393 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL || \
394 (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) { \
395 if (errno == 0) \
396 errno = ERANGE; \
397 } \
398 else if (errno == ERANGE) \
399 errno = 0; \
400 } while(0)
401
Neal Norwitz80292642002-12-19 15:12:26 +0000402/* Py_DEPRECATED(version)
Neal Norwitz93344ab2002-12-19 15:24:11 +0000403 * Declare a variable, type, or function deprecated.
Neal Norwitz80292642002-12-19 15:12:26 +0000404 * Usage:
405 * extern int old_var Py_DEPRECATED(2.3);
406 * typedef int T1 Py_DEPRECATED(2.4);
407 * extern int x() Py_DEPRECATED(2.5);
408 */
Neal Norwitz3dd8be42006-03-20 06:33:01 +0000409#if defined(__GNUC__) && ((__GNUC__ >= 4) || \
410 (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
Neal Norwitz80292642002-12-19 15:12:26 +0000411#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
412#else
Tim Peters4643bd92002-12-28 21:56:08 +0000413#define Py_DEPRECATED(VERSION_UNUSED)
Neal Norwitz80292642002-12-19 15:12:26 +0000414#endif
415
Thomas Wouters1e0c2f42000-07-24 16:06:23 +0000416/**************************************************************************
417Prototypes that are missing from the standard include files on some systems
418(and possibly only some versions of such systems.)
419
420Please be conservative with adding new ones, document them and enclose them
421in platform-specific #ifdefs.
422**************************************************************************/
423
424#ifdef SOLARIS
425/* Unchecked */
426extern int gethostname(char *, int);
427#endif
428
429#ifdef __BEOS__
430/* Unchecked */
431/* It's in the libs, but not the headers... - [cjh] */
Tim Peters60f42b52001-01-18 03:03:16 +0000432int shutdown( int, int );
Thomas Wouters1e0c2f42000-07-24 16:06:23 +0000433#endif
434
435#ifdef HAVE__GETPTY
Sjoerd Mullender0765fe32000-07-26 15:46:29 +0000436#include <sys/types.h> /* we need to import mode_t */
Thomas Wouters1e0c2f42000-07-24 16:06:23 +0000437extern char * _getpty(int *, int, mode_t, int);
438#endif
439
440#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)
441#if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H)
442/* BSDI does not supply a prototype for the 'openpty' and 'forkpty'
443 functions, even though they are included in libutil. */
444#include <termios.h>
445extern int openpty(int *, int *, char *, struct termios *, struct winsize *);
446extern int forkpty(int *, char *, struct termios *, struct winsize *);
447#endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */
448#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */
449
450
451/* These are pulled from various places. It isn't obvious on what platforms
452 they are necessary, nor what the exact prototype should look like (which
453 is likely to vary between platforms!) If you find you need one of these
454 declarations, please move them to a platform-specific block and include
455 proper prototypes. */
456#if 0
457
458/* From Modules/resource.c */
459extern int getrusage();
460extern int getpagesize();
461
462/* From Python/sysmodule.c and Modules/posixmodule.c */
463extern int fclose(FILE *);
464
465/* From Modules/posixmodule.c */
466extern int fdatasync(int);
Thomas Wouters1e0c2f42000-07-24 16:06:23 +0000467#endif /* 0 */
468
Peter Schneider-Kamp7e018902000-07-31 15:28:04 +0000469
470/************************
471 * WRAPPER FOR <math.h> *
472 ************************/
473
Peter Schneider-Kamp7e018902000-07-31 15:28:04 +0000474#ifndef HAVE_HYPOT
475extern double hypot(double, double);
Tim Peters60f42b52001-01-18 03:03:16 +0000476#endif
Peter Schneider-Kamp7e018902000-07-31 15:28:04 +0000477
Hye-Shik Changb5047fd2004-08-04 06:33:51 +0000478
Hye-Shik Changf3032612006-03-22 08:52:43 +0000479/* On 4.4BSD-descendants, ctype functions serves the whole range of
480 * wchar_t character set rather than single byte code points only.
481 * This characteristic can break some operations of string object
482 * including str.upper() and str.split() on UTF-8 locales. This
483 * workaround was provided by Tim Robbins of FreeBSD project.
484 */
Hye-Shik Changb5047fd2004-08-04 06:33:51 +0000485
486#ifdef __FreeBSD__
487#include <osreldate.h>
488#if __FreeBSD_version > 500039
489#include <ctype.h>
490#include <wctype.h>
491#undef isalnum
492#define isalnum(c) iswalnum(btowc(c))
493#undef isalpha
494#define isalpha(c) iswalpha(btowc(c))
495#undef islower
496#define islower(c) iswlower(btowc(c))
497#undef isspace
498#define isspace(c) iswspace(btowc(c))
499#undef isupper
500#define isupper(c) iswupper(btowc(c))
501#undef tolower
502#define tolower(c) towlower(btowc(c))
503#undef toupper
504#define toupper(c) towupper(btowc(c))
505#endif
506#endif
507
508
Mark Hammond8235ea12002-07-19 06:55:41 +0000509/* Declarations for symbol visibility.
510
511 PyAPI_FUNC(type): Declares a public Python API function and return type
Tim Peters4643bd92002-12-28 21:56:08 +0000512 PyAPI_DATA(type): Declares public Python data and its type
Mark Hammond8235ea12002-07-19 06:55:41 +0000513 PyMODINIT_FUNC: A Python module init function. If these functions are
Tim Peters4643bd92002-12-28 21:56:08 +0000514 inside the Python core, they are private to the core.
515 If in an extension module, it may be declared with
Mark Hammond8235ea12002-07-19 06:55:41 +0000516 external linkage depending on the platform.
517
518 As a number of platforms support/require "__declspec(dllimport/dllexport)",
519 we support a HAVE_DECLSPEC_DLL macro to save duplication.
520*/
521
Tim Peters4643bd92002-12-28 21:56:08 +0000522/*
Michael W. Hudsonf163d102003-02-10 19:36:46 +0000523 All windows ports, except cygwin, are handled in PC/pyconfig.h.
524
525 BeOS and cygwin are the only other autoconf platform requiring special
526 linkage handling and both of these use __declspec().
Mark Hammond8235ea12002-07-19 06:55:41 +0000527*/
528#if defined(__CYGWIN__) || defined(__BEOS__)
529# define HAVE_DECLSPEC_DLL
Peter Schneider-Kamp7e018902000-07-31 15:28:04 +0000530#endif
Mark Hammond8235ea12002-07-19 06:55:41 +0000531
Jason Tishler30765592003-09-04 11:04:06 +0000532/* only get special linkage if built as shared or platform is Cygwin */
533#if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
Mark Hammond8235ea12002-07-19 06:55:41 +0000534# if defined(HAVE_DECLSPEC_DLL)
535# ifdef Py_BUILD_CORE
536# define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
Mark Hammonda2905272002-07-29 13:42:14 +0000537# define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE
Mark Hammond8235ea12002-07-19 06:55:41 +0000538 /* module init functions inside the core need no external linkage */
Jason Tishler6bc06ec2003-09-04 11:59:50 +0000539 /* except for Cygwin to handle embedding (FIXME: BeOS too?) */
540# if defined(__CYGWIN__)
541# define PyMODINIT_FUNC __declspec(dllexport) void
542# else /* __CYGWIN__ */
543# define PyMODINIT_FUNC void
544# endif /* __CYGWIN__ */
Mark Hammond8235ea12002-07-19 06:55:41 +0000545# else /* Py_BUILD_CORE */
546 /* Building an extension module, or an embedded situation */
547 /* public Python functions and data are imported */
Jason Tishlerfb8595d2003-01-06 12:41:26 +0000548 /* Under Cygwin, auto-import functions to prevent compilation */
549 /* failures similar to http://python.org/doc/FAQ.html#3.24 */
550# if !defined(__CYGWIN__)
551# define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
552# endif /* !__CYGWIN__ */
Mark Hammonda2905272002-07-29 13:42:14 +0000553# define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
Mark Hammond8235ea12002-07-19 06:55:41 +0000554 /* module init functions outside the core must be exported */
555# if defined(__cplusplus)
556# define PyMODINIT_FUNC extern "C" __declspec(dllexport) void
557# else /* __cplusplus */
558# define PyMODINIT_FUNC __declspec(dllexport) void
559# endif /* __cplusplus */
560# endif /* Py_BUILD_CORE */
561# endif /* HAVE_DECLSPEC */
562#endif /* Py_ENABLE_SHARED */
563
564/* If no external linkage macros defined by now, create defaults */
565#ifndef PyAPI_FUNC
566# define PyAPI_FUNC(RTYPE) RTYPE
567#endif
568#ifndef PyAPI_DATA
Mark Hammonda2905272002-07-29 13:42:14 +0000569# define PyAPI_DATA(RTYPE) extern RTYPE
Mark Hammond8235ea12002-07-19 06:55:41 +0000570#endif
571#ifndef PyMODINIT_FUNC
572# if defined(__cplusplus)
573# define PyMODINIT_FUNC extern "C" void
574# else /* __cplusplus */
575# define PyMODINIT_FUNC void
576# endif /* __cplusplus */
577#endif
578
579/* Deprecated DL_IMPORT and DL_EXPORT macros */
580#if defined(Py_ENABLE_SHARED) && defined (HAVE_DECLSPEC_DLL)
581# if defined(Py_BUILD_CORE)
582# define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE
583# define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
584# else
585# define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE
586# define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
587# endif
588#endif
589#ifndef DL_EXPORT
590# define DL_EXPORT(RTYPE) RTYPE
591#endif
592#ifndef DL_IMPORT
593# define DL_IMPORT(RTYPE) RTYPE
594#endif
595/* End of deprecated DL_* macros */
Peter Schneider-Kamp7e018902000-07-31 15:28:04 +0000596
Peter Schneider-Kamp7e018902000-07-31 15:28:04 +0000597/* If the fd manipulation macros aren't defined,
598 here is a set that should do the job */
599
Guido van Rossum367e46a2000-08-01 18:28:44 +0000600#if 0 /* disabled and probably obsolete */
Peter Schneider-Kamp1c2b1782000-08-01 16:53:44 +0000601
Peter Schneider-Kamp7e018902000-07-31 15:28:04 +0000602#ifndef FD_SETSIZE
603#define FD_SETSIZE 256
604#endif
605
606#ifndef FD_SET
607
608typedef long fd_mask;
609
610#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
611#ifndef howmany
612#define howmany(x, y) (((x)+((y)-1))/(y))
613#endif /* howmany */
614
615typedef struct fd_set {
616 fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
617} fd_set;
618
619#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
620#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
621#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
622#define FD_ZERO(p) memset((char *)(p), '\0', sizeof(*(p)))
623
624#endif /* FD_SET */
Peter Schneider-Kamp1c2b1782000-08-01 16:53:44 +0000625
626#endif /* fd manipulation macros */
627
Vladimir Marangozov2c57e072000-08-11 11:48:33 +0000628
Fred Draked5fadf72000-09-26 05:46:01 +0000629/* limits.h constants that may be missing */
630
631#ifndef INT_MAX
632#define INT_MAX 2147483647
633#endif
634
635#ifndef LONG_MAX
636#if SIZEOF_LONG == 4
637#define LONG_MAX 0X7FFFFFFFL
638#elif SIZEOF_LONG == 8
639#define LONG_MAX 0X7FFFFFFFFFFFFFFFL
640#else
641#error "could not set LONG_MAX in pyport.h"
642#endif
643#endif
644
645#ifndef LONG_MIN
646#define LONG_MIN (-LONG_MAX-1)
647#endif
648
Tim Petersd57731f2000-10-05 01:42:25 +0000649#ifndef LONG_BIT
650#define LONG_BIT (8 * SIZEOF_LONG)
651#endif
652
653#if LONG_BIT != 8 * SIZEOF_LONG
654/* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent
655 * 32-bit platforms using gcc. We try to catch that here at compile-time
656 * rather than waiting for integer multiplication to trigger bogus
657 * overflows.
658 */
Andrew M. Kuchling234fb632001-01-12 15:06:28 +0000659#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
Tim Petersd57731f2000-10-05 01:42:25 +0000660#endif
661
Tim Peters7d3a5112000-07-08 04:17:21 +0000662#ifdef __cplusplus
663}
664#endif
665
Neil Schemenauer15691082001-10-23 02:20:37 +0000666/*
667 * Hide GCC attributes from compilers that don't support them.
668 */
Guido van Rossumbd67d6f2001-10-27 21:16:16 +0000669#if (!defined(__GNUC__) || __GNUC__ < 2 || \
Jack Jansen4892f242002-02-01 15:46:29 +0000670 (__GNUC__ == 2 && __GNUC_MINOR__ < 7) ) && \
Guido van Rossumbd67d6f2001-10-27 21:16:16 +0000671 !defined(RISCOS)
Neil Schemenauer96aa0ac2002-09-15 14:09:54 +0000672#define Py_GCC_ATTRIBUTE(x)
673#else
674#define Py_GCC_ATTRIBUTE(x) __attribute__(x)
Neil Schemenauer15691082001-10-23 02:20:37 +0000675#endif
676
Nicholas Bastin9ba301e2004-07-15 15:54:05 +0000677/* Eliminate end-of-loop code not reached warnings from SunPro C
678 * when using do{...}while(0) macros
679 */
680#ifdef __SUNPRO_C
681#pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)
682#endif
683
Tim Peters7d3a5112000-07-08 04:17:21 +0000684#endif /* Py_PYPORT_H */