Skip to content

Commit

Permalink
[engine] Remove two replace functions from KvpValue
Browse files Browse the repository at this point in the history
These were not used outside a test.

And that test was not leak free, as a result of the functions not doing
what they are supposed to do when the current value is not of the type
that is expected. (NULL is returned, but the value is not replaced)
  • Loading branch information
mkbosmans committed Apr 2, 2023
1 parent bd94965 commit 35aeed4
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 49 deletions.
20 changes: 0 additions & 20 deletions libgnucash/engine/kvp-value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,6 @@ KvpValueImpl::get_type() const noexcept
return KvpValue::Type::INVALID;
}

KvpFrame *
KvpValueImpl::replace_frame_nc (KvpFrame * new_value) noexcept
{
if (datastore.type() != type_id<KvpFrame *>())
return {};
auto ret = boost::get<KvpFrame *>(datastore);
datastore = new_value;
return ret;
}

GList *
KvpValueImpl::replace_glist_nc (GList * new_value) noexcept
{
if (datastore.type() != type_id<GList *>())
return {};
auto ret = boost::get<GList *>(datastore);
datastore = new_value;
return ret;
}

struct to_string_visitor : boost::static_visitor<void>
{
std::ostringstream & output;
Expand Down
16 changes: 0 additions & 16 deletions libgnucash/engine/kvp-value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,6 @@ struct KvpValueImpl
*/
~KvpValueImpl() noexcept;

/**
* Replaces the frame within this KvpValueImpl.
*
* If this KvpValueImpl doesn't contain a KvpFrame, nullptr
* is returned. Otherwise, the old KvpFrame * is returned.
*/
KvpFrame * replace_frame_nc (KvpFrame *) noexcept;

/**
* Replaces the glist within this KvpValueImpl.
*
* If this KvpValueImpl doesn't contain a GList, nullptr
* is returned. Otherwise, the old GList * is returned.
*/
GList * replace_glist_nc (GList *) noexcept;

/**
* Adds another value to this KvpValueImpl.
*
Expand Down
13 changes: 0 additions & 13 deletions libgnucash/engine/test/test-kvp-value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,6 @@
#include <memory>
#include <gtest/gtest.h>

TEST (KvpValueTest, Replace_Frame)
{
auto f1 = new KvpFrameImpl;
std::unique_ptr<KvpValueImpl> v1 {new KvpValueImpl {f1}};
auto f2 = new KvpFrameImpl;
EXPECT_EQ (f1, v1->replace_frame_nc (f2));
v1->set (5.2);
/*f1 and f2 should be deleted now*/
f1 = new KvpFrameImpl;
EXPECT_EQ (nullptr, v1->replace_frame_nc (f1));
delete f1;
}

TEST (KvpValueTest, Equality)
{
std::unique_ptr<KvpValueImpl> v1 {new KvpValueImpl { (int64_t)1}};
Expand Down

0 comments on commit 35aeed4

Please sign in to comment.