Browse Source

prototype: pEp::String - move alloc/free routines into class

heck-rework
heck 3 years ago
parent
commit
6b0ab94595
  1. 29
      test/test_nr1.cc

29
test/test_nr1.cc

@ -213,7 +213,7 @@ namespace pEp {
~String() ~String()
{ {
if (_is_owner) { if (_is_owner) {
_free(); _free(*_c_str_pp);
} }
} }
@ -226,7 +226,7 @@ namespace pEp {
} }
// DEALLOCATION // DEALLOCATION
_free(); _free(*_c_str_pp);
// ALLOCATION // ALLOCATION
*_c_str_pp = _copy(str); *_c_str_pp = _copy(str);
@ -296,22 +296,17 @@ namespace pEp {
static bool log_enabled; static bool log_enabled;
private: private:
// TODO: this is dodgy, do we really need _c_str_pp AND _c_str_p??? static char* _copy(const std::string& str)
void _free()
{ {
pEpLogClass("called"); char* ret = strdup(str.c_str());
// if the c_str points to a different address now, than the one we created pEpLog(CXX::Inspect::all(ret));
if (*_c_str_pp != _c_str_p) { return ret;
// a new string has been created, and we need to free it as well }
pEpLogClass("raw access string change detected");
pEp::free(*_c_str_pp); static void _free(char* ptr_type)
} else { {
// WE ASSUME THAT: pEpLog(CXX::Inspect::all(ptr_type));
// if the char* has been replaced, it has been freed, as well ::pEp_free(ptr_type);
if (_c_str_p != nullptr) {
pEp::free(_c_str_p);
}
}
} }
bool _is_bound{ false }; bool _is_bound{ false };

Loading…
Cancel
Save