Repository navigation
gh-91353: Fix void return type handling in ctypes (GH-32246) #32246
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
Merged
Merged
Changes from 1 commit
Commits
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
Next
Next commit
bpo-47197: Fix void return type handling in ctypes
_ctypes_get_ffi_type never returns ffi_type_void. If the return type is specified as None, we need set the libffi return type to void, but just taking the output from _ctypes_get_ffi_type will make the return type be sint. This fixes two spots where ctypes accidentally converts None return type to sint rather than void, causing crashes on Emscripten targets.
- Loading branch information
commit f48101008c4b2735ef51c557d3095d07e33aa6e5
There are no files selected for viewing
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
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
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.
I'm not familiar with ctypes. Would it make sense to check for None in
_ctypes_get_ffi_type()rather than here?Uh oh!
There was an error while loading. Please reload this page.
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.
I think this is better? I ran into a similar issue when writing the
libffiport:_ctypes_get_ffi_typeis used for the arguments. Return types need a little bit of special handling, like for instance it doesn't make sense to have an argument of typeffi_type_void. I would argue that it would be safest to do something like:but I'm not that familiar with the ctypes interface -- are we supposed to use
Noneif we are not sure about the argument's type? Similarly,looks kind of scary to me. Why did we pass in
NULLto this function? If this function set exceptions in these weird cases and they were handled as appropriate at the call site, the bug I'm fixing here probably wouldn't have happened in the first place.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.
The
NULLvalue is used to indicate not-set and is quite pervasive in the ctypes codebase. Function prototypes are not required to supply argtypes or restype. It seems_ctypes_get_ffi_type()is designed for arguments so the additional checking forPy_Noneoutside of it would be correct.