mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-92536: Update unicode struct size to ensure MemoryError is raised (GH-92867)
This commit is contained in:
parent
8781a041a0
commit
19a4252459
1 changed files with 6 additions and 10 deletions
|
@ -2370,14 +2370,9 @@ class UnicodeTest(string_tests.CommonTest,
|
||||||
self.assertIs(s.expandtabs(), s)
|
self.assertIs(s.expandtabs(), s)
|
||||||
|
|
||||||
def test_raiseMemError(self):
|
def test_raiseMemError(self):
|
||||||
if struct.calcsize('P') == 8:
|
null_byte = 1
|
||||||
# 64 bits pointers
|
ascii_struct_size = sys.getsizeof("a") - len("a") - null_byte
|
||||||
ascii_struct_size = 48
|
compact_struct_size = sys.getsizeof("\xff") - len("\xff") - null_byte
|
||||||
compact_struct_size = 72
|
|
||||||
else:
|
|
||||||
# 32 bits pointers
|
|
||||||
ascii_struct_size = 24
|
|
||||||
compact_struct_size = 36
|
|
||||||
|
|
||||||
for char in ('a', '\xe9', '\u20ac', '\U0010ffff'):
|
for char in ('a', '\xe9', '\u20ac', '\U0010ffff'):
|
||||||
code = ord(char)
|
code = ord(char)
|
||||||
|
@ -2395,6 +2390,7 @@ class UnicodeTest(string_tests.CommonTest,
|
||||||
# be allocatable, given enough memory.
|
# be allocatable, given enough memory.
|
||||||
maxlen = ((sys.maxsize - struct_size) // char_size)
|
maxlen = ((sys.maxsize - struct_size) // char_size)
|
||||||
alloc = lambda: char * maxlen
|
alloc = lambda: char * maxlen
|
||||||
|
with self.subTest(char=char):
|
||||||
self.assertRaises(MemoryError, alloc)
|
self.assertRaises(MemoryError, alloc)
|
||||||
self.assertRaises(MemoryError, alloc)
|
self.assertRaises(MemoryError, alloc)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue