8000 bpo-42866: Add traverse func to _multibytecodec.MultibyteCodec (GH-24… · python/cpython@11ef53a · GitHub
[go: up one dir, main page]

Skip to content

Commit 11ef53a

Browse files
authored
bpo-42866: Add traverse func to _multibytecodec.MultibyteCodec (GH-24166)
Convert _multibytecodec.MultibyteCodec type to a GC type and adds a traverse function.
1 parent e542d41 commit 11ef53a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Modules/cjkcodecs/multibytecodec.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,25 +721,34 @@ static struct PyMethodDef multibytecodec_methods[] = {
721721
{NULL, NULL},
722722
};
723723

724+
static int
725+
multibytecodec_traverse(PyObject *self, visitproc visit, void *arg)
726+
{
727+
Py_VISIT(Py_TYPE(self));
728+
return 0;
729+
}
730+
724731
static void
725732
multibytecodec_dealloc(MultibyteCodecObject *self)
726733
{
734+
PyObject_GC_UnTrack(self);
727735
PyTypeObject *tp = Py_TYPE(self);
728-
PyObject_Free(self);
736+
tp->tp_free(self);
729737
Py_DECREF(tp);
730738
}
731739

732740
static PyType_Slot multibytecodec_slots[] = {
733741
{Py_tp_dealloc, multibytecodec_dealloc},
734742
{Py_tp_getattro, PyObject_GenericGetAttr},
735743
{Py_tp_methods, multibytecodec_methods},
744+
{Py_tp_traverse, multibytecodec_traverse},
736745
{0, NULL},
737746
};
738747

739748
static PyType_Spec multibytecodec_spec = {
740749
.name = MODULE_NAME ".MultibyteCodec",
741750
.basicsize = sizeof(MultibyteCodecObject),
742-
.flags = Py_TPFLAGS_DEFAULT,
751+
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
743752
.slots = multibytecodec_slots,
744753
};
745754

@@ -1944,11 +1953,12 @@ _multibytecodec___create_codec(PyObject *module, PyObject *arg)
19441953
return NULL;
19451954

19461955
_multibytecodec_state *state = _multibytecodec_get_state(module);
1947-
self = PyObject_New(MultibyteCodecObject, state->multibytecodec_type);
1956+
self = PyObject_GC_New(MultibyteCodecObject, state->multibytecodec_type);
19481957
if (self == NULL)
19491958
return NULL;
19501959
self->codec = codec;
19511960

1961+
PyObject_GC_Track(self);
19521962
return (PyObject *)self;
19531963
}
19541964

0 commit comments

Comments
 (0)
0