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 |
| 14 | C-language operations whose spellings vary across platforms. |
| 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 |
| 25 | **************************************************************************/ |
| 26 | |
| 27 | |
| 28 | #ifdef __cplusplus |
| 29 | extern "C" { |
| 30 | #endif |
| 31 | |
| 32 | /* Py_ARITHMETIC_RIGHT_SHIFT |
| 33 | * C doesn't define whether a right-shift of a signed integer sign-extends |
| 34 | * or zero-fills. Here a macro to force sign extension: |
| 35 | * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) |
| 36 | * Return I >> J, forcing sign extension. |
| 37 | * Requirements: |
| 38 | * I is of basic signed type TYPE (char, short, int, long, or long long). |
| 39 | * TYPE is one of char, short, int, long, or long long, although long long |
| 40 | * must not be used except on platforms that support it. |
| 41 | * J is an integer >= 0 and strictly less than the number of bits in TYPE |
| 42 | * (because C doesn't define what happens for J outside that range either). |
| 43 | * Caution: |
| 44 | * I may be evaluated more than once. |
| 45 | */ |
| 46 | #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS |
| 47 | #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \ |
| 48 | ((I) < 0 ? ~((~(unsigned TYPE)(I)) >> (J)) : (I) >> (J)) |
| 49 | #else |
| 50 | #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J)) |
| 51 | #endif |
| 52 | |
| 53 | #ifdef __cplusplus |
| 54 | } |
| 55 | #endif |
| 56 | |
| 57 | #endif /* Py_PYPORT_H */ |