Skip to content

bpo-45598: Remove ffi header header #29352

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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,3 @@
ctypes now assumes that libffi provides ffi_prep_ciff, ffi_prep_closure_loc,
and ffi_closure_alloc functions, except when compiling with older macOS
libffi.
7 changes: 3 additions & 4 deletions Modules/_ctypes/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,19 +417,18 @@ CThunkObject *_ctypes_alloc_callback(PyObject *callable,
"ffi_prep_cif failed with %d", result);
goto error;
}
#if HAVE_FFI_PREP_CLOSURE_LOC
# if USING_APPLE_OS_LIBFFI
# define HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME __builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)
# elif defined(MS_WIN32)
# define HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME 0
# else
# define HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME 1
# endif
if (HAVE_FFI_PREP_CLOSURE_LOC_RUNTIME) {
result = ffi_prep_closure_loc(p->pcl_write, &p->cif, closure_fcn,
p,
p->pcl_exec);
} else
#endif
{
} else {
#if USING_APPLE_OS_LIBFFI && defined(__arm64__)
PyErr_Format(PyExc_NotImplementedError, "ffi_prep_closure_loc() is missing");
goto error;
Expand Down
21 changes: 7 additions & 14 deletions Modules/_ctypes/callproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,10 +828,10 @@ static int _call_function_pointer(int flags,

# if USING_APPLE_OS_LIBFFI
# define HAVE_FFI_PREP_CIF_VAR_RUNTIME __builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)
# elif HAVE_FFI_PREP_CIF_VAR
# define HAVE_FFI_PREP_CIF_VAR_RUNTIME true
# else
# elif defined(MS_WIN32)
# define HAVE_FFI_PREP_CIF_VAR_RUNTIME false
# else
# define HAVE_FFI_PREP_CIF_VAR_RUNTIME true
# endif

/* Even on Apple-arm64 the calling convention for variadic functions coincides
Expand All @@ -843,16 +843,12 @@ static int _call_function_pointer(int flags,
(void) is_variadic;

#if defined(__APPLE__) && defined(__arm64__)
if (is_variadic) {
if (HAVE_FFI_PREP_CIF_VAR_RUNTIME) {
} else {
PyErr_SetString(PyExc_NotImplementedError, "ffi_prep_cif_var() is missing");
return -1;
}
if (is_variadic && !HAVE_FFI_PREP_CIF_VAR_RUNTIME) {
PyErr_SetString(PyExc_NotImplementedError, "ffi_prep_cif_var() is missing");
return -1;
}
#endif

#if HAVE_FFI_PREP_CIF_VAR
if (is_variadic) {
if (HAVE_FFI_PREP_CIF_VAR_RUNTIME) {
if (FFI_OK != ffi_prep_cif_var(&cif,
Expand All @@ -876,10 +872,7 @@ static int _call_function_pointer(int flags,
return -1;
}
}
} else
#endif

{
} else {
if (FFI_OK != ffi_prep_cif(&cif,
cc,
argcount,
Expand Down
4 changes: 0 additions & 4 deletions Modules/_ctypes/malloc_closure.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,13 @@ static void more_core(void)
/* put the item back into the free list */
void Py_ffi_closure_free(void *p)
{
#if HAVE_FFI_CLOSURE_ALLOC
#if USING_APPLE_OS_LIBFFI
if (__builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)) {
#endif
ffi_closure_free(p);
return;
#if USING_APPLE_OS_LIBFFI
}
#endif
#endif
ITEM *item = (ITEM *)p;
item->next = free_list;
Expand All @@ -109,14 +107,12 @@ void Py_ffi_closure_free(void *p)
/* return one item from the free list, allocating more if needed */
void *Py_ffi_closure_alloc(size_t size, void** codeloc)
{
#if HAVE_FFI_CLOSURE_ALLOC
#if USING_APPLE_OS_LIBFFI
if (__builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)) {
#endif
return ffi_closure_alloc(size, codeloc);
#if USING_APPLE_OS_LIBFFI
}
#endif
#endif
ITEM *item;
if (!free_list)
Expand Down
16 changes: 0 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,6 @@ def is_macosx_sdk_path(path):
or path.startswith('/System/iOSSupport') )


def grep_headers_for(function, headers):
for header in headers:
with open(header, 'r', errors='surrogateescape') as f:
if function in f.read():
return True
return False


def find_file(filename, std_dirs, paths):
"""Searches for the directory where a given file is located,
and returns a possibly-empty list of additional directories, or None
Expand Down Expand Up @@ -2280,14 +2272,6 @@ def detect_ctypes(self):
break

if ffi_inc and ffi_lib:
ffi_headers = glob(os.path.join(ffi_inc, '*.h'))
if grep_headers_for('ffi_prep_cif_var', ffi_headers):
ext.extra_compile_args.append("-DHAVE_FFI_PREP_CIF_VAR=1")
if grep_headers_for('ffi_prep_closure_loc', ffi_headers):
ext.extra_compile_args.append("-DHAVE_FFI_PREP_CLOSURE_LOC=1")
if grep_headers_for('ffi_closure_alloc', ffi_headers):
ext.extra_compile_args.append("-DHAVE_FFI_CLOSURE_ALLOC=1")

ext.include_dirs.append(ffi_inc)
ext.libraries.append(ffi_lib)
self.use_system_libffi = True
Expand Down