fix(language): use PyLong_AsSize_t for pointer-sized language IDs#470
Merged
ObserverOfTime merged 1 commit intoJul 7, 2026
Merged
Conversation
PyLong_AsUnsignedLong truncates on Win64 (LLP64), where unsigned long is 32-bit but pointers are 64-bit, causing OverflowError when constructing a Language from a raw pointer int. Fixes tree-sitter#469
Contributor
Author
|
The one failing check (test_hash in tests/test_node.py) looks unrelated to this change — this PR only touches PyLong_AsSize_t for pointer-sized Language IDs, not Node.hash. |
Member
|
Thanks! |
Contributor
Author
|
You're very welcome! I'm glad I could help, and I look forward to tackling more issues |
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.
Fixes #469.
PyLong_AsUnsignedLong was introduced in 14e7893 for a value that's actually a pointer (Py_uintptr_t). On 64-bit Windows (LLP64), unsigned long is 32-bit while pointers are 64-bit, so this overflows for any real pointer value passed to the deprecated int-based Language() constructor — exactly the OverflowError reported in the issue.
Reverted that one call to PyLong_AsSize_t, which is pointer-width on all platforms (including Win64), matching the pre-refactor behavior. This doesn't affect the other unsigned long conversions from that commit, since those hold 32-bit byte offsets/counts, not pointers.