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 | |
| 26 | RETSIGTYPE |
| 27 | Meaning: Expands to void or int, depending on what the platform wants |
| 28 | signal handlers to return. Note that only void is ANSI! |
| 29 | Used in: Py_RETURN_FROM_SIGNAL_HANDLER |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 30 | **************************************************************************/ |
| 31 | |
| 32 | |
| 33 | #ifdef __cplusplus |
| 34 | extern "C" { |
| 35 | #endif |
| 36 | |
| 37 | /* Py_ARITHMETIC_RIGHT_SHIFT |
| 38 | * C doesn't define whether a right-shift of a signed integer sign-extends |
| 39 | * or zero-fills. Here a macro to force sign extension: |
| 40 | * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) |
| 41 | * Return I >> J, forcing sign extension. |
| 42 | * Requirements: |
| 43 | * I is of basic signed type TYPE (char, short, int, long, or long long). |
| 44 | * TYPE is one of char, short, int, long, or long long, although long long |
| 45 | * must not be used except on platforms that support it. |
| 46 | * J is an integer >= 0 and strictly less than the number of bits in TYPE |
| 47 | * (because C doesn't define what happens for J outside that range either). |
| 48 | * Caution: |
| 49 | * I may be evaluated more than once. |
| 50 | */ |
| 51 | #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS |
| 52 | #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \ |
| 53 | ((I) < 0 ? ~((~(unsigned TYPE)(I)) >> (J)) : (I) >> (J)) |
| 54 | #else |
| 55 | #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J)) |
| 56 | #endif |
| 57 | |
Tim Peters | 1be4684 | 2000-07-23 18:10:18 +0000 | [diff] [blame^] | 58 | /* Py_FORCE_EXPANSION |
| 59 | * "Simply" returns its argument. However, macro expansions within the |
| 60 | * argument are evaluated. This unfortunate trickery is needed to get |
| 61 | * token-pasting to work as desired in some cases. |
| 62 | */ |
| 63 | #define Py_FORCE_EXPANSION(X) X |
| 64 | |
| 65 | /* Py_RETURN_FROM_SIGNAL_HANDLER |
| 66 | * The return from a signal handler varies depending on whether RETSIGTYPE |
| 67 | * is int or void. The macro Py_RETURN_FROM_SIGNAL_HANDLER(VALUE) expands |
| 68 | * to |
| 69 | * return VALUE |
| 70 | * if RETSIGTYPE is int, else to nothing if RETSIGTYPE is void. |
| 71 | */ |
| 72 | #define int_PySIGRETURN(VALUE) return VALUE |
| 73 | #define void_PySIGRETURN(VALUE) |
| 74 | #define Py_RETURN_FROM_SIGNAL_HANDLER(VALUE) \ |
| 75 | Py_FORCE_EXPANSION(RETSIGTYPE) ## _PySIGRETURN(VALUE) |
| 76 | |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 77 | #ifdef __cplusplus |
| 78 | } |
| 79 | #endif |
| 80 | |
| 81 | #endif /* Py_PYPORT_H */ |