bpo-39632: Fix ctypes variadic function call convention#18560
Closed
ndessart wants to merge 1 commit intopython:mainfrom
Closed
bpo-39632: Fix ctypes variadic function call convention#18560ndessart wants to merge 1 commit intopython:mainfrom
ndessart wants to merge 1 commit intopython:mainfrom
Conversation
Author
|
The build is failing on macOS because ctypes uses an obsolete libffi version bundled into Modules/_ctypes/libffi_osx for this platform. This old version of libffi is missing I don't know why libffi is bundled only for mac but I guess that we could just bundle the latest release of libffi (currently libffi-3.3 for every target. Since this is my very first (rather ambitious) contribution to CPython, I think I will need some guidance moving forward. Thanks |
6e4a5ef to
045c53c
Compare
On armhf and for variadic functions (and contrary to non-variadic functions), the VFP co-processor registers are not used for float argument parameter passing. This specificity was completely disregarded by ctypes which used `ffi_prep_cif` systematically to prepare the parameter passing of a function while it should use `ffi_prep_cif_var` for variadic functions instead. As such variadic function call with float arguments through ctypes was broken on armhf targets. This change fixes and improves ctypes variadic function support. Functions that take a variable number of arguments should now be declared using an Ellipsis (...) as their last argument (just as a prototype for a C function). ctypes variadic functions declared this way automatically perform the default argument promotion. Small integer types are promoted to c_int and c_float is promoted to c_double. For reference/see also: - https://sourceware.org/ml/libffi-discuss/2016/msg00043.html - https://bugs.python.org/issue17580 - spacepy/spacepy#20 - https://en.cppreference.com/w/c/language/conversion#Default_argument_promotions
045c53c to
6b0f3f3
Compare
Member
|
@ndessart, are you interested in this? Could you fix merge conflicts? |
|
The following commit authors need to sign the Contributor License Agreement: |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
On armhf and for variadic functions (and contrary to non-variadic
functions), the VFP co-processor registers are not used for float
argument parameter passing. This specificity was completely
disregarded by ctypes which used
ffi_prep_cifsystematicallyto prepare the parameter passing of a function while it should
use
ffi_prep_cif_varfor variadic functions instead.As such variadic function call with float arguments through ctypes
was broken on armhf targets.
This change fixes and improves ctypes variadic function support.
Functions that take a variable number of arguments should now be
declared using an Ellipsis (...) as their last argument (just as
a prototype for a C function). ctypes variadic functions declared
this way automatically perform the default argument promotion.
Small integer types are promoted to c_int and c_float is promoted
to c_double.
I am new to CPython development but I think that without the
introduction of the Ellipsis in functions argtypes this could be
backported to the 3.7 and 3.8 maintenance branches.
For reference/see also:
https://bugs.python.org/issue39632