Skip to content

Commit

Permalink
bpo-1635741: Port mashal module to multi-phase init (#22149)
Browse files Browse the repository at this point in the history
Port the 'mashal' extension module to the multi-phase initialization
API (PEP 489).
  • Loading branch information
vstinner committed Sep 8, 2020
1 parent bb083d3 commit f315142
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Port the ``mashal`` extension module to the multi-phase initialization API
(:pep:`489`).
34 changes: 18 additions & 16 deletions Python/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1785,28 +1785,30 @@ dumps() -- marshal value as a bytes object\n\
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 = {
PyModuleDef_HEAD_INIT,
"marshal",
module_doc,
0,
marshal_methods,
NULL,
NULL,
NULL,
NULL
.m_name = "marshal",
.m_doc = module_doc,
.m_methods = marshal_methods,
.m_slots = marshalmodule_slots,
};

PyMODINIT_FUNC
PyMarshal_Init(void)
{
PyObject *mod = PyModule_Create(&marshalmodule);
if (mod == NULL)
return NULL;
if (PyModule_AddIntConstant(mod, "version", Py_MARSHAL_VERSION) < 0) {
Py_DECREF(mod);
return NULL;
}
return mod;
return PyModuleDef_Init(&marshalmodule);
}

0 comments on commit f315142

Please sign in to comment.