Skip to content

Commit 18ecceb

Browse files
committed
pythongh-93575: Use correct way to calculate PyUnicode struct sizes
1 parent 243ed54 commit 18ecceb

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Lib/test/test_unicode.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,9 +2370,10 @@ def test_expandtabs_optimization(self):
23702370
self.assertIs(s.expandtabs(), s)
23712371

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

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

0 commit comments

Comments
 (0)