@@ -400,10 +400,11 @@ typedef struct _queue {
400
400
_queueitem * first ;
401
401
_queueitem * last ;
402
402
} items ;
403
+ int fmt ;
403
404
} _queue ;
404
405
405
406
static int
406
- _queue_init (_queue * queue , Py_ssize_t maxsize )
407
+ _queue_init (_queue * queue , Py_ssize_t maxsize , int fmt )
407
408
{
408
409
PyThread_type_lock mutex = PyThread_allocate_lock ();
409
410
if (mutex == NULL ) {
@@ -415,6 +416,7 @@ _queue_init(_queue *queue, Py_ssize_t maxsize)
415
416
.items = {
416
417
.maxsize = maxsize ,
417
418
},
419
+ .fmt = fmt ,
418
420
};
419
421
return 0 ;
420
422
}
@@ -851,18 +853,26 @@ _queues_decref(_queues *queues, int64_t qid)
851
853
PyThread_release_lock (queues -> mutex );
852
854
}
853
855
854
- static int64_t *
856
+ struct queue_id_and_fmt {
857
+ int64_t id ;
858
+ int fmt ;
859
+ };
860
+
861
+ static struct queue_id_and_fmt *
855
862
_queues_list_all (_queues * queues , int64_t * count )
856
863
{
857
- int64_t * qids = NULL ;
864
+ struct queue_id_and_fmt * qids = NULL ;
858
865
PyThread_acquire_lock (queues -> mutex , WAIT_LOCK );
859
- int64_t * ids = PyMem_NEW (int64_t , (Py_ssize_t )(queues -> count ));
866
+ struct queue_id_and_fmt * ids = PyMem_NEW (struct queue_id_and_fmt ,
867
+ (Py_ssize_t )(queues -> count ));
860
868
if (ids == NULL ) {
861
869
goto done ;
862
870
}
863
871
_queueref * ref = queues -> head ;
864
872
for (int64_t i = 0 ; ref != NULL ; ref = ref -> next , i ++ ) {
865
- ids [i ] = ref -> qid ;
873
+ ids [i ].id = ref -> qid ;
874
+ assert (ref -> queue != NULL );
875
+ ids [i ].fmt = ref -> queue -> fmt ;
866
876
}
867
877
* count = queues -> count ;
868
878
@@ -898,13 +908,13 @@ _queue_free(_queue *queue)
898
908
899
909
// Create a new queue.
900
910
static int64_t
901
- queue_create (_queues * queues , Py_ssize_t maxsize )
911
+ queue_create (_queues * queues , Py_ssize_t maxsize , int fmt )
902
912
{
903
913
_queue * queue = GLOBAL_MALLOC (_queue );
904
914
if (queue == NULL ) {
905
915
return ERR_QUEUE_ALLOC ;
906
916
}
907
- int err = _queue_init (queue , maxsize );
917
+ int err = _queue_init (queue , maxsize , fmt );
908
918
if (err < 0 ) {
909
919
GLOBAL_FREE (queue );
910
920
return (int64_t )err ;
@@ -1275,14 +1285,15 @@ qidarg_converter(PyObject *arg, void *ptr)
1275
1285
static PyObject *
1276
1286
queuesmod_create (PyObject * self , PyObject * args , PyObject * kwds )
1277
1287
{
1278
- static char * kwlist [] = {"maxsize" , NULL };
1279
- Py_ssize_t maxsize = -1 ;
1280
- if (!PyArg_ParseTupleAndKeywords (args , kwds , "|n:create" , kwlist ,
1281
- & maxsize )) {
1288
+ static char * kwlist [] = {"maxsize" , "fmt" , NULL };
1289
+ Py_ssize_t maxsize ;
1290
+ int fmt ;
1291
+ if (!PyArg_ParseTupleAndKeywords (args , kwds , "ni:create" , kwlist ,
1292
+ & maxsize , & fmt )) {
1282
1293
return NULL ;
1283
1294
}
1284
1295
1285
- int64_t qid = queue_create (& _globals .queues , maxsize );
1296
+ int64_t qid = queue_create (& _globals .queues , maxsize , fmt );
1286
1297
if (qid < 0 ) {
1287
1298
(void )handle_queue_error ((int )qid , self , qid );
1288
1299
return NULL ;
@@ -1337,7 +1348,7 @@ static PyObject *
1337
1348
queuesmod_list_all (PyObject * self , PyObject * Py_UNUSED (ignored ))
1338
1349
{
1339
1350
int64_t count = 0 ;
1340
- int64_t * qids = _queues_list_all (& _globals .queues , & count );
1351
+ struct queue_id_and_fmt * qids = _queues_list_all (& _globals .queues , & count );
1341
1352
if (qids == NULL ) {
1342
1353
if (count == 0 ) {
1343
1354
return PyList_New (0 );
@@ -1348,14 +1359,14 @@ queuesmod_list_all(PyObject *self, PyObject *Py_UNUSED(ignored))
1348
1359
if (ids == NULL ) {
1349
1360
goto finally ;
1350
1361
}
1351
- int64_t * cur = qids ;
1362
+ struct queue_id_and_fmt * cur = qids ;
1352
1363
for (int64_t i = 0 ; i < count ; cur ++ , i ++ ) {
1353
- PyObject * qidobj = PyLong_FromLongLong ( * cur );
1354
- if (qidobj == NULL ) {
1364
+ PyObject * item = Py_BuildValue ( "Li" , cur -> id , cur -> fmt );
1365
+ if (item == NULL ) {
1355
1366
Py_SETREF (ids , NULL );
1356
1367
break ;
1357
1368
}
1358
- PyList_SET_ITEM (ids , (Py_ssize_t )i , qidobj );
1369
+ PyList_SET_ITEM (ids , (Py_ssize_t )i , item );
1359
1370
}
1360
1371
1361
1372
finally :
@@ -1512,6 +1523,33 @@ PyDoc_STRVAR(queuesmod_get_maxsize_doc,
1512
1523
\n\
1513
1524
Return the maximum number of items in the queue." );
1514
1525
1526
+ static PyObject *
1527
+ queuesmod_get_default_fmt (PyObject * self , PyObject * args , PyObject * kwds )
1528
+ {
1529
+ static char * kwlist [] = {"qid" , NULL };
1530
+ qidarg_converter_data qidarg ;
1531
+ if (!PyArg_ParseTupleAndKeywords (args , kwds ,
1532
+ "O&:get_default_fmt" , kwlist ,
1533
+ qidarg_converter , & qidarg )) {
1534
+ return NULL ;
1535
+ }
1536
+ int64_t qid = qidarg .id ;
1537
+
1538
+ _queue * queue = NULL ;
1539
+ int err = _queues_lookup (& _globals .queues , qid , & queue );
1540
+ if (handle_queue_error (err , self , qid )) {
1541
+ return NULL ;
1542
+ }
1543
+ int fmt = queue -> fmt ;
1544
+ _queue_unmark_waiter (queue , _globals .queues .mutex );
1545
+ return PyLong_FromLong (fmt );
1546
+ }
1547
+
1548
+ PyDoc_STRVAR (queuesmod_get_default_fmt_doc ,
1549
+ "get_default_fmt(qid)\n\
1550
+ \n\
1551
+ Return the default format to use for the queue." );
1552
+
1515
1553
static PyObject *
1516
1554
queuesmod_is_full (PyObject * self , PyObject * args , PyObject * kwds )
1517
1555
{
@@ -1606,6 +1644,8 @@ static PyMethodDef module_functions[] = {
1606
1644
METH_VARARGS | METH_KEYWORDS , queuesmod_release_doc },
1607
1645
{"get_maxsize" , _PyCFunction_CAST (queuesmod_get_maxsize ),
1608
1646
METH_VARARGS | METH_KEYWORDS , queuesmod_get_maxsize_doc },
1647
+ {"get_default_fmt" , _PyCFunction_CAST (queuesmod_get_default_fmt ),
1648
+ METH_VARARGS | METH_KEYWORDS , queuesmod_get_default_fmt_doc },
1609
1649
{"is_full" , _PyCFunction_CAST (queuesmod_is_full ),
1610
1650
METH_VARARGS | METH_KEYWORDS , queuesmod_is_full_doc },
1611
1651
{"get_count" , _PyCFunction_CAST (queuesmod_get_count ),
0 commit comments