Change to flush and close logic to fix #1760556.
[python.git] / Include / pyport.h
blob0020d7cf6ed0aa6b879d591732f0d5bd3eead2c9
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 /* uintptr_t is the C9X name for an unsigned integral type such that a
84 * legitimate void* can be cast to uintptr_t and then back to void* again
85 * without loss of information. Similarly for intptr_t, wrt a signed
86 * integral type.
88 #ifdef HAVE_UINTPTR_T
89 typedef uintptr_t Py_uintptr_t;
90 typedef intptr_t Py_intptr_t;
92 #elif SIZEOF_VOID_P <= SIZEOF_INT
93 typedef unsigned int Py_uintptr_t;
94 typedef int Py_intptr_t;
96 #elif SIZEOF_VOID_P <= SIZEOF_LONG
97 typedef unsigned long Py_uintptr_t;
98 typedef long Py_intptr_t;
100 #elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)
101 typedef unsigned PY_LONG_LONG Py_uintptr_t;
102 typedef PY_LONG_LONG Py_intptr_t;
104 #else
105 # error "Python needs a typedef for Py_uintptr_t in pyport.h."
106 #endif /* HAVE_UINTPTR_T */
108 /* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==
109 * sizeof(size_t). C99 doesn't define such a thing directly (size_t is an
110 * unsigned integral type). See PEP 353 for details.
112 #ifdef HAVE_SSIZE_T
113 typedef ssize_t Py_ssize_t;
114 #elif SIZEOF_VOID_P == SIZEOF_SIZE_T
115 typedef Py_intptr_t Py_ssize_t;
116 #else
117 # error "Python needs a typedef for Py_ssize_t in pyport.h."
118 #endif
120 /* Largest positive value of type Py_ssize_t. */
121 #define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
122 /* Smallest negative value of type Py_ssize_t. */
123 #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
125 /* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf
126 * format to convert an argument with the width of a size_t or Py_ssize_t.
127 * C99 introduced "z" for this purpose, but not all platforms support that;
128 * e.g., MS compilers use "I" instead.
130 * These "high level" Python format functions interpret "z" correctly on
131 * all platforms (Python interprets the format string itself, and does whatever
132 * the platform C requires to convert a size_t/Py_ssize_t argument):
134 * PyString_FromFormat
135 * PyErr_Format
136 * PyString_FromFormatV
138 * Lower-level uses require that you interpolate the correct format modifier
139 * yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for
140 * example,
142 * Py_ssize_t index;
143 * fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index);
145 * That will expand to %ld, or %Id, or to something else correct for a
146 * Py_ssize_t on the platform.
148 #ifndef PY_FORMAT_SIZE_T
149 # if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__)
150 # define PY_FORMAT_SIZE_T ""
151 # elif SIZEOF_SIZE_T == SIZEOF_LONG
152 # define PY_FORMAT_SIZE_T "l"
153 # elif defined(MS_WINDOWS)
154 # define PY_FORMAT_SIZE_T "I"
155 # else
156 # error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T"
157 # endif
158 #endif
160 /* Py_LOCAL can be used instead of static to get the fastest possible calling
161 * convention for functions that are local to a given module.
163 * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining,
164 * for platforms that support that.
166 * If PY_LOCAL_AGGRESSIVE is defined before python.h is included, more
167 * "aggressive" inlining/optimizaion is enabled for the entire module. This
168 * may lead to code bloat, and may slow things down for those reasons. It may
169 * also lead to errors, if the code relies on pointer aliasing. Use with
170 * care.
172 * NOTE: You can only use this for functions that are entirely local to a
173 * module; functions that are exported via method tables, callbacks, etc,
174 * should keep using static.
177 #undef USE_INLINE /* XXX - set via configure? */
179 #if defined(_MSC_VER)
180 #if defined(PY_LOCAL_AGGRESSIVE)
181 /* enable more aggressive optimization for visual studio */
182 #pragma optimize("agtw", on)
183 #endif
184 /* ignore warnings if the compiler decides not to inline a function */
185 #pragma warning(disable: 4710)
186 /* fastest possible local call under MSVC */
187 #define Py_LOCAL(type) static type __fastcall
188 #define Py_LOCAL_INLINE(type) static __inline type __fastcall
189 #elif defined(USE_INLINE)
190 #define Py_LOCAL(type) static type
191 #define Py_LOCAL_INLINE(type) static inline type
192 #else
193 #define Py_LOCAL(type) static type
194 #define Py_LOCAL_INLINE(type) static type
195 #endif
197 /* Py_MEMCPY can be used instead of memcpy in cases where the copied blocks
198 * are often very short. While most platforms have highly optimized code for
199 * large transfers, the setup costs for memcpy are often quite high. MEMCPY
200 * solves this by doing short copies "in line".
203 #if defined(_MSC_VER)
204 #define Py_MEMCPY(target, source, length) do { \
205 size_t i_, n_ = (length); \
206 char *t_ = (void*) (target); \
207 const char *s_ = (void*) (source); \
208 if (n_ >= 16) \
209 memcpy(t_, s_, n_); \
210 else \
211 for (i_ = 0; i_ < n_; i_++) \
212 t_[i_] = s_[i_]; \
213 } while (0)
214 #else
215 #define Py_MEMCPY memcpy
216 #endif
218 #include <stdlib.h>
220 #include <math.h> /* Moved here from the math section, before extern "C" */
222 /********************************************
223 * WRAPPER FOR <time.h> and/or <sys/time.h> *
224 ********************************************/
226 #ifdef TIME_WITH_SYS_TIME
227 #include <sys/time.h>
228 #include <time.h>
229 #else /* !TIME_WITH_SYS_TIME */
230 #ifdef HAVE_SYS_TIME_H
231 #include <sys/time.h>
232 #else /* !HAVE_SYS_TIME_H */
233 #include <time.h>
234 #endif /* !HAVE_SYS_TIME_H */
235 #endif /* !TIME_WITH_SYS_TIME */
238 /******************************
239 * WRAPPER FOR <sys/select.h> *
240 ******************************/
242 /* NB caller must include <sys/types.h> */
244 #ifdef HAVE_SYS_SELECT_H
246 #include <sys/select.h>
248 #endif /* !HAVE_SYS_SELECT_H */
250 /*******************************
251 * stat() and fstat() fiddling *
252 *******************************/
254 /* We expect that stat and fstat exist on most systems.
255 * It's confirmed on Unix, Mac and Windows.
256 * If you don't have them, add
257 * #define DONT_HAVE_STAT
258 * and/or
259 * #define DONT_HAVE_FSTAT
260 * to your pyconfig.h. Python code beyond this should check HAVE_STAT and
261 * HAVE_FSTAT instead.
262 * Also
263 * #define HAVE_SYS_STAT_H
264 * if <sys/stat.h> exists on your platform, and
265 * #define HAVE_STAT_H
266 * if <stat.h> does.
268 #ifndef DONT_HAVE_STAT
269 #define HAVE_STAT
270 #endif
272 #ifndef DONT_HAVE_FSTAT
273 #define HAVE_FSTAT
274 #endif
276 #ifdef RISCOS
277 #include <sys/types.h>
278 #include "unixstuff.h"
279 #endif
281 #ifdef HAVE_SYS_STAT_H
282 #if defined(PYOS_OS2) && defined(PYCC_GCC)
283 #include <sys/types.h>
284 #endif
285 #include <sys/stat.h>
286 #elif defined(HAVE_STAT_H)
287 #include <stat.h>
288 #endif
290 #if defined(PYCC_VACPP)
291 /* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */
292 #define S_IFMT (S_IFDIR|S_IFCHR|S_IFREG)
293 #endif
295 #ifndef S_ISREG
296 #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
297 #endif
299 #ifndef S_ISDIR
300 #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
301 #endif
304 #ifdef __cplusplus
305 /* Move this down here since some C++ #include's don't like to be included
306 inside an extern "C" */
307 extern "C" {
308 #endif
311 /* Py_ARITHMETIC_RIGHT_SHIFT
312 * C doesn't define whether a right-shift of a signed integer sign-extends
313 * or zero-fills. Here a macro to force sign extension:
314 * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
315 * Return I >> J, forcing sign extension.
316 * Requirements:
317 * I is of basic signed type TYPE (char, short, int, long, or long long).
318 * TYPE is one of char, short, int, long, or long long, although long long
319 * must not be used except on platforms that support it.
320 * J is an integer >= 0 and strictly less than the number of bits in TYPE
321 * (because C doesn't define what happens for J outside that range either).
322 * Caution:
323 * I may be evaluated more than once.
325 #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
326 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
327 ((I) < 0 ? ~((~(unsigned TYPE)(I)) >> (J)) : (I) >> (J))
328 #else
329 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
330 #endif
332 /* Py_FORCE_EXPANSION(X)
333 * "Simply" returns its argument. However, macro expansions within the
334 * argument are evaluated. This unfortunate trickery is needed to get
335 * token-pasting to work as desired in some cases.
337 #define Py_FORCE_EXPANSION(X) X
339 /* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW)
340 * Cast VALUE to type NARROW from type WIDE. In Py_DEBUG mode, this
341 * assert-fails if any information is lost.
342 * Caution:
343 * VALUE may be evaluated more than once.
345 #ifdef Py_DEBUG
346 #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
347 (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE))
348 #else
349 #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
350 #endif
352 /* Py_IS_NAN(X)
353 * Return 1 if float or double arg is a NaN, else 0.
354 * Caution:
355 * X is evaluated more than once.
356 * This may not work on all platforms. Each platform has *some*
357 * way to spell this, though -- override in pyconfig.h if you have
358 * a platform where it doesn't work.
360 #ifndef Py_IS_NAN
361 #define Py_IS_NAN(X) ((X) != (X))
362 #endif
364 /* Py_IS_INFINITY(X)
365 * Return 1 if float or double arg is an infinity, else 0.
366 * Caution:
367 * X is evaluated more than once.
368 * This implementation may set the underflow flag if |X| is very small;
369 * it really can't be implemented correctly (& easily) before C99.
370 * Override in pyconfig.h if you have a better spelling on your platform.
372 #ifndef Py_IS_INFINITY
373 #define Py_IS_INFINITY(X) ((X) && (X)*0.5 == (X))
374 #endif
376 /* Py_IS_FINITE(X)
377 * Return 1 if float or double arg is neither infinite nor NAN, else 0.
378 * Some compilers (e.g. VisualStudio) have intrisics for this, so a special
379 * macro for this particular test is useful
381 #ifndef Py_IS_FINITE
382 #define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X))
383 #endif
385 /* HUGE_VAL is supposed to expand to a positive double infinity. Python
386 * uses Py_HUGE_VAL instead because some platforms are broken in this
387 * respect. We used to embed code in pyport.h to try to worm around that,
388 * but different platforms are broken in conflicting ways. If you're on
389 * a platform where HUGE_VAL is defined incorrectly, fiddle your Python
390 * config to #define Py_HUGE_VAL to something that works on your platform.
392 #ifndef Py_HUGE_VAL
393 #define Py_HUGE_VAL HUGE_VAL
394 #endif
396 /* Py_OVERFLOWED(X)
397 * Return 1 iff a libm function overflowed. Set errno to 0 before calling
398 * a libm function, and invoke this macro after, passing the function
399 * result.
400 * Caution:
401 * This isn't reliable. C99 no longer requires libm to set errno under
402 * any exceptional condition, but does require +- HUGE_VAL return
403 * values on overflow. A 754 box *probably* maps HUGE_VAL to a
404 * double infinity, and we're cool if that's so, unless the input
405 * was an infinity and an infinity is the expected result. A C89
406 * system sets errno to ERANGE, so we check for that too. We're
407 * out of luck if a C99 754 box doesn't map HUGE_VAL to +Inf, or
408 * if the returned result is a NaN, or if a C89 box returns HUGE_VAL
409 * in non-overflow cases.
410 * X is evaluated more than once.
411 * Some platforms have better way to spell this, so expect some #ifdef'ery.
413 * OpenBSD uses 'isinf()' because a compiler bug on that platform causes
414 * the longer macro version to be mis-compiled. This isn't optimal, and
415 * should be removed once a newer compiler is available on that platform.
416 * The system that had the failure was running OpenBSD 3.2 on Intel, with
417 * gcc 2.95.3.
419 * According to Tim's checkin, the FreeBSD systems use isinf() to work
420 * around a FPE bug on that platform.
422 #if defined(__FreeBSD__) || defined(__OpenBSD__)
423 #define Py_OVERFLOWED(X) isinf(X)
424 #else
425 #define Py_OVERFLOWED(X) ((X) != 0.0 && (errno == ERANGE || \
426 (X) == Py_HUGE_VAL || \
427 (X) == -Py_HUGE_VAL))
428 #endif
430 /* Py_SET_ERRNO_ON_MATH_ERROR(x)
431 * If a libm function did not set errno, but it looks like the result
432 * overflowed or not-a-number, set errno to ERANGE or EDOM. Set errno
433 * to 0 before calling a libm function, and invoke this macro after,
434 * passing the function result.
435 * Caution:
436 * This isn't reliable. See Py_OVERFLOWED comments.
437 * X is evaluated more than once.
439 #if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64))
440 #define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM;
441 #else
442 #define _Py_SET_EDOM_FOR_NAN(X) ;
443 #endif
444 #define Py_SET_ERRNO_ON_MATH_ERROR(X) \
445 do { \
446 if (errno == 0) { \
447 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
448 errno = ERANGE; \
449 else _Py_SET_EDOM_FOR_NAN(X) \
451 } while(0)
453 /* Py_SET_ERANGE_ON_OVERFLOW(x)
454 * An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility.
456 #define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X)
458 /* Py_ADJUST_ERANGE1(x)
459 * Py_ADJUST_ERANGE2(x, y)
460 * Set errno to 0 before calling a libm function, and invoke one of these
461 * macros after, passing the function result(s) (Py_ADJUST_ERANGE2 is useful
462 * for functions returning complex results). This makes two kinds of
463 * adjustments to errno: (A) If it looks like the platform libm set
464 * errno=ERANGE due to underflow, clear errno. (B) If it looks like the
465 * platform libm overflowed but didn't set errno, force errno to ERANGE. In
466 * effect, we're trying to force a useful implementation of C89 errno
467 * behavior.
468 * Caution:
469 * This isn't reliable. See Py_OVERFLOWED comments.
470 * X and Y may be evaluated more than once.
472 #define Py_ADJUST_ERANGE1(X) \
473 do { \
474 if (errno == 0) { \
475 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
476 errno = ERANGE; \
478 else if (errno == ERANGE && (X) == 0.0) \
479 errno = 0; \
480 } while(0)
482 #define Py_ADJUST_ERANGE2(X, Y) \
483 do { \
484 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL || \
485 (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) { \
486 if (errno == 0) \
487 errno = ERANGE; \
489 else if (errno == ERANGE) \
490 errno = 0; \
491 } while(0)
493 /* Py_DEPRECATED(version)
494 * Declare a variable, type, or function deprecated.
495 * Usage:
496 * extern int old_var Py_DEPRECATED(2.3);
497 * typedef int T1 Py_DEPRECATED(2.4);
498 * extern int x() Py_DEPRECATED(2.5);
500 #if defined(__GNUC__) && ((__GNUC__ >= 4) || \
501 (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
502 #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
503 #else
504 #define Py_DEPRECATED(VERSION_UNUSED)
505 #endif
507 /**************************************************************************
508 Prototypes that are missing from the standard include files on some systems
509 (and possibly only some versions of such systems.)
511 Please be conservative with adding new ones, document them and enclose them
512 in platform-specific #ifdefs.
513 **************************************************************************/
515 #ifdef SOLARIS
516 /* Unchecked */
517 extern int gethostname(char *, int);
518 #endif
520 #ifdef __BEOS__
521 /* Unchecked */
522 /* It's in the libs, but not the headers... - [cjh] */
523 int shutdown( int, int );
524 #endif
526 #ifdef HAVE__GETPTY
527 #include <sys/types.h> /* we need to import mode_t */
528 extern char * _getpty(int *, int, mode_t, int);
529 #endif
531 #if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)
532 #if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H)
533 /* BSDI does not supply a prototype for the 'openpty' and 'forkpty'
534 functions, even though they are included in libutil. */
535 #include <termios.h>
536 extern int openpty(int *, int *, char *, struct termios *, struct winsize *);
537 extern int forkpty(int *, char *, struct termios *, struct winsize *);
538 #endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */
539 #endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */
542 /* These are pulled from various places. It isn't obvious on what platforms
543 they are necessary, nor what the exact prototype should look like (which
544 is likely to vary between platforms!) If you find you need one of these
545 declarations, please move them to a platform-specific block and include
546 proper prototypes. */
547 #if 0
549 /* From Modules/resource.c */
550 extern int getrusage();
551 extern int getpagesize();
553 /* From Python/sysmodule.c and Modules/posixmodule.c */
554 extern int fclose(FILE *);
556 /* From Modules/posixmodule.c */
557 extern int fdatasync(int);
558 #endif /* 0 */
561 /************************
562 * WRAPPER FOR <math.h> *
563 ************************/
565 #ifndef HAVE_HYPOT
566 extern double hypot(double, double);
567 #endif
570 /* On 4.4BSD-descendants, ctype functions serves the whole range of
571 * wchar_t character set rather than single byte code points only.
572 * This characteristic can break some operations of string object
573 * including str.upper() and str.split() on UTF-8 locales. This
574 * workaround was provided by Tim Robbins of FreeBSD project.
577 #ifdef __FreeBSD__
578 #include <osreldate.h>
579 #if __FreeBSD_version > 500039
580 #include <ctype.h>
581 #include <wctype.h>
582 #undef isalnum
583 #define isalnum(c) iswalnum(btowc(c))
584 #undef isalpha
585 #define isalpha(c) iswalpha(btowc(c))
586 #undef islower
587 #define islower(c) iswlower(btowc(c))
588 #undef isspace
589 #define isspace(c) iswspace(btowc(c))
590 #undef isupper
591 #define isupper(c) iswupper(btowc(c))
592 #undef tolower
593 #define tolower(c) towlower(btowc(c))
594 #undef toupper
595 #define toupper(c) towupper(btowc(c))
596 #endif
597 #endif
600 /* Declarations for symbol visibility.
602 PyAPI_FUNC(type): Declares a public Python API function and return type
603 PyAPI_DATA(type): Declares public Python data and its type
604 PyMODINIT_FUNC: A Python module init function. If these functions are
605 inside the Python core, they are private to the core.
606 If in an extension module, it may be declared with
607 external linkage depending on the platform.
609 As a number of platforms support/require "__declspec(dllimport/dllexport)",
610 we support a HAVE_DECLSPEC_DLL macro to save duplication.
614 All windows ports, except cygwin, are handled in PC/pyconfig.h.
616 BeOS and cygwin are the only other autoconf platform requiring special
617 linkage handling and both of these use __declspec().
619 #if defined(__CYGWIN__) || defined(__BEOS__)
620 # define HAVE_DECLSPEC_DLL
621 #endif
623 /* only get special linkage if built as shared or platform is Cygwin */
624 #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
625 # if defined(HAVE_DECLSPEC_DLL)
626 # ifdef Py_BUILD_CORE
627 # define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
628 # define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE
629 /* module init functions inside the core need no external linkage */
630 /* except for Cygwin to handle embedding (FIXME: BeOS too?) */
631 # if defined(__CYGWIN__)
632 # define PyMODINIT_FUNC __declspec(dllexport) void
633 # else /* __CYGWIN__ */
634 # define PyMODINIT_FUNC void
635 # endif /* __CYGWIN__ */
636 # else /* Py_BUILD_CORE */
637 /* Building an extension module, or an embedded situation */
638 /* public Python functions and data are imported */
639 /* Under Cygwin, auto-import functions to prevent compilation */
640 /* failures similar to http://python.org/doc/FAQ.html#3.24 */
641 # if !defined(__CYGWIN__)
642 # define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
643 # endif /* !__CYGWIN__ */
644 # define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
645 /* module init functions outside the core must be exported */
646 # if defined(__cplusplus)
647 # define PyMODINIT_FUNC extern "C" __declspec(dllexport) void
648 # else /* __cplusplus */
649 # define PyMODINIT_FUNC __declspec(dllexport) void
650 # endif /* __cplusplus */
651 # endif /* Py_BUILD_CORE */
652 # endif /* HAVE_DECLSPEC */
653 #endif /* Py_ENABLE_SHARED */
655 /* If no external linkage macros defined by now, create defaults */
656 #ifndef PyAPI_FUNC
657 # define PyAPI_FUNC(RTYPE) RTYPE
658 #endif
659 #ifndef PyAPI_DATA
660 # define PyAPI_DATA(RTYPE) extern RTYPE
661 #endif
662 #ifndef PyMODINIT_FUNC
663 # if defined(__cplusplus)
664 # define PyMODINIT_FUNC extern "C" void
665 # else /* __cplusplus */
666 # define PyMODINIT_FUNC void
667 # endif /* __cplusplus */
668 #endif
670 /* Deprecated DL_IMPORT and DL_EXPORT macros */
671 #if defined(Py_ENABLE_SHARED) && defined (HAVE_DECLSPEC_DLL)
672 # if defined(Py_BUILD_CORE)
673 # define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE
674 # define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
675 # else
676 # define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE
677 # define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
678 # endif
679 #endif
680 #ifndef DL_EXPORT
681 # define DL_EXPORT(RTYPE) RTYPE
682 #endif
683 #ifndef DL_IMPORT
684 # define DL_IMPORT(RTYPE) RTYPE
685 #endif
686 /* End of deprecated DL_* macros */
688 /* If the fd manipulation macros aren't defined,
689 here is a set that should do the job */
691 #if 0 /* disabled and probably obsolete */
693 #ifndef FD_SETSIZE
694 #define FD_SETSIZE 256
695 #endif
697 #ifndef FD_SET
699 typedef long fd_mask;
701 #define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
702 #ifndef howmany
703 #define howmany(x, y) (((x)+((y)-1))/(y))
704 #endif /* howmany */
706 typedef struct fd_set {
707 fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
708 } fd_set;
710 #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
711 #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
712 #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
713 #define FD_ZERO(p) memset((char *)(p), '\0', sizeof(*(p)))
715 #endif /* FD_SET */
717 #endif /* fd manipulation macros */
720 /* limits.h constants that may be missing */
722 #ifndef INT_MAX
723 #define INT_MAX 2147483647
724 #endif
726 #ifndef LONG_MAX
727 #if SIZEOF_LONG == 4
728 #define LONG_MAX 0X7FFFFFFFL
729 #elif SIZEOF_LONG == 8
730 #define LONG_MAX 0X7FFFFFFFFFFFFFFFL
731 #else
732 #error "could not set LONG_MAX in pyport.h"
733 #endif
734 #endif
736 #ifndef LONG_MIN
737 #define LONG_MIN (-LONG_MAX-1)
738 #endif
740 #ifndef LONG_BIT
741 #define LONG_BIT (8 * SIZEOF_LONG)
742 #endif
744 #if LONG_BIT != 8 * SIZEOF_LONG
745 /* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent
746 * 32-bit platforms using gcc. We try to catch that here at compile-time
747 * rather than waiting for integer multiplication to trigger bogus
748 * overflows.
750 #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
751 #endif
753 #ifdef __cplusplus
755 #endif
758 * Hide GCC attributes from compilers that don't support them.
760 #if (!defined(__GNUC__) || __GNUC__ < 2 || \
761 (__GNUC__ == 2 && __GNUC_MINOR__ < 7) ) && \
762 !defined(RISCOS)
763 #define Py_GCC_ATTRIBUTE(x)
764 #else
765 #define Py_GCC_ATTRIBUTE(x) __attribute__(x)
766 #endif
769 * Add PyArg_ParseTuple format where available.
771 #ifdef HAVE_ATTRIBUTE_FORMAT_PARSETUPLE
772 #define Py_FORMAT_PARSETUPLE(func,p1,p2) __attribute__((format(func,p1,p2)))
773 #else
774 #define Py_FORMAT_PARSETUPLE(func,p1,p2)
775 #endif
777 /* Eliminate end-of-loop code not reached warnings from SunPro C
778 * when using do{...}while(0) macros
780 #ifdef __SUNPRO_C
781 #pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)
782 #endif
785 * Older Microsoft compilers don't support the C99 long long literal suffixes,
786 * so these will be defined in PC/pyconfig.h for those compilers.
788 #ifndef Py_LL
789 #define Py_LL(x) x##LL
790 #endif
792 #ifndef Py_ULL
793 #define Py_ULL(x) Py_LL(x##U)
794 #endif
796 #endif /* Py_PYPORT_H */