From f932c9625f93f0bddceb337a1aabfb4327e37cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Fri, 13 Oct 2023 06:45:58 +0100 Subject: [PATCH] GH-110800: fix unexpected OverflowError in testMemoryErrorBigSource MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns add the suggested test markers Signed-off-by: Filipe Laíns fix incorrect logic Signed-off-by: Filipe Laíns add _size arg that got lost in the merge Signed-off-by: Filipe Laíns --- Lib/test/test_exceptions.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index eafa7d84638b76..6b31c253f06fd2 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -1,6 +1,7 @@ # Python test set -- part 5, built-in exceptions import copy +import ctypes import os import sys import unittest @@ -318,11 +319,18 @@ def baz(): check('(yield i) = 2', 1, 2) check('def f(*):\n pass', 1, 7) + @unittest.skipIf(ctypes.sizeof(ctypes.c_int) >= ctypes.sizeof(ctypes.c_ssize_t), + "INT_MAX is bigger than Py_ssize_t, so this is unreachable") @support.requires_resource('cpu') @support.bigmemtest(support._2G, memuse=1.5) def testMemoryErrorBigSource(self, _size): - with self.assertRaises(OverflowError): - exec(f"if True:\n {' ' * 2**31}print('hello world')") + # the line length needs to be more than INT_MAX, but we can't + # multiple a sequence by a number that doesn't fit Py_ssize_t, + # otherwise we will get an OverflowError (see PySequence_Repeat) + INT_MAX = 2 ** (ctypes.sizeof(ctypes.c_int) * 8) + padding = ' ' * (INT_MAX // 8) + with self.assertRaisesRegex(OverflowError, "column offset overflow"): + exec(f"if True:\n {padding}print('hello world')") @cpython_only def testSettingException(self):