diff options
author | Peter Bierma <zintensitydev@gmail.com> | 2024-09-26 10:29:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-26 10:29:43 (GMT) |
commit | f923605658a29ff9af5a62edc1fc10191977627b (patch) | |
tree | fa26fb24c84fc965468c0f68254451f78fa30314 /Lib/test/test_gc.py | |
parent | 0387c34f7c91428681ca8a4ba4e3d22b9acffde4 (diff) | |
download | cpython-f923605658a29ff9af5a62edc1fc10191977627b.zip cpython-f923605658a29ff9af5a62edc1fc10191977627b.tar.gz cpython-f923605658a29ff9af5a62edc1fc10191977627b.tar.bz2 |
gh-124538: Fix crash when using `gc.get_referents` on an untracked capsule object (#124559)
Diffstat (limited to 'Lib/test/test_gc.py')
-rw-r--r-- | Lib/test/test_gc.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py index 906f988..bb7df1f 100644 --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -1048,6 +1048,24 @@ class GCTests(unittest.TestCase): callback.assert_not_called() gc.enable() + @cpython_only + def test_get_referents_on_capsule(self): + # gh-124538: Calling gc.get_referents() on an untracked capsule must not crash. + import _datetime + import _socket + untracked_capsule = _datetime.datetime_CAPI + tracked_capsule = _socket.CAPI + + # For whoever sees this in the future: if this is failing + # after making datetime's capsule tracked, that's fine -- this isn't something + # users are relying on. Just find a different capsule that is untracked. + self.assertFalse(gc.is_tracked(untracked_capsule)) + self.assertTrue(gc.is_tracked(tracked_capsule)) + + self.assertEqual(len(gc.get_referents(untracked_capsule)), 0) + gc.get_referents(tracked_capsule) + + class IncrementalGCTests(unittest.TestCase): |