diff --git a/bin/clone-dependencies.sh b/bin/clone-dependencies.sh index b961855..3bb977b 100755 --- a/bin/clone-dependencies.sh +++ b/bin/clone-dependencies.sh @@ -15,7 +15,7 @@ set -u BDE_TOOLS_TAG=4.32.0.0 BDE_TAG=4.32.0.0 NTF_CORE_TAG=2.6.6 -BLAZINGMQ_TAG=BMQBRKR_0.94.8 +BLAZINGMQ_TAG=fix/bmqp-mocksession-dependency if [ ! -d "${DIR_THIRDPARTY}/bde-tools" ]; then diff --git a/src/cpp/pybmq_mocksession.cpp b/src/cpp/pybmq_mocksession.cpp index 6e1050a..84fa94c 100644 --- a/src/cpp/pybmq_mocksession.cpp +++ b/src/cpp/pybmq_mocksession.cpp @@ -26,6 +26,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -38,6 +41,38 @@ namespace pybmq { namespace { +typedef bdlcc::SharedObjectPool< + bdlbb::Blob, + bdlcc::ObjectPoolFunctors::DefaultCreator, + bdlcc::ObjectPoolFunctors::RemoveAll > + BlobSpPool; + +typedef bsl::shared_ptr BlobSpPoolSp; + +const int k_BLOB_POOL_GROWTH_STRATEGY = 1024; + +void +createBlob( + bdlbb::BlobBufferFactory* bufferFactory, + void* arena, + bslma::Allocator* allocator) +{ + new (arena) bdlbb::Blob(bufferFactory, allocator); +} + +BlobSpPoolSp +makeBlobSpPool(bdlbb::BlobBufferFactory* factory, bslma::Allocator* allocator) +{ + return bsl::allocate_shared( + allocator, + bdlf::BindUtil::bind( + &createBlob, + factory, + bdlf::PlaceHolders::_1, + bdlf::PlaceHolders::_2), + k_BLOB_POOL_GROWTH_STRATEGY); +} + #ifdef BSLS_PLATFORM_CMP_GNU void assertNotCalled() __attribute__((noreturn)); @@ -185,10 +220,13 @@ maybe_emit_messages(PyObject* mock, bmqa::MockSession* mock_session) throw bsl::runtime_error("propagating Python error"); bslma::Allocator* allocator_p = bslma::Default::defaultAllocator(); - mock_session->enqueueEvent(bmqa::MockSessionUtil::createPushEvent( - push_msg_params, - &factory, - allocator_p)); + BlobSpPoolSp blobSpPool = makeBlobSpPool(&factory, allocator_p); + mock_session->enqueueEvent( + bmqa::MockSessionUtil::createPushEvent( + push_msg_params, + blobSpPool.get(), + &factory, + allocator_p)); if (!mock_session->emitEvent()) { PyErr_SetString(PyExc_RuntimeError, "Failed to emit event"); throw bsl::runtime_error("propagating Python error"); @@ -253,8 +291,12 @@ maybe_emit_acks(PyObject* mock, bmqa::MockSession* mock_session) bdlbb::SimpleBlobBufferFactory factory(1024); bslma::Allocator* allocator_p = bslma::Default::defaultAllocator(); + BlobSpPoolSp blobSpPool = makeBlobSpPool(&factory, allocator_p); mock_session->enqueueEvent( - bmqa::MockSessionUtil::createAckEvent(ack_params, &factory, allocator_p)); + bmqa::MockSessionUtil::createAckEvent( + ack_params, + blobSpPool.get(), + allocator_p)); if (!mock_session->emitEvent()) { PyErr_SetString(PyExc_RuntimeError, "Failed to emit event"); throw bsl::runtime_error("propagating Python error");