Issue #5170: Fixed regression caused when fixing #5768.
[python.git] / Include / pyport.h
blobf44c43e24775bd463cae168fac628a87c678d973
1 #ifndef Py_PYPORT_H
2 #define Py_PYPORT_H
4 #include "pyconfig.h" /* include for defines */
6 #ifdef HAVE_STDINT_H
7 #include <stdint.h>
8 #endif
10 /**************************************************************************
11 Symbols and macros to supply platform-independent interfaces to basic
12 C language & library operations whose spellings vary across platforms.
14 Please try to make documentation here as clear as possible: by definition,
15 the stuff here is trying to illuminate C's darkest corners.
17 Config #defines referenced here:
19 SIGNED_RIGHT_SHIFT_ZERO_FILLS
20 Meaning: To be defined iff i>>j does not extend the sign bit when i is a
21 signed integral type and i < 0.
22 Used in: Py_ARITHMETIC_RIGHT_SHIFT
24 Py_DEBUG
25 Meaning: Extra checks compiled in for debug mode.
26 Used in: Py_SAFE_DOWNCAST
28 HAVE_UINTPTR_T
29 Meaning: The C9X type uintptr_t is supported by the compiler
30 Used in: Py_uintptr_t
32 HAVE_LONG_LONG
33 Meaning: The compiler supports the C type "long long"
34 Used in: PY_LONG_LONG
36 **************************************************************************/
39 /* For backward compatibility only. Obsolete, do not use. */
40 #ifdef HAVE_PROTOTYPES
41 #define Py_PROTO(x) x
42 #else
43 #define Py_PROTO(x) ()
44 #endif
45 #ifndef Py_FPROTO
46 #define Py_FPROTO(x) Py_PROTO(x)
47 #endif
49 /* typedefs for some C9X-defined synonyms for integral types.
51 * The names in Python are exactly the same as the C9X names, except with a
52 * Py_ prefix. Until C9X is universally implemented, this is the only way
53 * to ensure that Python gets reliable names that don't conflict with names
54 * in non-Python code that are playing their own tricks to define the C9X
55 * names.
57 * NOTE: don't go nuts here! Python has no use for *most* of the C9X
58 * integral synonyms. Only define the ones we actually need.
61 #ifdef HAVE_LONG_LONG
62 #ifndef PY_LONG_LONG
63 #define PY_LONG_LONG long long
64 #if defined(LLONG_MAX)
65 /* If LLONG_MAX is defined in limits.h, use that. */
66 #define PY_LLONG_MIN LLONG_MIN
67 #define PY_LLONG_MAX LLONG_MAX
68 #define PY_ULLONG_MAX ULLONG_MAX
69 #elif defined(__LONG_LONG_MAX__)
70 /* Otherwise, if GCC has a builtin define, use that. */
71 #define PY_LLONG_MAX __LONG_LONG_MAX__
72 #define PY_LLONG_MIN (-PY_LLONG_MAX-1)
73 #define PY_ULLONG_MAX (__LONG_LONG_MAX__*2ULL + 1ULL)
74 #else
75 /* Otherwise, rely on two's complement. */
76 #define PY_ULLONG_MAX (~0ULL)
77 #define PY_LLONG_MAX ((long long)(PY_ULLONG_MAX>>1))
78 #define PY_LLONG_MIN (-PY_LLONG_MAX-1)
79 #endif /* LLONG_MAX */
80 #endif
81 #endif /* HAVE_LONG_LONG */
83 /* a build with 30-bit digits for Python long integers needs an exact-width
84 * 32-bit unsigned integer type to store those digits. (We could just use
85 * type 'unsigned long', but that would be wasteful on a system where longs
86 * are 64-bits.) On Unix systems, the autoconf macro AC_TYPE_UINT32_T defines
87 * uint32_t to be such a type unless stdint.h or inttypes.h defines uint32_t.
88 * However, it doesn't set HAVE_UINT32_T, so we do that here.
90 #if (defined UINT32_MAX || defined uint32_t)
91 #ifndef PY_UINT32_T
92 #define HAVE_UINT32_T 1
93 #define PY_UINT32_T uint32_t
94 #endif
95 #endif
97 /* Macros for a 64-bit unsigned integer type; used for type 'twodigits' in the
98 * long integer implementation, when 30-bit digits are enabled.
100 #if (defined UINT64_MAX || defined uint64_t)
101 #ifndef PY_UINT64_T
102 #define HAVE_UINT64_T 1
103 #define PY_UINT64_T uint64_t
104 #endif
105 #endif
107 /* Signed variants of the above */
108 #if (defined INT32_MAX || defined int32_t)
109 #ifndef PY_INT32_T
110 #define HAVE_INT32_T 1
111 #define PY_INT32_T int32_t
112 #endif
113 #endif
114 #if (defined INT64_MAX || defined int64_t)
115 #ifndef PY_INT64_T
116 #define HAVE_INT64_T 1
117 #define PY_INT64_T int64_t
118 #endif
119 #endif
121 /* If PYLONG_BITS_IN_DIGIT is not defined then we'll use 30-bit digits if all
122 the necessary integer types are available, and we're on a 64-bit platform
123 (as determined by SIZEOF_VOID_P); otherwise we use 15-bit digits. */
125 #ifndef PYLONG_BITS_IN_DIGIT
126 #if (defined HAVE_UINT64_T && defined HAVE_INT64_T && \
127 defined HAVE_UINT32_T && defined HAVE_INT32_T && SIZEOF_VOID_P >= 8)
128 #define PYLONG_BITS_IN_DIGIT 30
129 #else
130 #define PYLONG_BITS_IN_DIGIT 15
131 #endif
132 #endif
134 /* uintptr_t is the C9X name for an unsigned integral type such that a
135 * legitimate void* can be cast to uintptr_t and then back to void* again
136 * without loss of information. Similarly for intptr_t, wrt a signed
137 * integral type.
139 #ifdef HAVE_UINTPTR_T
140 typedef uintptr_t Py_uintptr_t;
141 typedef intptr_t Py_intptr_t;
143 #elif SIZEOF_VOID_P <= SIZEOF_INT
144 typedef unsigned int Py_uintptr_t;
145 typedef int Py_intptr_t;
147 #elif SIZEOF_VOID_P <= SIZEOF_LONG
148 typedef unsigned long Py_uintptr_t;
149 typedef long Py_intptr_t;
151 #elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)
152 typedef unsigned PY_LONG_LONG Py_uintptr_t;
153 typedef PY_LONG_LONG Py_intptr_t;
155 #else
156 # error "Python needs a typedef for Py_uintptr_t in pyport.h."
157 #endif /* HAVE_UINTPTR_T */
159 /* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==
160 * sizeof(size_t). C99 doesn't define such a thing directly (size_t is an
161 * unsigned integral type). See PEP 353 for details.
163 #ifdef HAVE_SSIZE_T
164 typedef ssize_t Py_ssize_t;
165 #elif SIZEOF_VOID_P == SIZEOF_SIZE_T
166 typedef Py_intptr_t Py_ssize_t;
167 #else
168 # error "Python needs a typedef for Py_ssize_t in pyport.h."
169 #endif
171 /* Largest possible value of size_t.
172 SIZE_MAX is part of C99, so it might be defined on some
173 platforms. If it is not defined, (size_t)-1 is a portable
174 definition for C89, due to the way signed->unsigned
175 conversion is defined. */
176 #ifdef SIZE_MAX
177 #define PY_SIZE_MAX SIZE_MAX
178 #else
179 #define PY_SIZE_MAX ((size_t)-1)
180 #endif
182 /* Largest positive value of type Py_ssize_t. */
183 #define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
184 /* Smallest negative value of type Py_ssize_t. */
185 #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
187 #if SIZEOF_PID_T > SIZEOF_LONG
188 # error "Python doesn't support sizeof(pid_t) > sizeof(long)"
189 #endif
191 /* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf
192 * format to convert an argument with the width of a size_t or Py_ssize_t.
193 * C99 introduced "z" for this purpose, but not all platforms support that;
194 * e.g., MS compilers use "I" instead.
196 * These "high level" Python format functions interpret "z" correctly on
197 * all platforms (Python interprets the format string itself, and does whatever
198 * the platform C requires to convert a size_t/Py_ssize_t argument):
200 * PyString_FromFormat
201 * PyErr_Format
202 * PyString_FromFormatV
204 * Lower-level uses require that you interpolate the correct format modifier
205 * yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for
206 * example,
208 * Py_ssize_t index;
209 * fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index);
211 * That will expand to %ld, or %Id, or to something else correct for a
212 * Py_ssize_t on the platform.
214 #ifndef PY_FORMAT_SIZE_T
215 # if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__)
216 # define PY_FORMAT_SIZE_T ""
217 # elif SIZEOF_SIZE_T == SIZEOF_LONG
218 # define PY_FORMAT_SIZE_T "l"
219 # elif defined(MS_WINDOWS)
220 # define PY_FORMAT_SIZE_T "I"
221 # else
222 # error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T"
223 # endif
224 #endif
226 /* Py_LOCAL can be used instead of static to get the fastest possible calling
227 * convention for functions that are local to a given module.
229 * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining,
230 * for platforms that support that.
232 * If PY_LOCAL_AGGRESSIVE is defined before python.h is included, more
233 * "aggressive" inlining/optimizaion is enabled for the entire module. This
234 * may lead to code bloat, and may slow things down for those reasons. It may
235 * also lead to errors, if the code relies on pointer aliasing. Use with
236 * care.
238 * NOTE: You can only use this for functions that are entirely local to a
239 * module; functions that are exported via method tables, callbacks, etc,
240 * should keep using static.
243 #undef USE_INLINE /* XXX - set via configure? */
245 #if defined(_MSC_VER)
246 #if defined(PY_LOCAL_AGGRESSIVE)
247 /* enable more aggressive optimization for visual studio */
248 #pragma optimize("agtw", on)
249 #endif
250 /* ignore warnings if the compiler decides not to inline a function */
251 #pragma warning(disable: 4710)
252 /* fastest possible local call under MSVC */
253 #define Py_LOCAL(type) static type __fastcall
254 #define Py_LOCAL_INLINE(type) static __inline type __fastcall
255 #elif defined(USE_INLINE)
256 #define Py_LOCAL(type) static type
257 #define Py_LOCAL_INLINE(type) static inline type
258 #else
259 #define Py_LOCAL(type) static type
260 #define Py_LOCAL_INLINE(type) static type
261 #endif
263 /* Py_MEMCPY can be used instead of memcpy in cases where the copied blocks
264 * are often very short. While most platforms have highly optimized code for
265 * large transfers, the setup costs for memcpy are often quite high. MEMCPY
266 * solves this by doing short copies "in line".
269 #if defined(_MSC_VER)
270 #define Py_MEMCPY(target, source, length) do { \
271 size_t i_, n_ = (length); \
272 char *t_ = (void*) (target); \
273 const char *s_ = (void*) (source); \
274 if (n_ >= 16) \
275 memcpy(t_, s_, n_); \
276 else \
277 for (i_ = 0; i_ < n_; i_++) \
278 t_[i_] = s_[i_]; \
279 } while (0)
280 #else
281 #define Py_MEMCPY memcpy
282 #endif
284 #include <stdlib.h>
286 #include <math.h> /* Moved here from the math section, before extern "C" */
288 /********************************************
289 * WRAPPER FOR <time.h> and/or <sys/time.h> *
290 ********************************************/
292 #ifdef TIME_WITH_SYS_TIME
293 #include <sys/time.h>
294 #include <time.h>
295 #else /* !TIME_WITH_SYS_TIME */
296 #ifdef HAVE_SYS_TIME_H
297 #include <sys/time.h>
298 #else /* !HAVE_SYS_TIME_H */
299 #include <time.h>
300 #endif /* !HAVE_SYS_TIME_H */
301 #endif /* !TIME_WITH_SYS_TIME */
304 /******************************
305 * WRAPPER FOR <sys/select.h> *
306 ******************************/
308 /* NB caller must include <sys/types.h> */
310 #ifdef HAVE_SYS_SELECT_H
312 #include <sys/select.h>
314 #endif /* !HAVE_SYS_SELECT_H */
316 /*******************************
317 * stat() and fstat() fiddling *
318 *******************************/
320 /* We expect that stat and fstat exist on most systems.
321 * It's confirmed on Unix, Mac and Windows.
322 * If you don't have them, add
323 * #define DONT_HAVE_STAT
324 * and/or
325 * #define DONT_HAVE_FSTAT
326 * to your pyconfig.h. Python code beyond this should check HAVE_STAT and
327 * HAVE_FSTAT instead.
328 * Also
329 * #define HAVE_SYS_STAT_H
330 * if <sys/stat.h> exists on your platform, and
331 * #define HAVE_STAT_H
332 * if <stat.h> does.
334 #ifndef DONT_HAVE_STAT
335 #define HAVE_STAT
336 #endif
338 #ifndef DONT_HAVE_FSTAT
339 #define HAVE_FSTAT
340 #endif
342 #ifdef RISCOS
343 #include <sys/types.h>
344 #include "unixstuff.h"
345 #endif
347 #ifdef HAVE_SYS_STAT_H
348 #if defined(PYOS_OS2) && defined(PYCC_GCC)
349 #include <sys/types.h>
350 #endif
351 #include <sys/stat.h>
352 #elif defined(HAVE_STAT_H)
353 #include <stat.h>
354 #endif
356 #if defined(PYCC_VACPP)
357 /* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */
358 #define S_IFMT (S_IFDIR|S_IFCHR|S_IFREG)
359 #endif
361 #ifndef S_ISREG
362 #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
363 #endif
365 #ifndef S_ISDIR
366 #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
367 #endif
370 #ifdef __cplusplus
371 /* Move this down here since some C++ #include's don't like to be included
372 inside an extern "C" */
373 extern "C" {
374 #endif
377 /* Py_ARITHMETIC_RIGHT_SHIFT
378 * C doesn't define whether a right-shift of a signed integer sign-extends
379 * or zero-fills. Here a macro to force sign extension:
380 * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
381 * Return I >> J, forcing sign extension. Arithmetically, return the
382 * floor of I/2**J.
383 * Requirements:
384 * I should have signed integer type. In the terminology of C99, this can
385 * be either one of the five standard signed integer types (signed char,
386 * short, int, long, long long) or an extended signed integer type.
387 * J is an integer >= 0 and strictly less than the number of bits in the
388 * type of I (because C doesn't define what happens for J outside that
389 * range either).
390 * TYPE used to specify the type of I, but is now ignored. It's been left
391 * in for backwards compatibility with versions <= 2.6 or 3.0.
392 * Caution:
393 * I may be evaluated more than once.
395 #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
396 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
397 ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))
398 #else
399 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
400 #endif
402 /* Py_FORCE_EXPANSION(X)
403 * "Simply" returns its argument. However, macro expansions within the
404 * argument are evaluated. This unfortunate trickery is needed to get
405 * token-pasting to work as desired in some cases.
407 #define Py_FORCE_EXPANSION(X) X
409 /* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW)
410 * Cast VALUE to type NARROW from type WIDE. In Py_DEBUG mode, this
411 * assert-fails if any information is lost.
412 * Caution:
413 * VALUE may be evaluated more than once.
415 #ifdef Py_DEBUG
416 #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
417 (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE))
418 #else
419 #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
420 #endif
422 /* Py_SET_ERRNO_ON_MATH_ERROR(x)
423 * If a libm function did not set errno, but it looks like the result
424 * overflowed or not-a-number, set errno to ERANGE or EDOM. Set errno
425 * to 0 before calling a libm function, and invoke this macro after,
426 * passing the function result.
427 * Caution:
428 * This isn't reliable. See Py_OVERFLOWED comments.
429 * X is evaluated more than once.
431 #if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64))
432 #define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM;
433 #else
434 #define _Py_SET_EDOM_FOR_NAN(X) ;
435 #endif
436 #define Py_SET_ERRNO_ON_MATH_ERROR(X) \
437 do { \
438 if (errno == 0) { \
439 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
440 errno = ERANGE; \
441 else _Py_SET_EDOM_FOR_NAN(X) \
443 } while(0)
445 /* Py_SET_ERANGE_ON_OVERFLOW(x)
446 * An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility.
448 #define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X)
450 /* Py_ADJUST_ERANGE1(x)
451 * Py_ADJUST_ERANGE2(x, y)
452 * Set errno to 0 before calling a libm function, and invoke one of these
453 * macros after, passing the function result(s) (Py_ADJUST_ERANGE2 is useful
454 * for functions returning complex results). This makes two kinds of
455 * adjustments to errno: (A) If it looks like the platform libm set
456 * errno=ERANGE due to underflow, clear errno. (B) If it looks like the
457 * platform libm overflowed but didn't set errno, force errno to ERANGE. In
458 * effect, we're trying to force a useful implementation of C89 errno
459 * behavior.
460 * Caution:
461 * This isn't reliable. See Py_OVERFLOWED comments.
462 * X and Y may be evaluated more than once.
464 #define Py_ADJUST_ERANGE1(X) \
465 do { \
466 if (errno == 0) { \
467 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
468 errno = ERANGE; \
470 else if (errno == ERANGE && (X) == 0.0) \
471 errno = 0; \
472 } while(0)
474 #define Py_ADJUST_ERANGE2(X, Y) \
475 do { \
476 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL || \
477 (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) { \
478 if (errno == 0) \
479 errno = ERANGE; \
481 else if (errno == ERANGE) \
482 errno = 0; \
483 } while(0)
485 /* Py_DEPRECATED(version)
486 * Declare a variable, type, or function deprecated.
487 * Usage:
488 * extern int old_var Py_DEPRECATED(2.3);
489 * typedef int T1 Py_DEPRECATED(2.4);
490 * extern int x() Py_DEPRECATED(2.5);
492 #if defined(__GNUC__) && ((__GNUC__ >= 4) || \
493 (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
494 #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
495 #else
496 #define Py_DEPRECATED(VERSION_UNUSED)
497 #endif
499 /**************************************************************************
500 Prototypes that are missing from the standard include files on some systems
501 (and possibly only some versions of such systems.)
503 Please be conservative with adding new ones, document them and enclose them
504 in platform-specific #ifdefs.
505 **************************************************************************/
507 #ifdef SOLARIS
508 /* Unchecked */
509 extern int gethostname(char *, int);
510 #endif
512 #ifdef __BEOS__
513 /* Unchecked */
514 /* It's in the libs, but not the headers... - [cjh] */
515 int shutdown( int, int );
516 #endif
518 #ifdef HAVE__GETPTY
519 #include <sys/types.h> /* we need to import mode_t */
520 extern char * _getpty(int *, int, mode_t, int);
521 #endif
523 /* On QNX 6, struct termio must be declared by including sys/termio.h
524 if TCGETA, TCSETA, TCSETAW, or TCSETAF are used. sys/termio.h must
525 be included before termios.h or it will generate an error. */
526 #ifdef HAVE_SYS_TERMIO_H
527 #include <sys/termio.h>
528 #endif
530 #if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)
531 #if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H)
532 /* BSDI does not supply a prototype for the 'openpty' and 'forkpty'
533 functions, even though they are included in libutil. */
534 #include <termios.h>
535 extern int openpty(int *, int *, char *, struct termios *, struct winsize *);
536 extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
537 #endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */
538 #endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */
541 /* These are pulled from various places. It isn't obvious on what platforms
542 they are necessary, nor what the exact prototype should look like (which
543 is likely to vary between platforms!) If you find you need one of these
544 declarations, please move them to a platform-specific block and include
545 proper prototypes. */
546 #if 0
548 /* From Modules/resource.c */
549 extern int getrusage();
550 extern int getpagesize();
552 /* From Python/sysmodule.c and Modules/posixmodule.c */
553 extern int fclose(FILE *);
555 /* From Modules/posixmodule.c */
556 extern int fdatasync(int);
557 #endif /* 0 */
560 /* On 4.4BSD-descendants, ctype functions serves the whole range of
561 * wchar_t character set rather than single byte code points only.
562 * This characteristic can break some operations of string object
563 * including str.upper() and str.split() on UTF-8 locales. This
564 * workaround was provided by Tim Robbins of FreeBSD project.
567 #ifdef __FreeBSD__
568 #include <osreldate.h>
569 #if __FreeBSD_version > 500039
570 #include <ctype.h>
571 #include <wctype.h>
572 #undef isalnum
573 #define isalnum(c) iswalnum(btowc(c))
574 #undef isalpha
575 #define isalpha(c) iswalpha(btowc(c))
576 #undef islower
577 #define islower(c) iswlower(btowc(c))
578 #undef isspace
579 #define isspace(c) iswspace(btowc(c))
580 #undef isupper
581 #define isupper(c) iswupper(btowc(c))
582 #undef tolower
583 #define tolower(c) towlower(btowc(c))
584 #undef toupper
585 #define toupper(c) towupper(btowc(c))
586 #endif
587 #endif
590 /* Declarations for symbol visibility.
592 PyAPI_FUNC(type): Declares a public Python API function and return type
593 PyAPI_DATA(type): Declares public Python data and its type
594 PyMODINIT_FUNC: A Python module init function. If these functions are
595 inside the Python core, they are private to the core.
596 If in an extension module, it may be declared with
597 external linkage depending on the platform.
599 As a number of platforms support/require "__declspec(dllimport/dllexport)",
600 we support a HAVE_DECLSPEC_DLL macro to save duplication.
604 All windows ports, except cygwin, are handled in PC/pyconfig.h.
606 BeOS and cygwin are the only other autoconf platform requiring special
607 linkage handling and both of these use __declspec().
609 #if defined(__CYGWIN__) || defined(__BEOS__)
610 # define HAVE_DECLSPEC_DLL
611 #endif
613 /* only get special linkage if built as shared or platform is Cygwin */
614 #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
615 # if defined(HAVE_DECLSPEC_DLL)
616 # ifdef Py_BUILD_CORE
617 # define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
618 # define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE
619 /* module init functions inside the core need no external linkage */
620 /* except for Cygwin to handle embedding (FIXME: BeOS too?) */
621 # if defined(__CYGWIN__)
622 # define PyMODINIT_FUNC __declspec(dllexport) void
623 # else /* __CYGWIN__ */
624 # define PyMODINIT_FUNC void
625 # endif /* __CYGWIN__ */
626 # else /* Py_BUILD_CORE */
627 /* Building an extension module, or an embedded situation */
628 /* public Python functions and data are imported */
629 /* Under Cygwin, auto-import functions to prevent compilation */
630 /* failures similar to http://python.org/doc/FAQ.html#3.24 */
631 # if !defined(__CYGWIN__)
632 # define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
633 # endif /* !__CYGWIN__ */
634 # define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
635 /* module init functions outside the core must be exported */
636 # if defined(__cplusplus)
637 # define PyMODINIT_FUNC extern "C" __declspec(dllexport) void
638 # else /* __cplusplus */
639 # define PyMODINIT_FUNC __declspec(dllexport) void
640 # endif /* __cplusplus */
641 # endif /* Py_BUILD_CORE */
642 # endif /* HAVE_DECLSPEC */
643 #endif /* Py_ENABLE_SHARED */
645 /* If no external linkage macros defined by now, create defaults */
646 #ifndef PyAPI_FUNC
647 # define PyAPI_FUNC(RTYPE) RTYPE
648 #endif
649 #ifndef PyAPI_DATA
650 # define PyAPI_DATA(RTYPE) extern RTYPE
651 #endif
652 #ifndef PyMODINIT_FUNC
653 # if defined(__cplusplus)
654 # define PyMODINIT_FUNC extern "C" void
655 # else /* __cplusplus */
656 # define PyMODINIT_FUNC void
657 # endif /* __cplusplus */
658 #endif
660 /* Deprecated DL_IMPORT and DL_EXPORT macros */
661 #if defined(Py_ENABLE_SHARED) && defined (HAVE_DECLSPEC_DLL)
662 # if defined(Py_BUILD_CORE)
663 # define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE
664 # define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
665 # else
666 # define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE
667 # define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
668 # endif
669 #endif
670 #ifndef DL_EXPORT
671 # define DL_EXPORT(RTYPE) RTYPE
672 #endif
673 #ifndef DL_IMPORT
674 # define DL_IMPORT(RTYPE) RTYPE
675 #endif
676 /* End of deprecated DL_* macros */
678 /* If the fd manipulation macros aren't defined,
679 here is a set that should do the job */
681 #if 0 /* disabled and probably obsolete */
683 #ifndef FD_SETSIZE
684 #define FD_SETSIZE 256
685 #endif
687 #ifndef FD_SET
689 typedef long fd_mask;
691 #define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
692 #ifndef howmany
693 #define howmany(x, y) (((x)+((y)-1))/(y))
694 #endif /* howmany */
696 typedef struct fd_set {
697 fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
698 } fd_set;
700 #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
701 #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
702 #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
703 #define FD_ZERO(p) memset((char *)(p), '\0', sizeof(*(p)))
705 #endif /* FD_SET */
707 #endif /* fd manipulation macros */
710 /* limits.h constants that may be missing */
712 #ifndef INT_MAX
713 #define INT_MAX 2147483647
714 #endif
716 #ifndef LONG_MAX
717 #if SIZEOF_LONG == 4
718 #define LONG_MAX 0X7FFFFFFFL
719 #elif SIZEOF_LONG == 8
720 #define LONG_MAX 0X7FFFFFFFFFFFFFFFL
721 #else
722 #error "could not set LONG_MAX in pyport.h"
723 #endif
724 #endif
726 #ifndef LONG_MIN
727 #define LONG_MIN (-LONG_MAX-1)
728 #endif
730 #ifndef LONG_BIT
731 #define LONG_BIT (8 * SIZEOF_LONG)
732 #endif
734 #if LONG_BIT != 8 * SIZEOF_LONG
735 /* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent
736 * 32-bit platforms using gcc. We try to catch that here at compile-time
737 * rather than waiting for integer multiplication to trigger bogus
738 * overflows.
740 #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
741 #endif
743 #ifdef __cplusplus
745 #endif
748 * Hide GCC attributes from compilers that don't support them.
750 #if (!defined(__GNUC__) || __GNUC__ < 2 || \
751 (__GNUC__ == 2 && __GNUC_MINOR__ < 7) ) && \
752 !defined(RISCOS)
753 #define Py_GCC_ATTRIBUTE(x)
754 #else
755 #define Py_GCC_ATTRIBUTE(x) __attribute__(x)
756 #endif
759 * Add PyArg_ParseTuple format where available.
761 #ifdef HAVE_ATTRIBUTE_FORMAT_PARSETUPLE
762 #define Py_FORMAT_PARSETUPLE(func,p1,p2) __attribute__((format(func,p1,p2)))
763 #else
764 #define Py_FORMAT_PARSETUPLE(func,p1,p2)
765 #endif
768 * Specify alignment on compilers that support it.
770 #if defined(__GNUC__) && __GNUC__ >= 3
771 #define Py_ALIGNED(x) __attribute__((aligned(x)))
772 #else
773 #define Py_ALIGNED(x)
774 #endif
776 /* Eliminate end-of-loop code not reached warnings from SunPro C
777 * when using do{...}while(0) macros
779 #ifdef __SUNPRO_C
780 #pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)
781 #endif
784 * Older Microsoft compilers don't support the C99 long long literal suffixes,
785 * so these will be defined in PC/pyconfig.h for those compilers.
787 #ifndef Py_LL
788 #define Py_LL(x) x##LL
789 #endif
791 #ifndef Py_ULL
792 #define Py_ULL(x) Py_LL(x##U)
793 #endif
795 #endif /* Py_PYPORT_H */