mirror of
https://github.com/python/cpython.git
synced 2025-10-17 04:08:28 +00:00
gh-118362: Fix thread safety around lookups from the type cache in the face of concurrent mutators (#118454)
Add _PyType_LookupRef and use incref before setting attribute on type Makes setting an attribute on a class and signaling type modified atomic Avoid adding re-entrancy exposing the type cache in an inconsistent state by decrefing after type is updated
This commit is contained in:
parent
e6b213ee3f
commit
5a1618a2c8
18 changed files with 439 additions and 126 deletions
|
@ -882,6 +882,25 @@ class TestInlineValues(unittest.TestCase):
|
|||
f.a = 3
|
||||
self.assertEqual(f.a, 3)
|
||||
|
||||
def test_store_attr_type_cache(self):
|
||||
"""Verifies that the type cache doesn't provide a value which is
|
||||
inconsistent from the dict."""
|
||||
class X:
|
||||
def __del__(inner_self):
|
||||
v = C.a
|
||||
self.assertEqual(v, C.__dict__['a'])
|
||||
|
||||
class C:
|
||||
a = X()
|
||||
|
||||
# prime the cache
|
||||
C.a
|
||||
C.a
|
||||
|
||||
# destructor shouldn't be able to see inconsisent state
|
||||
C.a = X()
|
||||
C.a = X()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue