mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
[3.13] gh-126018: Avoid aborting due to unnecessary assert in sys.audit
(GH-126020) (#126042)
(cherry picked from commit 80eec52fc8
)
Co-authored-by: devdanzin <74280297+devdanzin@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
9e37bfae5a
commit
e4157f0fd7
4 changed files with 20 additions and 1 deletions
|
@ -567,6 +567,17 @@ def test_winapi_createnamedpipe(pipe_name):
|
||||||
_winapi.CreateNamedPipe(pipe_name, _winapi.PIPE_ACCESS_DUPLEX, 8, 2, 0, 0, 0, 0)
|
_winapi.CreateNamedPipe(pipe_name, _winapi.PIPE_ACCESS_DUPLEX, 8, 2, 0, 0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
|
def test_assert_unicode():
|
||||||
|
import sys
|
||||||
|
sys.addaudithook(lambda *args: None)
|
||||||
|
try:
|
||||||
|
sys.audit(9)
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Expected sys.audit(9) to fail.")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from test.support import suppress_msvcrt_asserts
|
from test.support import suppress_msvcrt_asserts
|
||||||
|
|
||||||
|
|
|
@ -307,5 +307,12 @@ class AuditTest(unittest.TestCase):
|
||||||
|
|
||||||
self.assertEqual(actual, expected)
|
self.assertEqual(actual, expected)
|
||||||
|
|
||||||
|
def test_assert_unicode(self):
|
||||||
|
# See gh-126018
|
||||||
|
returncode, _, stderr = self.run_python("test_assert_unicode")
|
||||||
|
if returncode:
|
||||||
|
self.fail(stderr)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix a crash in :func:`sys.audit` when passing a non-string as first argument
|
||||||
|
and Python was compiled in debug mode.
|
|
@ -518,7 +518,6 @@ sys_audit(PyObject *self, PyObject *const *args, Py_ssize_t argc)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(args[0] != NULL);
|
assert(args[0] != NULL);
|
||||||
assert(PyUnicode_Check(args[0]));
|
|
||||||
|
|
||||||
if (!should_audit(tstate->interp)) {
|
if (!should_audit(tstate->interp)) {
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue