Skip to content

Commit cdde29d

Browse files
gh-99337: Fix compile errors with gcc 12 on macOS (#99470)
Fix a number of compile errors with GCC-12 on macOS: 1. In pylifecycle.c the compile rejects _Pragma within a declaration 2. posixmodule.c was missing a number of ..._RUNTIME macros for non-clang on macOS 3. _ctypes assumed that __builtin_available is always present on macOS
1 parent 6d8da23 commit cdde29d

File tree

7 files changed

+54
-9
lines changed

7 files changed

+54
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a compilation issue with GCC 12 on macOS.

Modules/_ctypes/callbacks.c

+6
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,15 @@ CThunkObject *_ctypes_alloc_callback(PyObject *callable,
403403
"ffi_prep_cif failed with %d", result);
404404
goto error;
405405
}
406+
407+
406408
#if HAVE_FFI_PREP_CLOSURE_LOC
407409
# ifdef USING_APPLE_OS_LIBFFI
410+
# ifdef HAVE_BUILTIN_AVAILABLE
408411
# define HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME __builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)
412+
# else
413+
# define HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME (ffi_prep_closure_loc != NULL)
414+
# endif
409415
# else
410416
# define HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME 1
411417
# endif

Modules/_ctypes/callproc.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101

102102
#define CTYPES_CAPSULE_NAME_PYMEM "_ctypes pymem"
103103

104+
104105
static void pymem_destructor(PyObject *ptr)
105106
{
106107
void *p = PyCapsule_GetPointer(ptr, CTYPES_CAPSULE_NAME_PYMEM);
@@ -831,7 +832,11 @@ static int _call_function_pointer(int flags,
831832
#endif
832833

833834
# ifdef USING_APPLE_OS_LIBFFI
835+
# ifdef HAVE_BUILTIN_AVAILABLE
834836
# define HAVE_FFI_PREP_CIF_VAR_RUNTIME __builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)
837+
# else
838+
# define HAVE_FFI_PREP_CIF_VAR_RUNTIME (ffi_prep_cif_var != NULL)
839+
# endif
835840
# elif HAVE_FFI_PREP_CIF_VAR
836841
# define HAVE_FFI_PREP_CIF_VAR_RUNTIME true
837842
# else
@@ -1444,8 +1449,13 @@ copy_com_pointer(PyObject *self, PyObject *args)
14441449
#else
14451450
#ifdef __APPLE__
14461451
#ifdef HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH
1447-
#define HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH_RUNTIME \
1448-
__builtin_available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
1452+
# ifdef HAVE_BUILTIN_AVAILABLE
1453+
# define HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH_RUNTIME \
1454+
__builtin_available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
1455+
# else
1456+
# define HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH_RUNTIME \
1457+
(_dyld_shared_cache_contains_path != NULL)
1458+
# endif
14491459
#else
14501460
// Support the deprecated case of compiling on an older macOS version
14511461
static void *libsystem_b_handle;

Modules/_ctypes/ctypes.h

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
#endif
2727
#endif
2828

29+
#if defined(__has_builtin)
30+
#if __has_builtin(__builtin_available)
31+
#define HAVE_BUILTIN_AVAILABLE 1
32+
#endif
33+
#endif
34+
2935
typedef struct tagPyCArgObject PyCArgObject;
3036
typedef struct tagCDataObject CDataObject;
3137
typedef PyObject *(* GETFUNC)(void *, Py_ssize_t size);

Modules/_ctypes/malloc_closure.c

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
/* #define MALLOC_CLOSURE_DEBUG */ /* enable for some debugging output */
2525

26+
2627
/******************************************************************/
2728

2829
typedef union _tagITEM {
@@ -96,7 +97,11 @@ void Py_ffi_closure_free(void *p)
9697
{
9798
#ifdef HAVE_FFI_CLOSURE_ALLOC
9899
#ifdef USING_APPLE_OS_LIBFFI
100+
# ifdef HAVE_BUILTIN_AVAILABLE
99101
if (__builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)) {
102+
# else
103+
if (ffi_closure_free != NULL) {
104+
# endif
100105
#endif
101106
ffi_closure_free(p);
102107
return;
@@ -114,7 +119,11 @@ void *Py_ffi_closure_alloc(size_t size, void** codeloc)
114119
{
115120
#ifdef HAVE_FFI_CLOSURE_ALLOC
116121
#ifdef USING_APPLE_OS_LIBFFI
122+
# ifdef HAVE_BUILTIN_AVAILABLE
117123
if (__builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)) {
124+
# else
125+
if (ffi_closure_alloc != NULL) {
126+
# endif
118127
#endif
119128
return ffi_closure_alloc(size, codeloc);
120129
#ifdef USING_APPLE_OS_LIBFFI

Modules/posixmodule.c

+16-4
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@
154154
# define HAVE_SYMLINKAT_RUNTIME (symlinkat != NULL)
155155
# endif
156156

157+
# ifdef HAVE_UTIMENSAT
158+
# define HAVE_UTIMENSAT_RUNTIME (utimensat != NULL)
159+
# endif
160+
161+
# ifdef HAVE_FUTIMENS
162+
# define HAVE_FUTIMENS_RUNTIME (futimens != NULL)
163+
# endif
164+
165+
# ifdef HAVE_PWRITEV
166+
# define HAVE_PWRITEV_RUNTIME (pwritev != NULL)
167+
# endif
168+
157169
#endif
158170

159171
#ifdef HAVE_FUTIMESAT
@@ -9838,7 +9850,7 @@ os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
98389850
} while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
98399851
#else
98409852
do {
9841-
#ifdef __APPLE__
9853+
#if defined(__APPLE__) && defined(__clang__)
98429854
/* This entire function will be removed from the module dict when the API
98439855
* is not available.
98449856
*/
@@ -9853,7 +9865,7 @@ os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
98539865
Py_END_ALLOW_THREADS
98549866
} while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
98559867

9856-
#ifdef __APPLE__
9868+
#if defined(__APPLE__) && defined(__clang__)
98579869
#pragma clang diagnostic pop
98589870
#endif
98599871

@@ -10480,7 +10492,7 @@ os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
1048010492
} while (result < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
1048110493
#else
1048210494

10483-
#ifdef __APPLE__
10495+
#if defined(__APPLE__) && defined(__clang__)
1048410496
/* This entire function will be removed from the module dict when the API
1048510497
* is not available.
1048610498
*/
@@ -10496,7 +10508,7 @@ os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
1049610508
Py_END_ALLOW_THREADS
1049710509
} while (result < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
1049810510

10499-
#ifdef __APPLE__
10511+
#if defined(__APPLE__) && defined(__clang__)
1050010512
#pragma clang diagnostic pop
1050110513
#endif
1050210514

Python/pylifecycle.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ static void call_ll_exitfuncs(_PyRuntimeState *runtime);
8282
* interpreter state for various runtime debugging tools, but is *not* an
8383
* officially supported feature */
8484

85+
/* Suppress deprecation warning for PyBytesObject.ob_shash */
86+
_Py_COMP_DIAG_PUSH
87+
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
88+
8589
#if defined(MS_WINDOWS)
8690

8791
#pragma section("PyRuntime", read, write)
@@ -95,9 +99,6 @@ __attribute__((
9599

96100
#endif
97101

98-
/* Suppress deprecation warning for PyBytesObject.ob_shash */
99-
_Py_COMP_DIAG_PUSH
100-
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
101102
_PyRuntimeState _PyRuntime
102103
#if defined(__linux__) && (defined(__GNUC__) || defined(__clang__))
103104
__attribute__ ((section (".PyRuntime")))

0 commit comments

Comments
 (0)