Skip to content

Commit fb655e0

Browse files
authored
_ctypes callbacks.c uses _Py_COMP_DIAG_IGNORE_DEPR_DECLS (#105732)
Replace #pragma with _Py_COMP_DIAG_PUSH, _Py_COMP_DIAG_IGNORE_DEPR_DECLS and _Py_COMP_DIAG_POP to ease Python maintenance. Also add a comment explaining why callbacks.c ignores a deprecation warning.
1 parent 5cdd5ba commit fb655e0

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

Modules/_ctypes/callbacks.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -416,25 +416,29 @@ CThunkObject *_ctypes_alloc_callback(PyObject *callable,
416416
PyErr_Format(PyExc_NotImplementedError, "ffi_prep_closure_loc() is missing");
417417
goto error;
418418
#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
427437
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
436439
#endif
437440
}
441+
438442
if (result != FFI_OK) {
439443
PyErr_Format(PyExc_RuntimeError,
440444
"ffi_prep_closure failed with %d", result);

0 commit comments

Comments
 (0)