8000 bpo-42866: Add traverse func to _multibytecodec.MultibyteCodec by vstinner · Pull Request #24166 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-42866: Add traverse func 8000 to _multibytecodec.MultibyteCodec #24166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Modules/cjkcodecs/multibytecodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,25 +721,34 @@ static struct PyMethodDef multibytecodec_methods[] = {
{NULL, NULL},
};

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

static void
multibytecodec_dealloc(MultibyteCodecObject *self)
{
PyObject_GC_UnTrack(self);
PyTypeObject *tp = Py_TYPE(self);
PyObject_Free(self);
tp->tp_free(self);
Py_DECREF(tp);
}

static PyType_Slot multibytecodec_slots[] = {
{Py_tp_dealloc, multibytecodec_dealloc},
{Py_tp_getattro, PyObject_GenericGetAttr},
{Py_tp_methods, multibytecodec_methods},
{Py_tp_traverse, multibytecodec_traverse},
{0, NULL},
};

static PyType_Spec multibytecodec_spec = {
.name = MODULE_NAME ".MultibyteCodec",
.basicsize = sizeof(MultibyteCodecObject),
.flags = Py_TPFLAGS_DEFAULT,
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.slots = multibytecodec_slots,
};

Expand Down Expand Up @@ -1944,11 +1953,12 @@ _multibytecodec___create_codec(PyObject *module, PyObject *arg)
return NULL;

_multibytecodec_state *state = _multibytecodec_get_state(module);
self = PyObject_New(MultibyteCodecObject, state->multibytecodec_type);
self = PyObject_GC_New(MultibyteCodecObject, state->multibytecodec_type);
if (self == NULL)
return NULL;
self->codec = codec;

PyObject_GC_Track(self);
return (PyObject *)self;
}

Expand Down
0