@@ -416,25 +416,29 @@ CThunkObject *_ctypes_alloc_callback(PyObject *callable,
416
416
PyErr_Format (PyExc_NotImplementedError , "ffi_prep_closure_loc() is missing" );
417
417
goto error ;
418
418
#else
419
- #if defined(__clang__ )
420
- #pragma clang diagnostic push
421
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
422
- #endif
423
- #if defined(__GNUC__ ) && ((__GNUC__ > 4 ) || ((__GNUC__ == 4 ) && (__GNUC_MINOR__ > 5 )))
424
- #pragma GCC diagnostic push
425
- #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
426
- #endif
419
+ // GH-85272, GH-23327, GH-100540: On macOS,
420
+ // HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME is checked at runtime because the
421
+ // symbol might not be available at runtime when targeting macOS 10.14
422
+ // or earlier. Even if ffi_prep_closure_loc() is called in practice,
423
+ // the deprecated ffi_prep_closure() code path is needed if
424
+ // HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME is false.
425
+ //
426
+ // On non-macOS platforms, even if HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME is
427
+ // defined as 1 and ffi_prep_closure_loc() is used in practice, this
428
+ // code path is still compiled and emits a compiler warning. The
429
+ // deprecated code path is likely to be removed by a simple
430
+ // optimization pass.
431
+ //
432
+ // Ignore the compiler warning on the ffi_prep_closure() deprecation,
433
+ // rather than using complex #if/#else code paths for the different
434
+ // platforms.
435
+ _Py_COMP_DIAG_PUSH
436
+ _Py_COMP_DIAG_IGNORE_DEPR_DECLS
427
437
result = ffi_prep_closure (p -> pcl_write , & p -> cif , closure_fcn , p );
428
-
429
- #if defined(__clang__ )
430
- #pragma clang diagnostic pop
431
- #endif
432
- #if defined(__GNUC__ ) && ((__GNUC__ > 4 ) || ((__GNUC__ == 4 ) && (__GNUC_MINOR__ > 5 )))
433
- #pragma GCC diagnostic pop
434
- #endif
435
-
438
+ _Py_COMP_DIAG_POP
436
439
#endif
437
440
}
441
+
438
442
if (result != FFI_OK ) {
439
443
PyErr_Format (PyExc_RuntimeError ,
440
444
"ffi_prep_closure failed with %d" , result );
0 commit comments