8000 bpo-42972: Fully support GC for mmap heap types · python/cpython@425ab89 · GitHub
[go: up one dir, main page]

Skip to content

Commit 425ab89

Browse files
author
Erlend E. Aasland
committed
bpo-42972: Fully support GC for mmap heap types
1 parent bd404cc commit 425ab89

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Modules/mmapmodule.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,18 @@ get_mmap_state(PyObject *module)
126126
return state;
127127
}
128128

129+
static int
130+
mmap_object_traverse(mmap_object *m_obj, visitproc visit, void *arg)
131+
{
132+
Py_VISIT(Py_TYPE(m_obj));
133+
return 0;
134+
}
135+
129136
static void
130137
mmap_object_dealloc(mmap_object *m_obj)
131138
{
132139
PyTypeObject *tp = Py_TYPE(m_obj);
140+
PyObject_GC_UnTrack(m_obj);
133141

134142
#ifdef MS_WINDOWS
135143
Py_BEGIN_ALLOW_THREADS
@@ -1085,15 +1093,14 @@ To map anonymous memory, pass -1 as the fileno (both versions).");
10851093

10861094
static PyType_Slot mmap_object_slots[] = {
10871095
{Py_tp_new, new_mmap_object},
1088-
{Py_tp_alloc, PyType_GenericAlloc},
10891096
{Py_tp_dealloc, mmap_object_dealloc},
1090-
{Py_tp_free, PyObject_Del},
10911097
{Py_tp_repr, mmap__repr__method},
10921098
{Py_tp_doc, (void *)mmap_doc},
10931099
{Py_tp_methods, mmap_object_methods},
10941100
{Py_tp_members, mmap_object_members},
10951101
{Py_tp_getset, mmap_object_getset},
10961102
{Py_tp_getattro, PyObject_GenericGetAttr},
1103+
{Py_tp_traverse, mmap_object_traverse},
10971104

10981105
/* as sequence */
10991106
{Py_sq_length, mmap_length},
@@ -1114,7 +1121,7 @@ static PyType_Slot mmap_object_slots[] = {
11141121
static PyType_Spec mmap_object_spec = {
11151122
.name = "mmap.mmap",
11161123
.basicsize = sizeof(mmap_object),
1117-
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
1124+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC),
11181125
.slots = mmap_object_slots,
11191126
};
11201127

0 commit comments

Comments
 (0)
0