Skip to content

Commit f932c96

Browse files
committed
pythonGH-110800: fix unexpected OverflowError in testMemoryErrorBigSource
Signed-off-by: Filipe Laíns <[email protected]> add the suggested test markers Signed-off-by: Filipe Laíns <[email protected]> fix incorrect logic Signed-off-by: Filipe Laíns <[email protected]> add _size arg that got lost in the merge Signed-off-by: Filipe Laíns <[email protected]>
1 parent 11bbe6c commit f932c96

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Lib/test/test_exceptions.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Python test set -- part 5, built-in exceptions
22

33
import copy
4+
import ctypes
45
import os
56
import sys
67
import unittest
@@ -318,11 +319,18 @@ def baz():
318319
check('(yield i) = 2', 1, 2)
319320
check('def f(*):\n pass', 1, 7)
320321

322+
@unittest.skipIf(ctypes.sizeof(ctypes.c_int) >= ctypes.sizeof(ctypes.c_ssize_t),
323+
"INT_MAX is bigger than Py_ssize_t, so this is unreachable")
321324
@support.requires_resource('cpu')
322325
@support.bigmemtest(support._2G, memuse=1.5)
323326
def testMemoryErrorBigSource(self, _size):
324-
with self.assertRaises(OverflowError):
325-
exec(f"if True:\n {' ' * 2**31}print('hello world')")
327+
# the line length needs to be more than INT_MAX, but we can't
328+
# multiple a sequence by a number that doesn't fit Py_ssize_t,
329+
# otherwise we will get an OverflowError (see PySequence_Repeat)
330+
INT_MAX = 2 ** (ctypes.sizeof(ctypes.c_int) * 8)
331+
padding = ' ' * (INT_MAX // 8)
332+
with self.assertRaisesRegex(OverflowError, "column offset overflow"):
333+
exec(f"if True:\n {padding}print('hello world')")
326334

327335
@cpython_only
328336
def testSettingException(self):

0 commit comments

Comments
 (0)