@@ -7,13 +7,16 @@ typedef struct {
7
7
PyObject * EmptyError ;
8
8
} simplequeue_state ;
9
9
10
- static simplequeue_state global_state ;
11
-
12
10
static simplequeue_state *
13
- simplequeue_get_state ()
11
+ simplequeue_get_state (PyObject * module )
14
12
{
15
- return & global_state ;
13
+ simplequeue_state * state = PyModule_GetState (module );
14
+ assert (state );
15
+ return state ;
16
16
}
17
+ static struct PyModuleDef queuemodule ;
18
+ #define simplequeue_get_state_by_type (tp ) \
19
+ (simplequeue_get_state(_PyType_GetModuleByDef(type, &queuemodule)))
17
20
18
21
typedef struct {
19
22
PyObject_HEAD
@@ -26,9 +29,9 @@ typedef struct {
26
29
27
30
/*[clinic input]
28
31
module _queue
29
- class _queue.SimpleQueue "simplequeueobject *" "simplequeue_get_state( )->SimpleQueueType"
32
+ class _queue.SimpleQueue "simplequeueobject *" "simplequeue_get_state_by_type(type )->SimpleQueueType"
30
33
[clinic start generated code]*/
31
- /*[clinic end generated code: output=da39a3ee5e6b4b0d input=ffce1ca094e64f3a ]*/
34
+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=0a4023fe4d198c8d ]*/
32
35
33
36
static void
34
37
simplequeue_dealloc (simplequeueobject * self )
@@ -166,6 +169,9 @@ simplequeue_pop_item(simplequeueobject *self)
166
169
167
170
/*[clinic input]
168
171
_queue.SimpleQueue.get
172
+
173
+ cls: defining_class
174
+ /
169
175
block: bool = True
170
176
timeout: object = None
171
177
@@ -182,9 +188,9 @@ in that case).
182
188
[clinic start generated code]*/
183
189
184
190
static PyObject *
185
- _queue_SimpleQueue_get_impl (simplequeueobject * self , int block ,
186
- PyObject * timeout )
187
- /*[clinic end generated code: output=ec82a7157dcccd1a input=4bf691f9f01fa297 ]*/
191
+ _queue_SimpleQueue_get_impl (simplequeueobject * self , PyTypeObject * cls ,
192
+ int block , PyObject * timeout )
193
+ /*[clinic end generated code: output=1969aefa7db63666 input=5fc4d56b9a54757e ]*/
188
194
{
189
195
_PyTime_t endtime = 0 ;
190
196
_PyTime_t timeout_val ;
@@ -236,8 +242,10 @@ _queue_SimpleQueue_get_impl(simplequeueobject *self, int block,
236
242
return NULL ;
237
243
}
238
244
if (r == PY_LOCK_FAILURE ) {
245
+ PyObject * module = PyType_GetModule (cls );
246
+ simplequeue_state * state = simplequeue_get_state (module );
239
247
/* Timed out */
240
- PyErr_SetNone (simplequeue_get_state () -> EmptyError );
248
+ PyErr_SetNone (state -> EmptyError );
241
249
return NULL ;
242
250
}
243
251
self -> locked = 1 ;
@@ -262,17 +270,21 @@ _queue_SimpleQueue_get_impl(simplequeueobject *self, int block,
262
270
/*[clinic input]
263
271
_queue.SimpleQueue.get_nowait
264
272
273
+ cls: defining_class
274
+ /
275
+
265
276
Remove and return an item from the queue without blocking.
266
277
267
278
Only get an item if one is immediately available. Otherwise
268
279
raise the Empty exception.
269
280
[clinic start generated code]*/
270
281
271
282
static PyObject *
272
- _queue_SimpleQueue_get_nowait_impl (simplequeueobject * self )
273
- /*[clinic end generated code: output=a89731a75dbe4937 input=6fe5102db540a1b9]*/
283
+ _queue_SimpleQueue_get_nowait_impl (simplequeueobject * self ,
284
+ PyTypeObject * cls )
285
+ /*[clinic end generated code: output=620c58e2750f8b8a input=842f732bf04216d3]*/
274
286
{
275
- return _queue_SimpleQueue_get_impl (self , 0 , Py_None );
287
+ return _queue_SimpleQueue_get_impl (self , cls , 0 , Py_None );
276
288
}
277
289
278
290
/*[clinic input]
@@ -347,29 +359,25 @@ PyDoc_STRVAR(queue_module_doc,
347
359
This module is an implementation detail, please do not use it directly." );
348
360
349
361
static struct PyModuleDef queuemodule = {
350
- PyModuleDef_HEAD_INIT ,
351
- "_queue" ,
352
- queue_module_doc ,
353
- -1 ,
354
- NULL ,
355
- NULL ,
356
- NULL ,
357
- NULL ,
358
- NULL
362
+ .m_base = PyModuleDef_HEAD_INIT ,
363
+ .m_name = "_queue" ,
364
+ .m_doc = queue_module_doc ,
365
+ .m_size = sizeof (simplequeue_state ),
359
366
};
360
367
361
368
362
369
PyMODINIT_FUNC
363
370
PyInit__queue (void )
364
371
{
365
372
PyObject * m ;
366
- simplequeue_state * state = simplequeue_get_state () ;
373
+ simplequeue_state * state ;
367
374
368
375
/* Create the module */
369
376
m = PyModule_Create (& queuemodule );
370
377
if (m == NULL )
371
378
return NULL ;
372
379
380
+ state = simplequeue_get_state (m );
373
381
state -> EmptyError = PyErr_NewExceptionWithDoc (
374
382
"_queue.Empty" ,
375
383
"Exception raised by Queue.get(block=0)/get_nowait()." ,
0 commit comments