Skip to content
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

GH-104510: Fix refleaks in _io base types #104516

Merged
merged 3 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
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
fix by inheriting vsitor
  • Loading branch information
kumaraditya303 committed May 16, 2023
commit 1e710b403a7df12a92f89a307910ceae385cd3cd
8 changes: 0 additions & 8 deletions Modules/_io/_iomodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,3 @@ extern PyObject *_PyIOBase_cannot_pickle(PyObject *self, PyObject *args);
#ifdef HAVE_WINDOWS_CONSOLE_IO
extern char _PyIO_get_console_type(PyObject *);
#endif


typedef struct {
PyObject_HEAD

PyObject *dict;
PyObject *weakreflist;
} iobase;
11 changes: 1 addition & 10 deletions Modules/_io/bufferedio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2424,14 +2424,6 @@ _io_BufferedRandom___init___impl(buffered *self, PyObject *raw,
#include "clinic/bufferedio.c.h"
#undef clinic_state

static int
bufferediobase_traverse(PyObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
Py_VISIT(((iobase *)self)->dict);
return 0;
}

static PyMethodDef bufferediobase_methods[] = {
_IO__BUFFEREDIOBASE_DETACH_METHODDEF
_IO__BUFFEREDIOBASE_READ_METHODDEF
Expand All @@ -2445,13 +2437,12 @@ static PyMethodDef bufferediobase_methods[] = {
static PyType_Slot bufferediobase_slots[] = {
{Py_tp_doc, (void *)bufferediobase_doc},
{Py_tp_methods, bufferediobase_methods},
{Py_tp_traverse, bufferediobase_traverse},
{0, NULL},
};

PyType_Spec bufferediobase_spec = {
.name = "_io._BufferedIOBase",
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
Py_TPFLAGS_IMMUTABLETYPE),
.slots = bufferediobase_slots,
};
Expand Down
17 changes: 7 additions & 10 deletions Modules/_io/iobase.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class _io._RawIOBase "PyObject *" "clinic_state()->PyRawIOBase_Type"
* IOBase class, an abstract class
kumaraditya303 marked this conversation as resolved.
Show resolved Hide resolved
*/

typedef struct {
PyObject_HEAD

PyObject *dict;
PyObject *weakreflist;
} iobase;

PyDoc_STRVAR(iobase_doc,
"The abstract base class for all I/O classes.\n"
Expand Down Expand Up @@ -1030,14 +1036,6 @@ rawiobase_write(PyObject *self, PyObject *args)
return NULL;
}

static int
rawiobase_traverse(PyObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
Py_VISIT(((iobase *)self)->dict);
return 0;
}

static PyMethodDef rawiobase_methods[] = {
_IO__RAWIOBASE_READ_METHODDEF
_IO__RAWIOBASE_READALL_METHODDEF
Expand All @@ -1049,13 +1047,12 @@ static PyMethodDef rawiobase_methods[] = {
static PyType_Slot rawiobase_slots[] = {
{Py_tp_doc, (void *)rawiobase_doc},
{Py_tp_methods, rawiobase_methods},
{Py_tp_traverse, rawiobase_traverse},
{0, NULL},
};

PyType_Spec rawiobase_spec = {
.name = "_io._RawIOBase",
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = rawiobase_slots,
};
10 changes: 1 addition & 9 deletions Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,6 @@ textiobase_errors_get(PyObject *self, void *context)
Py_RETURN_NONE;
}

static int
textiobase_traverse(PyObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
Py_VISIT(((iobase *)self)->dict);
return 0;
}

static PyMethodDef textiobase_methods[] = {
_IO__TEXTIOBASE_DETACH_METHODDEF
Expand All @@ -194,13 +187,12 @@ static PyType_Slot textiobase_slots[] = {
{Py_tp_doc, (void *)textiobase_doc},
{Py_tp_methods, textiobase_methods},
{Py_tp_getset, textiobase_getset},
{Py_tp_traverse, textiobase_traverse},
{0, NULL},
};

PyType_Spec textiobase_spec = {
.name = "_io._TextIOBase",
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = textiobase_slots,
};
Expand Down