diff options
author | Victor Stinner <vstinner@python.org> | 2020-03-06 23:54:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-06 23:54:20 (GMT) |
commit | 9e5d30cc99e34f4c3e7b2cd851de20816c9d1927 (patch) | |
tree | 71e726c4695b9b3b0a31d7d2516ce8ee83b52721 /Lib | |
parent | 7b3c252dc7f44d4bdc4c7c82d225ebd09c78f520 (diff) | |
download | cpython-9e5d30cc99e34f4c3e7b2cd851de20816c9d1927.zip cpython-9e5d30cc99e34f4c3e7b2cd851de20816c9d1927.tar.gz cpython-9e5d30cc99e34f4c3e7b2cd851de20816c9d1927.tar.bz2 |
bpo-39882: Py_FatalError() logs the function name (GH-18819)
The Py_FatalError() function is replaced with a macro which logs
automatically the name of the current function, unless the
Py_LIMITED_API macro is defined.
Changes:
* Add _Py_FatalErrorFunc() function.
* Remove the function name from the message of Py_FatalError() calls
which included the function name.
* Update tests.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_capi.py | 20 | ||||
-rw-r--r-- | Lib/test/test_exceptions.py | 5 | ||||
-rw-r--r-- | Lib/test/test_faulthandler.py | 7 | ||||
-rw-r--r-- | Lib/test/test_io.py | 3 | ||||
-rw-r--r-- | Lib/test/test_sys.py | 5 |
5 files changed, 26 insertions, 14 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index e65973c..ff18a21 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -61,8 +61,8 @@ class CAPITest(unittest.TestCase): self.assertEqual(out, b'') # This used to cause an infinite loop. self.assertTrue(err.rstrip().startswith( - b'Fatal Python error:' - b' PyThreadState_Get: no current thread')) + b'Fatal Python error: ' + b'PyThreadState_Get: no current thread')) def test_memoryview_from_NULL_pointer(self): self.assertRaises(ValueError, _testcapi.make_memoryview_from_NULL_pointer) @@ -197,7 +197,8 @@ class CAPITest(unittest.TestCase): """) rc, out, err = assert_python_failure('-c', code) self.assertRegex(err.replace(b'\r', b''), - br'Fatal Python error: a function returned NULL ' + br'Fatal Python error: _Py_CheckFunctionResult: ' + br'a function returned NULL ' br'without setting an error\n' br'Python runtime state: initialized\n' br'SystemError: <built-in function ' @@ -225,8 +226,9 @@ class CAPITest(unittest.TestCase): """) rc, out, err = assert_python_failure('-c', code) self.assertRegex(err.replace(b'\r', b''), - br'Fatal Python error: a function returned a ' - br'result with an error set\n' + br'Fatal Python error: _Py_CheckFunctionResult: ' + br'a function returned a result ' + br'with an error set\n' br'Python runtime state: initialized\n' br'ValueError\n' br'\n' @@ -668,7 +670,7 @@ class PyMemDebugTests(unittest.TestCase): r"\n" r"Enable tracemalloc to get the memory block allocation traceback\n" r"\n" - r"Fatal Python error: bad trailing pad byte") + r"Fatal Python error: _PyMem_DebugRawFree: bad trailing pad byte") regex = regex.format(ptr=self.PTR_REGEX) regex = re.compile(regex, flags=re.DOTALL) self.assertRegex(out, regex) @@ -684,14 +686,14 @@ class PyMemDebugTests(unittest.TestCase): r"\n" r"Enable tracemalloc to get the memory block allocation traceback\n" r"\n" - r"Fatal Python error: bad ID: Allocated using API 'm', verified using API 'r'\n") + r"Fatal Python error: _PyMem_DebugRawFree: bad ID: Allocated using API 'm', verified using API 'r'\n") regex = regex.format(ptr=self.PTR_REGEX) self.assertRegex(out, regex) def check_malloc_without_gil(self, code): out = self.check(code) - expected = ('Fatal Python error: Python memory allocator called ' - 'without holding the GIL') + expected = ('Fatal Python error: _PyMem_DebugMalloc: ' + 'Python memory allocator called without holding the GIL') self.assertIn(expected, out) def test_pymem_malloc_without_gil(self): diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 22a2236..2d3a13a 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -1078,8 +1078,9 @@ class ExceptionTests(unittest.TestCase): """ 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) + self.assertIn(b'Fatal Python error: _PyErr_NormalizeException: ' + b'Cannot recover from MemoryErrors while ' + b'normalizing exceptions.', err) @cpython_only def test_MemoryError(self): diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py index ac8cf46..c64afe8 100644 --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -123,7 +123,9 @@ class FaultHandlerTests(unittest.TestCase): self.assertRegex(output, regex) self.assertNotEqual(exitcode, 0) - def check_fatal_error(self, code, line_number, name_regex, **kw): + def check_fatal_error(self, code, line_number, name_regex, func=None, **kw): + if func: + name_regex = '%s: %s' % (func, name_regex) fatal_error = 'Fatal Python error: %s' % name_regex self.check_error(code, line_number, fatal_error, **kw) @@ -173,6 +175,7 @@ class FaultHandlerTests(unittest.TestCase): 3, 'in new thread', know_current_thread=False, + func='faulthandler_fatal_error_thread', py_fatal_error=True) def test_sigabrt(self): @@ -230,6 +233,7 @@ class FaultHandlerTests(unittest.TestCase): """, 2, 'xyz', + func='faulthandler_fatal_error_py', py_fatal_error=True) def test_fatal_error_without_gil(self): @@ -239,6 +243,7 @@ class FaultHandlerTests(unittest.TestCase): """, 2, 'xyz', + func='faulthandler_fatal_error_py', py_fatal_error=True) @unittest.skipIf(sys.platform.startswith('openbsd'), diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 4a7cbe5..fe07b56 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -4247,7 +4247,8 @@ class CMiscIOTest(MiscIOTest): err = res.err.decode() if res.rc != 0: # Failure: should be a fatal error - pattern = (r"Fatal Python error: could not acquire lock " + pattern = (r"Fatal Python error: _enter_buffered_busy: " + r"could not acquire lock " r"for <(_io\.)?BufferedWriter name='<{stream_name}>'> " r"at interpreter shutdown, possibly due to " r"daemon threads".format_map(locals())) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index c5bd8a4..027f87e 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -269,6 +269,8 @@ class SysModuleTest(unittest.TestCase): finally: sys.setrecursionlimit(oldlimit) + # The error message is specific to CPython + @test.support.cpython_only def test_recursionlimit_fatalerror(self): # A fatal error occurs if a second recursion limit is hit when recovering # from a first one. @@ -290,7 +292,8 @@ class SysModuleTest(unittest.TestCase): err = sub.communicate()[1] self.assertTrue(sub.returncode, sub.returncode) self.assertIn( - b"Fatal Python error: Cannot recover from stack overflow", + b"Fatal Python error: _Py_CheckRecursiveCall: " + b"Cannot recover from stack overflow", err) def test_getwindowsversion(self): |