Skip to content

bpo-1635741 port some simple modules to multi-phase initialization #21985

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

Closed
wants to merge 8 commits into from
Closed
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,5 @@
Port :mod:`_curses_panel` to multi-phase init Port :mod:`_opcode` to
multi-phase init Port :mod:`_testbuffer` to multi-phase init Port
:mod:`overlapped` to multi-phase init and convert to heap types Port
:mod:`signalmodule` to multi-phase init Port :mod:`termios` to multi-phase
init
56 changes: 28 additions & 28 deletions Modules/_curses_panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,6 @@ _curses_panel_update_panels_impl(PyObject *module)
Py_RETURN_NONE;
}


/* List of functions defined in the module */

static PyMethodDef PyCurses_methods[] = {
Expand All @@ -622,33 +621,12 @@ static PyMethodDef PyCurses_methods[] = {
};

/* Initialization function for the module */


static struct PyModuleDef _curses_panelmodule = {
PyModuleDef_HEAD_INIT,
"_curses_panel",
NULL,
sizeof(_curses_panelstate),
PyCurses_methods,
NULL,
_curses_panel_traverse,
_curses_panel_clear,
_curses_panel_free
};

PyMODINIT_FUNC
PyInit__curses_panel(void)
static int _curses_exec(PyObject *m)
{
PyObject *m, *d, *v;

/* Create the module and add the functions */
m = PyModule_Create(&_curses_panelmodule);
if (m == NULL)
goto fail;
d = PyModule_GetDict(m);
PyObject *d = PyModule_GetDict(m);

/* Initialize object type */
v = PyType_FromSpec(&PyCursesPanel_Type_spec);
PyObject *v = PyType_FromSpec(&PyCursesPanel_Type_spec);
if (v == NULL)
goto fail;
((PyTypeObject *)v)->tp_new = NULL;
Expand All @@ -671,8 +649,30 @@ PyInit__curses_panel(void)
Py_INCREF(get_curses_panelstate(m)->PyCursesPanel_Type);
PyModule_AddObject(m, "panel",
(PyObject *)get_curses_panelstate(m)->PyCursesPanel_Type);
return m;
return 0;

fail:
Py_XDECREF(m);
return NULL;
return -1;
}

static PyModuleDef_Slot _curses_slots[] = {
{Py_mod_exec, _curses_exec},
{0, NULL}
};

static struct PyModuleDef _curses_panelmodule = {
PyModuleDef_HEAD_INIT,
.m_name = "_curses_panel",
.m_size = sizeof(_curses_panelstate),
.m_methods = PyCurses_methods,
.m_slots = _curses_slots,
.m_traverse = _curses_panel_traverse,
.m_clear = _curses_panel_clear,
.m_free = _curses_panel_free
};

PyMODINIT_FUNC
PyInit__opcode(void)
{
return PyModuleDef_Init(&_curses_panelmodule);
}
26 changes: 14 additions & 12 deletions Modules/_opcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,32 @@ _opcode_stack_effect_impl(PyObject *module, int opcode, PyObject *oparg,
return effect;
}




static PyMethodDef
opcode_functions[] = {
_OPCODE_STACK_EFFECT_METHODDEF
{NULL, NULL, 0, NULL}
};

static int opcode_exec(PyObject *m) {
return 0;
}

static PyModuleDef_Slot opcode_slots[] = {
{Py_mod_exec, opcode_exec},
{0, NULL}
};

static struct PyModuleDef opcodemodule = {
PyModuleDef_HEAD_INIT,
"_opcode",
"Opcode support module.",
-1,
opcode_functions,
NULL,
NULL,
NULL,
NULL
.m_name = "_opcode",
.m_doc = "Opcode support module.",
.m_size = 0,
.m_methods = opcode_functions,
.m_slots = opcode_slots
};

PyMODINIT_FUNC
PyInit__opcode(void)
{
return PyModule_Create(&opcodemodule);
return PyModuleDef_Init(&opcodemodule);
}
44 changes: 19 additions & 25 deletions Modules/_testbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2813,28 +2813,8 @@ static struct PyMethodDef _testbuffer_functions[] = {
{NULL, NULL}
};

static struct PyModuleDef _testbuffermodule = {
PyModuleDef_HEAD_INIT,
"_testbuffer",
NULL,
-1,
_testbuffer_functions,
NULL,
NULL,
NULL,
NULL
};


PyMODINIT_FUNC
PyInit__testbuffer(void)
static int testbuffer_exec(PyObject *m)
{
PyObject *m;

m = PyModule_Create(&_testbuffermodule);
if (m == NULL)
return NULL;

Py_SET_TYPE(&NDArray_Type, &PyType_Type);
Py_INCREF(&NDArray_Type);
PyModule_AddObject(m, "ndarray", (PyObject *)&NDArray_Type);
Expand All @@ -2845,16 +2825,16 @@ PyInit__testbuffer(void)

structmodule = PyImport_ImportModule("struct");
if (structmodule == NULL)
return NULL;
return -1;

Struct = PyObject_GetAttrString(structmodule, "Struct");
calcsize = PyObject_GetAttrString(structmodule, "calcsize");
if (Struct == NULL || calcsize == NULL)
return NULL;
return -1;

simple_format = PyUnicode_FromString(simple_fmt);
if (simple_format == NULL)
return NULL;
return -1;

PyModule_AddIntMacro(m, ND_MAX_NDIM);
PyModule_AddIntMacro(m, ND_VAREXPORT);
Expand Down Expand Up @@ -2887,8 +2867,22 @@ PyInit__testbuffer(void)
PyModule_AddIntMacro(m, PyBUF_READ);
PyModule_AddIntMacro(m, PyBUF_WRITE);

return m;
return 0;
}

static PyModuleDef_Slot _testbuffer_slots[] = {
{Py_mod_exec, testbuffer_exec},
{0, NULL}
};

static struct PyModuleDef _testbuffermodule = {
PyModuleDef_HEAD_INIT,
.m_name = "_testbuffer",
.m_size = 0,
.m_methods = _testbuffer_functions,
.m_slots = _testbuffer_slots
};

PyMODINIT_FUNC PyInit__testbuffer(void) {
return PyModuleDef_Init(&_testbuffermodule);
}
Loading