mirror of
https://github.com/python/cpython.git
synced 2026-10-28 10:25:05 +08:00
gh-160208: Add a private wrapper around __STDC_VERSION__ (GH-160376)
The wrapper is undefined on C++, where it can have an arbitrary compiler-specific value.
This commit is contained in:
1 parent
ef08833eec
commit
8335bcbf26
5 files changed
+19
-22
No files matched your search
@@ -585,7 +585,7 @@ static inline void _Py_atomic_fence_release(void);
|
||||
# define Py_ATOMIC_GCC_H
|
||||
# include "pyatomic_gcc.h"
|
||||
# undef Py_ATOMIC_GCC_H
|
||||
#elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)
|
||||
#elif _Py_STDC_VERSION >= 201112L && !defined(__STDC_NO_ATOMICS__)
|
||||
# define Py_ATOMIC_STD_H
|
||||
# include "pyatomic_std.h"
|
||||
# undef Py_ATOMIC_STD_H
|
||||
|
||||
+14
-7
@@ -1,6 +1,13 @@
|
||||
#ifndef Py_PYMACRO_H
|
||||
#define Py_PYMACRO_H
|
||||
|
||||
// _Py_STDC_VERSION: the version of the C standard.
|
||||
// gh-160208: The C++ standard allows __STDC_VERSION__ to be defined to an
|
||||
// arbitrary value, which means we can't use __STDC_VERSION__ on C++.
|
||||
#if !defined(__cplusplus) && defined(__STDC_VERSION__)
|
||||
# define _Py_STDC_VERSION __STDC_VERSION__
|
||||
#endif
|
||||
|
||||
// gh-91782: On FreeBSD 12, if the _POSIX_C_SOURCE and _XOPEN_SOURCE macros are
|
||||
// defined, <sys/cdefs.h> disables C11 support and <assert.h> does not define
|
||||
// the static_assert() macro.
|
||||
@@ -18,8 +25,8 @@
|
||||
// behaviour. So only define if building as C, not C++ (if __cplusplus is
|
||||
// not defined), and only for C11-17.
|
||||
#if !defined(static_assert) && (defined(__GNUC__) || defined(__clang__)) \
|
||||
&& !defined(__cplusplus) && defined(__STDC_VERSION__) \
|
||||
&& __STDC_VERSION__ >= 201112L && __STDC_VERSION__ <= 201710L
|
||||
&& !defined(_Py_STDC_VERSION) \
|
||||
&& _Py_STDC_VERSION >= 201112L && _Py_STDC_VERSION <= 201710L
|
||||
# define static_assert _Static_assert
|
||||
#endif
|
||||
|
||||
@@ -75,9 +82,9 @@
|
||||
# endif
|
||||
# elif defined(_MSC_VER)
|
||||
# define _Py_ALIGNED_DEF(N, T) __declspec(align(N)) T
|
||||
# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
|
||||
# elif defined(_Py_STDC_VERSION) && _Py_STDC_VERSION >= 202311L
|
||||
# define _Py_ALIGNED_DEF(N, T) alignas(N) alignas(T) T
|
||||
# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
||||
# elif defined(_Py_STDC_VERSION) && _Py_STDC_VERSION >= 201112L
|
||||
# define _Py_ALIGNED_DEF(N, T) _Alignas(N) _Alignas(T) T
|
||||
# elif (defined(__GNUC__) || defined(__clang__))
|
||||
# define _Py_ALIGNED_DEF(N, T) __attribute__((aligned(N))) T
|
||||
@@ -100,7 +107,7 @@
|
||||
// predefined value of _Py_ANONYMOUS if it exists.
|
||||
#ifndef _Py_ANONYMOUS
|
||||
# if (defined(__GNUC__) || defined(__clang__)) \
|
||||
&& !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
|
||||
&& !(defined(_Py_STDC_VERSION) && _Py_STDC_VERSION >= 201112L)
|
||||
# define _Py_ANONYMOUS __extension__
|
||||
# else
|
||||
# define _Py_ANONYMOUS
|
||||
@@ -162,7 +169,7 @@
|
||||
/* Argument must be a char or an int in [-128, 127] or [0, 255]. */
|
||||
#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
|
||||
|
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \
|
||||
#if (defined(_Py_STDC_VERSION) && _Py_STDC_VERSION >= 201112L \
|
||||
&& !defined(__cplusplus) && !defined(_MSC_VER))
|
||||
# define Py_BUILD_ASSERT_EXPR(cond) \
|
||||
((void)sizeof(struct { int dummy; _Static_assert(cond, #cond); }), \
|
||||
@@ -185,7 +192,7 @@
|
||||
(sizeof(char [1 - 2*!(cond)]) - 1)
|
||||
#endif
|
||||
|
||||
#if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) \
|
||||
#if ((defined(_Py_STDC_VERSION) && _Py_STDC_VERSION >= 201112L) \
|
||||
|| (defined(__cplusplus) && __cplusplus >= 201103L))
|
||||
// Use static_assert() on C11 and newer
|
||||
# define Py_BUILD_ASSERT(cond) \
|
||||
|
||||
+3
-3
@@ -50,7 +50,7 @@
|
||||
// to prevent C++ compiler warnings. On C23 and newer and on C++11 and newer,
|
||||
// _Py_NULL is defined as nullptr.
|
||||
#if !defined(_MSC_VER) && \
|
||||
((defined (__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) \
|
||||
((defined (_Py_STDC_VERSION) && _Py_STDC_VERSION >= 202311L) \
|
||||
|| (defined(__cplusplus) && __cplusplus >= 201103))
|
||||
# define _Py_NULL nullptr
|
||||
#else
|
||||
@@ -491,7 +491,7 @@ extern "C" {
|
||||
#ifdef WITH_THREAD
|
||||
# ifdef thread_local
|
||||
# define _Py_thread_local thread_local
|
||||
# elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
|
||||
# elif _Py_STDC_VERSION >= 201112L && !defined(__STDC_NO_THREADS__)
|
||||
# define _Py_thread_local _Thread_local
|
||||
# elif defined(_MSC_VER) /* AKA NT_THREADS */
|
||||
# define _Py_thread_local __declspec(thread)
|
||||
@@ -543,7 +543,7 @@ extern "C" {
|
||||
//
|
||||
// gh-157649: Do not use decltype() on C++, since it produces invalid code in
|
||||
// Py_CLEAR()/Py_SETREF().
|
||||
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
|
||||
#if defined (_Py_STDC_VERSION) && _Py_STDC_VERSION >= 202311L
|
||||
# define _Py_TYPEOF(expr) typeof(expr)
|
||||
#elif (defined(__GNUC__) || defined(__clang__) \
|
||||
|| (defined(_MSC_VER) && _MSC_VER >= 1939 && !defined(__cplusplus)))
|
||||
|
||||
@@ -13,16 +13,6 @@
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#ifdef thread_local
|
||||
# define _Py_thread_local thread_local
|
||||
#elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
|
||||
# define _Py_thread_local _Thread_local
|
||||
#elif defined(_MSC_VER) /* AKA NT_THREADS */
|
||||
# define _Py_thread_local __declspec(thread)
|
||||
#elif defined(__GNUC__) /* includes clang */
|
||||
# define _Py_thread_local __thread
|
||||
#endif
|
||||
|
||||
#if defined(_Py_FFI_SUPPORT_C_COMPLEX)
|
||||
# include <complex.h> // csqrt()
|
||||
# undef I // for _ctypes_test_generated.c.h
|
||||
|
||||
@@ -2694,7 +2694,7 @@ static PyObject *
|
||||
math_issubnormal_impl(PyObject *module, double x)
|
||||
/*[clinic end generated code: output=4e76ac98ddcae761 input=9a20aba7107d0d95]*/
|
||||
{
|
||||
#if !defined(_MSC_VER) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
|
||||
#if !defined(_MSC_VER) && defined(_Py_STDC_VERSION) && _Py_STDC_VERSION >= 202311L
|
||||
return PyBool_FromLong(issubnormal(x));
|
||||
#else
|
||||
return PyBool_FromLong(isfinite(x) && x && !isnormal(x));
|
||||
|
||||
Reference in new issue
Block a user