Skip to content

Commit

Permalink
bpo-44263: Fix _decimal and _testcapi GC protocol (GH-26464)
Browse files Browse the repository at this point in the history
* _testcapi.heapgctype: implement a traverse function since the type
  is defined with Py_TPFLAGS_HAVE_GC.
* _decimal: PyDecSignalDictMixin_Type is no longer defined with
  Py_TPFLAGS_HAVE_GC since it has no traverse function.
(cherry picked from commit 142e5c5)

Co-authored-by: Victor Stinner <vstinner@python.org>
  • Loading branch information
miss-islington and vstinner committed May 31, 2021
1 parent 9bcb76c commit 46b16d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Modules/_decimal/_decimal.c
Expand Up @@ -696,8 +696,7 @@ static PyTypeObject PyDecSignalDictMixin_Type =
PyObject_GenericGetAttr, /* tp_getattro */
(setattrofunc) 0, /* tp_setattro */
(PyBufferProcs *) 0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|
Py_TPFLAGS_HAVE_GC, /* tp_flags */
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
0, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
Expand Down
8 changes: 8 additions & 0 deletions Modules/_testcapimodule.c
Expand Up @@ -6257,6 +6257,13 @@ heapctype_init(PyObject *self, PyObject *args, PyObject *kwargs)
return 0;
}

static int
heapgcctype_traverse(HeapCTypeObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
return 0;
}

static void
heapgcctype_dealloc(HeapCTypeObject *self)
{
Expand All @@ -6270,6 +6277,7 @@ static PyType_Slot HeapGcCType_slots[] = {
{Py_tp_init, heapctype_init},
{Py_tp_members, heapctype_members},
{Py_tp_dealloc, heapgcctype_dealloc},
{Py_tp_traverse, heapgcctype_traverse},
{Py_tp_doc, (char*)heapgctype__doc__},
{0, 0},
};
Expand Down

0 comments on commit 46b16d0

Please sign in to comment.