Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

771 lines
24 KiB

  1. #ifndef Py_PYPORT_H
  2. #define Py_PYPORT_H
  3. #include "pyconfig.h" /* include for defines */
  4. #ifdef HAVE_STDINT_H
  5. #include <stdint.h>
  6. #endif
  7. /**************************************************************************
  8. Symbols and macros to supply platform-independent interfaces to basic
  9. C language & library operations whose spellings vary across platforms.
  10. Please try to make documentation here as clear as possible: by definition,
  11. the stuff here is trying to illuminate C's darkest corners.
  12. Config #defines referenced here:
  13. SIGNED_RIGHT_SHIFT_ZERO_FILLS
  14. Meaning: To be defined iff i>>j does not extend the sign bit when i is a
  15. signed integral type and i < 0.
  16. Used in: Py_ARITHMETIC_RIGHT_SHIFT
  17. Py_DEBUG
  18. Meaning: Extra checks compiled in for debug mode.
  19. Used in: Py_SAFE_DOWNCAST
  20. HAVE_UINTPTR_T
  21. Meaning: The C9X type uintptr_t is supported by the compiler
  22. Used in: Py_uintptr_t
  23. HAVE_LONG_LONG
  24. Meaning: The compiler supports the C type "long long"
  25. Used in: PY_LONG_LONG
  26. **************************************************************************/
  27. /* For backward compatibility only. Obsolete, do not use. */
  28. #ifdef HAVE_PROTOTYPES
  29. #define Py_PROTO(x) x
  30. #else
  31. #define Py_PROTO(x) ()
  32. #endif
  33. #ifndef Py_FPROTO
  34. #define Py_FPROTO(x) Py_PROTO(x)
  35. #endif
  36. /* typedefs for some C9X-defined synonyms for integral types.
  37. *
  38. * The names in Python are exactly the same as the C9X names, except with a
  39. * Py_ prefix. Until C9X is universally implemented, this is the only way
  40. * to ensure that Python gets reliable names that don't conflict with names
  41. * in non-Python code that are playing their own tricks to define the C9X
  42. * names.
  43. *
  44. * NOTE: don't go nuts here! Python has no use for *most* of the C9X
  45. * integral synonyms. Only define the ones we actually need.
  46. */
  47. #ifdef HAVE_LONG_LONG
  48. #ifndef PY_LONG_LONG
  49. #define PY_LONG_LONG long long
  50. #endif
  51. #endif /* HAVE_LONG_LONG */
  52. /* uintptr_t is the C9X name for an unsigned integral type such that a
  53. * legitimate void* can be cast to uintptr_t and then back to void* again
  54. * without loss of information. Similarly for intptr_t, wrt a signed
  55. * integral type.
  56. */
  57. #ifdef HAVE_UINTPTR_T
  58. typedef uintptr_t Py_uintptr_t;
  59. typedef intptr_t Py_intptr_t;
  60. #elif SIZEOF_VOID_P <= SIZEOF_INT
  61. typedef unsigned int Py_uintptr_t;
  62. typedef int Py_intptr_t;
  63. #elif SIZEOF_VOID_P <= SIZEOF_LONG
  64. typedef unsigned long Py_uintptr_t;
  65. typedef long Py_intptr_t;
  66. #elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)
  67. typedef unsigned PY_LONG_LONG Py_uintptr_t;
  68. typedef PY_LONG_LONG Py_intptr_t;
  69. #else
  70. # error "Python needs a typedef for Py_uintptr_t in pyport.h."
  71. #endif /* HAVE_UINTPTR_T */
  72. /* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==
  73. * sizeof(size_t). C99 doesn't define such a thing directly (size_t is an
  74. * unsigned integral type). See PEP 353 for details.
  75. */
  76. #ifdef HAVE_SSIZE_T
  77. typedef ssize_t Py_ssize_t;
  78. #elif SIZEOF_VOID_P == SIZEOF_SIZE_T
  79. typedef Py_intptr_t Py_ssize_t;
  80. #else
  81. # error "Python needs a typedef for Py_ssize_t in pyport.h."
  82. #endif
  83. /* Largest positive value of type Py_ssize_t. */
  84. #define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
  85. /* Smallest negative value of type Py_ssize_t. */
  86. #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
  87. /* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf
  88. * format to convert an argument with the width of a size_t or Py_ssize_t.
  89. * C99 introduced "z" for this purpose, but not all platforms support that;
  90. * e.g., MS compilers use "I" instead.
  91. *
  92. * These "high level" Python format functions interpret "z" correctly on
  93. * all platforms (Python interprets the format string itself, and does whatever
  94. * the platform C requires to convert a size_t/Py_ssize_t argument):
  95. *
  96. * PyString_FromFormat
  97. * PyErr_Format
  98. * PyString_FromFormatV
  99. *
  100. * Lower-level uses require that you interpolate the correct format modifier
  101. * yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for
  102. * example,
  103. *
  104. * Py_ssize_t index;
  105. * fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index);
  106. *
  107. * That will expand to %ld, or %Id, or to something else correct for a
  108. * Py_ssize_t on the platform.
  109. */
  110. #ifndef PY_FORMAT_SIZE_T
  111. # if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__)
  112. # define PY_FORMAT_SIZE_T ""
  113. # elif SIZEOF_SIZE_T == SIZEOF_LONG
  114. # define PY_FORMAT_SIZE_T "l"
  115. # elif defined(MS_WINDOWS)
  116. # define PY_FORMAT_SIZE_T "I"
  117. # else
  118. # error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T"
  119. # endif
  120. #endif
  121. /* Py_LOCAL can be used instead of static to get the fastest possible calling
  122. * convention for functions that are local to a given module.
  123. *
  124. * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining,
  125. * for platforms that support that.
  126. *
  127. * If PY_LOCAL_AGGRESSIVE is defined before python.h is included, more
  128. * "aggressive" inlining/optimizaion is enabled for the entire module. This
  129. * may lead to code bloat, and may slow things down for those reasons. It may
  130. * also lead to errors, if the code relies on pointer aliasing. Use with
  131. * care.
  132. *
  133. * NOTE: You can only use this for functions that are entirely local to a
  134. * module; functions that are exported via method tables, callbacks, etc,
  135. * should keep using static.
  136. */
  137. #undef USE_INLINE /* XXX - set via configure? */
  138. #if defined(_MSC_VER)
  139. #if defined(PY_LOCAL_AGGRESSIVE)
  140. /* enable more aggressive optimization for visual studio */
  141. #pragma optimize("agtw", on)
  142. #endif
  143. /* ignore warnings if the compiler decides not to inline a function */
  144. #pragma warning(disable: 4710)
  145. /* fastest possible local call under MSVC */
  146. #define Py_LOCAL(type) static type __fastcall
  147. #define Py_LOCAL_INLINE(type) static __inline type __fastcall
  148. #elif defined(USE_INLINE)
  149. #define Py_LOCAL(type) static type
  150. #define Py_LOCAL_INLINE(type) static inline type
  151. #else
  152. #define Py_LOCAL(type) static type
  153. #define Py_LOCAL_INLINE(type) static type
  154. #endif
  155. /* Py_MEMCPY can be used instead of memcpy in cases where the copied blocks
  156. * are often very short. While most platforms have highly optimized code for
  157. * large transfers, the setup costs for memcpy are often quite high. MEMCPY
  158. * solves this by doing short copies "in line".
  159. */
  160. #if defined(_MSC_VER)
  161. #define Py_MEMCPY(target, source, length) do { \
  162. size_t i_, n_ = (length); \
  163. char *t_ = (void*) (target); \
  164. const char *s_ = (void*) (source); \
  165. if (n_ >= 16) \
  166. memcpy(t_, s_, n_); \
  167. else \
  168. for (i_ = 0; i_ < n_; i_++) \
  169. t_[i_] = s_[i_]; \
  170. } while (0)
  171. #else
  172. #define Py_MEMCPY memcpy
  173. #endif
  174. #include <stdlib.h>
  175. #include <math.h> /* Moved here from the math section, before extern "C" */
  176. /********************************************
  177. * WRAPPER FOR <time.h> and/or <sys/time.h> *
  178. ********************************************/
  179. #ifdef TIME_WITH_SYS_TIME
  180. #include <sys/time.h>
  181. #include <time.h>
  182. #else /* !TIME_WITH_SYS_TIME */
  183. #ifdef HAVE_SYS_TIME_H
  184. #include <sys/time.h>
  185. #else /* !HAVE_SYS_TIME_H */
  186. #include <time.h>
  187. #endif /* !HAVE_SYS_TIME_H */
  188. #endif /* !TIME_WITH_SYS_TIME */
  189. /******************************
  190. * WRAPPER FOR <sys/select.h> *
  191. ******************************/
  192. /* NB caller must include <sys/types.h> */
  193. #ifdef HAVE_SYS_SELECT_H
  194. #include <sys/select.h>
  195. #endif /* !HAVE_SYS_SELECT_H */
  196. /*******************************
  197. * stat() and fstat() fiddling *
  198. *******************************/
  199. /* We expect that stat and fstat exist on most systems.
  200. * It's confirmed on Unix, Mac and Windows.
  201. * If you don't have them, add
  202. * #define DONT_HAVE_STAT
  203. * and/or
  204. * #define DONT_HAVE_FSTAT
  205. * to your pyconfig.h. Python code beyond this should check HAVE_STAT and
  206. * HAVE_FSTAT instead.
  207. * Also
  208. * #define HAVE_SYS_STAT_H
  209. * if <sys/stat.h> exists on your platform, and
  210. * #define HAVE_STAT_H
  211. * if <stat.h> does.
  212. */
  213. #ifndef DONT_HAVE_STAT
  214. #define HAVE_STAT
  215. #endif
  216. #ifndef DONT_HAVE_FSTAT
  217. #define HAVE_FSTAT
  218. #endif
  219. #ifdef RISCOS
  220. #include <sys/types.h>
  221. #include "unixstuff.h"
  222. #endif
  223. #ifdef HAVE_SYS_STAT_H
  224. #if defined(PYOS_OS2) && defined(PYCC_GCC)
  225. #include <sys/types.h>
  226. #endif
  227. #include <sys/stat.h>
  228. #elif defined(HAVE_STAT_H)
  229. #include <stat.h>
  230. #endif
  231. #if defined(PYCC_VACPP)
  232. /* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */
  233. #define S_IFMT (S_IFDIR|S_IFCHR|S_IFREG)
  234. #endif
  235. #ifndef S_ISREG
  236. #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
  237. #endif
  238. #ifndef S_ISDIR
  239. #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
  240. #endif
  241. #ifdef __cplusplus
  242. /* Move this down here since some C++ #include's don't like to be included
  243. inside an extern "C" */
  244. extern "C" {
  245. #endif
  246. /* Py_ARITHMETIC_RIGHT_SHIFT
  247. * C doesn't define whether a right-shift of a signed integer sign-extends
  248. * or zero-fills. Here a macro to force sign extension:
  249. * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
  250. * Return I >> J, forcing sign extension.
  251. * Requirements:
  252. * I is of basic signed type TYPE (char, short, int, long, or long long).
  253. * TYPE is one of char, short, int, long, or long long, although long long
  254. * must not be used except on platforms that support it.
  255. * J is an integer >= 0 and strictly less than the number of bits in TYPE
  256. * (because C doesn't define what happens for J outside that range either).
  257. * Caution:
  258. * I may be evaluated more than once.
  259. */
  260. #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
  261. #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
  262. ((I) < 0 ? ~((~(unsigned TYPE)(I)) >> (J)) : (I) >> (J))
  263. #else
  264. #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
  265. #endif
  266. /* Py_FORCE_EXPANSION(X)
  267. * "Simply" returns its argument. However, macro expansions within the
  268. * argument are evaluated. This unfortunate trickery is needed to get
  269. * token-pasting to work as desired in some cases.
  270. */
  271. #define Py_FORCE_EXPANSION(X) X
  272. /* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW)
  273. * Cast VALUE to type NARROW from type WIDE. In Py_DEBUG mode, this
  274. * assert-fails if any information is lost.
  275. * Caution:
  276. * VALUE may be evaluated more than once.
  277. */
  278. #ifdef Py_DEBUG
  279. #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
  280. (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE))
  281. #else
  282. #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
  283. #endif
  284. /* Py_IS_NAN(X)
  285. * Return 1 if float or double arg is a NaN, else 0.
  286. * Caution:
  287. * X is evaluated more than once.
  288. * This may not work on all platforms. Each platform has *some*
  289. * way to spell this, though -- override in pyconfig.h if you have
  290. * a platform where it doesn't work.
  291. */
  292. #ifndef Py_IS_NAN
  293. #define Py_IS_NAN(X) ((X) != (X))
  294. #endif
  295. /* Py_IS_INFINITY(X)
  296. * Return 1 if float or double arg is an infinity, else 0.
  297. * Caution:
  298. * X is evaluated more than once.
  299. * This implementation may set the underflow flag if |X| is very small;
  300. * it really can't be implemented correctly (& easily) before C99.
  301. * Override in pyconfig.h if you have a better spelling on your platform.
  302. */
  303. #ifndef Py_IS_INFINITY
  304. #define Py_IS_INFINITY(X) ((X) && (X)*0.5 == (X))
  305. #endif
  306. /* Py_IS_FINITE(X)
  307. * Return 1 if float or double arg is neither infinite nor NAN, else 0.
  308. * Some compilers (e.g. VisualStudio) have intrisics for this, so a special
  309. * macro for this particular test is useful
  310. */
  311. #ifndef Py_IS_FINITE
  312. #define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X))
  313. #endif
  314. /* HUGE_VAL is supposed to expand to a positive double infinity. Python
  315. * uses Py_HUGE_VAL instead because some platforms are broken in this
  316. * respect. We used to embed code in pyport.h to try to worm around that,
  317. * but different platforms are broken in conflicting ways. If you're on
  318. * a platform where HUGE_VAL is defined incorrectly, fiddle your Python
  319. * config to #define Py_HUGE_VAL to something that works on your platform.
  320. */
  321. #ifndef Py_HUGE_VAL
  322. #define Py_HUGE_VAL HUGE_VAL
  323. #endif
  324. /* Py_OVERFLOWED(X)
  325. * Return 1 iff a libm function overflowed. Set errno to 0 before calling
  326. * a libm function, and invoke this macro after, passing the function
  327. * result.
  328. * Caution:
  329. * This isn't reliable. C99 no longer requires libm to set errno under
  330. * any exceptional condition, but does require +- HUGE_VAL return
  331. * values on overflow. A 754 box *probably* maps HUGE_VAL to a
  332. * double infinity, and we're cool if that's so, unless the input
  333. * was an infinity and an infinity is the expected result. A C89
  334. * system sets errno to ERANGE, so we check for that too. We're
  335. * out of luck if a C99 754 box doesn't map HUGE_VAL to +Inf, or
  336. * if the returned result is a NaN, or if a C89 box returns HUGE_VAL
  337. * in non-overflow cases.
  338. * X is evaluated more than once.
  339. * Some platforms have better way to spell this, so expect some #ifdef'ery.
  340. *
  341. * OpenBSD uses 'isinf()' because a compiler bug on that platform causes
  342. * the longer macro version to be mis-compiled. This isn't optimal, and
  343. * should be removed once a newer compiler is available on that platform.
  344. * The system that had the failure was running OpenBSD 3.2 on Intel, with
  345. * gcc 2.95.3.
  346. *
  347. * According to Tim's checkin, the FreeBSD systems use isinf() to work
  348. * around a FPE bug on that platform.
  349. */
  350. #if defined(__FreeBSD__) || defined(__OpenBSD__)
  351. #define Py_OVERFLOWED(X) isinf(X)
  352. #else
  353. #define Py_OVERFLOWED(X) ((X) != 0.0 && (errno == ERANGE || \
  354. (X) == Py_HUGE_VAL || \
  355. (X) == -Py_HUGE_VAL))
  356. #endif
  357. /* Py_SET_ERRNO_ON_MATH_ERROR(x)
  358. * If a libm function did not set errno, but it looks like the result
  359. * overflowed or not-a-number, set errno to ERANGE or EDOM. Set errno
  360. * to 0 before calling a libm function, and invoke this macro after,
  361. * passing the function result.
  362. * Caution:
  363. * This isn't reliable. See Py_OVERFLOWED comments.
  364. * X is evaluated more than once.
  365. */
  366. #if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64))
  367. #define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM;
  368. #else
  369. #define _Py_SET_EDOM_FOR_NAN(X) ;
  370. #endif
  371. #define Py_SET_ERRNO_ON_MATH_ERROR(X) \
  372. do { \
  373. if (errno == 0) { \
  374. if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
  375. errno = ERANGE; \
  376. else _Py_SET_EDOM_FOR_NAN(X) \
  377. } \
  378. } while(0)
  379. /* Py_SET_ERANGE_ON_OVERFLOW(x)
  380. * An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility.
  381. */
  382. #define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X)
  383. /* Py_ADJUST_ERANGE1(x)
  384. * Py_ADJUST_ERANGE2(x, y)
  385. * Set errno to 0 before calling a libm function, and invoke one of these
  386. * macros after, passing the function result(s) (Py_ADJUST_ERANGE2 is useful
  387. * for functions returning complex results). This makes two kinds of
  388. * adjustments to errno: (A) If it looks like the platform libm set
  389. * errno=ERANGE due to underflow, clear errno. (B) If it looks like the
  390. * platform libm overflowed but didn't set errno, force errno to ERANGE. In
  391. * effect, we're trying to force a useful implementation of C89 errno
  392. * behavior.
  393. * Caution:
  394. * This isn't reliable. See Py_OVERFLOWED comments.
  395. * X and Y may be evaluated more than once.
  396. */
  397. #define Py_ADJUST_ERANGE1(X) \
  398. do { \
  399. if (errno == 0) { \
  400. if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
  401. errno = ERANGE; \
  402. } \
  403. else if (errno == ERANGE && (X) == 0.0) \
  404. errno = 0; \
  405. } while(0)
  406. #define Py_ADJUST_ERANGE2(X, Y) \
  407. do { \
  408. if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL || \
  409. (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) { \
  410. if (errno == 0) \
  411. errno = ERANGE; \
  412. } \
  413. else if (errno == ERANGE) \
  414. errno = 0; \
  415. } while(0)
  416. /* Py_DEPRECATED(version)
  417. * Declare a variable, type, or function deprecated.
  418. * Usage:
  419. * extern int old_var Py_DEPRECATED(2.3);
  420. * typedef int T1 Py_DEPRECATED(2.4);
  421. * extern int x() Py_DEPRECATED(2.5);
  422. */
  423. #if defined(__GNUC__) && ((__GNUC__ >= 4) || \
  424. (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
  425. #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
  426. #else
  427. #define Py_DEPRECATED(VERSION_UNUSED)
  428. #endif
  429. /**************************************************************************
  430. Prototypes that are missing from the standard include files on some systems
  431. (and possibly only some versions of such systems.)
  432. Please be conservative with adding new ones, document them and enclose them
  433. in platform-specific #ifdefs.
  434. **************************************************************************/
  435. #ifdef SOLARIS
  436. /* Unchecked */
  437. extern int gethostname(char *, int);
  438. #endif
  439. #ifdef __BEOS__
  440. /* Unchecked */
  441. /* It's in the libs, but not the headers... - [cjh] */
  442. int shutdown( int, int );
  443. #endif
  444. #ifdef HAVE__GETPTY
  445. #include <sys/types.h> /* we need to import mode_t */
  446. extern char * _getpty(int *, int, mode_t, int);
  447. #endif
  448. #if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)
  449. #if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H)
  450. /* BSDI does not supply a prototype for the 'openpty' and 'forkpty'
  451. functions, even though they are included in libutil. */
  452. #include <termios.h>
  453. extern int openpty(int *, int *, char *, struct termios *, struct winsize *);
  454. extern int forkpty(int *, char *, struct termios *, struct winsize *);
  455. #endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */
  456. #endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */
  457. /* These are pulled from various places. It isn't obvious on what platforms
  458. they are necessary, nor what the exact prototype should look like (which
  459. is likely to vary between platforms!) If you find you need one of these
  460. declarations, please move them to a platform-specific block and include
  461. proper prototypes. */
  462. #if 0
  463. /* From Modules/resource.c */
  464. extern int getrusage();
  465. extern int getpagesize();
  466. /* From Python/sysmodule.c and Modules/posixmodule.c */
  467. extern int fclose(FILE *);
  468. /* From Modules/posixmodule.c */
  469. extern int fdatasync(int);
  470. #endif /* 0 */
  471. /************************
  472. * WRAPPER FOR <math.h> *
  473. ************************/
  474. #ifndef HAVE_HYPOT
  475. extern double hypot(double, double);
  476. #endif
  477. /* On 4.4BSD-descendants, ctype functions serves the whole range of
  478. * wchar_t character set rather than single byte code points only.
  479. * This characteristic can break some operations of string object
  480. * including str.upper() and str.split() on UTF-8 locales. This
  481. * workaround was provided by Tim Robbins of FreeBSD project.
  482. */
  483. #ifdef __FreeBSD__
  484. #include <osreldate.h>
  485. #if __FreeBSD_version > 500039
  486. #include <ctype.h>
  487. #include <wctype.h>
  488. #undef isalnum
  489. #define isalnum(c) iswalnum(btowc(c))
  490. #undef isalpha
  491. #define isalpha(c) iswalpha(btowc(c))
  492. #undef islower
  493. #define islower(c) iswlower(btowc(c))
  494. #undef isspace
  495. #define isspace(c) iswspace(btowc(c))
  496. #undef isupper
  497. #define isupper(c) iswupper(btowc(c))
  498. #undef tolower
  499. #define tolower(c) towlower(btowc(c))
  500. #undef toupper
  501. #define toupper(c) towupper(btowc(c))
  502. #endif
  503. #endif
  504. /* Declarations for symbol visibility.
  505. PyAPI_FUNC(type): Declares a public Python API function and return type
  506. PyAPI_DATA(type): Declares public Python data and its type
  507. PyMODINIT_FUNC: A Python module init function. If these functions are
  508. inside the Python core, they are private to the core.
  509. If in an extension module, it may be declared with
  510. external linkage depending on the platform.
  511. As a number of platforms support/require "__declspec(dllimport/dllexport)",
  512. we support a HAVE_DECLSPEC_DLL macro to save duplication.
  513. */
  514. /*
  515. All windows ports, except cygwin, are handled in PC/pyconfig.h.
  516. BeOS and cygwin are the only other autoconf platform requiring special
  517. linkage handling and both of these use __declspec().
  518. */
  519. #if defined(__CYGWIN__) || defined(__BEOS__)
  520. # define HAVE_DECLSPEC_DLL
  521. #endif
  522. /* only get special linkage if built as shared or platform is Cygwin */
  523. #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
  524. # if defined(HAVE_DECLSPEC_DLL)
  525. # ifdef Py_BUILD_CORE
  526. # define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
  527. # define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE
  528. /* module init functions inside the core need no external linkage */
  529. /* except for Cygwin to handle embedding (FIXME: BeOS too?) */
  530. # if defined(__CYGWIN__)
  531. # define PyMODINIT_FUNC __declspec(dllexport) void
  532. # else /* __CYGWIN__ */
  533. # define PyMODINIT_FUNC void
  534. # endif /* __CYGWIN__ */
  535. # else /* Py_BUILD_CORE */
  536. /* Building an extension module, or an embedded situation */
  537. /* public Python functions and data are imported */
  538. /* Under Cygwin, auto-import functions to prevent compilation */
  539. /* failures similar to http://python.org/doc/FAQ.html#3.24 */
  540. # if !defined(__CYGWIN__)
  541. # define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
  542. # endif /* !__CYGWIN__ */
  543. # define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
  544. /* module init functions outside the core must be exported */
  545. # if defined(__cplusplus)
  546. # define PyMODINIT_FUNC extern "C" __declspec(dllexport) void
  547. # else /* __cplusplus */
  548. # define PyMODINIT_FUNC __declspec(dllexport) void
  549. # endif /* __cplusplus */
  550. # endif /* Py_BUILD_CORE */
  551. # endif /* HAVE_DECLSPEC */
  552. #endif /* Py_ENABLE_SHARED */
  553. /* If no external linkage macros defined by now, create defaults */
  554. #ifndef PyAPI_FUNC
  555. # define PyAPI_FUNC(RTYPE) RTYPE
  556. #endif
  557. #ifndef PyAPI_DATA
  558. # define PyAPI_DATA(RTYPE) extern RTYPE
  559. #endif
  560. #ifndef PyMODINIT_FUNC
  561. # if defined(__cplusplus)
  562. # define PyMODINIT_FUNC extern "C" void
  563. # else /* __cplusplus */
  564. # define PyMODINIT_FUNC void
  565. # endif /* __cplusplus */
  566. #endif
  567. /* Deprecated DL_IMPORT and DL_EXPORT macros */
  568. #if defined(Py_ENABLE_SHARED) && defined (HAVE_DECLSPEC_DLL)
  569. # if defined(Py_BUILD_CORE)
  570. # define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE
  571. # define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
  572. # else
  573. # define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE
  574. # define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
  575. # endif
  576. #endif
  577. #ifndef DL_EXPORT
  578. # define DL_EXPORT(RTYPE) RTYPE
  579. #endif
  580. #ifndef DL_IMPORT
  581. # define DL_IMPORT(RTYPE) RTYPE
  582. #endif
  583. /* End of deprecated DL_* macros */
  584. /* If the fd manipulation macros aren't defined,
  585. here is a set that should do the job */
  586. #if 0 /* disabled and probably obsolete */
  587. #ifndef FD_SETSIZE
  588. #define FD_SETSIZE 256
  589. #endif
  590. #ifndef FD_SET
  591. typedef long fd_mask;
  592. #define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
  593. #ifndef howmany
  594. #define howmany(x, y) (((x)+((y)-1))/(y))
  595. #endif /* howmany */
  596. typedef struct fd_set {
  597. fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
  598. } fd_set;
  599. #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  600. #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
  601. #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  602. #define FD_ZERO(p) memset((char *)(p), '\0', sizeof(*(p)))
  603. #endif /* FD_SET */
  604. #endif /* fd manipulation macros */
  605. /* limits.h constants that may be missing */
  606. #ifndef INT_MAX
  607. #define INT_MAX 2147483647
  608. #endif
  609. #ifndef LONG_MAX
  610. #if SIZEOF_LONG == 4
  611. #define LONG_MAX 0X7FFFFFFFL
  612. #elif SIZEOF_LONG == 8
  613. #define LONG_MAX 0X7FFFFFFFFFFFFFFFL
  614. #else
  615. #error "could not set LONG_MAX in pyport.h"
  616. #endif
  617. #endif
  618. #ifndef LONG_MIN
  619. #define LONG_MIN (-LONG_MAX-1)
  620. #endif
  621. #ifndef LONG_BIT
  622. #define LONG_BIT (8 * SIZEOF_LONG)
  623. #endif
  624. #if LONG_BIT != 8 * SIZEOF_LONG
  625. /* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent
  626. * 32-bit platforms using gcc. We try to catch that here at compile-time
  627. * rather than waiting for integer multiplication to trigger bogus
  628. * overflows.
  629. */
  630. #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
  631. #endif
  632. #ifdef __cplusplus
  633. }
  634. #endif
  635. /*
  636. * Hide GCC attributes from compilers that don't support them.
  637. */
  638. #if (!defined(__GNUC__) || __GNUC__ < 2 || \
  639. (__GNUC__ == 2 && __GNUC_MINOR__ < 7) ) && \
  640. !defined(RISCOS)
  641. #define Py_GCC_ATTRIBUTE(x)
  642. #else
  643. #define Py_GCC_ATTRIBUTE(x) __attribute__(x)
  644. #endif
  645. /* Eliminate end-of-loop code not reached warnings from SunPro C
  646. * when using do{...}while(0) macros
  647. */
  648. #ifdef __SUNPRO_C
  649. #pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)
  650. #endif
  651. /*
  652. * Older Microsoft compilers don't support the C99 long long literal suffixes,
  653. * so these will be defined in PC/pyconfig.h for those compilers.
  654. */
  655. #ifndef Py_LL
  656. #define Py_LL(x) x##LL
  657. #endif
  658. #ifndef Py_ULL
  659. #define Py_ULL(x) Py_LL(x##U)
  660. #endif
  661. #endif /* Py_PYPORT_H */