summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_exceptions.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-11-28 02:41:53 (GMT)
committerGitHub <noreply@github.com>2023-11-28 02:41:53 (GMT)
commit0aceac557d78a4e284e72481fcb3a3ec45ecedba (patch)
tree77a924b3bbcf55107188f3f0b57ba7ac6c6b7602 /Lib/test/test_exceptions.py
parent1e1a30f9f49ed5104a4be194d094b13703bcc0de (diff)
downloadcpython-0aceac557d78a4e284e72481fcb3a3ec45ecedba.zip
cpython-0aceac557d78a4e284e72481fcb3a3ec45ecedba.tar.gz
cpython-0aceac557d78a4e284e72481fcb3a3ec45ecedba.tar.bz2
[3.12] gh-109894: Fix initialization of static `MemoryError` in subinterpreter (gh-110911) (gh-111238)
Fixes GH-109894 * set `interp.static_objects.last_resort_memory_error.args` to empty tuple to avoid crash on `PyErr_Display()` call * allow `_PyExc_InitGlobalObjects()` to be called on subinterpreter init --------- (cherry picked from commit 47d3e2ed930a9f3d228aed4f62133737dae74cf7) Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r--Lib/test/test_exceptions.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index ad0b7c2..2d6c333 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -1785,6 +1785,20 @@ class ExceptionTests(unittest.TestCase):
gc_collect()
+ def test_memory_error_in_subinterp(self):
+ # gh-109894: subinterpreters shouldn't count on last resort memory error
+ # when MemoryError is raised through PyErr_NoMemory() call,
+ # and should preallocate memory errors as does the main interpreter.
+ # interp.static_objects.last_resort_memory_error.args
+ # should be initialized to empty tuple to avoid crash on attempt to print it.
+ code = f"""if 1:
+ import _testcapi
+ _testcapi.run_in_subinterp(\"[0]*{sys.maxsize}\")
+ exit(0)
+ """
+ rc, _, err = script_helper.assert_python_ok("-c", code)
+ self.assertIn(b'MemoryError', err)
+
class NameErrorTests(unittest.TestCase):
def test_name_error_has_name(self):