GH-95245: Move weakreflist into the pre-header. (GH-95996)

This commit is contained in:
Mark Shannon 2022-08-16 13:57:18 +01:00 committed by GitHub
parent 829aab8592
commit 5a8c15819c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 105 additions and 20 deletions

View file

@ -579,6 +579,37 @@ def test_heaptype_with_weakref(self):
self.assertEqual(ref(), inst)
self.assertEqual(inst.weakreflist, ref)
def test_heaptype_with_managed_weakref(self):
inst = _testcapi.HeapCTypeWithManagedWeakref()
ref = weakref.ref(inst)
self.assertEqual(ref(), inst)
def test_sublclassing_managed_weakref(self):
class C(_testcapi.HeapCTypeWithManagedWeakref):
pass
inst = C()
ref = weakref.ref(inst)
self.assertEqual(ref(), inst)
def test_sublclassing_managed_both(self):
class C1(_testcapi.HeapCTypeWithManagedWeakref, _testcapi.HeapCTypeWithManagedDict):
pass
class C2(_testcapi.HeapCTypeWithManagedDict, _testcapi.HeapCTypeWithManagedWeakref):
pass
for cls in (C1, C2):
inst = cls()
ref = weakref.ref(inst)
self.assertEqual(ref(), inst)
inst.spam = inst
del inst
ref = weakref.ref(cls())
self.assertIs(ref(), None)
def test_heaptype_with_buffer(self):
inst = _testcapi.HeapCTypeWithBuffer()
b = bytes(inst)