-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: c wrapper #2
Conversation
Some refactoring to allow creating libnegentropy.so shared library
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there no concept of blobs in C? I see char*
those are null terminated strings right?
I'm guessing blobs would be implemented the same way?
Actually char* is nothing but a representation of memory. Null terminated chars cause trouble only when you start using operations like length or copying a char*. since underlying implementation is c++ which uses std::string which inturn supports null chars in string, this should not be a problem. But to ensure this doesn't cause an issue, i will add a test to validate this. And yes, in C blobs are generally passed around as char* along with a len param. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I don't understand much of the c or cpp code but it seams we have all the functionalities we need except error handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just adding some comments for future review
|
||
result->have_ids_len = haveIds.size(); | ||
result->need_ids_len = needIds.size(); | ||
result->have_ids = (buffer*)malloc(result->have_ids_len*sizeof(buffer)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this memory being released?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had implemented a free_result function which releases memory for all these buffers.
} | ||
|
||
//Note: This function assumes that all relevant heap memory is alloced and just tries to free | ||
void free_result(result* r){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I see, yes I think it is necessary to explore the callback approach that we have mentioned. This might bring mem leaks in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this is a stop-gap approach as callbacks are having additional trouble in nim.
I could not use a closure based callback and hence took this approach to begin with.
I will test a callback model in sample code and then migrate to callback approach(which will not involve such memory leak issues). Also in callback i could use stack memory for many things and reduce amount of heap allocations.
Merging this as will take up pending items in a separate PR. |
As integrating a c++ library to nim has some drawbacks, approach taken is to write a C API wrapper to be integrated into nwaku.
To that end, all required functionalities have been wrapped into C API.
Tasks:
Following shall be taken up separately as this PR is becoming huge: