blob: 4faba7c9f0eae81def76272e82550487c52c78d5 [file] [log] [blame]
Tim Peters7d3a5112000-07-08 04:17:21 +00001/***********************************************************
2Copyright (c) 2000, BeOpen.com.
3All rights reserved.
4
5See the file "Misc/COPYRIGHT" for information on usage and
6redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7******************************************************************/
8
9#ifndef Py_PYPORT_H
Vladimir Marangozov14a4d882000-07-10 04:59:49 +000010#define Py_PYPORT_H
Tim Peters7d3a5112000-07-08 04:17:21 +000011
12/**************************************************************************
13Symbols and macros to supply platform-independent interfaces to basic
Tim Peters1be46842000-07-23 18:10:18 +000014C language & library operations whose spellings vary across platforms.
Tim Peters7d3a5112000-07-08 04:17:21 +000015
16Please try to make documentation here as clear as possible: by definition,
17the stuff here is trying to illuminate C's darkest corners.
18
19Config #defines referenced here:
20
21SIGNED_RIGHT_SHIFT_ZERO_FILLS
22Meaning: To be defined iff i>>j does not extend the sign bit when i is a
23 signed integral type and i < 0.
24Used in: Py_ARITHMETIC_RIGHT_SHIFT
Tim Peters1be46842000-07-23 18:10:18 +000025
26RETSIGTYPE
27Meaning: Expands to void or int, depending on what the platform wants
28 signal handlers to return. Note that only void is ANSI!
29Used in: Py_RETURN_FROM_SIGNAL_HANDLER
Tim Peters7d3a5112000-07-08 04:17:21 +000030**************************************************************************/
31
32
33#ifdef __cplusplus
34extern "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 Peters1be46842000-07-23 18:10:18 +000058/* 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 Peters7d3a5112000-07-08 04:17:21 +000077#ifdef __cplusplus
78}
79#endif
80
81#endif /* Py_PYPORT_H */