Skip to content

Commit

Permalink
fixed mem leak and switched '_ptr' to '_p' to comply with bloomberg s…
Browse files Browse the repository at this point in the history
…tyling
  • Loading branch information
Jonathan Adotey committed Dec 6, 2023
1 parent 85adf3e commit b09e215
Show file tree
Hide file tree
Showing 19 changed files with 399 additions and 276 deletions.
12 changes: 8 additions & 4 deletions src/groups/z_bmq/z_bmqa/demo.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const int K_NUM_MESSAGES = 5;
};


void postEvent(const char* text,
void postEvent(const char* text,
z_bmqa_QueueId* queueId,
z_bmqa_Session* session){

Expand All @@ -46,6 +46,9 @@ void postEvent(const char* text,
z_bmqa_MessageEventBuilder__messageEvent(builder, &messageEvent);

z_bmqa_Session__post(session, messageEvent);

z_bmqa_MessageEventBuilder__delete(&builder);

}


Expand All @@ -68,6 +71,8 @@ void produce(z_bmqa_Session* session){
}

z_bmqa_Session__closeQueueSync(session, queueId);

z_bmqa_QueueId__delete(&queueId);
}

int run_c_producer(){
Expand All @@ -86,10 +91,9 @@ int run_c_producer(){
//stop the session
z_bmqa_Session__stop(session);

printf("Good2\n");

// z_bmqa_Session__delete(&session);
// z_bmqt_SessionOptions__delete(&options);
z_bmqa_Session__delete(&session);
z_bmqt_SessionOptions__delete(&options);

return 0;

Expand Down
9 changes: 5 additions & 4 deletions src/groups/z_bmq/z_bmqa/package/z_bmqa.mem
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
z_bmqa_queueid
z_bmqa_session
z_bmqa_event
z_bmqa_confirmeventbuilder
z_bmqa_event
z_bmqa_message
z_bmqa_messageevent
z_bmqa_messageeventbuilder
z_bmqa_messageproperties
z_bmqa_message
z_bmqa_queueid
z_bmqa_session
40 changes: 25 additions & 15 deletions src/groups/z_bmq/z_bmqa/z_bmqa_confirmeventbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@
#include <bmqa_confirmeventbuilder.h>


int z_bmqa_ConfirmEventBuilder__delete(z_bmqa_ConfirmEventBuilder const** builder_obj) {
using namespace BloombergLP;

const bmqa::ConfirmEventBuilder* builder_p = reinterpret_cast<const bmqa::ConfirmEventBuilder*>(*builder_obj);
delete builder_p;
*builder_obj = NULL;

return 0;
}

int z_bmqa_ConfirmEventBuilder__create(z_bmqa_ConfirmEventBuilder** builder_obj) {
using namespace BloombergLP;

bmqa::ConfirmEventBuilder* builder_ptr = new bmqa::ConfirmEventBuilder();
*builder_obj = reinterpret_cast<z_bmqa_ConfirmEventBuilder*>(builder_ptr);
bmqa::ConfirmEventBuilder* builder_p = new bmqa::ConfirmEventBuilder();
*builder_obj = reinterpret_cast<z_bmqa_ConfirmEventBuilder*>(builder_p);

return 0;
}
Expand All @@ -15,43 +25,43 @@ int z_bmqa_ConfirmEventBuilder__addMessageConfirmation(z_bmqa_ConfirmEventBuilde
const z_bmqa_Message* message) {
using namespace BloombergLP;

bmqa::ConfirmEventBuilder* builder_ptr = reinterpret_cast<bmqa::ConfirmEventBuilder*>(builder_obj);
const bmqa::Message* message_ptr = reinterpret_cast<const bmqa::Message*>(message);
return builder_ptr->addMessageConfirmation(*message_ptr);
bmqa::ConfirmEventBuilder* builder_p = reinterpret_cast<bmqa::ConfirmEventBuilder*>(builder_obj);
const bmqa::Message* message_p = reinterpret_cast<const bmqa::Message*>(message);
return builder_p->addMessageConfirmation(*message_p);
}

int z_bmqa_ConfirmEventBuilder__addMessageConfirmationWithCookie(z_bmqa_ConfirmEventBuilder* builder_obj,
const z_bmqa_MessageConfirmationCookie* cookie) {
using namespace BloombergLP;

bmqa::ConfirmEventBuilder* builder_ptr = reinterpret_cast<bmqa::ConfirmEventBuilder*>(builder_obj);
const bmqa::MessageConfirmationCookie* cookie_ptr = reinterpret_cast<const bmqa::MessageConfirmationCookie*>(cookie);
return builder_ptr->addMessageConfirmation(*cookie_ptr);
bmqa::ConfirmEventBuilder* builder_p = reinterpret_cast<bmqa::ConfirmEventBuilder*>(builder_obj);
const bmqa::MessageConfirmationCookie* cookie_p = reinterpret_cast<const bmqa::MessageConfirmationCookie*>(cookie);
return builder_p->addMessageConfirmation(*cookie_p);
}

int z_bmqa_ConfirmEventBuilder__reset(z_bmqa_ConfirmEventBuilder* builder_obj) {
using namespace BloombergLP;

bmqa::ConfirmEventBuilder* builder_ptr = reinterpret_cast<bmqa::ConfirmEventBuilder*>(builder_obj);
builder_ptr->reset();
bmqa::ConfirmEventBuilder* builder_p = reinterpret_cast<bmqa::ConfirmEventBuilder*>(builder_obj);
builder_p->reset();

return 0;
}

int z_bmqa_ConfirmEventBuilder__messageCount(const z_bmqa_ConfirmEventBuilder* builder_obj) {
using namespace BloombergLP;

const bmqa::ConfirmEventBuilder* builder_ptr = reinterpret_cast<const bmqa::ConfirmEventBuilder*>(builder_obj);
return builder_ptr->messageCount();
const bmqa::ConfirmEventBuilder* builder_p = reinterpret_cast<const bmqa::ConfirmEventBuilder*>(builder_obj);
return builder_p->messageCount();
}

int z_bmqa_ConfirmEventBuilder__blob(z_bmqa_ConfirmEventBuilder* builder_obj, z_bmqt_Blob const** blob_obj) {
using namespace BloombergLP;

const bmqa::ConfirmEventBuilder* builder_ptr = reinterpret_cast<const bmqa::ConfirmEventBuilder*>(builder_obj);
const bmqa::ConfirmEventBuilder* builder_p = reinterpret_cast<const bmqa::ConfirmEventBuilder*>(builder_obj);

const bdlbb::Blob* blob_ptr = &(builder_ptr->blob());
*blob_obj = reinterpret_cast<const z_bmqt_Blob*>(blob_ptr);
const bdlbb::Blob* blob_p = &(builder_p->blob());
*blob_obj = reinterpret_cast<const z_bmqt_Blob*>(blob_p);

return 0;
}
2 changes: 2 additions & 0 deletions src/groups/z_bmq/z_bmqa/z_bmqa_confirmeventbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ extern "C" {
typedef struct z_bmqa_ConfirmEventBuilder z_bmqa_ConfirmEventBuilder;
typedef struct z_bmqa_MessageConfirmationCookie z_bmqa_MessageConfirmationCookie;

int z_bmqa_ConfirmEventBuilder__delete(z_bmqa_ConfirmEventBuilder** builder_obj);

int z_bmqa_ConfirmEventBuilder__create(z_bmqa_ConfirmEventBuilder** builder_obj);

int z_bmqa_ConfirmEventBuilder__addMessageConfirmation(z_bmqa_ConfirmEventBuilder* builder_obj,
Expand Down
28 changes: 24 additions & 4 deletions src/groups/z_bmq/z_bmqa/z_bmqa_message.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
#include <bmqa_message.h>
#include <z_bmqa_message.h>

int z_bmqa_Message__delete(z_bmqa_Message** message_obj) {
using namespace BloombergLP;

bmqa::Message* message_p = reinterpret_cast<bmqa::Message*>(*message_obj);
delete message_p;
*message_obj = NULL;

return 0;
}

int z_bmqa_Message__deleteConst(z_bmqa_Message const** message_obj) {
using namespace BloombergLP;

const bmqa::Message* message_p = reinterpret_cast<const bmqa::Message*>(*message_obj);
delete message_p;
*message_obj = NULL;

return 0;
}

int z_bmqa_Message__createEmpty(z_bmqa_Message** message_obj){
using namespace BloombergLP;

bmqa::Message* message_ptr = new bmqa::Message();
bmqa::Message* message_p = new bmqa::Message();

*message_obj = reinterpret_cast<z_bmqa_Message*>(message_ptr);
*message_obj = reinterpret_cast<z_bmqa_Message*>(message_p);
return 0;
}

int z_bmqa_Message__setDataRef(z_bmqa_Message* message_obj, const char* data, int length){
using namespace BloombergLP;

bmqa::Message* message_ptr = reinterpret_cast<bmqa::Message*>(message_obj);
bmqa::Message* message_p = reinterpret_cast<bmqa::Message*>(message_obj);

message_ptr->setDataRef(data, length);
message_p->setDataRef(data, length);
return 0;
}
4 changes: 4 additions & 0 deletions src/groups/z_bmq/z_bmqa/z_bmqa_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ extern "C" {

typedef struct z_bmqa_Message z_bmqa_Message;

int z_bmqa_Message__delete(z_bmqa_Message** message_obj);

int z_bmqa_Message__deleteConst(z_bmqa_Message const** message_obj);

int z_bmqa_Message__createEmpty(z_bmqa_Message** message_obj);

int z_bmqa_Message__setDataRef(z_bmqa_Message* message_obj, const char* data, int length);
Expand Down
22 changes: 22 additions & 0 deletions src/groups/z_bmq/z_bmqa/z_bmqa_messageevent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <z_bmqa_messageevent.h>
#include <bmqa_messageevent.h>

int z_bmqa_MessageEvent__delete(z_bmqa_MessageEvent** event_obj) {
using namespace BloombergLP;

bmqa::MessageEvent* event_p = reinterpret_cast<bmqa::MessageEvent*>(*event_obj);
delete event_p;
*event_obj = NULL;

return 0;
}

int z_bmqa_MessageEvent__deleteConst(z_bmqa_MessageEvent const** event_obj) {
using namespace BloombergLP;

const bmqa::MessageEvent* event_p = reinterpret_cast<const bmqa::MessageEvent*>(*event_obj);
delete event_p;
*event_obj = NULL;

return 0;
}
12 changes: 12 additions & 0 deletions src/groups/z_bmq/z_bmqa/z_bmqa_messageevent.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
#ifndef INCLUDED_Z_BMQA_MESSAGEEVENT
#define INCLUDED_Z_BMQA_MESSAGEEVENT

#if defined(__cplusplus)
extern "C" {
#endif

typedef struct z_bmqa_MessageEvent z_bmqa_MessageEvent;

int z_bmqa_MessageEvent__delete(z_bmqa_MessageEvent** event_obj);

int z_bmqa_MessageEvent__deleteConst(z_bmqa_MessageEvent const** event_obj);

#if defined(__cplusplus)
}
#endif

#endif
60 changes: 40 additions & 20 deletions src/groups/z_bmq/z_bmqa/z_bmqa_messageeventbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,92 @@



int z_bmqa_MessageEventBuilder__delete(z_bmqa_MessageEventBuilder** builder_obj) {
using namespace BloombergLP;

bmqa::MessageEventBuilder* builder_p = reinterpret_cast<bmqa::MessageEventBuilder*>(*builder_obj);
delete builder_p;
*builder_obj = NULL;

return 0;
}

int z_bmqa_MessageEventBuilder__deleteConst(z_bmqa_MessageEventBuilder const** builder_obj) {
using namespace BloombergLP;

const bmqa::MessageEventBuilder* builder_p = reinterpret_cast<const bmqa::MessageEventBuilder*>(*builder_obj);
delete builder_p;
*builder_obj = NULL;

return 0;
}

int z_bmqa_MessageEventBuilder__create(z_bmqa_MessageEventBuilder** builder_obj) {
using namespace BloombergLP;

bmqa::MessageEventBuilder* builder_ptr = new bmqa::MessageEventBuilder();
*builder_obj = reinterpret_cast<z_bmqa_MessageEventBuilder*>(builder_ptr);
bmqa::MessageEventBuilder* builder_p = new bmqa::MessageEventBuilder();
*builder_obj = reinterpret_cast<z_bmqa_MessageEventBuilder*>(builder_p);

return 0;
}

int z_bmqa_MessageEventBuilder__startMessage(z_bmqa_MessageEventBuilder* builder_obj, z_bmqa_Message** out_obj) {
using namespace BloombergLP;

bmqa::MessageEventBuilder* builder_ptr = reinterpret_cast<bmqa::MessageEventBuilder*>(builder_obj);
bmqa::Message* message_ptr = &builder_ptr->startMessage();
*out_obj = reinterpret_cast<z_bmqa_Message*>(message_ptr);
bmqa::MessageEventBuilder* builder_p = reinterpret_cast<bmqa::MessageEventBuilder*>(builder_obj);
bmqa::Message* message_p = &builder_p->startMessage();
*out_obj = reinterpret_cast<z_bmqa_Message*>(message_p);

return 0;
}

int z_bmqa_MessageEventBuilder__packMessage(z_bmqa_MessageEventBuilder* builder_obj, const z_bmqa_QueueId* queueId) {
using namespace BloombergLP;

bmqa::MessageEventBuilder* builder_ptr = reinterpret_cast<bmqa::MessageEventBuilder*>(builder_obj);
const bmqa::QueueId* queueId_ptr = reinterpret_cast<const bmqa::QueueId*>(queueId);
return builder_ptr->packMessage(*queueId_ptr);
bmqa::MessageEventBuilder* builder_p = reinterpret_cast<bmqa::MessageEventBuilder*>(builder_obj);
const bmqa::QueueId* queueId_p = reinterpret_cast<const bmqa::QueueId*>(queueId);
return builder_p->packMessage(*queueId_p);
}

int z_bmqa_MessageEventBuilder__reset(z_bmqa_MessageEventBuilder* builder_obj) {
using namespace BloombergLP;

bmqa::MessageEventBuilder* builder_ptr = reinterpret_cast<bmqa::MessageEventBuilder*>(builder_obj);
builder_ptr->reset();
bmqa::MessageEventBuilder* builder_p = reinterpret_cast<bmqa::MessageEventBuilder*>(builder_obj);
builder_p->reset();

return 0;
}

int z_bmqa_MessageEventBuilder__messageEvent(z_bmqa_MessageEventBuilder* builder_obj, z_bmqa_MessageEvent const** event_obj) {
using namespace BloombergLP;

bmqa::MessageEventBuilder* builder_ptr = reinterpret_cast<bmqa::MessageEventBuilder*>(builder_obj);
const bmqa::MessageEvent* event_ptr = &(builder_ptr->messageEvent());
*event_obj = reinterpret_cast<const z_bmqa_MessageEvent*>(event_ptr);
bmqa::MessageEventBuilder* builder_p = reinterpret_cast<bmqa::MessageEventBuilder*>(builder_obj);
const bmqa::MessageEvent* event_p = &(builder_p->messageEvent());
*event_obj = reinterpret_cast<const z_bmqa_MessageEvent*>(event_p);

return 0;
}

int z_bmqa_MessageEventBuilder__currentMessage(z_bmqa_MessageEventBuilder* builder_obj, z_bmqa_Message** message_obj) {
using namespace BloombergLP;

bmqa::MessageEventBuilder* builder_ptr = reinterpret_cast<bmqa::MessageEventBuilder*>(builder_obj);
bmqa::Message* message_ptr = &(builder_ptr->currentMessage());
*message_obj = reinterpret_cast<z_bmqa_Message*>(message_ptr);
bmqa::MessageEventBuilder* builder_p = reinterpret_cast<bmqa::MessageEventBuilder*>(builder_obj);
bmqa::Message* message_p = &(builder_p->currentMessage());
*message_obj = reinterpret_cast<z_bmqa_Message*>(message_p);

return 0;
}

int z_bmqa_MessageEventBuilder__messageCount(const z_bmqa_MessageEventBuilder* builder_obj) {
using namespace BloombergLP;

const bmqa::MessageEventBuilder* builder_ptr = reinterpret_cast<const bmqa::MessageEventBuilder*>(builder_obj);
return builder_ptr->messageCount();
const bmqa::MessageEventBuilder* builder_p = reinterpret_cast<const bmqa::MessageEventBuilder*>(builder_obj);
return builder_p->messageCount();
}

int z_bmqa_MessageEventBuilder__messageEventSize(const z_bmqa_MessageEventBuilder* builder_obj) {
using namespace BloombergLP;

const bmqa::MessageEventBuilder* builder_ptr = reinterpret_cast<const bmqa::MessageEventBuilder*>(builder_obj);
return builder_ptr->messageEventSize();
const bmqa::MessageEventBuilder* builder_p = reinterpret_cast<const bmqa::MessageEventBuilder*>(builder_obj);
return builder_p->messageEventSize();
}
4 changes: 4 additions & 0 deletions src/groups/z_bmq/z_bmqa/z_bmqa_messageeventbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ extern "C" {

typedef struct z_bmqa_MessageEventBuilder z_bmqa_MessageEventBuilder;

int z_bmqa_MessageEventBuilder__delete(z_bmqa_MessageEventBuilder** builder_obj);

int z_bmqa_MessageEventBuilder__deleteConst(z_bmqa_MessageEventBuilder const** builder_obj);

int z_bmqa_MessageEventBuilder__create(z_bmqa_MessageEventBuilder** builder_obj);

int z_bmqa_MessageEventBuilder__startMessage(z_bmqa_MessageEventBuilder* builder_obj, z_bmqa_Message** out_obj);
Expand Down
Loading

0 comments on commit b09e215

Please sign in to comment.