mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
[3.13] gh-130163: Fix crashes related to PySys_GetObject() (GH-130503) (GH-130556)
The use of PySys_GetObject() and _PySys_GetAttr(), which return a borrowed
reference, has been replaced by using one of the following functions, which
return a strong reference and distinguish a missing attribute from an error:
_PySys_GetOptionalAttr(), _PySys_GetOptionalAttrString(),
_PySys_GetRequiredAttr(), and _PySys_GetRequiredAttrString().
(cherry picked from commit 0ef4ffeefd
)
This commit is contained in:
parent
b0d3f49195
commit
7c1b76fce8
23 changed files with 505 additions and 180 deletions
|
@ -2,6 +2,7 @@ import builtins
|
|||
import codecs
|
||||
import _datetime
|
||||
import gc
|
||||
import io
|
||||
import locale
|
||||
import operator
|
||||
import os
|
||||
|
@ -80,6 +81,18 @@ class DisplayHookTest(unittest.TestCase):
|
|||
code = compile("42", "<string>", "single")
|
||||
self.assertRaises(ValueError, eval, code)
|
||||
|
||||
def test_gh130163(self):
|
||||
class X:
|
||||
def __repr__(self):
|
||||
sys.stdout = io.StringIO()
|
||||
support.gc_collect()
|
||||
return 'foo'
|
||||
|
||||
with support.swap_attr(sys, 'stdout', None):
|
||||
sys.stdout = io.StringIO() # the only reference
|
||||
sys.displayhook(X()) # should not crash
|
||||
|
||||
|
||||
class ActiveExceptionTests(unittest.TestCase):
|
||||
def test_exc_info_no_exception(self):
|
||||
self.assertEqual(sys.exc_info(), (None, None, None))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue