[Python-checkins] bpo-1635741: Port _queue to multiphase initialization (GH-23376)
miss-islington
webhook-mailer at python.org
Thu Nov 19 03:24:46 EST 2020
https://github.com/python/cpython/commit/3094dd5fb5fa3ed91f5e2887887b193edbc976d2
commit: 3094dd5fb5fa3ed91f5e2887887b193edbc976d2
branch: master
author: Christian Heimes <christian at python.org>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2020-11-19T00:24:37-08:00
summary:
bpo-1635741: Port _queue to multiphase initialization (GH-23376)
Signed-off-by: Christian Heimes <christian at python.org>
Automerge-Triggered-By: GH:tiran
files:
A Misc/NEWS.d/next/C API/2020-11-18-20-11-13.bpo-1635741.fe3iRb.rst
M Modules/_queuemodule.c
diff --git a/Misc/NEWS.d/next/C API/2020-11-18-20-11-13.bpo-1635741.fe3iRb.rst b/Misc/NEWS.d/next/C API/2020-11-18-20-11-13.bpo-1635741.fe3iRb.rst
new file mode 100644
index 0000000000000..78df4fe043226
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2020-11-18-20-11-13.bpo-1635741.fe3iRb.rst
@@ -0,0 +1 @@
+Port _queue extension module to multiphase initialization (:pep:`489`)
diff --git a/Modules/_queuemodule.c b/Modules/_queuemodule.c
index 7cf73992795c6..a2b6ac87a72eb 100644
--- a/Modules/_queuemodule.c
+++ b/Modules/_queuemodule.c
@@ -381,11 +381,46 @@ PyDoc_STRVAR(queue_module_doc,
"C implementation of the Python queue module.\n\
This module is an implementation detail, please do not use it directly.");
+static int
+queuemodule_exec(PyObject *module)
+{
+ simplequeue_state *state = simplequeue_get_state(module);
+
+ state->EmptyError = PyErr_NewExceptionWithDoc(
+ "_queue.Empty",
+ "Exception raised by Queue.get(block=0)/get_nowait().",
+ NULL, NULL);
+ if (state->EmptyError == NULL) {
+ return -1;
+ }
+ if (PyModule_AddObjectRef(module, "Empty", state->EmptyError) < 0) {
+ return -1;
+ }
+
+ state->SimpleQueueType = (PyTypeObject *)PyType_FromModuleAndSpec(
+ module, &simplequeue_spec, NULL);
+ if (state->SimpleQueueType == NULL) {
+ return -1;
+ }
+ if (PyModule_AddType(module, state->SimpleQueueType) < 0) {
+ return -1;
+ }
+
+ return 0;
+}
+
+static PyModuleDef_Slot queuemodule_slots[] = {
+ {Py_mod_exec, queuemodule_exec},
+ {0, NULL}
+};
+
+
static struct PyModuleDef queuemodule = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "_queue",
.m_doc = queue_module_doc,
.m_size = sizeof(simplequeue_state),
+ .m_slots = queuemodule_slots,
.m_traverse = queue_traverse,
.m_clear = queue_clear,
.m_free = queue_free,
@@ -395,41 +430,5 @@ static struct PyModuleDef queuemodule = {
PyMODINIT_FUNC
PyInit__queue(void)
{
- PyObject *m;
- simplequeue_state *state;
-
- /* Create the module */
- m = PyModule_Create(&queuemodule);
- if (m == NULL)
- return NULL;
-
- state = simplequeue_get_state(m);
- state->EmptyError = PyErr_NewExceptionWithDoc(
- "_queue.Empty",
- "Exception raised by Queue.get(block=0)/get_nowait().",
- NULL, NULL);
- if (state->EmptyError == NULL)
- goto error;
-
- Py_INCREF(state->EmptyError);
- if (PyModule_AddObject(m, "Empty", state->EmptyError) < 0) {
- Py_DECREF(state->EmptyError);
- goto error;
- }
-
- state->SimpleQueueType = (PyTypeObject *)PyType_FromModuleAndSpec(m,
- &simplequeue_spec,
- NULL);
- if (state->SimpleQueueType == NULL) {
- goto error;
- }
- if (PyModule_AddType(m, state->SimpleQueueType) < 0) {
- goto error;
- }
-
- return m;
-
-error:
- Py_DECREF(m);
- return NULL;
+ return PyModuleDef_Init(&queuemodule);
}
More information about the Python-checkins
mailing list