[Python-checkins] bpo-1635741: Port mashal module to multi-phase init (#22149)

Victor Stinner webhook-mailer at python.org
Tue Sep 8 09:34:00 EDT 2020


https://github.com/python/cpython/commit/f315142ddc61e54a59028db562aec5f62db783e1
commit: f315142ddc61e54a59028db562aec5f62db783e1
branch: master
author: Victor Stinner <vstinner at python.org>
committer: GitHub <noreply at github.com>
date: 2020年09月08日T15:33:52+02:00
summary:
bpo-1635741: Port mashal module to multi-phase init (#22149)
Port the 'mashal' extension module to the multi-phase initialization
API (PEP 489).
files:
A Misc/NEWS.d/next/Library/2020-09-08-13-55-34.bpo-1635741.56MLP-.rst
M Python/marshal.c
diff --git a/Misc/NEWS.d/next/Library/2020-09-08-13-55-34.bpo-1635741.56MLP-.rst b/Misc/NEWS.d/next/Library/2020-09-08-13-55-34.bpo-1635741.56MLP-.rst
new file mode 100644
index 0000000000000..8b5bd5efdc2c0
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-09-08-13-55-34.bpo-1635741.56MLP-.rst
@@ -0,0 +1,2 @@
+Port the ``mashal`` extension module to the multi-phase initialization API
+(:pep:`489`).
diff --git a/Python/marshal.c b/Python/marshal.c
index c4538bd373a82..91a0f8acb1248 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -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);
 }


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /