]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-99337: Fix compile errors with gcc 12 on macOS (#99470)
authorRonald Oussoren <ronaldoussoren@mac.com>
Mon, 21 Nov 2022 09:50:20 +0000 (10:50 +0100)
committerGitHub <noreply@github.com>
Mon, 21 Nov 2022 09:50:20 +0000 (10:50 +0100)
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

Misc/NEWS.d/next/Build/2022-11-15-08-40-22.gh-issue-99337.5LoQDE.rst [new file with mode: 0644]
Modules/_ctypes/callbacks.c
Modules/_ctypes/callproc.c
Modules/_ctypes/ctypes.h
Modules/_ctypes/malloc_closure.c
Modules/posixmodule.c
Python/pylifecycle.c

diff --git a/Misc/NEWS.d/next/Build/2022-11-15-08-40-22.gh-issue-99337.5LoQDE.rst b/Misc/NEWS.d/next/Build/2022-11-15-08-40-22.gh-issue-99337.5LoQDE.rst
new file mode 100644 (file)
index 0000000..f7396ab
--- /dev/null
@@ -0,0 +1 @@
+Fix a compilation issue with GCC 12 on macOS.
index 8df2f541808b4a3f14d51ee154b968c6ecc21c81..459632b90907fd6ea77197778533d79af1509e2d 100644 (file)
@@ -403,9 +403,15 @@ CThunkObject *_ctypes_alloc_callback(PyObject *callable,
                      "ffi_prep_cif failed with %d", result);
         goto error;
     }
+
+
 #if HAVE_FFI_PREP_CLOSURE_LOC
 #   ifdef USING_APPLE_OS_LIBFFI
+#    ifdef HAVE_BUILTIN_AVAILABLE
 #      define HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME __builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)
+#    else
+#      define HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME (ffi_prep_closure_loc != NULL)
+#    endif
 #   else
 #      define HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME 1
 #   endif
index a6c005b84a3f88e0597cf5ef19790025c7648d65..28b7cd4069718b5dab147b21f6366f2ab8c42f3d 100644 (file)
 
 #define CTYPES_CAPSULE_NAME_PYMEM "_ctypes pymem"
 
+
 static void pymem_destructor(PyObject *ptr)
 {
     void *p = PyCapsule_GetPointer(ptr, CTYPES_CAPSULE_NAME_PYMEM);
@@ -831,7 +832,11 @@ static int _call_function_pointer(int flags,
 #endif
 
 #   ifdef USING_APPLE_OS_LIBFFI
+#    ifdef HAVE_BUILTIN_AVAILABLE
 #      define HAVE_FFI_PREP_CIF_VAR_RUNTIME __builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)
+#    else
+#      define HAVE_FFI_PREP_CIF_VAR_RUNTIME (ffi_prep_cif_var != NULL)
+#    endif
 #   elif HAVE_FFI_PREP_CIF_VAR
 #      define HAVE_FFI_PREP_CIF_VAR_RUNTIME true
 #   else
@@ -1444,8 +1449,13 @@ copy_com_pointer(PyObject *self, PyObject *args)
 #else
 #ifdef __APPLE__
 #ifdef HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH
-#define HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH_RUNTIME \
-    __builtin_available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
+#  ifdef HAVE_BUILTIN_AVAILABLE
+#    define HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH_RUNTIME \
+        __builtin_available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
+#  else
+#    define HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH_RUNTIME \
+         (_dyld_shared_cache_contains_path != NULL)
+#  endif
 #else
 // Support the deprecated case of compiling on an older macOS version
 static void *libsystem_b_handle;
index 88eb9f59922a0498b42ca41092b4f2546034d60f..a7029b6e6da2b81fa1175d1c0bc22b22bc6ef977 100644 (file)
   #endif
 #endif
 
+#if defined(__has_builtin)
+#if __has_builtin(__builtin_available)
+#define HAVE_BUILTIN_AVAILABLE 1
+#endif
+#endif
+
 typedef struct tagPyCArgObject PyCArgObject;
 typedef struct tagCDataObject CDataObject;
 typedef PyObject *(* GETFUNC)(void *, Py_ssize_t size);
index d47153f1d7f3e8238ad1efaf73ca0ea4257470ab..3a859322772ba720d518588208b3141f40c9ffdb 100644 (file)
@@ -23,6 +23,7 @@
 
 /* #define MALLOC_CLOSURE_DEBUG */ /* enable for some debugging output */
 
+
 /******************************************************************/
 
 typedef union _tagITEM {
@@ -96,7 +97,11 @@ void Py_ffi_closure_free(void *p)
 {
 #ifdef HAVE_FFI_CLOSURE_ALLOC
 #ifdef USING_APPLE_OS_LIBFFI
+# ifdef HAVE_BUILTIN_AVAILABLE
     if (__builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)) {
+#  else
+    if (ffi_closure_free != NULL) {
+#  endif
 #endif
         ffi_closure_free(p);
         return;
@@ -114,7 +119,11 @@ void *Py_ffi_closure_alloc(size_t size, void** codeloc)
 {
 #ifdef HAVE_FFI_CLOSURE_ALLOC
 #ifdef USING_APPLE_OS_LIBFFI
+# ifdef HAVE_BUILTIN_AVAILABLE
     if (__builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)) {
+# else
+    if (ffi_closure_alloc != NULL) {
+#  endif
 #endif
         return ffi_closure_alloc(size, codeloc);
 #ifdef USING_APPLE_OS_LIBFFI
index 5968c1940e76f42e230ef213b8851e0a7ee5e315..6d65ae97c9e3186fa2a607acbe0340d3dd5be01d 100644 (file)
 #    define HAVE_SYMLINKAT_RUNTIME (symlinkat != NULL)
 #  endif
 
+#  ifdef HAVE_UTIMENSAT
+#    define HAVE_UTIMENSAT_RUNTIME (utimensat != NULL)
+#  endif
+
+#  ifdef HAVE_FUTIMENS
+#    define HAVE_FUTIMENS_RUNTIME (futimens != NULL)
+#  endif
+
+#  ifdef HAVE_PWRITEV
+#    define HAVE_PWRITEV_RUNTIME (pwritev != NULL)
+#  endif
+
 #endif
 
 #ifdef HAVE_FUTIMESAT
@@ -9838,7 +9850,7 @@ os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
     } while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
 #else
     do {
-#ifdef __APPLE__
+#if defined(__APPLE__) && defined(__clang__)
 /* This entire function will be removed from the module dict when the API
  * is not available.
  */
@@ -9853,7 +9865,7 @@ os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
         Py_END_ALLOW_THREADS
     } while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
 
-#ifdef __APPLE__
+#if defined(__APPLE__) && defined(__clang__)
 #pragma clang diagnostic pop
 #endif
 
@@ -10480,7 +10492,7 @@ os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
     } while (result < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
 #else
 
-#ifdef __APPLE__
+#if defined(__APPLE__) && defined(__clang__)
 /* This entire function will be removed from the module dict when the API
  * is not available.
  */
@@ -10496,7 +10508,7 @@ os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
         Py_END_ALLOW_THREADS
     } while (result < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
 
-#ifdef __APPLE__
+#if defined(__APPLE__) && defined(__clang__)
 #pragma clang diagnostic pop
 #endif
 
index 10636b4d15d73746706b61e353194b356d43cf61..8209132ebc6c2744ae52ce5d1dcd63d789e4e18a 100644 (file)
@@ -82,6 +82,10 @@ static void call_ll_exitfuncs(_PyRuntimeState *runtime);
  * interpreter state for various runtime debugging tools, but is *not* an
  * officially supported feature */
 
+/* Suppress deprecation warning for PyBytesObject.ob_shash */
+_Py_COMP_DIAG_PUSH
+_Py_COMP_DIAG_IGNORE_DEPR_DECLS
+
 #if defined(MS_WINDOWS)
 
 #pragma section("PyRuntime", read, write)
@@ -95,9 +99,6 @@ __attribute__((
 
 #endif
 
-/* Suppress deprecation warning for PyBytesObject.ob_shash */
-_Py_COMP_DIAG_PUSH
-_Py_COMP_DIAG_IGNORE_DEPR_DECLS
 _PyRuntimeState _PyRuntime
 #if defined(__linux__) && (defined(__GNUC__) || defined(__clang__))
 __attribute__ ((section (".PyRuntime")))