summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2020-11-19 08:24:37 (GMT)
committerGitHub <noreply@github.com>2020-11-19 08:24:37 (GMT)
commit3094dd5fb5fa3ed91f5e2887887b193edbc976d2 (patch)
tree1e01bb851a4480db07fb440cd321ab34c362e1a6
parentfa2eee975dbf7d2728021ef9d97328bbe88351cf (diff)
downloadcpython-3094dd5fb5fa3ed91f5e2887887b193edbc976d2.zip
cpython-3094dd5fb5fa3ed91f5e2887887b193edbc976d2.tar.gz
cpython-3094dd5fb5fa3ed91f5e2887887b193edbc976d2.tar.bz2
bpo-1635741: Port _queue to multiphase initialization (GH-23376)
Signed-off-by: Christian Heimes <christian@python.org> Automerge-Triggered-By: GH:tiran
-rw-r--r--Misc/NEWS.d/next/C API/2020-11-18-20-11-13.bpo-1635741.fe3iRb.rst1
-rw-r--r--Modules/_queuemodule.c73
2 files changed, 37 insertions, 37 deletions
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 0000000..78df4fe
--- /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 7cf7399..a2b6ac8 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);
}