1
1
#include "Python.h"
2
+ #include "structmember.h" // PyMemberDef
2
3
#include <stddef.h> // offsetof()
3
4
4
5
/*[clinic input]
5
6
module _queue
6
- class _queue.SimpleQueue "simplequeueobject *" "& PySimpleQueueType"
7
+ class _queue.SimpleQueue "simplequeueobject *" "PySimpleQueueType"
7
8
[clinic start generated code]*/
8
- /*[clinic end generated code: output=da39a3ee5e6b4b0d input=cf49af81bcbbbea6 ]*/
9
+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=ec6b5cf35d0220ff ]*/
9
10
10
- static PyTypeObject PySimpleQueueType ; /* forward decl */
11
+ static PyTypeObject * PySimpleQueueType = NULL ;
11
12
12
13
static PyObject * EmptyError ;
13
14
@@ -25,6 +26,8 @@ typedef struct {
25
26
static void
26
27
simplequeue_dealloc (simplequeueobject * self )
27
28
{
29
+ PyTypeObject * tp = Py_TYPE (self );
30
+
28
31
PyObject_GC_UnTrack (self );
29
32
if (self -> lock != NULL ) {
30
33
/* Unlock the lock so it's safe to free it */
@@ -36,6 +39,7 @@ simplequeue_dealloc(simplequeueobject *self)
36
39
if (self -> weakreflist != NULL )
37
40
PyObject_ClearWeakRefs ((PyObject * ) self );
38
41
Py_TYPE (self )-> tp_free (self );
42
+ Py_DECREF (tp );
39
43
}
40
44
41
45
static int
@@ -306,48 +310,26 @@ static PyMethodDef simplequeue_methods[] = {
306
310
{NULL , NULL } /* sentinel */
307
311
};
308
312
313
+ static struct PyMemberDef simplequeue_members [] = {
314
+ {"__weaklistoffset__" , T_PYSSIZET , offsetof(simplequeueobject , weakreflist ), READONLY },
315
+ {NULL },
316
+ };
309
317
310
- static PyTypeObject PySimpleQueueType = {
311
- PyVarObject_HEAD_INIT (NULL , 0 )
312
- "_queue.SimpleQueue" , /*tp_name*/
313
- sizeof (simplequeueobject ), /*tp_basicsize*/
314
- 0 , /*tp_itemsize*/
315
- /* methods */
316
- (destructor )simplequeue_dealloc , /*tp_dealloc*/
317
- 0 , /*tp_vectorcall_offset*/
318
- 0 , /*tp_getattr*/
319
- 0 , /*tp_setattr*/
320
- 0 , /*tp_as_async*/
321
- 0 , /*tp_repr*/
322
- 0 , /*tp_as_number*/
323
- 0 , /*tp_as_sequence*/
324
- 0 , /*tp_as_mapping*/
325
- 0 , /*tp_hash*/
326
- 0 , /*tp_call*/
327
- 0 , /*tp_str*/
328
- 0 , /*tp_getattro*/
329
- 0 , /*tp_setattro*/
330
- 0 , /*tp_as_buffer*/
331
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE
332
- | Py_TPFLAGS_HAVE_GC , /* tp_flags */
333
- simplequeue_new__doc__ , /*tp_doc*/
334
- (traverseproc )simplequeue_traverse , /*tp_traverse*/
335
- 0 , /*tp_clear*/
336
- 0 , /*tp_richcompare*/
337
- offsetof(simplequeueobject , weakreflist ), /*tp_weaklistoffset*/
338
- 0 , /*tp_iter*/
339
- 0 , /*tp_iternext*/
340
- simplequeue_methods , /*tp_methods*/
341
- 0 , /* tp_members */
342
- 0 , /* tp_getset */
343
- 0 , /* tp_base */
344
- 0 , /* tp_dict */
345
- 0 , /* tp_descr_get */
346
- 0 , /* tp_descr_set */
347
- 0 , /* tp_dictoffset */
348
- 0 , /* tp_init */
349
- 0 , /* tp_alloc */
350
- simplequeue_new /* tp_new */
318
+ static PyType_Slot simplequeue_slots [] = {
319
+ {Py_tp_dealloc , simplequeue_dealloc },
320
+ {Py_tp_doc , (void * )simplequeue_new__doc__ },
321
+ {Py_tp_traverse , simplequeue_traverse },
322
+ {Py_tp_members , simplequeue_members },
323
+ {Py_tp_methods , simplequeue_methods },
324
+ {Py_tp_new , simplequeue_new },
325
+ {0 , NULL },
326
+ };
327
+
328
+ static PyType_Spec simplequeue_spec = {
329
+ .name = "_queue.SimpleQueue" ,
330
+ .basicsize = sizeof (simplequeueobject ),
331
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC ,
332
+ .slots = simplequeue_slots ,
351
333
};
352
334
353
335
@@ -385,15 +367,27 @@ PyInit__queue(void)
385
367
"Exception raised by Queue.get(block=0)/get_nowait()." ,
386
368
NULL , NULL );
387
369
if (EmptyError == NULL )
388
- return NULL ;
370
+ goto error ;
389
371
390
372
Py_INCREF (EmptyError );
391
- if (PyModule_AddObject (m , "Empty" , EmptyError ) < 0 )
392
- return NULL ;
373
+ if (PyModule_AddObject (m , "Empty" , EmptyError ) < 0 ) {
374
+ Py_DECREF (EmptyError );
375
+ goto error ;
376
+ }
393
377
394
- if (PyModule_AddType (m , & PySimpleQueueType ) < 0 ) {
395
- return NULL ;
378
+ PySimpleQueueType = (PyTypeObject * )PyType_FromModuleAndSpec (m ,
379
+ & simplequeue_spec ,
380
+ NULL );
381
+ if (PySimpleQueueType == NULL ) {
382
+ goto error ;
383
+ }
384
+ if (PyModule_AddType (m , PySimpleQueueType ) < 0 ) {
385
+ goto error ;
396
386
}
397
387
398
388
return m ;
389
+
390
+ error :
391
+ Py_DECREF (m );
392
+ return NULL ;
399
393
}
0 commit comments