@@ -18,7 +18,7 @@ CThunkObject_dealloc(PyObject *myself)
1818 Py_XDECREF (self -> callable );
1919 Py_XDECREF (self -> restype );
2020 if (self -> pcl_write )
21- ffi_closure_free (self -> pcl_write );
21+ Py_ffi_closure_free (self -> pcl_write );
2222 PyObject_GC_Del (self );
2323}
2424
@@ -361,8 +361,7 @@ CThunkObject *_ctypes_alloc_callback(PyObject *callable,
361361
362362 assert (CThunk_CheckExact ((PyObject * )p ));
363363
364- p -> pcl_write = ffi_closure_alloc (sizeof (ffi_closure ),
365- & p -> pcl_exec );
364+ p -> pcl_write = Py_ffi_closure_alloc (sizeof (ffi_closure ), & p -> pcl_exec );
366365 if (p -> pcl_write == NULL ) {
367366 PyErr_NoMemory ();
368367 goto error ;
@@ -408,13 +407,29 @@ CThunkObject *_ctypes_alloc_callback(PyObject *callable,
408407 "ffi_prep_cif failed with %d" , result );
409408 goto error ;
410409 }
411- #if defined(X86_DARWIN ) || defined(POWERPC_DARWIN )
412- result = ffi_prep_closure (p -> pcl_write , & p -> cif , closure_fcn , p );
410+ #if HAVE_FFI_PREP_CLOSURE_LOC
411+ # if USING_APPLE_OS_LIBFFI
412+ # define HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME __builtin_available(macos 11, ios 13, watchos 6, tvos 13, *)
413+ # else
414+ # define HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME true
415+ # endif
416+ if (HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME ) {
417+ result = ffi_prep_closure_loc (p -> pcl_write , & p -> cif , closure_fcn ,
418+ p ,
419+ p -> pcl_exec );
420+ } else
421+ #endif
422+ {
423+ #if USING_APPLE_OS_LIBFFI && defined(__arm64__ )
424+ PyErr_Format (PyExc_NotImplementedError , "ffi_prep_closure_loc() is missing" );
425+ goto error ;
413426#else
414- result = ffi_prep_closure_loc (p -> pcl_write , & p -> cif , closure_fcn ,
415- p ,
416- p -> pcl_exec );
427+ #pragma clang diagnostic push
428+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
429+ result = ffi_prep_closure (p -> pcl_write , & p -> cif , closure_fcn , p );
430+ #pragma clang diagnostic pop
417431#endif
432+ }
418433 if (result != FFI_OK ) {
419434 PyErr_Format (PyExc_RuntimeError ,
420435 "ffi_prep_closure failed with %d" , result );
0 commit comments