Issue #4258: Make it possible to use 30-bit digits for PyLongs:
- new configure option --enable-big-digits
- new structseq sys.int_info giving information about the internal format
By default, 30-bit digits are enabled on 64-bit machines but
disabled on 32-bit machines.
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 9f0c139..427b721 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -333,6 +333,9 @@
self.assert_(isinstance(sys.executable, str))
self.assertEqual(len(sys.float_info), 11)
self.assertEqual(sys.float_info.radix, 2)
+ self.assertEqual(len(sys.int_info), 2)
+ self.assert_(sys.int_info.bits_per_digit % 5 == 0)
+ self.assert_(sys.int_info.sizeof_digit >= 1)
self.assert_(isinstance(sys.hexversion, int))
self.assert_(isinstance(sys.maxsize, int))
self.assert_(isinstance(sys.maxunicode, int))
@@ -437,6 +440,7 @@
if hasattr(sys, "gettotalrefcount"):
self.header += '2P'
self.vheader += '2P'
+ self.longdigit = sys.int_info.sizeof_digit
import _testcapi
self.gc_headsize = _testcapi.SIZEOF_PYGC_HEAD
self.file = open(test.support.TESTFN, 'wb')
@@ -471,7 +475,7 @@
size = self.calcsize
gc_header_size = self.gc_headsize
# bool objects are not gc tracked
- self.assertEqual(sys.getsizeof(True), size(vh) + self.H)
+ self.assertEqual(sys.getsizeof(True), size(vh) + self.longdigit)
# but lists are
self.assertEqual(sys.getsizeof([]), size(vh + 'PP') + gc_header_size)
@@ -479,8 +483,8 @@
h = self.header
vh = self.vheader
size = self.calcsize
- self.assertEqual(sys.getsizeof(True), size(vh) + self.H)
- self.assertEqual(sys.getsizeof(True, -1), size(vh) + self.H)
+ self.assertEqual(sys.getsizeof(True), size(vh) + self.longdigit)
+ self.assertEqual(sys.getsizeof(True, -1), size(vh) + self.longdigit)
def test_objecttypes(self):
# check all types defined in Objects/
@@ -489,7 +493,7 @@
size = self.calcsize
check = self.check_sizeof
# bool
- check(True, size(vh) + self.H)
+ check(True, size(vh) + self.longdigit)
# buffer
# XXX
# builtin_function_or_method
@@ -607,11 +611,12 @@
check(reversed([]), size(h + 'lP'))
# long
check(0, size(vh))
- check(1, size(vh) + self.H)
- check(-1, size(vh) + self.H)
- check(32768, size(vh) + 2*self.H)
- check(32768*32768-1, size(vh) + 2*self.H)
- check(32768*32768, size(vh) + 3*self.H)
+ check(1, size(vh) + self.longdigit)
+ check(-1, size(vh) + self.longdigit)
+ PyLong_BASE = 2**sys.int_info.bits_per_digit
+ check(PyLong_BASE, size(vh) + 2*self.longdigit)
+ check(PyLong_BASE**2-1, size(vh) + 2*self.longdigit)
+ check(PyLong_BASE**2, size(vh) + 3*self.longdigit)
# memory
check(memoryview(b''), size(h + 'P PP2P2i7P'))
# module