Skip to content

Commit b26dd72

Browse files
committed
fix tests on 32-bit platforms
1 parent 31f36de commit b26dd72

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

Lib/test/test_frame.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import copy
22
import operator
3+
import platform
34
import re
45
import sys
56
import textwrap
@@ -236,9 +237,14 @@ def test_sizeof_overflow(self):
236237
evil_stacksize = int(_testcapi.INT_MAX / ps - fss - co_nlocalsplus)
237238
# an evil code with a valid (but very large) stack size
238239
evil_code = f.f_code.replace(co_stacksize=evil_stacksize - 1)
239-
frame = _testcapi.frame_new(evil_code, globals(), locals())
240-
message = re.escape("size exceeds INT_MAX")
241-
self.assertRaisesRegex(OverflowError, message, frame.__sizeof__)
240+
241+
if sys.maxsize == 2147483647: # 32-bit machine
242+
with self.assertRaises(MemoryError):
243+
frame = _testcapi.frame_new(evil_code, globals(), locals())
244+
else:
245+
frame = _testcapi.frame_new(evil_code, globals(), locals())
246+
message = re.escape("size exceeds INT_MAX")
247+
self.assertRaisesRegex(OverflowError, message, frame.__sizeof__)
242248

243249

244250
class ReprTest(unittest.TestCase):

Lib/test/test_generators.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,14 @@ def f(): yield
288288

289289
if support.Py_GIL_DISABLED:
290290
self.skipTest("segmentation fault on free-threaded builds")
291-
# the following crashes on free-threaded builds for now
292-
evil_gi_func = types.FunctionType(evil, {})()
293-
message = re.escape("size exceeds INT_MAX")
294-
self.assertRaisesRegex(OverflowError, message, evil_gi.__sizeof__)
291+
elif sys.maxsize == 2147483647: # 32-bit machine
292+
with self.assertRaises(MemoryError):
293+
evil_gi = types.FunctionType(evil, {})()
294+
else:
295+
# the following crashes on free-threaded builds for now
296+
evil_gi = types.FunctionType(evil, {})()
297+
message = re.escape("size exceeds INT_MAX")
298+
self.assertRaisesRegex(OverflowError, message, evil_gi.__sizeof__)
295299

296300

297301
class ModifyUnderlyingIterableTest(unittest.TestCase):

Objects/codeobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,9 @@ _PyCode_Validate(struct _PyCodeConstructor *con)
439439
/*
440440
* The framesize = stacksize + nlocalsplus + FRAME_SPECIALS_SIZE is used
441441
* as framesize * sizeof(PyObject *) and assumed to be < INT_MAX. Thus,
442-
* we need to dynamically limit the value of stacksize.
442+
* we need to dynamically limit the value of stacksize. Note that this
443+
* usually prevents crashes due to assertions but a MemoryError may still
444+
* be triggered later.
443445
*
444446
* See https://github.com/python/cpython/issues/126119 for details.
445447
*/

0 commit comments

Comments
 (0)