Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
pymacro.h250 linesDownload Raw Back to include
1#ifndef Py_PYMACRO_H2#define Py_PYMACRO_H3 4// gh-91782: On FreeBSD 12, if the _POSIX_C_SOURCE and _XOPEN_SOURCE macros are5// defined, <sys/cdefs.h> disables C11 support and <assert.h> does not define6// the static_assert() macro.7// https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=2552908//9// macOS <= 10.10 doesn't define static_assert in assert.h at all despite10// having C11 compiler support.11//12// static_assert is defined in glibc from version 2.16. Compiler support for13// the C11 _Static_assert keyword is in gcc >= 4.6.14//15// MSVC makes static_assert a keyword in C11-17, contrary to the standards.16//17// In C++11 and C2x, static_assert is a keyword, redefining is undefined18// behaviour. So only define if building as C, not C++ (if __cplusplus is19// not defined), and only for C11-17.20#if !defined(static_assert) && (defined(__GNUC__) || defined(__clang__)) \21     && !defined(__cplusplus) && defined(__STDC_VERSION__) \22     && __STDC_VERSION__ >= 201112L && __STDC_VERSION__ <= 201710L23#  define static_assert _Static_assert24#endif25 26 27// _Py_ALIGN_AS: this compiler's spelling of `alignas` keyword,28// We currently use alignas for free-threaded builds only; additional compat29// checking would be great before we add it to the default build.30// Standards/compiler support:31// - `alignas` is a keyword in C23 and C++11.32// - `_Alignas` is a keyword in C1133// - GCC & clang has __attribute__((aligned))34//   (use that for older standards in pedantic mode)35// - MSVC has __declspec(align)36// - `_Alignas` is common C compiler extension37// Older compilers may name it differently; to allow compilation on such38// unsupported platforms, we don't redefine _Py_ALIGN_AS if it's already39// defined. Note that defining it wrong (including defining it to nothing) will40// cause ABI incompatibilities.41#ifdef Py_GIL_DISABLED42#   ifndef _Py_ALIGN_AS43#       ifdef __cplusplus44#           if __cplusplus >= 201103L45#               define _Py_ALIGN_AS(V) alignas(V)46#           elif defined(__GNUC__) || defined(__clang__)47#               define _Py_ALIGN_AS(V) __attribute__((aligned(V)))48#           elif defined(_MSC_VER)49#               define _Py_ALIGN_AS(V) __declspec(align(V))50#           else51#               define _Py_ALIGN_AS(V) alignas(V)52#           endif53#       elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L54#           define _Py_ALIGN_AS(V) alignas(V)55#       elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L56#           define _Py_ALIGN_AS(V) _Alignas(V)57#       elif (defined(__GNUC__) || defined(__clang__))58#           define _Py_ALIGN_AS(V) __attribute__((aligned(V)))59#       elif defined(_MSC_VER)60#           define _Py_ALIGN_AS(V) __declspec(align(V))61#       else62#           define _Py_ALIGN_AS(V) _Alignas(V)63#       endif64#   endif65#endif66 67/* Minimum value between x and y */68#define Py_MIN(x, y) (((x) > (y)) ? (y) : (x))69 70/* Maximum value between x and y */71#define Py_MAX(x, y) (((x) > (y)) ? (x) : (y))72 73/* Absolute value of the number x */74#define Py_ABS(x) ((x) < 0 ? -(x) : (x))75/* Safer implementation that avoids an undefined behavior for the minimal76   value of the signed integer type if its absolute value is larger than77   the maximal value of the signed integer type (in the two's complement78   representations, which is common).79 */80#define _Py_ABS_CAST(T, x) ((x) >= 0 ? ((T) (x)) : ((T) (((T) -((x) + 1)) + 1u)))81 82#define _Py_XSTRINGIFY(x) #x83 84/* Convert the argument to a string. For example, Py_STRINGIFY(123) is replaced85   with "123" by the preprocessor. Defines are also replaced by their value.86   For example Py_STRINGIFY(__LINE__) is replaced by the line number, not87   by "__LINE__". */88#define Py_STRINGIFY(x) _Py_XSTRINGIFY(x)89 90/* Get the size of a structure member in bytes */91#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)92 93/* Argument must be a char or an int in [-128, 127] or [0, 255]. */94#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))95 96#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \97     && !defined(__cplusplus) && !defined(_MSC_VER))98#  define Py_BUILD_ASSERT_EXPR(cond) \99    ((void)sizeof(struct { int dummy; _Static_assert(cond, #cond); }), \100     0)101#else102   /* Assert a build-time dependency, as an expression.103    *104    * Your compile will fail if the condition isn't true, or can't be evaluated105    * by the compiler. This can be used in an expression: its value is 0.106    *107    * Example:108    *109    * #define foo_to_char(foo)  \110    *     ((char *)(foo)        \111    *      + Py_BUILD_ASSERT_EXPR(offsetof(struct foo, string) == 0))112    *113    * Written by Rusty Russell, public domain, http://ccodearchive.net/114    */115#  define Py_BUILD_ASSERT_EXPR(cond) \116    (sizeof(char [1 - 2*!(cond)]) - 1)117#endif118 119#if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) \120     || (defined(__cplusplus) && __cplusplus >= 201103L))121   // Use static_assert() on C11 and newer122#  define Py_BUILD_ASSERT(cond) \123        do { \124            static_assert((cond), #cond); \125        } while (0)126#else127#  define Py_BUILD_ASSERT(cond)  \128        do { \129            (void)Py_BUILD_ASSERT_EXPR(cond); \130        } while(0)131#endif132 133/* Get the number of elements in a visible array134 135   This does not work on pointers, or arrays declared as [], or function136   parameters. With correct compiler support, such usage will cause a build137   error (see Py_BUILD_ASSERT_EXPR).138 139   Written by Rusty Russell, public domain, http://ccodearchive.net/140 141   Requires at GCC 3.1+ */142#if (defined(__GNUC__) && !defined(__STRICT_ANSI__) && \143    (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)) || (__GNUC__ >= 4)))144/* Two gcc extensions.145   &a[0] degrades to a pointer: a different type from an array */146#define Py_ARRAY_LENGTH(array) \147    (sizeof(array) / sizeof((array)[0]) \148     + Py_BUILD_ASSERT_EXPR(!__builtin_types_compatible_p(typeof(array), \149                                                          typeof(&(array)[0]))))150#else151#define Py_ARRAY_LENGTH(array) \152    (sizeof(array) / sizeof((array)[0]))153#endif154 155 156/* Define macros for inline documentation. */157#define PyDoc_VAR(name) static const char name[]158#define PyDoc_STRVAR(name,str) PyDoc_VAR(name) = PyDoc_STR(str)159#ifdef WITH_DOC_STRINGS160#define PyDoc_STR(str) str161#else162#define PyDoc_STR(str) ""163#endif164 165/* Below "a" is a power of 2. */166/* Round down size "n" to be a multiple of "a". */167#define _Py_SIZE_ROUND_DOWN(n, a) ((size_t)(n) & ~(size_t)((a) - 1))168/* Round up size "n" to be a multiple of "a". */169#define _Py_SIZE_ROUND_UP(n, a) (((size_t)(n) + \170        (size_t)((a) - 1)) & ~(size_t)((a) - 1))171/* Round pointer "p" down to the closest "a"-aligned address <= "p". */172#define _Py_ALIGN_DOWN(p, a) ((void *)((uintptr_t)(p) & ~(uintptr_t)((a) - 1)))173/* Round pointer "p" up to the closest "a"-aligned address >= "p". */174#define _Py_ALIGN_UP(p, a) ((void *)(((uintptr_t)(p) + \175        (uintptr_t)((a) - 1)) & ~(uintptr_t)((a) - 1)))176/* Check if pointer "p" is aligned to "a"-bytes boundary. */177#define _Py_IS_ALIGNED(p, a) (!((uintptr_t)(p) & (uintptr_t)((a) - 1)))178 179/* Use this for unused arguments in a function definition to silence compiler180 * warnings. Example:181 *182 * int func(int a, int Py_UNUSED(b)) { return a; }183 */184#if defined(__GNUC__) || defined(__clang__)185#  define Py_UNUSED(name) _unused_ ## name __attribute__((unused))186#elif defined(_MSC_VER)187   // Disable warning C4100: unreferenced formal parameter,188   // declare the parameter,189   // restore old compiler warnings.190#  define Py_UNUSED(name) \191        __pragma(warning(push)) \192        __pragma(warning(suppress: 4100)) \193        _unused_ ## name \194        __pragma(warning(pop))195#else196#  define Py_UNUSED(name) _unused_ ## name197#endif198 199#if defined(RANDALL_WAS_HERE)200#  define Py_UNREACHABLE() \201    Py_FatalError( \202        "If you're seeing this, the code is in what I thought was\n" \203        "an unreachable state.\n\n" \204        "I could give you advice for what to do, but honestly, why\n" \205        "should you trust me?  I clearly screwed this up.  I'm writing\n" \206        "a message that should never appear, yet I know it will\n" \207        "probably appear someday.\n\n" \208        "On a deep level, I know I'm not up to this task.\n" \209        "I'm so sorry.\n" \210        "https://xkcd.com/2200")211#elif defined(Py_DEBUG)212#  define Py_UNREACHABLE() \213    Py_FatalError( \214        "We've reached an unreachable state. Anything is possible.\n" \215        "The limits were in our heads all along. Follow your dreams.\n" \216        "https://xkcd.com/2200")217#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))218#  define Py_UNREACHABLE() __builtin_unreachable()219#elif defined(__clang__) || defined(__INTEL_COMPILER)220#  define Py_UNREACHABLE() __builtin_unreachable()221#elif defined(_MSC_VER)222#  define Py_UNREACHABLE() __assume(0)223#else224#  define Py_UNREACHABLE() \225    Py_FatalError("Unreachable C code path reached")226#endif227 228#define _Py_CONTAINER_OF(ptr, type, member) \229    (type*)((char*)ptr - offsetof(type, member))230 231// Prevent using an expression as a l-value.232// For example, "int x; _Py_RVALUE(x) = 1;" fails with a compiler error.233#define _Py_RVALUE(EXPR) ((void)0, (EXPR))234 235// Return non-zero if the type is signed, return zero if it's unsigned.236// Use "<= 0" rather than "< 0" to prevent the compiler warning:237// "comparison of unsigned expression in '< 0' is always false".238#define _Py_IS_TYPE_SIGNED(type) ((type)(-1) <= 0)239 240#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030E0000 // 3.14241// Version helpers. These are primarily macros, but have exported equivalents.242PyAPI_FUNC(uint32_t) Py_PACK_FULL_VERSION(int x, int y, int z, int level, int serial);243PyAPI_FUNC(uint32_t) Py_PACK_VERSION(int x, int y);244#define Py_PACK_FULL_VERSION _Py_PACK_FULL_VERSION245#define Py_PACK_VERSION(X, Y) Py_PACK_FULL_VERSION(X, Y, 0, 0, 0)246#endif // Py_LIMITED_API < 3.14247 248 249#endif /* Py_PYMACRO_H */250 
codekingpro/portable-devtools · Team Ai