-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
bpo-41100: ctypes fixes for arm64 Mac OS #21249
Closed
lawrence-danna-apple
wants to merge
10
commits into
python:master
from
lawrence-danna-apple:postback-ctypes-combined
Closed
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ff883bc
use system libffi for Mac OS 10.15 and up
lawrence-danna-apple 36b35bc
ctypes: use the correct ABI for variadic functions
lawrence-danna-apple bacf128
ctypes: probe libffi for ffi_closure_alloc and ffi_prep_cif_var
lawrence-danna-apple 971ef00
📜🤖 Added by blurb_it.
blurb-it[bot] da30587
fix spelling in Doc/library/ctypes.rst
lawrence-danna-apple 80f852b
use system libffi for older releases of Mac OS
lawrence-danna-apple aeac14b
remove FUNCFLAG_VARIADIC
lawrence-danna-apple 62fe20a
fixup! use system libffi for older releases of Mac OS
lawrence-danna-apple e160a59
fixup! use system libffi for older releases of Mac OS
lawrence-danna-apple bca75fd
Fix build failure on Mac OS 10.10 / Xcode 6, remove libffi_osx
lawrence-danna-apple File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Core and Builtins/2020-07-01-01-30-04.bpo-41100.hCrjJJ.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
setup.py: probe libffi for ffi_closure_alloc and ffi_prep_cif_var |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,6 +229,13 @@ def macosx_sdk_specified(): | |
macosx_sdk_root() | ||
return MACOS_SDK_SPECIFIED | ||
|
||
def is_macosx_at_least(vers): | ||
if MACOS: | ||
dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') | ||
if dep_target: | ||
return tuple(map(int, dep_target.split('.'))) >= vers | ||
return False | ||
|
||
|
||
def is_macosx_sdk_path(path): | ||
""" | ||
|
@@ -239,6 +246,13 @@ def is_macosx_sdk_path(path): | |
or path.startswith('/Library/') ) | ||
|
||
|
||
def grep_headers_for(function, headers): | ||
for header in headers: | ||
with open(header, 'r') 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 | ||
|
@@ -2136,7 +2150,12 @@ def configure_ctypes(self, ext): | |
|
||
def detect_ctypes(self): | ||
# Thomas Heller's _ctypes module | ||
self.use_system_libffi = False | ||
|
||
if not sysconfig.get_config_var("LIBFFI_INCLUDEDIR") and is_macosx_at_least((10,15)): | ||
self.use_system_libffi = True | ||
else: | ||
self.use_system_libffi = '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS") | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to just drop "use_system_libffi" and unconditionally use the system headers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
include_dirs = [] | ||
extra_compile_args = ['-DPy_BUILD_CORE_MODULE'] | ||
extra_link_args = [] | ||
|
@@ -2183,31 +2202,47 @@ def detect_ctypes(self): | |
sources=['_ctypes/_ctypes_test.c'], | ||
libraries=['m'])) | ||
|
||
ffi_inc = sysconfig.get_config_var("LIBFFI_INCLUDEDIR") | ||
ffi_lib = None | ||
|
||
ffi_inc_dirs = self.inc_dirs.copy() | ||
if MACOS: | ||
if '--with-system-ffi' not in sysconfig.get_config_var("CONFIG_ARGS"): | ||
if not self.use_system_libffi: | ||
return | ||
# OS X 10.5 comes with libffi.dylib; the include files are | ||
# in /usr/include/ffi | ||
ffi_inc_dirs.append('/usr/include/ffi') | ||
|
||
ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")] | ||
if not ffi_inc or ffi_inc[0] == '': | ||
ffi_inc = find_file('ffi.h', [], ffi_inc_dirs) | ||
if ffi_inc is not None: | ||
ffi_h = ffi_inc[0] + '/ffi.h' | ||
ffi_in_sdk = os.path.join(macosx_sdk_root(), "usr/include/ffi") | ||
if os.path.exists(ffi_in_sdk): | ||
ffi_inc = ffi_in_sdk | ||
ffi_lib = 'ffi' | ||
else: | ||
# OS X 10.5 comes with libffi.dylib; the include files are | ||
# in /usr/include/ffi | ||
ffi_inc_dirs.append('/usr/include/ffi') | ||
|
||
if not ffi_inc: | ||
found = find_file('ffi.h', [], ffi_inc_dirs) | ||
if found: | ||
ffi_inc = found[0] | ||
if ffi_inc: | ||
ffi_h = ffi_inc + '/ffi.h' | ||
if not os.path.exists(ffi_h): | ||
ffi_inc = None | ||
print('Header file {} does not exist'.format(ffi_h)) | ||
ffi_lib = None | ||
if ffi_inc is not None: | ||
if ffi_lib is None and ffi_inc: | ||
for lib_name in ('ffi', 'ffi_pic'): | ||
if (self.compiler.find_library_file(self.lib_dirs, lib_name)): | ||
ffi_lib = lib_name | ||
break | ||
|
||
if ffi_inc and ffi_lib: | ||
ext.include_dirs.extend(ffi_inc) | ||
ffi_headers = glob(os.path.join(ffi_inc, '*.h')) | ||
if grep_headers_for('ffi_closure_alloc', ffi_headers): | ||
try: | ||
sources.remove('_ctypes/malloc_closure.c') | ||
except ValueError: | ||
pass | ||
if grep_headers_for('ffi_prep_cif_var', ffi_headers): | ||
ext.extra_compile_args.append("-DHAVE_FFI_PREP_CIF_VAR=1") | ||
ext.include_dirs.append(ffi_inc) | ||
ext.libraries.append(ffi_lib) | ||
self.use_system_libffi = True | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary removal of a blank line (not important)