bpo-1635741: Port mashal module to multi-phase init (#22149)
Port the 'mashal' extension module to the multi-phase initialization API (PEP 489).
This commit is contained in:
parent
bb083d33f7
commit
f315142ddc
|
@ -0,0 +1,2 @@
|
||||||
|
Port the ``mashal`` extension module to the multi-phase initialization API
|
||||||
|
(:pep:`489`).
|
|
@ -1785,28 +1785,30 @@ dumps() -- marshal value as a bytes object\n\
|
||||||
loads() -- read value from a bytes-like object");
|
loads() -- read value from a bytes-like object");
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
marshal_module_exec(PyObject *mod)
|
||||||
|
{
|
||||||
|
if (PyModule_AddIntConstant(mod, "version", Py_MARSHAL_VERSION) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyModuleDef_Slot marshalmodule_slots[] = {
|
||||||
|
{Py_mod_exec, marshal_module_exec},
|
||||||
|
{0, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
static struct PyModuleDef marshalmodule = {
|
static struct PyModuleDef marshalmodule = {
|
||||||
PyModuleDef_HEAD_INIT,
|
PyModuleDef_HEAD_INIT,
|
||||||
"marshal",
|
.m_name = "marshal",
|
||||||
module_doc,
|
.m_doc = module_doc,
|
||||||
0,
|
.m_methods = marshal_methods,
|
||||||
marshal_methods,
|
.m_slots = marshalmodule_slots,
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PyMODINIT_FUNC
|
PyMODINIT_FUNC
|
||||||
PyMarshal_Init(void)
|
PyMarshal_Init(void)
|
||||||
{
|
{
|
||||||
PyObject *mod = PyModule_Create(&marshalmodule);
|
return PyModuleDef_Init(&marshalmodule);
|
||||||
if (mod == NULL)
|
|
||||||
return NULL;
|
|
||||||
if (PyModule_AddIntConstant(mod, "version", Py_MARSHAL_VERSION) < 0) {
|
|
||||||
Py_DECREF(mod);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return mod;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue