fix: added functions to cleanup memory

This commit is contained in:
Prem Chaitanya Prathi 2024-03-07 16:02:47 +05:30
parent 1a59da6c32
commit b2bc08786b
No known key found for this signature in database
2 changed files with 17 additions and 1 deletions

View File

@ -34,6 +34,16 @@ void* storage_new(const char* db_path, const char* name){
return storage; return storage;
} }
void storage_delete(void* storage){
negentropy::storage::BTreeMem* lmdbStorage = reinterpret_cast<negentropy::storage::BTreeMem*>(storage);
delete lmdbStorage;
}
void negentropy_delete(void* negentropy){
Negentropy<negentropy::storage::BTreeMem>* ngn_inst = reinterpret_cast<Negentropy<negentropy::storage::BTreeMem>*>(negentropy);
delete ngn_inst;
}
void* negentropy_new(void* storage, uint64_t frameSizeLimit){ void* negentropy_new(void* storage, uint64_t frameSizeLimit){
//TODO: Make these typecasts into macros?? //TODO: Make these typecasts into macros??
negentropy::storage::BTreeMem* lmdbStorage; negentropy::storage::BTreeMem* lmdbStorage;
@ -60,6 +70,7 @@ size_t negentropy_initiate(void* negentropy, buffer* out){
std::cout << "output of initiate is, len:" << output->size() << ", output:"; std::cout << "output of initiate is, len:" << output->size() << ", output:";
printHexString(std::string_view(*output)); printHexString(std::string_view(*output));
} catch(negentropy::err e){ } catch(negentropy::err e){
std::cout << "Exception raised in initiate " << e.what() << std::endl;
//TODO:Find a way to return this error //TODO:Find a way to return this error
return 0; return 0;
} }
@ -112,6 +123,7 @@ size_t reconcile(void* negentropy, buffer* query, buffer* output){
printHexString(std::string_view(*out)); printHexString(std::string_view(*out));
} catch(negentropy::err e){ } catch(negentropy::err e){
//TODO:Find a way to return this error //TODO:Find a way to return this error
std::cout << "Exception raised in reconcile " << e.what() << std::endl;
return 0; return 0;
} }
memcpy( output->data, out->c_str() ,out->size()); memcpy( output->data, out->c_str() ,out->size());
@ -149,7 +161,7 @@ int reconcile_with_ids(void* negentropy, buffer* query,reconcile_cbk cbk, char*
transform(haveIds, have_ids); transform(haveIds, have_ids);
transform(needIds, need_ids); transform(needIds, need_ids);
} catch(negentropy::err e){ } catch(negentropy::err e){
std::cout << "caught error "<< e.what() << std::endl; std::cout << "exception raised in reconcile_with_ids"<< e.what() << std::endl;
//TODO:Find a way to return this error and cleanup partially allocated memory if any //TODO:Find a way to return this error and cleanup partially allocated memory if any
return -1; return -1;
} }

View File

@ -26,8 +26,12 @@ typedef struct _result_ {
EXTERNC void* storage_new(const char* db_path, const char* name); EXTERNC void* storage_new(const char* db_path, const char* name);
EXTERNC void storage_delete(void* storage);
EXTERNC void* negentropy_new(void* storage, uint64_t frameSizeLimit); EXTERNC void* negentropy_new(void* storage, uint64_t frameSizeLimit);
EXTERNC void negentropy_delete(void* negentropy);
EXTERNC size_t negentropy_initiate(void* negentropy, buffer* output); EXTERNC size_t negentropy_initiate(void* negentropy, buffer* output);
EXTERNC void negentropy_setinitiator(void* negentropy); EXTERNC void negentropy_setinitiator(void* negentropy);