8000 bpo-44116: Add GC support to _csv heap types by erlend-aasland · Pull Request #26074 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-44116: Add GC support to _csv heap types #26074

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 4 commits into from
May 12, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use tp_clear iso. tp_finalize
  • Loading branch information
Erlend E. Aasland committed May 12, 2021
commit 19e2952e43e013f1d49fd0437878e4b1c7f0ce66
67 changes: 24 additions & 43 deletions Modules/_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,19 +315,13 @@ static PyGetSetDef Dialect_getsetlist[] = {
static void
Dialect_dealloc(DialectObj *self)
{
PyObject_GC_UnTrack(self);
PyTypeObject *tp = Py_TYPE(self);
Py_CLEAR(self->lineterminator);
tp->tp_free((PyObject *)self);
PyObject_GC_UnTrack(self);
tp->tp_clear((PyObject *)self);
PyObject_GC_Del(self);
Py_DECREF(tp);
}

static void
Dialect_finalize(DialectObj *self)
{
Py_CLEAR(self->lineterminator);
}

static char *dialect_kws[] = {
"dialect",
"delimiter",
Expand Down Expand Up @@ -514,8 +508,16 @@ PyDoc_STRVAR(Dialect_Type_doc,
"The Dialect type records CSV parsing and generation options.\n");

static int
Dialect_traverse(PyObject *self, visitproc visit, void *arg)
Dialect_clear(DialectObj *self)
{
Py_CLEAR(self->lineterminator);
return 0;
}

static int
Dialect_traverse(DialectObj *self, visitproc visit, void *arg)
{
Py_VISIT(self->lineterminator);
Py_VISIT(Py_TYPE(self));
return 0;
}
Expand All @@ -526,8 +528,8 @@ static PyType_Slot Dialect_Type_slots[] = {
{Py_tp_getset, Dialect_getsetlist},
{Py_tp_new, dialect_new},
{Py_tp_methods, dialect_methods},< 8000 /span>
{Py_tp_finalize, Dialect_finalize},
{Py_tp_dealloc, Dialect_dealloc},
{Py_tp_clear, Dialect_clear},
{Py_tp_traverse, Dialect_traverse},
{0, NULL}
};
Expand Down Expand Up @@ -894,29 +896,11 @@ Reader_dealloc(ReaderObj *self)
{
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);
Py_CLEAR(self->dialect);
Py_CLEAR(self->input_iter);
Py_CLEAR(self->fields);
if (self->field != NULL) {
PyMem_Free(self->field);
self->field = NULL;
}
tp->tp_clear((PyObject *)self);
PyObject_GC_Del(self);
Py_DECREF(tp);
}

static void
Reader_finalize(ReaderObj *self)
{
Py_CLEAR(self->dialect);
Py_CLEAR(self->input_iter);
Py_CLEAR(self->fields);
if (self->field != NULL) {
PyMem_Free(self->field);
self->field = NULL;
}
}

static int
Reader_traverse(ReaderObj *self, visitproc visit, void *arg)
{
Expand All @@ -933,6 +917,10 @@ Reader_clear(ReaderObj *self)
Py_CLEAR(self->dialect);
Py_CLEAR(self->input_iter);
Py_CLEAR(self->fields);
if (self->field != NULL) {
PyMem_Free(self->field);
self->field = NULL;
}
return 0;
}

Expand All @@ -958,12 +946,11 @@ static struct PyMemberDef Reader_memberlist[] = {
static PyType_Slot Reader_Type_slots[] = {
{Py_tp_doc, (char*)Reader_Type_doc},
{Py_tp_traverse, Reader_traverse},
{Py_tp_clear, Reader_clear},
{Py_tp_iter, PyObject_SelfIter},
{Py_tp_iternext, Reader_iternext},
{Py_tp_methods, Reader_methods},
{Py_tp_members, Reader_memberlist},
{Py_tp_finalize, Reader_finalize},
{Py_tp_clear, Reader_clear},
{Py_tp_dealloc, Reader_dealloc},
{0, NULL}
};
Expand Down Expand Up @@ -1359,27 +1346,22 @@ Writer_clear(WriterObj *self)
Py_CLEAR(self->dialect);
Py_CLEAR(self->write);
Py_CLEAR(self->error_obj);
if (self->rec != NULL) {
PyMem_Free(self->rec);
}
return 0;
}

static void
Writer_dealloc(WriterObj *self)
{
PyObject_GC_UnTrack(self);
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);
tp->tp_clear((PyObject *)self);
PyObject_GC_Del(self);
Py_DECREF(tp);
}

static void
Writer_finalize(WriterObj *self)
{
Writer_clear(self);
if (self->rec != NULL) {
PyMem_Free(self->rec);
}
}

PyDoc_STRVAR(Writer_Type_doc,
"CSV writer\n"
"\n"
Expand All @@ -1388,7 +1370,6 @@ PyDoc_STRVAR(Writer_Type_doc,
);

static PyType_Slot Writer_Type_slots[] = {
{Py_tp_finalize, Writer_finalize},
{Py_tp_doc, (char*)Writer_Type_doc},
{Py_tp_traverse, Writer_traverse},
{Py_tp_clear, Writer_clear},
Expand Down
0