From 2958deb2c6ab2b3b50837502a620e0c0ce3be34c Mon Sep 17 00:00:00 2001 From: Ronald Oussoren Date: Mon, 14 Nov 2022 13:26:55 +0100 Subject: [PATCH 1/6] GCC 12 complains about _Pragma inside a decleration --- Python/pylifecycle.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 44f844249b13b9..c23223cd587b18 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -83,6 +83,8 @@ int _Py_UnhandledKeyboardInterrupt = 0; * found without any external information. This is meant to ease access to the * interpreter state for various runtime debugging tools, but is *not* an * officially supported feature */ +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS #if defined(MS_WINDOWS) @@ -98,8 +100,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"))) From 2ddc86002480279cd195f783fefcaa2e2ed7be47 Mon Sep 17 00:00:00 2001 From: Ronald Oussoren Date: Mon, 14 Nov 2022 13:27:24 +0100 Subject: [PATCH 2/6] Fix a number of compile errors with GCC-12 on macOS --- Modules/_ctypes/callbacks.c | 14 ++++++++++++++ Modules/_ctypes/callproc.c | 20 ++++++++++++++++++-- Modules/_ctypes/malloc_closure.c | 15 +++++++++++++++ Modules/posixmodule.c | 20 ++++++++++++++++---- 4 files changed, 63 insertions(+), 6 deletions(-) diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c index 8df2f541808b4a..9e5fc8aafb3bbb 100644 --- a/Modules/_ctypes/callbacks.c +++ b/Modules/_ctypes/callbacks.c @@ -26,6 +26,14 @@ #include #endif +#ifdef __APPLE__ +#if defined(__has_builtin) +#if __has_builtin(__builtin_available) +#define HAVE_BUILTIN_AVAILABLE 1 +#endif +#endif +#endif + /**************************************************************/ static void @@ -403,9 +411,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 diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index 520a0f921bb8a6..e4117107016141 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -101,6 +101,13 @@ #define CTYPES_CAPSULE_NAME_PYMEM "_ctypes pymem" +#if defined(__has_builtin) +#if __has_builtin(__builtin_available) +#define HAVE_BUILTIN_AVAILABLE 1 +#endif +#endif + + static void pymem_destructor(PyObject *ptr) { void *p = PyCapsule_GetPointer(ptr, CTYPES_CAPSULE_NAME_PYMEM); @@ -831,7 +838,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 +1455,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; diff --git a/Modules/_ctypes/malloc_closure.c b/Modules/_ctypes/malloc_closure.c index d47153f1d7f3e8..7ab3a8192b8b0f 100644 --- a/Modules/_ctypes/malloc_closure.c +++ b/Modules/_ctypes/malloc_closure.c @@ -23,6 +23,13 @@ /* #define MALLOC_CLOSURE_DEBUG */ /* enable for some debugging output */ +#if defined(__has_builtin) +#if __has_builtin(__builtin_available) +#define HAVE_BUILTIN_AVAILABLE 1 +#endif +#endif + + /******************************************************************/ typedef union _tagITEM { @@ -96,7 +103,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 +125,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 diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index d863f9f63248f5..4a32e5f1095b7a 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -154,6 +154,18 @@ # 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 @@ -9842,7 +9854,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. */ @@ -9857,7 +9869,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 @@ -10484,7 +10496,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. */ @@ -10500,7 +10512,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 From ddcfddfed4da0c97673f370aaba26faff1ba08e9 Mon Sep 17 00:00:00 2001 From: Ronald Oussoren Date: Tue, 15 Nov 2022 09:29:12 +0100 Subject: [PATCH 3/6] Centralize definition of HAVE_BUILTIN_AVAILABLE in the ctypes extension --- Modules/_ctypes/callbacks.c | 8 -------- Modules/_ctypes/callproc.c | 6 ------ Modules/_ctypes/ctypes.h | 6 ++++++ Modules/_ctypes/malloc_closure.c | 6 ------ 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c index 9e5fc8aafb3bbb..459632b90907fd 100644 --- a/Modules/_ctypes/callbacks.c +++ b/Modules/_ctypes/callbacks.c @@ -26,14 +26,6 @@ #include #endif -#ifdef __APPLE__ -#if defined(__has_builtin) -#if __has_builtin(__builtin_available) -#define HAVE_BUILTIN_AVAILABLE 1 -#endif -#endif -#endif - /**************************************************************/ static void diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index e4117107016141..0ccc1a5349106e 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -101,12 +101,6 @@ #define CTYPES_CAPSULE_NAME_PYMEM "_ctypes pymem" -#if defined(__has_builtin) -#if __has_builtin(__builtin_available) -#define HAVE_BUILTIN_AVAILABLE 1 -#endif -#endif - static void pymem_destructor(PyObject *ptr) { diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h index 88eb9f59922a04..a7029b6e6da2b8 100644 --- a/Modules/_ctypes/ctypes.h +++ b/Modules/_ctypes/ctypes.h @@ -26,6 +26,12 @@ #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); diff --git a/Modules/_ctypes/malloc_closure.c b/Modules/_ctypes/malloc_closure.c index 7ab3a8192b8b0f..6442d691297646 100644 --- a/Modules/_ctypes/malloc_closure.c +++ b/Modules/_ctypes/malloc_closure.c @@ -23,12 +23,6 @@ /* #define MALLOC_CLOSURE_DEBUG */ /* enable for some debugging output */ -#if defined(__has_builtin) -#if __has_builtin(__builtin_available) -#define HAVE_BUILTIN_AVAILABLE 1 -#endif -#endif - /******************************************************************/ From addf1b9c1ccf520248ed8f35a3c543f2cb647b75 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 15 Nov 2022 08:40:25 +0000 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Build/2022-11-15-08-40-22.gh-issue-99337.5LoQDE.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Build/2022-11-15-08-40-22.gh-issue-99337.5LoQDE.rst 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 index 00000000000000..f7396abde13b88 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2022-11-15-08-40-22.gh-issue-99337.5LoQDE.rst @@ -0,0 +1 @@ +Fix a compilation issue with GCC 12 on macOS. From 4096bf2186f6312087ab45ee73833063bef1126c Mon Sep 17 00:00:00 2001 From: Ronald Oussoren Date: Thu, 17 Nov 2022 17:04:24 +0100 Subject: [PATCH 5/6] Adjust test for ffi_closure_free weak symbol The new form matches the way we test for other weak symbols (for example in posixmodule.c) --- Modules/_ctypes/malloc_closure.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_ctypes/malloc_closure.c b/Modules/_ctypes/malloc_closure.c index 6442d691297646..3a859322772ba7 100644 --- a/Modules/_ctypes/malloc_closure.c +++ b/Modules/_ctypes/malloc_closure.c @@ -100,7 +100,7 @@ void Py_ffi_closure_free(void *p) # ifdef HAVE_BUILTIN_AVAILABLE if (__builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)) { # else - if (&ffi_closure_free != NULL) { + if (ffi_closure_free != NULL) { # endif #endif ffi_closure_free(p); From b6c8cc2ab56e327407097a4bb4bfe1b46ffdec5b Mon Sep 17 00:00:00 2001 From: Ronald Oussoren Date: Thu, 17 Nov 2022 17:05:02 +0100 Subject: [PATCH 6/6] Move the comment about suppressing deprecation warnings I earlier moved the pragma, but not the comment that explains why it is necessary. --- Python/pylifecycle.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index c23223cd587b18..539e323edebad8 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -83,6 +83,8 @@ int _Py_UnhandledKeyboardInterrupt = 0; * found without any external information. This is meant to ease access to the * 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 @@ -99,7 +101,6 @@ __attribute__(( #endif -/* Suppress deprecation warning for PyBytesObject.ob_shash */ _PyRuntimeState _PyRuntime #if defined(__linux__) && (defined(__GNUC__) || defined(__clang__)) __attribute__ ((section (".PyRuntime")))