Skip to content

Commit 3094dd5

Browse files
authored
bpo-1635741: Port _queue to multiphase initialization (GH-23376)
Signed-off-by: Christian Heimes <christian@python.org> Automerge-Triggered-By: GH:tiran
1 parent fa2eee9 commit 3094dd5

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Port _queue extension module to multiphase initialization (:pep:`489`)

Modules/_queuemodule.c

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,46 @@ PyDoc_STRVAR(queue_module_doc,
381381
"C implementation of the Python queue module.\n\
382382
This module is an implementation detail, please do not use it directly.");
383383

384+
static int
385+
queuemodule_exec(PyObject *module)
386+
{
387+
simplequeue_state *state = simplequeue_get_state(module);
388+
389+
state->EmptyError = PyErr_NewExceptionWithDoc(
390+
"_queue.Empty",
391+
"Exception raised by Queue.get(block=0)/get_nowait().",
392+
NULL, NULL);
393+
if (state->EmptyError == NULL) {
394+
return -1;
395+
}
396+
if (PyModule_AddObjectRef(module, "Empty", state->EmptyError) < 0) {
397+
return -1;
398+
}
399+
400+
state->SimpleQueueType = (PyTypeObject *)PyType_FromModuleAndSpec(
401+
module, &simplequeue_spec, NULL);
402+
if (state->SimpleQueueType == NULL) {
403+
return -1;
404+
}
405+
if (PyModule_AddType(module, state->SimpleQueueType) < 0) {
406+
return -1;
407+
}
408+
409+
return 0;
410+
}
411+
412+
static PyModuleDef_Slot queuemodule_slots[] = {
413+
{Py_mod_exec, queuemodule_exec},
414+
{0, NULL}
415+
};
416+
417+
384418
static struct PyModuleDef queuemodule = {
385419
.m_base = PyModuleDef_HEAD_INIT,
386420
.m_name = "_queue",
387421
.m_doc = queue_module_doc,
388422
.m_size = sizeof(simplequeue_state),
423+
.m_slots = queuemodule_slots,
389424
.m_traverse = queue_traverse,
390425
.m_clear = queue_clear,
391426
.m_free = queue_free,
@@ -395,41 +430,5 @@ static struct PyModuleDef queuemodule = {
395430
PyMODINIT_FUNC
396431
PyInit__queue(void)
397432
{
398-
PyObject *m;
399-
simplequeue_state *state;
400-
401-
/* Create the module */
402-
m = PyModule_Create(&queuemodule);
403-
if (m == NULL)
404-
return NULL;
405-
406-
state = simplequeue_get_state(m);
407-
state->EmptyError = PyErr_NewExceptionWithDoc(
408-
"_queue.Empty",
409-
"Exception raised by Queue.get(block=0)/get_nowait().",
410-
NULL, NULL);
411-
if (state->EmptyError == NULL)
412-
goto error;
413-
414-
Py_INCREF(state->EmptyError);
415-
if (PyModule_AddObject(m, "Empty", state->EmptyError) < 0) {
416-
Py_DECREF(state->EmptyError);
417-
goto error;
418-
}
419-
420-
state->SimpleQueueType = (PyTypeObject *)PyType_FromModuleAndSpec(m,
421-
&simplequeue_spec,
422-
NULL);
423-
if (state->SimpleQueueType == NULL) {
424-
goto error;
425-
}
426-
if (PyModule_AddType(m, state->SimpleQueueType) < 0) {
427-
goto error;
428-
}
429-
430-
return m;
431-
432-
error:
433-
Py_DECREF(m);
434-
return NULL;
433+
return PyModuleDef_Init(&queuemodule);
435434
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy