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

bpo-1635741: Port mmap module to multiphase initialization #19459

Merged
merged 4 commits into from
Jun 5, 2020
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
Next Next commit
Port mmap module to multiphase initialization
  • Loading branch information
corona10 committed Jun 5, 2020
commit 18e988aa6e96b01fc8804b010cb5483f57187d86
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Port :mod:`mmap` to multiphase initialization.
55 changes: 28 additions & 27 deletions Modules/mmapmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1519,33 +1519,17 @@ setint(PyObject *d, const char *name, long value)
}
}


static struct PyModuleDef mmapmodule = {
PyModuleDef_HEAD_INIT,
"mmap",
NULL,
-1,
NULL,
NULL,
NULL,
NULL,
NULL
};

PyMODINIT_FUNC
PyInit_mmap(void)
static int
mmap_exec(PyObject *module)
{
PyObject *dict, *module;

if (PyType_Ready(&mmap_object_type) < 0)
return NULL;
if (PyType_Ready(&mmap_object_type) < 0) {
return -1;
}

module = PyModule_Create(&mmapmodule);
if (module == NULL)
return NULL;
dict = PyModule_GetDict(module);
if (!dict)
return NULL;
PyObject *dict = PyModule_GetDict(module);
if (!dict) {
return -1;
}
PyDict_SetItemString(dict, "error", PyExc_OSError);
PyDict_SetItemString(dict, "mmap", (PyObject*) &mmap_object_type);
#ifdef PROT_EXEC
Expand Down Expand Up @@ -1660,6 +1644,23 @@ PyInit_mmap(void)
setint(dict, "MADV_PROTECT", MADV_PROTECT);
#endif
#endif // HAVE_MADVISE

return module;
return 0;
}

static PyModuleDef_Slot mmap_slots[] = {
{Py_mod_exec, mmap_exec},
{0, NULL}
};

static struct PyModuleDef mmapmodule = {
PyModuleDef_HEAD_INIT,
.m_name = "mmap",
.m_size = 0,
.m_slots = mmap_slots,
};

PyMODINIT_FUNC
PyInit_mmap(void)
{
return PyModuleDef_Init(&mmapmodule);
}