Fix struct sizes. Drop -1, since the resulting string was actually the largest one
that could be allocated.
This commit is contained in:
parent
f02aa65acb
commit
287eca658d
|
@ -1585,12 +1585,12 @@ class UnicodeTest(string_tests.CommonTest,
|
||||||
def test_raiseMemError(self):
|
def test_raiseMemError(self):
|
||||||
if struct.calcsize('P') == 8:
|
if struct.calcsize('P') == 8:
|
||||||
# 64 bits pointers
|
# 64 bits pointers
|
||||||
ascii_struct_size = 64
|
ascii_struct_size = 48
|
||||||
compact_struct_size = 88
|
compact_struct_size = 72
|
||||||
else:
|
else:
|
||||||
# 32 bits pointers
|
# 32 bits pointers
|
||||||
ascii_struct_size = 32
|
ascii_struct_size = 24
|
||||||
compact_struct_size = 44
|
compact_struct_size = 36
|
||||||
|
|
||||||
for char in ('a', '\xe9', '\u20ac', '\U0010ffff'):
|
for char in ('a', '\xe9', '\u20ac', '\U0010ffff'):
|
||||||
code = ord(char)
|
code = ord(char)
|
||||||
|
@ -1604,8 +1604,9 @@ class UnicodeTest(string_tests.CommonTest,
|
||||||
char_size = 4 # sizeof(Py_UCS4)
|
char_size = 4 # sizeof(Py_UCS4)
|
||||||
struct_size = compact_struct_size
|
struct_size = compact_struct_size
|
||||||
# Note: sys.maxsize is half of the actual max allocation because of
|
# Note: sys.maxsize is half of the actual max allocation because of
|
||||||
# the signedness of Py_ssize_t. -1 because of the null character.
|
# the signedness of Py_ssize_t. Strings of maxlen-1 should in principle
|
||||||
maxlen = ((sys.maxsize - struct_size) // char_size) - 1
|
# be allocatable, given enough memory.
|
||||||
|
maxlen = ((sys.maxsize - struct_size) // char_size)
|
||||||
alloc = lambda: char * maxlen
|
alloc = lambda: char * maxlen
|
||||||
self.assertRaises(MemoryError, alloc)
|
self.assertRaises(MemoryError, alloc)
|
||||||
self.assertRaises(MemoryError, alloc)
|
self.assertRaises(MemoryError, alloc)
|
||||||
|
|
Loading…
Reference in New Issue