Skip to content

Commit 79ac8c1

Browse files
gh-94395: Remove unneeded module state from mmap (#94396)
1 parent 5631013 commit 79ac8c1

File tree

1 file changed

+8
-46
lines changed

1 file changed

+8
-46
lines changed

Modules/mmapmodule.c

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,6 @@ typedef struct {
120120
access_mode access;
121121
} mmap_object;
122122

123-
typedef struct {
124-
PyTypeObject *mmap_object_type;
125-
} mmap_state;
126-
127-
static mmap_state *
128-
get_mmap_state(PyObject *module)
129-
{
130-
mmap_state *state = PyModule_GetState(module);
131-
assert(state);
132-
return state;
133-
}
134-
135123
static int
136124
mmap_object_traverse(mmap_object *m_obj, visitproc visit, void *arg)
137125
{
@@ -1555,46 +1543,23 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
15551543
}
15561544
#endif /* MS_WINDOWS */
15571545

1558-
static int
1559-
mmap_traverse(PyObject *module, visitproc visit, void *arg)
1560-
{
1561-
mmap_state *state = get_mmap_state(module);
1562-
Py_VISIT(state->mmap_object_type);
1563-
return 0;
1564-
}
1565-
1566-
static int
1567-
mmap_clear(PyObject *module)
1568-
{
1569-
mmap_state *state = get_mmap_state(module);
1570-
Py_CLEAR(state->mmap_object_type);
1571-
return 0;
1572-
}
1573-
1574-
static void
1575-
mmap_free(void *module)
1576-
{
1577-
mmap_clear((PyObject *)module);
1578-
}
1579-
15801546
static int
15811547
mmap_exec(PyObject *module)
15821548
{
1583-
mmap_state *state = get_mmap_state(module);
1584-
15851549
Py_INCREF(PyExc_OSError);
15861550
if (PyModule_AddObject(module, "error", PyExc_OSError) < 0) {
15871551
Py_DECREF(PyExc_OSError);
15881552
return -1;
15891553
}
15901554

1591-
state->mmap_object_type = (PyTypeObject *)PyType_FromModuleAndSpec(module,
1592-
&mmap_object_spec,
1593-
NULL);
1594-
if (state->mmap_object_type == NULL) {
1555+
PyObject *mmap_object_type = PyType_FromModuleAndSpec(module,
1556+
&mmap_object_spec, NULL);
1557+
if (mmap_object_type == NULL) {
15951558
return -1;
15961559
}
1597-
if (PyModule_AddType(module, state->mmap_object_type) < 0) {
1560+
int rc = PyModule_AddType(module, (PyTypeObject *)mmap_object_type);
1561+
Py_DECREF(mmap_object_type);
1562+
if (rc < 0) {
15981563
return -1;
15991564
}
16001565

@@ -1744,13 +1709,10 @@ static PyModuleDef_Slot mmap_slots[] = {
17441709
};
17451710

17461711
static struct PyModuleDef mmapmodule = {
1747-
PyModuleDef_HEAD_INIT,
1712+
.m_base = PyModuleDef_HEAD_INIT,
17481713
.m_name = "mmap",
1749-
.m_size = sizeof(mmap_state),
1714+
.m_size = 0,
17501715
.m_slots = mmap_slots,
1751-
.m_traverse = mmap_traverse,
1752-
.m_clear = mmap_clear,
1753-
.m_free = mmap_free,
17541716
};
17551717

17561718
PyMODINIT_FUNC

0 commit comments

Comments
 (0)