Skip to content

bpo-1635741: Port _heapq module to multiphase initialization. #19057

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

Merged
merged 2 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Port _heapq module to multiphase initialization.
31 changes: 19 additions & 12 deletions Modules/_heapqmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,6 @@ _heapq__heapify_max(PyObject *module, PyObject *heap)
return heapify_internal(heap, siftup_max);
}


static PyMethodDef heapq_methods[] = {
_HEAPQ_HEAPPUSH_METHODDEF
_HEAPQ_HEAPPUSHPOP_METHODDEF
Expand Down Expand Up @@ -694,13 +693,29 @@ Believe me, real good tape sorts were quite spectacular to watch!\n\
From all times, sorting has always been a Great Art! :-)\n");


static int
heapq_exec(PyObject *m)
{
PyObject *about = PyUnicode_FromString(__about__);
if (PyModule_AddObject(m, "__about__", about) < 0) {
Py_DECREF(about);
return -1;
}
return 0;
}

static struct PyModuleDef_Slot heapq_slots[] = {
{Py_mod_exec, heapq_exec},
{0, NULL}
};

static struct PyModuleDef _heapqmodule = {
PyModuleDef_HEAD_INIT,
"_heapq",
module_doc,
-1,
0,
heapq_methods,
NULL,
heapq_slots,
NULL,
NULL,
NULL
Expand All @@ -709,13 +724,5 @@ static struct PyModuleDef _heapqmodule = {
PyMODINIT_FUNC
PyInit__heapq(void)
{
PyObject *m, *about;

m = PyModule_Create(&_heapqmodule);
if (m == NULL)
return NULL;
about = PyUnicode_DecodeUTF8(__about__, strlen(__about__), NULL);
PyModule_AddObject(m, "__about__", about);
return m;
return PyModuleDef_Init(&_heapqmodule);
}