mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-111926: Make weakrefs thread-safe in free-threaded builds (#117168)
Most mutable data is protected by a striped lock that is keyed on the referenced object's address. The weakref's hash is protected using the weakref's per-object lock. Note that this only affects free-threaded builds. Apart from some minor refactoring, the added code is all either gated by `ifdef`s or is a no-op (e.g. `Py_BEGIN_CRITICAL_SECTION`).
This commit is contained in:
parent
e16062dd34
commit
df73179048
17 changed files with 490 additions and 326 deletions
|
@ -1708,11 +1708,15 @@ class SizeofTest(unittest.TestCase):
|
|||
# TODO: add check that forces layout of unicodefields
|
||||
# weakref
|
||||
import weakref
|
||||
check(weakref.ref(int), size('2Pn3P'))
|
||||
if support.Py_GIL_DISABLED:
|
||||
expected = size('2Pn4P')
|
||||
else:
|
||||
expected = size('2Pn3P')
|
||||
check(weakref.ref(int), expected)
|
||||
# weakproxy
|
||||
# XXX
|
||||
# weakcallableproxy
|
||||
check(weakref.proxy(int), size('2Pn3P'))
|
||||
check(weakref.proxy(int), expected)
|
||||
|
||||
def check_slots(self, obj, base, extra):
|
||||
expected = sys.getsizeof(base) + struct.calcsize(extra)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue