mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	[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 cdde29dde9)
Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
			
			
This commit is contained in:
		
							parent
							
								
									f381644819
								
							
						
					
					
						commit
						aa067868ec
					
				
					 7 changed files with 54 additions and 9 deletions
				
			
		|  | @ -0,0 +1 @@ | ||||||
|  | Fix a compilation issue with GCC 12 on macOS. | ||||||
|  | @ -405,9 +405,15 @@ CThunkObject *_ctypes_alloc_callback(PyObject *callable, | ||||||
|                      "ffi_prep_cif failed with %d", result); |                      "ffi_prep_cif failed with %d", result); | ||||||
|         goto error; |         goto error; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| #if HAVE_FFI_PREP_CLOSURE_LOC | #if HAVE_FFI_PREP_CLOSURE_LOC | ||||||
| #   ifdef USING_APPLE_OS_LIBFFI | #   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, *) | #      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 | #   else | ||||||
| #      define HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME 1 | #      define HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME 1 | ||||||
| #   endif | #   endif | ||||||
|  |  | ||||||
|  | @ -96,6 +96,7 @@ | ||||||
| 
 | 
 | ||||||
| #define CTYPES_CAPSULE_NAME_PYMEM "_ctypes pymem" | #define CTYPES_CAPSULE_NAME_PYMEM "_ctypes pymem" | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| static void pymem_destructor(PyObject *ptr) | static void pymem_destructor(PyObject *ptr) | ||||||
| { | { | ||||||
|     void *p = PyCapsule_GetPointer(ptr, CTYPES_CAPSULE_NAME_PYMEM); |     void *p = PyCapsule_GetPointer(ptr, CTYPES_CAPSULE_NAME_PYMEM); | ||||||
|  | @ -829,7 +830,11 @@ static int _call_function_pointer(int flags, | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #   ifdef USING_APPLE_OS_LIBFFI | #   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, *) | #      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 | #   elif HAVE_FFI_PREP_CIF_VAR | ||||||
| #      define HAVE_FFI_PREP_CIF_VAR_RUNTIME true | #      define HAVE_FFI_PREP_CIF_VAR_RUNTIME true | ||||||
| #   else | #   else | ||||||
|  | @ -1442,8 +1447,13 @@ copy_com_pointer(PyObject *self, PyObject *args) | ||||||
| #else | #else | ||||||
| #ifdef __APPLE__ | #ifdef __APPLE__ | ||||||
| #ifdef HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH | #ifdef HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH | ||||||
| #define HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH_RUNTIME \ | #  ifdef HAVE_BUILTIN_AVAILABLE | ||||||
|     __builtin_available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *) | #    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 | #else | ||||||
| // Support the deprecated case of compiling on an older macOS version
 | // Support the deprecated case of compiling on an older macOS version
 | ||||||
| static void *libsystem_b_handle; | static void *libsystem_b_handle; | ||||||
|  |  | ||||||
|  | @ -26,6 +26,12 @@ | ||||||
|   #endif |   #endif | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  | #if defined(__has_builtin) | ||||||
|  | #if __has_builtin(__builtin_available) | ||||||
|  | #define HAVE_BUILTIN_AVAILABLE 1 | ||||||
|  | #endif | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
| typedef struct tagPyCArgObject PyCArgObject; | typedef struct tagPyCArgObject PyCArgObject; | ||||||
| typedef struct tagCDataObject CDataObject; | typedef struct tagCDataObject CDataObject; | ||||||
| typedef PyObject *(* GETFUNC)(void *, Py_ssize_t size); | typedef PyObject *(* GETFUNC)(void *, Py_ssize_t size); | ||||||
|  |  | ||||||
|  | @ -20,6 +20,7 @@ | ||||||
| 
 | 
 | ||||||
| /* #define MALLOC_CLOSURE_DEBUG */ /* enable for some debugging output */ | /* #define MALLOC_CLOSURE_DEBUG */ /* enable for some debugging output */ | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| /******************************************************************/ | /******************************************************************/ | ||||||
| 
 | 
 | ||||||
| typedef union _tagITEM { | typedef union _tagITEM { | ||||||
|  | @ -93,7 +94,11 @@ void Py_ffi_closure_free(void *p) | ||||||
| { | { | ||||||
| #ifdef HAVE_FFI_CLOSURE_ALLOC | #ifdef HAVE_FFI_CLOSURE_ALLOC | ||||||
| #ifdef USING_APPLE_OS_LIBFFI | #ifdef USING_APPLE_OS_LIBFFI | ||||||
|  | # ifdef HAVE_BUILTIN_AVAILABLE | ||||||
|     if (__builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)) { |     if (__builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)) { | ||||||
|  | #  else | ||||||
|  |     if (ffi_closure_free != NULL) { | ||||||
|  | #  endif | ||||||
| #endif | #endif | ||||||
|         ffi_closure_free(p); |         ffi_closure_free(p); | ||||||
|         return; |         return; | ||||||
|  | @ -111,7 +116,11 @@ void *Py_ffi_closure_alloc(size_t size, void** codeloc) | ||||||
| { | { | ||||||
| #ifdef HAVE_FFI_CLOSURE_ALLOC | #ifdef HAVE_FFI_CLOSURE_ALLOC | ||||||
| #ifdef USING_APPLE_OS_LIBFFI | #ifdef USING_APPLE_OS_LIBFFI | ||||||
|  | # ifdef HAVE_BUILTIN_AVAILABLE | ||||||
|     if (__builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)) { |     if (__builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)) { | ||||||
|  | # else | ||||||
|  |     if (ffi_closure_alloc != NULL) { | ||||||
|  | #  endif | ||||||
| #endif | #endif | ||||||
|         return ffi_closure_alloc(size, codeloc); |         return ffi_closure_alloc(size, codeloc); | ||||||
| #ifdef USING_APPLE_OS_LIBFFI | #ifdef USING_APPLE_OS_LIBFFI | ||||||
|  |  | ||||||
|  | @ -154,6 +154,18 @@ | ||||||
| #    define HAVE_SYMLINKAT_RUNTIME (symlinkat != NULL) | #    define HAVE_SYMLINKAT_RUNTIME (symlinkat != NULL) | ||||||
| #  endif | #  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 | #endif | ||||||
| 
 | 
 | ||||||
| #ifdef HAVE_FUTIMESAT | #ifdef HAVE_FUTIMESAT | ||||||
|  | @ -9817,7 +9829,7 @@ os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, | ||||||
|     } while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); |     } while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); | ||||||
| #else | #else | ||||||
|     do { |     do { | ||||||
| #ifdef __APPLE__ | #if defined(__APPLE__) && defined(__clang__) | ||||||
| /* This entire function will be removed from the module dict when the API
 | /* This entire function will be removed from the module dict when the API
 | ||||||
|  * is not available. |  * is not available. | ||||||
|  */ |  */ | ||||||
|  | @ -9832,7 +9844,7 @@ os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, | ||||||
|         Py_END_ALLOW_THREADS |         Py_END_ALLOW_THREADS | ||||||
|     } while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); |     } while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); | ||||||
| 
 | 
 | ||||||
| #ifdef __APPLE__ | #if defined(__APPLE__) && defined(__clang__) | ||||||
| #pragma clang diagnostic pop | #pragma clang diagnostic pop | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  | @ -10459,7 +10471,7 @@ os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, | ||||||
|     } while (result < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); |     } while (result < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); | ||||||
| #else | #else | ||||||
| 
 | 
 | ||||||
| #ifdef __APPLE__ | #if defined(__APPLE__) && defined(__clang__) | ||||||
| /* This entire function will be removed from the module dict when the API
 | /* This entire function will be removed from the module dict when the API
 | ||||||
|  * is not available. |  * is not available. | ||||||
|  */ |  */ | ||||||
|  | @ -10475,7 +10487,7 @@ os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, | ||||||
|         Py_END_ALLOW_THREADS |         Py_END_ALLOW_THREADS | ||||||
|     } while (result < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); |     } while (result < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); | ||||||
| 
 | 
 | ||||||
| #ifdef __APPLE__ | #if defined(__APPLE__) && defined(__clang__) | ||||||
| #pragma clang diagnostic pop | #pragma clang diagnostic pop | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -82,6 +82,10 @@ int _Py_UnhandledKeyboardInterrupt = 0; | ||||||
|  * interpreter state for various runtime debugging tools, but is *not* an |  * interpreter state for various runtime debugging tools, but is *not* an | ||||||
|  * officially supported feature */ |  * officially supported feature */ | ||||||
| 
 | 
 | ||||||
|  | /* Suppress deprecation warning for PyBytesObject.ob_shash */ | ||||||
|  | _Py_COMP_DIAG_PUSH | ||||||
|  | _Py_COMP_DIAG_IGNORE_DEPR_DECLS | ||||||
|  | 
 | ||||||
| #if defined(MS_WINDOWS) | #if defined(MS_WINDOWS) | ||||||
| 
 | 
 | ||||||
| #pragma section("PyRuntime", read, write) | #pragma section("PyRuntime", read, write) | ||||||
|  | @ -95,9 +99,6 @@ __attribute__(( | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| /* Suppress deprecation warning for PyBytesObject.ob_shash */ |  | ||||||
| _Py_COMP_DIAG_PUSH |  | ||||||
| _Py_COMP_DIAG_IGNORE_DEPR_DECLS |  | ||||||
| _PyRuntimeState _PyRuntime | _PyRuntimeState _PyRuntime | ||||||
| #if defined(__linux__) && (defined(__GNUC__) || defined(__clang__)) | #if defined(__linux__) && (defined(__GNUC__) || defined(__clang__)) | ||||||
| __attribute__ ((section (".PyRuntime"))) | __attribute__ ((section (".PyRuntime"))) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Miss Islington (bot)
						Miss Islington (bot)