@@ -69,7 +69,8 @@ basic_properties_to_PyDict(amqp_basic_properties_t*, PyObject*);
69
69
_PYRMQ_INLINE int
70
70
PyDict_to_basic_properties (PyObject * ,
71
71
amqp_basic_properties_t * ,
72
- amqp_connection_state_t );
72
+ amqp_connection_state_t ,
73
+ amqp_pool_t * );
73
74
74
75
_PYRMQ_INLINE void
75
76
amqp_basic_deliver_to_PyDict (PyObject * , uint64_t , amqp_bytes_t ,
@@ -97,8 +98,8 @@ int PyRabbitMQ_HandleAMQError(PyRabbitMQ_Connection *, unsigned int,
97
98
void PyRabbitMQ_SetErr_UnexpectedHeader (amqp_frame_t * );
98
99
int PyRabbitMQ_Not_Connected (PyRabbitMQ_Connection * );
99
100
100
- static amqp_table_t PyDict_ToAMQTable (amqp_connection_state_t , PyObject * );
101
- static amqp_array_t PyList_ToAMQArray (amqp_connection_state_t , PyObject * );
101
+ static amqp_table_t PyDict_ToAMQTable (amqp_connection_state_t , PyObject * , amqp_pool_t * );
102
+ static amqp_array_t PyList_ToAMQArray (amqp_connection_state_t , PyObject * , amqp_pool_t * );
102
103
103
104
static PyObject * AMQTable_toPyDict (amqp_table_t * table );
104
105
static PyObject * AMQArray_toPyList (amqp_array_t * array );
@@ -211,7 +212,7 @@ AMQArray_SetIntValue(amqp_array_t *array, int value)
211
212
}
212
213
213
214
static amqp_table_t
214
- PyDict_ToAMQTable (amqp_connection_state_t conn , PyObject * src )
215
+ PyDict_ToAMQTable (amqp_connection_state_t conn , PyObject * src , amqp_pool_t * pool )
215
216
{
216
217
PyObject * dkey = NULL ;
217
218
PyObject * dvalue = NULL ;
@@ -226,21 +227,20 @@ PyDict_ToAMQTable(amqp_connection_state_t conn, PyObject *src)
226
227
227
228
/* allocate new table */
228
229
dst .num_entries = 0 ;
229
- dst .entries = amqp_pool_alloc (& conn -> frame_pool ,
230
- size * sizeof (amqp_table_entry_t ));
230
+ dst .entries = amqp_pool_alloc (pool , size * sizeof (amqp_table_entry_t ));
231
231
while (PyDict_Next (src , & pos , & dkey , & dvalue )) {
232
232
233
233
if (PyDict_Check (dvalue )) {
234
234
/* Dict */
235
235
AMQTable_SetTableValue (& dst ,
236
236
PyString_AS_AMQBYTES (dkey ),
237
- PyDict_ToAMQTable (conn , dvalue ));
237
+ PyDict_ToAMQTable (conn , dvalue , pool ));
238
238
}
239
239
else if (PyList_Check (dvalue )) {
240
240
/* List */
241
241
AMQTable_SetArrayValue (& dst ,
242
242
PyString_AS_AMQBYTES (dkey ),
243
- PyList_ToAMQArray (conn , dvalue ));
243
+ PyList_ToAMQArray (conn , dvalue , pool ));
244
244
}
245
245
else if (PyLong_Check (dvalue ) || PyInt_Check (dvalue )) {
246
246
/* Int | Long */
@@ -293,7 +293,7 @@ PyDict_ToAMQTable(amqp_connection_state_t conn, PyObject *src)
293
293
}
294
294
295
295
static amqp_array_t
296
- PyList_ToAMQArray (amqp_connection_state_t conn , PyObject * src )
296
+ PyList_ToAMQArray (amqp_connection_state_t conn , PyObject * src , amqp_pool_t * pool )
297
297
{
298
298
PyObject * dvalue = NULL ;
299
299
PY_SIZE_TYPE size = 0 ;
@@ -306,21 +306,20 @@ PyList_ToAMQArray(amqp_connection_state_t conn, PyObject *src)
306
306
307
307
/* allocate new array */
308
308
dst .num_entries = 0 ;
309
- dst .entries = amqp_pool_alloc (& conn -> frame_pool ,
310
- size * sizeof (amqp_field_value_t ));
309
+ dst .entries = amqp_pool_alloc (pool , size * sizeof (amqp_field_value_t ));
311
310
for (pos = 0 ; pos < size ; ++ pos ) {
312
311
313
312
dvalue = PyList_GetItem (src , pos );
314
313
315
314
if (PyDict_Check (dvalue )) {
316
315
/* Dict */
317
316
AMQArray_SetTableValue (& dst ,
318
- PyDict_ToAMQTable (conn , dvalue ));
317
+ PyDict_ToAMQTable (conn , dvalue , pool ));
319
318
}
320
319
else if (PyList_Check (dvalue )) {
321
320
/* List */
322
321
AMQArray_SetArrayValue (& dst ,
323
- PyList_ToAMQArray (conn , dvalue ));
322
+ PyList_ToAMQArray (conn , dvalue , pool ));
324
323
}
325
324
else if (PyLong_Check (dvalue ) || PyInt_Check (dvalue )) {
326
325
/* Int | Long */
@@ -618,7 +617,8 @@ AMQArray_toPyList(amqp_array_t *array)
618
617
_PYRMQ_INLINE int
619
618
PyDict_to_basic_properties (PyObject * p ,
620
619
amqp_basic_properties_t * props ,
621
- amqp_connection_state_t conn )
620
+ amqp_connection_state_t conn ,
621
+ amqp_pool_t * pool )
622
622
{
623
623
PyObject * value = NULL ;
624
624
props -> headers = AMQP_EMPTY_TABLE ;
@@ -683,7 +683,7 @@ PyDict_to_basic_properties(PyObject *p,
683
683
}
684
684
685
685
if ((value = PyDict_GetItemString (p , "headers" )) != NULL ) {
686
- props -> headers = PyDict_ToAMQTable (conn , value );
686
+ props -> headers = PyDict_ToAMQTable (conn , value , pool );
687
687
if (PyErr_Occurred ())
688
688
return -1 ;
689
689
}
@@ -1000,7 +1000,6 @@ PyRabbitMQ_Connection_close(PyRabbitMQ_Connection *self)
1000
1000
Py_BEGIN_ALLOW_THREADS
1001
1001
reply = amqp_connection_close (self -> conn , AMQP_REPLY_SUCCESS );
1002
1002
amqp_destroy_connection (self -> conn );
1003
- close (self -> sockfd );
1004
1003
self -> sockfd = 0 ;
1005
1004
Py_END_ALLOW_THREADS
1006
1005
}
@@ -1300,6 +1299,7 @@ PyRabbitMQ_Connection_queue_bind(PyRabbitMQ_Connection *self,
1300
1299
PyObject * arguments = NULL ;
1301
1300
1302
1301
amqp_table_t bargs = AMQP_EMPTY_TABLE ;
1302
+ amqp_pool_t * channel_pool = NULL ;
1303
1303
amqp_rpc_reply_t reply ;
1304
1304
1305
1305
if (PyRabbitMQ_Not_Connected (self ))
@@ -1312,7 +1312,12 @@ PyRabbitMQ_Connection_queue_bind(PyRabbitMQ_Connection *self,
1312
1312
if ((exchange = Maybe_Unicode (exchange )) == NULL ) goto bail ;
1313
1313
if ((routing_key = Maybe_Unicode (routing_key )) == NULL ) goto bail ;
1314
1314
1315
- bargs = PyDict_ToAMQTable (self -> conn , arguments );
1315
+ channel_pool = amqp_get_or_create_channel_pool (self -> conn , (amqp_channel_t )channel );
1316
+ if (channel_pool == NULL ) {
1317
+ PyErr_NoMemory ();
1318
+ goto bail ;
1319
+ }
1320
+ bargs = PyDict_ToAMQTable (self -> conn , arguments , channel_pool );
1316
1321
if (PyErr_Occurred ())
1317
1322
goto bail ;
1318
1323
@@ -1349,6 +1354,7 @@ PyRabbitMQ_Connection_queue_unbind(PyRabbitMQ_Connection *self,
1349
1354
PyObject * arguments = NULL ;
1350
1355
1351
1356
amqp_table_t uargs = AMQP_EMPTY_TABLE ;
1357
+ amqp_pool_t * channel_pool = NULL ;
1352
1358
amqp_rpc_reply_t reply ;
1353
1359
1354
1360
if (PyRabbitMQ_Not_Connected (self ))
@@ -1360,7 +1366,13 @@ PyRabbitMQ_Connection_queue_unbind(PyRabbitMQ_Connection *self,
1360
1366
if ((queue = Maybe_Unicode (queue )) == NULL ) goto bail ;
1361
1367
if ((exchange = Maybe_Unicode (exchange )) == NULL ) goto bail ;
1362
1368
if ((routing_key = Maybe_Unicode (routing_key )) == NULL ) goto bail ;
1363
- uargs = PyDict_ToAMQTable (self -> conn , arguments );
1369
+
1370
+ channel_pool = amqp_get_or_create_channel_pool (self -> conn , (amqp_channel_t )channel );
1371
+ if (channel_pool == NULL ) {
1372
+ PyErr_NoMemory ();
1373
+ goto bail ;
1374
+ }
1375
+ uargs = PyDict_ToAMQTable (self -> conn , arguments , channel_pool );
1364
1376
if (PyErr_Occurred ())
1365
1377
goto bail ;
1366
1378
@@ -1442,6 +1454,7 @@ PyRabbitMQ_Connection_queue_declare(PyRabbitMQ_Connection *self,
1442
1454
1443
1455
amqp_queue_declare_ok_t * ok ;
1444
1456
amqp_rpc_reply_t reply ;
1457
+ amqp_pool_t * channel_pool = NULL ;
1445
1458
amqp_table_t qargs = AMQP_EMPTY_TABLE ;
1446
1459
PyObject * ret = NULL ;
1447
1460
@@ -1453,7 +1466,12 @@ PyRabbitMQ_Connection_queue_declare(PyRabbitMQ_Connection *self,
1453
1466
& exclusive , & auto_delete , & arguments ))
1454
1467
goto bail ;
1455
1468
if ((queue = Maybe_Unicode (queue )) == NULL ) goto bail ;
1456
- qargs = PyDict_ToAMQTable (self -> conn , arguments );
1469
+ channel_pool = amqp_get_or_create_channel_pool (self -> conn , (amqp_channel_t )channel );
1470
+ if (channel_pool == NULL ) {
1471
+ PyErr_NoMemory ();
1472
+ goto bail ;
1473
+ }
1474
+ qargs = PyDict_ToAMQTable (self -> conn , arguments , channel_pool );
1457
1475
if (PyErr_Occurred ())
1458
1476
goto bail ;
1459
1477
@@ -1538,6 +1556,7 @@ PyRabbitMQ_Connection_exchange_declare(PyRabbitMQ_Connection *self,
1538
1556
unsigned int auto_delete = 0 ;
1539
1557
1540
1558
amqp_table_t eargs = AMQP_EMPTY_TABLE ;
1559
+ amqp_pool_t * channel_pool = NULL ;
1541
1560
amqp_rpc_reply_t reply ;
1542
1561
1543
1562
if (PyRabbitMQ_Not_Connected (self ))
@@ -1549,7 +1568,12 @@ PyRabbitMQ_Connection_exchange_declare(PyRabbitMQ_Connection *self,
1549
1568
goto bail ;
1550
1569
if ((exchange = Maybe_Unicode (exchange )) == NULL ) goto bail ;
1551
1570
if ((type = Maybe_Unicode (type )) == NULL ) goto bail ;
1552
- eargs = PyDict_ToAMQTable (self -> conn , arguments );
1571
+ channel_pool = amqp_get_or_create_channel_pool (self -> conn , (amqp_channel_t )channel );
1572
+ if (channel_pool == NULL ) {
1573
+ PyErr_NoMemory ();
1574
+ goto bail ;
1575
+ }
1576
+ eargs = PyDict_ToAMQTable (self -> conn , arguments , channel_pool );
1553
1577
if (PyErr_Occurred ())
1554
1578
goto bail ;
1555
1579
@@ -1627,6 +1651,7 @@ PyRabbitMQ_Connection_basic_publish(PyRabbitMQ_Connection *self,
1627
1651
int ret = 0 ;
1628
1652
amqp_basic_properties_t props ;
1629
1653
amqp_bytes_t bytes ;
1654
+ amqp_pool_t * channel_pool = NULL ;
1630
1655
memset (& props , 0 , sizeof (props ));
1631
1656
1632
1657
if (PyRabbitMQ_Not_Connected (self ))
@@ -1640,7 +1665,8 @@ PyRabbitMQ_Connection_basic_publish(PyRabbitMQ_Connection *self,
1640
1665
if ((routing_key = Maybe_Unicode (routing_key )) == NULL ) goto bail ;
1641
1666
1642
1667
Py_INCREF (propdict );
1643
- if (!PyDict_to_basic_properties (propdict , & props , self -> conn ))
1668
+ channel_pool = amqp_get_or_create_channel_pool (self -> conn , (amqp_channel_t )channel );
1669
+ if (!PyDict_to_basic_properties (propdict , & props , self -> conn , channel_pool ))
1644
1670
goto bail ;
1645
1671
Py_DECREF (propdict );
1646
1672
@@ -1792,6 +1818,7 @@ PyRabbitMQ_Connection_basic_consume(PyRabbitMQ_Connection *self,
1792
1818
1793
1819
amqp_basic_consume_ok_t * ok ;
1794
1820
amqp_rpc_reply_t reply ;
1821
+ amqp_pool_t * channel_pool = NULL ;
1795
1822
amqp_table_t cargs = AMQP_EMPTY_TABLE ;
1796
1823
1797
1824
if (PyRabbitMQ_Not_Connected (self ))
@@ -1804,7 +1831,12 @@ PyRabbitMQ_Connection_basic_consume(PyRabbitMQ_Connection *self,
1804
1831
if ((queue = Maybe_Unicode (queue )) == NULL ) goto bail ;
1805
1832
if ((consumer_tag = Maybe_Unicode (consumer_tag )) == NULL ) goto bail ;
1806
1833
1807
- cargs = PyDict_ToAMQTable (self -> conn , arguments );
1834
+ channel_pool = amqp_get_or_create_channel_pool (self -> conn , (amqp_channel_t )channel );
1835
+ if (channel_pool == NULL ) {
1836
+ PyErr_NoMemory ();
1837
+ goto bail ;
1838
+ }
1839
+ cargs = PyDict_ToAMQTable (self -> conn , arguments , channel_pool );
1808
1840
if (PyErr_Occurred ()) goto bail ;
1809
1841
1810
1842
Py_BEGIN_ALLOW_THREADS ;
0 commit comments