FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-92536: Compute unicode struct sizes to ensure MemError is raised by sweeneyde · Pull Request #92867 · python/cpython · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
16 changes: 6 additions & 10 deletions Lib/test/test_unicode.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2370,14 +2370,9 @@ def test_expandtabs_optimization(self):
self.assertIs(s.expandtabs(), s)

def test_raiseMemError(self):
if struct.calcsize('P') == 8:
# 64 bits pointers
ascii_struct_size = 48
compact_struct_size = 72
else:
# 32 bits pointers
ascii_struct_size = 24
compact_struct_size = 36
null_byte = 1
ascii_struct_size = sys.getsizeof("a") - len("a") - null_byte
compact_struct_size = sys.getsizeof("\xff") - len("\xff") - null_byte

for char in ('a', '\xe9', '\u20ac', '\U0010ffff'):
code = ord(char)
Expand All @@ -2395,8 +2390,9 @@ def test_raiseMemError(self):
# be allocatable, given enough memory.
maxlen = ((sys.maxsize - struct_size) // char_size)
alloc = lambda: char * maxlen
self.assertRaises(MemoryError, alloc)
self.assertRaises(MemoryError, alloc)
with self.subTest(char=char):
self.assertRaises(MemoryError, alloc)
self.assertRaises(MemoryError, alloc)

def test_format_subclass(self):
class S(str):
Expand Down

Back | FazBrowse Home | New Git URL