Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/mfast/coder/common/template_repo.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ class template_repo_base {
template_repo_base(mfast::allocator *dictionary_alloc)
: dictionary_alloc_(dictionary_alloc) {}
virtual ~template_repo_base() {
for (auto &elem : vector_enties_) {
for (auto &elem : vector_entries_) {
if (elem->of_array.capacity_in_bytes_)
{
dictionary_alloc_->deallocate(elem->of_array.content_,
elem->of_array.capacity_in_bytes_);
elem->of_array.capacity_in_bytes_ = 0;
elem->of_array.content_ = nullptr;
}
}
}

Expand All @@ -33,17 +37,20 @@ class template_repo_base {
void add_reset_entry(value_storage *entry) {
reset_entries_.push_back(entry);
}
#ifdef TESTING_TEMPLATE_REPO_BASE
public:
#endif
void add_vector_entry(value_storage *entry) {
if (dictionary_alloc_)
vector_enties_.push_back(entry);
vector_entries_.push_back(entry);
}

protected:
friend class dictionary_builder;

typedef std::vector<value_storage *> value_entries_t;
value_entries_t reset_entries_;
value_entries_t vector_enties_; // for string and byteVector
value_entries_t vector_entries_; // for string and byteVector
arena_allocator instruction_alloc_;
mfast::allocator *dictionary_alloc_;
};
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ add_executable (mfast_test
aggregate_view_test.cpp
simple_coder_test.cpp
scp_reset_test.cpp
template_repo_base.cpp
message_pmap_test.cpp
)

Expand Down
41 changes: 41 additions & 0 deletions tests/template_repo_base.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "catch.hpp"

#define TESTING_TEMPLATE_REPO_BASE
#include <mfast/coder/common/template_repo.h>
#include <mfast/value_storage.h>
#include <mfast/malloc_allocator.h>
#include <mfast/instructions/template_instruction.h>
#include <mfast/coder/common/dictionary_builder.h>

class template_repo_base_impl : public mfast::template_repo_base
{
public:
template_repo_base_impl(mfast::allocator *dictionary_alloc)
: mfast::template_repo_base(dictionary_alloc) {}

virtual mfast::template_instruction *get_template(uint32_t)
{
return nullptr;
}
};

TEST_CASE("Test template repo base with repeated pointers","[test_template_repo_base]")
{
using namespace mfast;

value_storage* storage_1_ = new value_storage();
{
const char * test_data = "Test_Data";
storage_1_->of_array.len_ = static_cast<uint32_t>(std::strlen(test_data) + 1);
storage_1_->of_array.content_ = malloc_allocator::instance()->allocate(storage_1_->of_array.len_);
storage_1_->of_array.capacity_in_bytes_ = 9;
}

{
template_repo_base_impl templ_repo(malloc_allocator::instance());
templ_repo.add_vector_entry(storage_1_);
templ_repo.add_vector_entry(storage_1_);
}

delete storage_1_;
}