8000 gh-119714: Add PyLong_GetNumBits() function by vstinner · Pull Request #119715 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-119714: Add PyLong_GetNumBits() function #119715

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

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add OverflowError test
  • Loading branch information
vstinner committed Jun 3, 2024
commit afc665e3b5fc5530c580a7d79d77cb591004d0b1
12 changes: 12 additions & 0 deletions Lib/test/test_capi/test_long.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import sys
import test.support as support
from test.support import bigmemtest

from test.support import import_helper

Expand Down Expand Up @@ -752,6 +753,17 @@ def test_long_getnumbits(self):

# CRASHES numbits(NULL)

# The test is always skipped on 64-bit platforms, it requires way too much
# memory. It's only run on 32-bit platforms.
@bigmemtest(size=(_testcapi.PY_SSIZE_T_MAX // sys.int_info.bits_per_digit
* sys.int_info.sizeof_digit) + sys.getsizeof(123),
memuse=1, dry_run=False)
def test_long_getnumbits_overflow(self, size):
numbits = _testcapi.pylong_getnumbits
big_int = 1 << _testcapi.PY_SSIZE_T_MAX
with self.assertRaises(OverflowError):
numbits(big_int)


if __name__ == "__main__":
unittest.main()
0