File indexing completed on 2025-01-18 10:06:50
0001 #ifndef Py_PYMACRO_H
0002 #define Py_PYMACRO_H
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #if !defined(static_assert) && (defined(__GNUC__) || defined(__clang__)) \
0021 && !defined(__cplusplus) && defined(__STDC_VERSION__) \
0022 && __STDC_VERSION__ >= 201112L && __STDC_VERSION__ <= 201710L
0023 # define static_assert _Static_assert
0024 #endif
0025
0026
0027 #define Py_MIN(x, y) (((x) > (y)) ? (y) : (x))
0028
0029
0030 #define Py_MAX(x, y) (((x) > (y)) ? (x) : (y))
0031
0032
0033 #define Py_ABS(x) ((x) < 0 ? -(x) : (x))
0034
0035 #define _Py_XSTRINGIFY(x) #x
0036
0037
0038
0039
0040
0041 #define Py_STRINGIFY(x) _Py_XSTRINGIFY(x)
0042
0043
0044 #define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
0045
0046
0047 #define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 #define Py_BUILD_ASSERT_EXPR(cond) \
0062 (sizeof(char [1 - 2*!(cond)]) - 1)
0063
0064 #define Py_BUILD_ASSERT(cond) do { \
0065 (void)Py_BUILD_ASSERT_EXPR(cond); \
0066 } while(0)
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 #if (defined(__GNUC__) && !defined(__STRICT_ANSI__) && \
0078 (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)) || (__GNUC__ >= 4)))
0079
0080
0081 #define Py_ARRAY_LENGTH(array) \
0082 (sizeof(array) / sizeof((array)[0]) \
0083 + Py_BUILD_ASSERT_EXPR(!__builtin_types_compatible_p(typeof(array), \
0084 typeof(&(array)[0]))))
0085 #else
0086 #define Py_ARRAY_LENGTH(array) \
0087 (sizeof(array) / sizeof((array)[0]))
0088 #endif
0089
0090
0091
0092 #define PyDoc_VAR(name) static const char name[]
0093 #define PyDoc_STRVAR(name,str) PyDoc_VAR(name) = PyDoc_STR(str)
0094 #ifdef WITH_DOC_STRINGS
0095 #define PyDoc_STR(str) str
0096 #else
0097 #define PyDoc_STR(str) ""
0098 #endif
0099
0100
0101
0102 #define _Py_SIZE_ROUND_DOWN(n, a) ((size_t)(n) & ~(size_t)((a) - 1))
0103
0104 #define _Py_SIZE_ROUND_UP(n, a) (((size_t)(n) + \
0105 (size_t)((a) - 1)) & ~(size_t)((a) - 1))
0106
0107 #define _Py_ALIGN_DOWN(p, a) ((void *)((uintptr_t)(p) & ~(uintptr_t)((a) - 1)))
0108
0109 #define _Py_ALIGN_UP(p, a) ((void *)(((uintptr_t)(p) + \
0110 (uintptr_t)((a) - 1)) & ~(uintptr_t)((a) - 1)))
0111
0112 #define _Py_IS_ALIGNED(p, a) (!((uintptr_t)(p) & (uintptr_t)((a) - 1)))
0113
0114
0115
0116
0117
0118
0119 #if defined(__GNUC__) || defined(__clang__)
0120 # define Py_UNUSED(name) _unused_ ## name __attribute__((unused))
0121 #else
0122 # define Py_UNUSED(name) _unused_ ## name
0123 #endif
0124
0125 #if defined(RANDALL_WAS_HERE)
0126 # define Py_UNREACHABLE() \
0127 Py_FatalError( \
0128 "If you're seeing this, the code is in what I thought was\n" \
0129 "an unreachable state.\n\n" \
0130 "I could give you advice for what to do, but honestly, why\n" \
0131 "should you trust me? I clearly screwed this up. I'm writing\n" \
0132 "a message that should never appear, yet I know it will\n" \
0133 "probably appear someday.\n\n" \
0134 "On a deep level, I know I'm not up to this task.\n" \
0135 "I'm so sorry.\n" \
0136 "https://xkcd.com/2200")
0137 #elif defined(Py_DEBUG)
0138 # define Py_UNREACHABLE() \
0139 Py_FatalError( \
0140 "We've reached an unreachable state. Anything is possible.\n" \
0141 "The limits were in our heads all along. Follow your dreams.\n" \
0142 "https://xkcd.com/2200")
0143 #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
0144 # define Py_UNREACHABLE() __builtin_unreachable()
0145 #elif defined(__clang__) || defined(__INTEL_COMPILER)
0146 # define Py_UNREACHABLE() __builtin_unreachable()
0147 #elif defined(_MSC_VER)
0148 # define Py_UNREACHABLE() __assume(0)
0149 #else
0150 # define Py_UNREACHABLE() \
0151 Py_FatalError("Unreachable C code path reached")
0152 #endif
0153
0154
0155
0156 #define _Py_RVALUE(EXPR) ((void)0, (EXPR))
0157
0158
0159
0160
0161 #define _Py_IS_TYPE_SIGNED(type) ((type)(-1) <= 0)
0162
0163 #endif