8000 bpo-1635741: Port mashal module to multi-phase init (#22149) · python/cpython@f315142 · GitHub
[go: up one dir, main page]

Skip to content

Commit f315142

Browse files
authored
bpo-1635741: Port mashal module to multi-phase init (#22149)
Port the 'mashal' extension module to the multi-phase initialization API (PEP 489).
1 parent bb083d3 commit f315142

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Port the ``mashal`` extension module to the multi-phase initialization API
2+
(:pep:`489`).

Python/marshal.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,28 +1785,30 @@ dumps() -- marshal value as a bytes object\n\
17851785
loads() -- read value from a bytes-like object");
17861786

17871787

1788+
static int
1789+
marshal_module_exec(PyObject *mod)
1790+
{
1791+
if (PyModule_AddIntConstant(mod, "version", Py_MARSHAL_VERSION) < 0) {
1792+
return -1;
1793+
}
1794+
return 0;
1795+
}
1796+
1797+
static PyModuleDef_Slot marshalmodule_slots[] = {
1798+
{Py_mod_exec, marshal_module_exec},
1799+
{0, NULL}
1800+
};
17881801

17891802
static struct PyModuleDef marshalmodule = {
17901803
PyModuleDef_HEAD_INIT,
1791-
"marshal",
1792-
module_doc,
1793-
0,
1794-
marshal_methods,
1795-
NULL,
1796-
NULL,
1797-
NULL,
1798-
NULL
1804+
.m_name = "marshal",
1805+
.m_doc = module_doc,
1806+
.m_methods = marshal_methods,
1807+
.m_slots = marshalmodule_slots,
17991808
};
18001809

18011810
PyMODINIT_FUNC
18021811
PyMarshal_Init(void)
18031812
{
1804-
PyObject *mod = PyModule_Create(&marshalmodule);
1805-
if (mod == NULL)
1806-
return NULL;
1807-
if (PyModule_AddIntConstant(mod, "version", Py_MARSHAL_VERSION) < 0) {
1808-
Py_DECREF(mod);
1809-
return NULL;
1810-
}
1811-
return mod;
1813+
return PyModuleDef_Init(&marshalmodule);
18121814
}

0 commit comments

Comments
 (0)
0