Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-99337: Fix compile errors with gcc 12 on macOS #99470

Merged
merged 6 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a compilation issue with GCC 12 on macOS.
6 changes: 6 additions & 0 deletions Modules/_ctypes/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions Modules/_ctypes/callproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@

#define CTYPES_CAPSULE_NAME_PYMEM "_ctypes pymem"


static void pymem_destructor(PyObject *ptr)
{
void *p = PyCapsule_GetPointer(ptr, CTYPES_CAPSULE_NAME_PYMEM);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions Modules/_ctypes/ctypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions Modules/_ctypes/malloc_closure.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

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


/******************************************************************/

typedef union _tagITEM {
Expand Down Expand Up @@ -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) {
ronaldoussoren marked this conversation as resolved.
Show resolved Hide resolved
# endif
#endif
ffi_closure_free(p);
return;
Expand All @@ -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
Expand Down
20 changes: 16 additions & 4 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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

Expand Down Expand Up @@ -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.
*/
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
ronaldoussoren marked this conversation as resolved.
Show resolved Hide resolved
_Py_COMP_DIAG_IGNORE_DEPR_DECLS

#if defined(MS_WINDOWS)

Expand All @@ -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")))
Expand Down