Skip to content

Commit

Permalink
pythongh-93575: Use correct way to calculate PyUnicode struct sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
tiran committed Jun 8, 2022
1 parent 243ed54 commit 18ecceb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Lib/test/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2370,9 +2370,10 @@ def test_expandtabs_optimization(self):
self.assertIs(s.expandtabs(), s)

def test_raiseMemError(self):
null_byte = 1
ascii_struct_size = sys.getsizeof("a") - len("a") - null_byte
compact_struct_size = sys.getsizeof("\xff") - len("\xff") - null_byte
asciifields = "nnb"
compactfields = asciifields + "nP"
ascii_struct_size = support.calcobjsize(asciifields)
compact_struct_size = support.calcobjsize(compactfields)

for char in ('a', '\xe9', '\u20ac', '\U0010ffff'):
code = ord(char)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix issue with test_unicode test_raiseMemError. The test case now use
``test.support.calcobjsize`` to calculate size of PyUnicode structs.
:func:`sys.getsizeof` may return different size when string has UTF-8
memory.

0 comments on commit 18ecceb

Please sign in to comment.