Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 1 | /*********************************************************** |
| 2 | Copyright (c) 2000, BeOpen.com. |
| 3 | All rights reserved. |
| 4 | |
| 5 | See the file "Misc/COPYRIGHT" for information on usage and |
| 6 | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 7 | ******************************************************************/ |
| 8 | |
| 9 | #ifndef Py_PYPORT_H |
Vladimir Marangozov | 14a4d88 | 2000-07-10 04:59:49 +0000 | [diff] [blame] | 10 | #define Py_PYPORT_H |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 11 | |
| 12 | /************************************************************************** |
| 13 | Symbols and macros to supply platform-independent interfaces to basic |
Tim Peters | 1be4684 | 2000-07-23 18:10:18 +0000 | [diff] [blame] | 14 | C language & library operations whose spellings vary across platforms. |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 15 | |
| 16 | Please try to make documentation here as clear as possible: by definition, |
| 17 | the stuff here is trying to illuminate C's darkest corners. |
| 18 | |
| 19 | Config #defines referenced here: |
| 20 | |
| 21 | SIGNED_RIGHT_SHIFT_ZERO_FILLS |
| 22 | Meaning: To be defined iff i>>j does not extend the sign bit when i is a |
| 23 | signed integral type and i < 0. |
| 24 | Used in: Py_ARITHMETIC_RIGHT_SHIFT |
Tim Peters | 1be4684 | 2000-07-23 18:10:18 +0000 | [diff] [blame] | 25 | |
Tim Peters | 8315ea5 | 2000-07-23 19:28:35 +0000 | [diff] [blame] | 26 | Py_DEBUG |
| 27 | Meaning: Extra checks compiled in for debug mode. |
| 28 | Used in: Py_SAFE_DOWNCAST |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 29 | **************************************************************************/ |
| 30 | |
| 31 | |
| 32 | #ifdef __cplusplus |
| 33 | extern "C" { |
| 34 | #endif |
| 35 | |
| 36 | /* Py_ARITHMETIC_RIGHT_SHIFT |
| 37 | * C doesn't define whether a right-shift of a signed integer sign-extends |
| 38 | * or zero-fills. Here a macro to force sign extension: |
| 39 | * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) |
| 40 | * Return I >> J, forcing sign extension. |
| 41 | * Requirements: |
| 42 | * I is of basic signed type TYPE (char, short, int, long, or long long). |
| 43 | * TYPE is one of char, short, int, long, or long long, although long long |
| 44 | * must not be used except on platforms that support it. |
| 45 | * J is an integer >= 0 and strictly less than the number of bits in TYPE |
| 46 | * (because C doesn't define what happens for J outside that range either). |
| 47 | * Caution: |
| 48 | * I may be evaluated more than once. |
| 49 | */ |
| 50 | #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS |
| 51 | #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \ |
| 52 | ((I) < 0 ? ~((~(unsigned TYPE)(I)) >> (J)) : (I) >> (J)) |
| 53 | #else |
| 54 | #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J)) |
| 55 | #endif |
| 56 | |
Tim Peters | 1be4684 | 2000-07-23 18:10:18 +0000 | [diff] [blame] | 57 | /* Py_FORCE_EXPANSION |
| 58 | * "Simply" returns its argument. However, macro expansions within the |
| 59 | * argument are evaluated. This unfortunate trickery is needed to get |
| 60 | * token-pasting to work as desired in some cases. |
| 61 | */ |
| 62 | #define Py_FORCE_EXPANSION(X) X |
| 63 | |
Tim Peters | 8315ea5 | 2000-07-23 19:28:35 +0000 | [diff] [blame] | 64 | /* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) |
| 65 | * Cast VALUE to type NARROW from type WIDE. In Py_DEBUG mode, this |
| 66 | * assert-fails if any information is lost. |
| 67 | * Caution: |
| 68 | * VALUE may be evaluated more than once. |
| 69 | */ |
| 70 | #ifdef Py_DEBUG |
| 71 | #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \ |
| 72 | (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE)) |
| 73 | #else |
| 74 | #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE) |
| 75 | #endif |
| 76 | |
Thomas Wouters | 1e0c2f4 | 2000-07-24 16:06:23 +0000 | [diff] [blame] | 77 | |
| 78 | |
| 79 | /************************************************************************** |
| 80 | Prototypes that are missing from the standard include files on some systems |
| 81 | (and possibly only some versions of such systems.) |
| 82 | |
| 83 | Please be conservative with adding new ones, document them and enclose them |
| 84 | in platform-specific #ifdefs. |
| 85 | **************************************************************************/ |
| 86 | |
| 87 | #ifdef SOLARIS |
| 88 | /* Unchecked */ |
| 89 | extern int gethostname(char *, int); |
| 90 | #endif |
| 91 | |
| 92 | #ifdef __BEOS__ |
| 93 | /* Unchecked */ |
| 94 | /* It's in the libs, but not the headers... - [cjh] */ |
| 95 | int shutdown( int, int ); |
| 96 | #endif |
| 97 | |
| 98 | #ifdef HAVE__GETPTY |
Sjoerd Mullender | 0765fe3 | 2000-07-26 15:46:29 +0000 | [diff] [blame] | 99 | #include <sys/types.h> /* we need to import mode_t */ |
Thomas Wouters | 1e0c2f4 | 2000-07-24 16:06:23 +0000 | [diff] [blame] | 100 | extern char * _getpty(int *, int, mode_t, int); |
| 101 | #endif |
| 102 | |
| 103 | #if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) |
| 104 | #if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) |
| 105 | /* BSDI does not supply a prototype for the 'openpty' and 'forkpty' |
| 106 | functions, even though they are included in libutil. */ |
| 107 | #include <termios.h> |
| 108 | extern int openpty(int *, int *, char *, struct termios *, struct winsize *); |
| 109 | extern int forkpty(int *, char *, struct termios *, struct winsize *); |
| 110 | #endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */ |
| 111 | #endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */ |
| 112 | |
| 113 | |
| 114 | /* These are pulled from various places. It isn't obvious on what platforms |
| 115 | they are necessary, nor what the exact prototype should look like (which |
| 116 | is likely to vary between platforms!) If you find you need one of these |
| 117 | declarations, please move them to a platform-specific block and include |
| 118 | proper prototypes. */ |
| 119 | #if 0 |
| 120 | |
| 121 | /* From Modules/resource.c */ |
| 122 | extern int getrusage(); |
| 123 | extern int getpagesize(); |
| 124 | |
| 125 | /* From Python/sysmodule.c and Modules/posixmodule.c */ |
| 126 | extern int fclose(FILE *); |
| 127 | |
| 128 | /* From Modules/posixmodule.c */ |
| 129 | extern int fdatasync(int); |
| 130 | /* XXX These are supposedly for SunOS4.1.3 but "shouldn't hurt elsewhere" */ |
| 131 | extern int rename(const char *, const char *); |
| 132 | extern int pclose(FILE *); |
| 133 | extern int lstat(const char *, struct stat *); |
| 134 | extern int symlink(const char *, const char *); |
| 135 | extern int fsync(int fd); |
| 136 | |
| 137 | #endif /* 0 */ |
| 138 | |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 139 | #ifdef __cplusplus |
| 140 | } |
| 141 | #endif |
| 142 | |
| 143 | #endif /* Py_PYPORT_H */ |