8000 bpo-30697: fix PyErr_NormalizeException() when no memory by xdegaye · Pull Request #2327 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-30697: fix PyErr_NormalizeException() when no memory #2327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 26, 2017
Prev Previous commit
Next Next commit
Add the test case on memory exhaustion (last test)
  • Loading branch information
xdegaye committed Jul 1, 2017
commit af6896e590b2bff4ec946dae76943e122e30fe51
26 changes: 25 additions & 1 deletion Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

from test.support import (TESTFN, captured_stderr, check_impl_detail,
check_warnings, cpython_only, gc_collect, run_unittest,
no_tracing, unlink, import_module, script_helper)
no_tracing, unlink, import_module, script_helper,
SuppressCrashReport)

class NaiveException(Exception):
def __init__(self, x):
Expand Down Expand Up @@ -985,6 +986,29 @@ def test_recursion_normalizing_infinite_exception(self):
b'while normalizing an exception', err)
self.assertIn(b'Done.', out)

@cpython_only
def test_recursion_normalizing_with_no_memory(self):
# Issue #30697. Test that in the abort that occurs when there is no
# memory left and the size of the Python frames stack is greater than
# the size of the list of preallocated MemoryError instances, the
# Fatal Python error message mentions MemoryError.
code = """if 1:
import _testcapi
class C(): pass
def recurse(cnt):
cnt -= 1
if cnt:
recurse(cnt)
else:
_testcapi.set_nomemory(0)
C()
recurse(16)
"""
with SuppressCrashReport():
rc, out, err = script_helper.assert_python_failure("-c", code)
self.assertIn(b'Fatal Python error: Cannot recover from '
b'MemoryErrors while normalizing exceptions.', err)

@cpython_only
def test_MemoryError(self):
# PyErr_NoMemory always raises the same exception instance.
Expand Down
0