Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e30fe27

Browse files
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 1cd3d85) Co-authored-by: Victor Stinner <[email protected]>
1 parent 2f2ea96 commit e30fe27

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The _thread.RLock type now fully implement the GC protocol: add a traverse
2+
function and the :const:`Py_TPFLAGS_HAVE_GC` flag. Patch by Victor Stinner.

Modules/_threadmodule.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,14 @@ typedef struct {
327327
PyObject *in_weakreflist;
328328
} rlockobject;
329329

330+
static int
331+
rlock_traverse(rlockobject *self, visitproc visit, void *arg)
332+
{
333+
Py_VISIT(Py_TYPE(self));
334+
return 0;
335+
}
336+
337+
330338
static void
331339
rlock_dealloc(rlockobject *self)
332340
{
@@ -579,13 +587,14 @@ static PyType_Slot rlock_type_slots[] = {
579587
{Py_tp_alloc, PyType_GenericAlloc},
580588
{Py_tp_new, rlock_new},
581589
{Py_tp_members, rlock_type_members},
590+
{Py_tp_traverse, rlock_traverse},
582591
{0, 0},
583592
};
584593

585594
static PyType_Spec rlock_type_spec = {
586595
.name = "_thread.RLock",
587596
.basicsize = sizeof(rlockobject),
588-
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
597+
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
589598
.slots = rlock_type_slots,
590599
};
591600

0 commit comments

Comments
 (0)