2
2
#include "structmember.h" // PyMemberDef
3
3
#include <stddef.h> // offsetof()
4
4
5
- /*[clinic input]
6
- module _queue
7
- class _queue.SimpleQueue "simplequeueobject *" "PySimpleQueueType"
8
- [clinic start generated code]*/
9
- /*[clinic end generated code: output=da39a3ee5e6b4b0d input=ec6b5cf35d0220ff]*/
10
-
11
- static PyTypeObject * PySimpleQueueType = NULL ;
5
+ typedef struct {
6
+ PyTypeObject * SimpleQueueType ;
7
+ PyObject * EmptyError ;
8
+ } simplequeue_state ;
12
9
13
- static PyObject * EmptyError ;
10
+ static simplequeue_state global_state ;
14
11
12
+ static simplequeue_state *
13
+ simplequeue_get_state ()
14
+ {
15
+ return & global_state ;
16
+ }
15
17
16
18
typedef struct {
17
19
PyObject_HEAD
@@ -22,6 +24,11 @@ typedef struct {
22
24
PyObject * weakreflist ;
23
25
} simplequeueobject ;
24
26
27
+ /*[clinic input]
28
+ module _queue
29
+ class _queue.SimpleQueue "simplequeueobject *" "simplequeue_get_state()->SimpleQueueType"
30
+ [clinic start generated code]*/
31
+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=ffce1ca094e64f3a]*/
25
32
26
33
static void
27
34
simplequeue_dealloc (simplequeueobject * self )
@@ -230,7 +237,7 @@ _queue_SimpleQueue_get_impl(simplequeueobject *self, int block,
230
237
}
231
238
if (r == PY_LOCK_FAILURE ) {
232
239
/* Timed out */
233
- PyErr_SetNone (EmptyError );
240
+ PyErr_SetNone (simplequeue_get_state () -> EmptyError );
234
241
return NULL ;
235
242
}
236
243
self -> locked = 1 ;
@@ -356,32 +363,33 @@ PyMODINIT_FUNC
356
363
PyInit__queue (void )
357
364
{
358
365
PyObject * m ;
366
+ simplequeue_state * state = simplequeue_get_state ();
359
367
360
368
/* Create the module */
361
369
m = PyModule_Create (& queuemodule );
362
370
if (m == NULL )
363
371
return NULL ;
364
372
365
- EmptyError = PyErr_NewExceptionWithDoc (
373
+ state -> EmptyError = PyErr_NewExceptionWithDoc (
366
374
"_queue.Empty" ,
367
375
"Exception raised by Queue.get(block=0)/get_nowait()." ,
368
376
NULL , NULL );
369
- if (EmptyError == NULL )
377
+ if (state -> EmptyError == NULL )
370
378
goto error ;
371
379
372
- Py_INCREF (EmptyError );
373
- if (PyModule_AddObject (m , "Empty" , EmptyError ) < 0 ) {
374
- Py_DECREF (EmptyError );
380
+ Py_INCREF (state -> EmptyError );
381
+ if (PyModule_AddObject (m , "Empty" , state -> EmptyError ) < 0 ) {
382
+ Py_DECREF (state -> EmptyError );
375
383
goto error ;
376
384
}
377
385
378
- PySimpleQueueType = (PyTypeObject * )PyType_FromModuleAndSpec (m ,
386
+ state -> SimpleQueueType = (PyTypeObject * )PyType_FromModuleAndSpec (m ,
379
387
& simplequeue_spec ,
380
388
NULL );
381
- if (PySimpleQueueType == NULL ) {
389
+ if (state -> SimpleQueueType == NULL ) {
382
390
goto error ;
383
391
}
384
- if (PyModule_AddType (m , PySimpleQueueType ) < 0 ) {
392
+ if (PyModule_AddType (m , state -> SimpleQueueType ) < 0 ) {
385
393
goto error ;
386
394
}
387
395
0 commit comments