Skip to content

Conversation

BobTheBuidler
Copy link
Contributor

@BobTheBuidler BobTheBuidler commented Aug 16, 2025

This PR adds a new primitive for int.bit_length and is already ready for review.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! bit_length can be useful in low-level code, where a generic method call can really slow things down.

def bit_length(n: int) -> int:
return n.bit_length()
def test_bit_length() -> None:
assert bit_length(0) == 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: This would be a bit more robust if you'd have say bit_length_python function that does return getattr(n, "bit_length")() and you can assert that bit_length(n) == bit_length_python(n).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that's odd, I implemented the tests as you asked here but now we get segfaults on Python3.14

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also on the 32-bit test runner

Copy link
Contributor Author

@BobTheBuidler BobTheBuidler Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay... well after implementing your bitscan idea the issue has resolved itself on python3.14... somehow

I still don't understand how getattr(x, "bit_length")() would cause segfault behavior

@BobTheBuidler
Copy link
Contributor Author

I'm not entirely sure how to proceed here, I can't think of any reason our use of getattr would lead to segfault behavior where there was none before

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants