Skip to content

Commit aa06786

Browse files
[3.11] gh-99337: Fix compile errors with gcc 12 on macOS (GH-99470) (#99638)
gh-99337: Fix compile errors with gcc 12 on macOS (GH-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 (cherry picked from commit cdde29d) Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com> Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
1 parent f381644 commit aa06786

File tree

7 files changed

+54
-9
lines changed

7 files changed

+54
-9
lines changed
Lines changed: 1 addition & 0 deletions
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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,15 @@ CThunkObject *_ctypes_alloc_callback(PyObject *callable,
405405
"ffi_prep_cif failed with %d", result);
406406
goto error;
407407
}
408+
409+
408410
#if HAVE_FFI_PREP_CLOSURE_LOC
409411
# ifdef USING_APPLE_OS_LIBFFI
412+
# ifdef HAVE_BUILTIN_AVAILABLE
410413
# define HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME __builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)
414+
# else
415+
# define HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME (ffi_prep_closure_loc != NULL)
416+
# endif
411417
# else
412418
# define HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME 1
413419
# endif

Modules/_ctypes/callproc.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696

9797
#define CTYPES_CAPSULE_NAME_PYMEM "_ctypes pymem"
9898

99+
99100
static void pymem_destructor(PyObject *ptr)
100101
{
101102
void *p = PyCapsule_GetPointer(ptr, CTYPES_CAPSULE_NAME_PYMEM);
@@ -829,7 +830,11 @@ static int _call_function_pointer(int flags,
829830
#endif
830831

831832
# ifdef USING_APPLE_OS_LIBFFI
833+
# ifdef HAVE_BUILTIN_AVAILABLE
832834
# define HAVE_FFI_PREP_CIF_VAR_RUNTIME __builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)
835+
# else
836+
# define HAVE_FFI_PREP_CIF_VAR_RUNTIME (ffi_prep_cif_var != NULL)
837+
# endif
833838
# elif HAVE_FFI_PREP_CIF_VAR
834839
# define HAVE_FFI_PREP_CIF_VAR_RUNTIME true
835840
# else
@@ -1442,8 +1447,13 @@ copy_com_pointer(PyObject *self, PyObject *args)
14421447
#else
14431448
#ifdef __APPLE__
14441449
#ifdef HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH
1445-
#define HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH_RUNTIME \
1446-
__builtin_available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
1450+
# ifdef HAVE_BUILTIN_AVAILABLE
1451+
# define HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH_RUNTIME \
1452+
__builtin_available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
1453+
# else
1454+
# define HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH_RUNTIME \
1455+
(_dyld_shared_cache_contains_path != NULL)
1456+
# endif
14471457
#else
14481458
// Support the deprecated case of compiling on an older macOS version
14491459
static void *libsystem_b_handle;

Modules/_ctypes/ctypes.h

Lines changed: 6 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
/* #define MALLOC_CLOSURE_DEBUG */ /* enable for some debugging output */
2222

23+
2324
/******************************************************************/
2425

2526
typedef union _tagITEM {
@@ -93,7 +94,11 @@ void Py_ffi_closure_free(void *p)
9394
{
9495
#ifdef HAVE_FFI_CLOSURE_ALLOC
9596
#ifdef USING_APPLE_OS_LIBFFI
97+
# ifdef HAVE_BUILTIN_AVAILABLE
9698
if (__builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)) {
99+
# else
100+
if (ffi_closure_free != NULL) {
101+
# endif
97102
#endif
98103
ffi_closure_free(p);
99104
return;
@@ -111,7 +116,11 @@ void *Py_ffi_closure_alloc(size_t size, void** codeloc)
111116
{
112117
#ifdef HAVE_FFI_CLOSURE_ALLOC
113118
#ifdef USING_APPLE_OS_LIBFFI
119+
# ifdef HAVE_BUILTIN_AVAILABLE
114120
if (__builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)) {
121+
# else
122+
if (ffi_closure_alloc != NULL) {
123+
# endif
115124
#endif
116125
return ffi_closure_alloc(size, codeloc);
117126
#ifdef USING_APPLE_OS_LIBFFI

Modules/posixmodule.c

Lines changed: 16 additions & 4 deletions
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
@@ -9817,7 +9829,7 @@ os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
98179829
} while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
98189830
#else
98199831
do {
9820-
#ifdef __APPLE__
9832+
#if defined(__APPLE__) && defined(__clang__)
98219833
/* This entire function will be removed from the module dict when the API
98229834
* is not available.
98239835
*/
@@ -9832,7 +9844,7 @@ os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
98329844
Py_END_ALLOW_THREADS
98339845
} while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
98349846

9835-
#ifdef __APPLE__
9847+
#if defined(__APPLE__) && defined(__clang__)
98369848
#pragma clang diagnostic pop
98379849
#endif
98389850

@@ -10459,7 +10471,7 @@ os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
1045910471
} while (result < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
1046010472
#else
1046110473

10462-
#ifdef __APPLE__
10474+
#if defined(__APPLE__) && defined(__clang__)
1046310475
/* This entire function will be removed from the module dict when the API
1046410476
* is not available.
1046510477
*/
@@ -10475,7 +10487,7 @@ os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
1047510487
Py_END_ALLOW_THREADS
1047610488
} while (result < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
1047710489

10478-
#ifdef __APPLE__
10490+
#if defined(__APPLE__) && defined(__clang__)
1047910491
#pragma clang diagnostic pop
1048010492
#endif
1048110493

Python/pylifecycle.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ int _Py_UnhandledKeyboardInterrupt = 0;
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy