[Python-checkins] bpo-42972: _thread.RLock implements the GH protocol (GH-26734)

miss-islington webhook-mailer at python.org
Tue Jun 15 09:29:52 EDT 2021


https://github.com/python/cpython/commit/e30fe27dabbc6b48736c3c17d57f6fa542376e8f
commit: e30fe27dabbc6b48736c3c17d57f6fa542376e8f
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-06-15T06:29:44-07:00
summary:

bpo-42972: _thread.RLock implements the GH protocol (GH-26734)


The _thread.RLock type now fully implement the GC protocol: add a
traverse function and the Py_TPFLAGS_HAVE_GC flag.
(cherry picked from commit 1cd3d859a49b047dd08abb6f44f0539564d3525a)

Co-authored-by: Victor Stinner <vstinner at python.org>

files:
A Misc/NEWS.d/next/Library/2021-06-15-13-51-25.bpo-42972.UnyYo1.rst
M Modules/_threadmodule.c

diff --git a/Misc/NEWS.d/next/Library/2021-06-15-13-51-25.bpo-42972.UnyYo1.rst b/Misc/NEWS.d/next/Library/2021-06-15-13-51-25.bpo-42972.UnyYo1.rst
new file mode 100644
index 0000000000000..fbcc12c9f90a2
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-06-15-13-51-25.bpo-42972.UnyYo1.rst
@@ -0,0 +1,2 @@
+The _thread.RLock type now fully implement the GC protocol: add a traverse
+function and the :const:`Py_TPFLAGS_HAVE_GC` flag. Patch by Victor Stinner.
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 6924d6553a1ff..5a2001c8fbf26 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -327,6 +327,14 @@ typedef struct {
     PyObject *in_weakreflist;
 } rlockobject;
 
+static int
+rlock_traverse(rlockobject *self, visitproc visit, void *arg)
+{
+    Py_VISIT(Py_TYPE(self));
+    return 0;
+}
+
+
 static void
 rlock_dealloc(rlockobject *self)
 {
@@ -579,13 +587,14 @@ static PyType_Slot rlock_type_slots[] = {
     {Py_tp_alloc, PyType_GenericAlloc},
     {Py_tp_new, rlock_new},
     {Py_tp_members, rlock_type_members},
+    {Py_tp_traverse, rlock_traverse},
     {0, 0},
 };
 
 static PyType_Spec rlock_type_spec = {
     .name = "_thread.RLock",
     .basicsize = sizeof(rlockobject),
-    .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+    .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
     .slots = rlock_type_slots,
 };
 



More information about the Python-checkins mailing list