[Python-checkins] gh-94395: Remove unneeded module state from mmap (#94396)
erlend-aasland
webhook-mailer at python.org
Wed Jun 29 01:21:15 EDT 2022
https://github.com/python/cpython/commit/79ac8c1c0d7cfc955a82af123471c28944e61c18
commit: 79ac8c1c0d7cfc955a82af123471c28944e61c18
branch: main
author: Erlend Egeberg Aasland <erlend.aasland at protonmail.com>
committer: erlend-aasland <erlend.aasland at protonmail.com>
date: 2022-06-29T07:20:53+02:00
summary:
gh-94395: Remove unneeded module state from mmap (#94396)
files:
M Modules/mmapmodule.c
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index ec36465728c3a..5c05aa738ef56 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -120,18 +120,6 @@ typedef struct {
access_mode access;
} mmap_object;
-typedef struct {
- PyTypeObject *mmap_object_type;
-} mmap_state;
-
-static mmap_state *
-get_mmap_state(PyObject *module)
-{
- mmap_state *state = PyModule_GetState(module);
- assert(state);
- return state;
-}
-
static int
mmap_object_traverse(mmap_object *m_obj, visitproc visit, void *arg)
{
@@ -1555,46 +1543,23 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
}
#endif /* MS_WINDOWS */
-static int
-mmap_traverse(PyObject *module, visitproc visit, void *arg)
-{
- mmap_state *state = get_mmap_state(module);
- Py_VISIT(state->mmap_object_type);
- return 0;
-}
-
-static int
-mmap_clear(PyObject *module)
-{
- mmap_state *state = get_mmap_state(module);
- Py_CLEAR(state->mmap_object_type);
- return 0;
-}
-
-static void
-mmap_free(void *module)
-{
- mmap_clear((PyObject *)module);
-}
-
static int
mmap_exec(PyObject *module)
{
- mmap_state *state = get_mmap_state(module);
-
Py_INCREF(PyExc_OSError);
if (PyModule_AddObject(module, "error", PyExc_OSError) < 0) {
Py_DECREF(PyExc_OSError);
return -1;
}
- state->mmap_object_type = (PyTypeObject *)PyType_FromModuleAndSpec(module,
- &mmap_object_spec,
- NULL);
- if (state->mmap_object_type == NULL) {
+ PyObject *mmap_object_type = PyType_FromModuleAndSpec(module,
+ &mmap_object_spec, NULL);
+ if (mmap_object_type == NULL) {
return -1;
}
- if (PyModule_AddType(module, state->mmap_object_type) < 0) {
+ int rc = PyModule_AddType(module, (PyTypeObject *)mmap_object_type);
+ Py_DECREF(mmap_object_type);
+ if (rc < 0) {
return -1;
}
@@ -1744,13 +1709,10 @@ static PyModuleDef_Slot mmap_slots[] = {
};
static struct PyModuleDef mmapmodule = {
- PyModuleDef_HEAD_INIT,
+ .m_base = PyModuleDef_HEAD_INIT,
.m_name = "mmap",
- .m_size = sizeof(mmap_state),
+ .m_size = 0,
.m_slots = mmap_slots,
- .m_traverse = mmap_traverse,
- .m_clear = mmap_clear,
- .m_free = mmap_free,
};
PyMODINIT_FUNC
More information about the Python-checkins
mailing list