Properly add link attributes to extern static pointer bindings - #44
Open
emmatyping wants to merge 1 commit into
Open
Properly add link attributes to extern static pointer bindings#44emmatyping wants to merge 1 commit into
emmatyping wants to merge 1 commit into
Conversation
The previous manual parsing for cpython-sys was not robust to different bindgen outputs. Rather than manual parsing, we now use syn and prettyplease to parse the bindgen output.
davidhewitt
reviewed
Aug 10, 2026
| let syn::Item::ForeignMod(foreign_mod) = item else { | ||
| continue; | ||
| }; | ||
| let [syn::ForeignItem::Static(static_item)] = foreign_mod.items.as_slice() else { |
There was a problem hiding this comment.
Is it expected that these extern blocks have a single item only?
Author
There was a problem hiding this comment.
Yes, bindgen will emit one extern block per global, e.g. (taken from a generated c_api.rs):
unsafe extern "C" {
pub static mut PyLong_Type: PyTypeObject;
}
unsafe extern "C" {
pub static mut PyBool_Type: PyTypeObject;
}I'll add a comment because this is somewhat load bearing on how bindgen generates extern data from C.
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.
The previous manual parsing for cpython-sys was not robust to different bindgen outputs. Rather than manual parsing, we now use syn and prettyplease to parse/unparse the bindgen output. These are not actually new dependencies as bindgen already depends on them.
The previous implementation of parsing was not properly handling some bindgen output (e.g. everything could end up on one line), so linker attributes were not added to items like
PyExc_TypeError, causing link-time errors.This should fix the Windows build errors seen in #35.