Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6562b29

Browse files
committed
Issue #23644: Fix issues with C++ when compiling Python extensions
Disable completly pyatomic.h on C++, because <stdatomic.h> is not compatible with C++. <pyatomic.h> is only needed by the optimized PyThreadState_GET() macro in pystate.h. Instead, declare PyThreadState_GET() as an alias to PyThreadState_Get(), as done for limited API.
1 parent b28de01 commit 6562b29

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

Include/pyatomic.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
#ifndef Py_LIMITED_API
1+
/* Issue #23644: <stdatomic.h> is incompatible with C++, see:
2+
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60932 */
3+
#if !defined(Py_LIMITED_API) && !defined(__cplusplus)
24
#ifndef Py_ATOMIC_H
35
#define Py_ATOMIC_H
46

57
#include "dynamic_annotations.h"
68

79
#include "pyconfig.h"
810

9-
#ifdef __cplusplus
10-
extern "C" {
11-
#endif
12-
1311
#if defined(HAVE_STD_ATOMIC)
1412
#include <stdatomic.h>
1513
#endif
@@ -250,9 +248,5 @@ _Py_ANNOTATE_MEMORY_ORDER(const volatile void *address, _Py_memory_order order)
250248
#define _Py_atomic_load_relaxed(ATOMIC_VAL) \
251249
_Py_atomic_load_explicit(ATOMIC_VAL, _Py_memory_order_relaxed)
252250

253-
#ifdef __cplusplus
254-
}
255-
#endif
256-
257251
#endif /* Py_ATOMIC_H */
258252
#endif /* Py_LIMITED_API */

Include/pystate.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,16 @@ PyAPI_FUNC(int) PyThreadState_SetAsyncExc(long, PyObject *);
174174
/* Variable and macro for in-line access to current thread state */
175175

176176
/* Assuming the current thread holds the GIL, this is the
177-
PyThreadState for the current thread. */
178-
#ifndef Py_LIMITED_API
177+
PyThreadState for the current thread.
178+
179+
Issue #23644: pyatomic.h is incompatible with C++ (yet). Disable
180+
PyThreadState_GET() optimization: declare it as an alias to
181+
PyThreadState_Get(), as done for limited API. */
182+
#if !defined(Py_LIMITED_API) && !defined(__cplusplus)
179183
PyAPI_DATA(_Py_atomic_address) _PyThreadState_Current;
180184
#endif
181185

182-
#if defined(Py_DEBUG) || defined(Py_LIMITED_API)
186+
#if defined(Py_DEBUG) || defined(Py_LIMITED_API) || defined(__cplusplus)
183187
#define PyThreadState_GET() PyThreadState_Get()
184188
#else
185189
#define PyThreadState_GET() \

0 commit comments

Comments
 (0)