Merge lp:~michihenning/persistent-cache-cpp/fix-move-construct into lp:persistent-cache-cpp/devel

Proposed by Michi Henning
Status: Merged
Approved by: James Henstridge
Approved revision: 41
Merged at revision: 39
Proposed branch: lp:~michihenning/persistent-cache-cpp/fix-move-construct
Merge into: lp:persistent-cache-cpp/devel
Prerequisite: lp:~michihenning/persistent-cache-cpp/fix-copyright-xenial
Diff against target: 83 lines (+37/-6)
4 files modified
debian/changelog (+7/-0)
include/core/persistent_cache_stats.h (+1/-1)
src/core/persistent_cache_stats.cpp (+9/-5)
tests/core/persistent_string_cache/persistent_string_cache_test.cpp (+20/-0)
To merge this branch: bzr merge lp:~michihenning/persistent-cache-cpp/fix-move-construct
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
James Henstridge Approve
Unity API Team Pending
Review via email: mp+280105@code.launchpad.net

This proposal supersedes a proposal from 2015-12-09.

Commit message

Fixed assertion failure when move-constructing from internal stats instance.

Description of the change

Fixed assertion failure when move-constructing from internal stats instance.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
41. By Michi Henning

Merged dependent branch.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
James Henstridge (jamesh) wrote :

Looks good.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2015-08-19 21:50:26 +0000
3+++ debian/changelog 2015-12-10 06:07:16 +0000
4@@ -1,3 +1,10 @@
5+persistent-cache-cpp (1.0.4+15.10.20150819.2-0ubuntu2) UNRELEASED; urgency=medium
6+
7+ * Fixed assertion failure when move-constructing a stats instance from
8+ the internal instance.
9+
10+ -- Michi Henning <michi.henning@canonical.com> Wed, 09 Dec 2015 16:16:41 +1000
11+
12 persistent-cache-cpp (1.0.4+15.10.20150819.2-0ubuntu1) wily; urgency=medium
13
14 [ Michi Henning ]
15
16=== modified file 'include/core/persistent_cache_stats.h'
17--- include/core/persistent_cache_stats.h 2015-08-19 04:44:35 +0000
18+++ include/core/persistent_cache_stats.h 2015-12-10 06:07:16 +0000
19@@ -236,7 +236,7 @@
20 // We store a shared_ptr for efficiency. When the caller
21 // retrieves the stats, we set p_ to point at the PersistentStringCacheStats
22 // inside the cache. If the caller makes a copy or assigns,
23- // We create a new instance, to provide value semantics. This means
24+ // we create a new instance, to provide value semantics. This means
25 // that we don't have to copy all of the stats each time the caller
26 // gets them.
27 std::shared_ptr<internal::PersistentStringCacheStats const> p_;
28
29=== modified file 'src/core/persistent_cache_stats.cpp'
30--- src/core/persistent_cache_stats.cpp 2015-08-19 05:31:09 +0000
31+++ src/core/persistent_cache_stats.cpp 2015-12-10 06:07:16 +0000
32@@ -60,11 +60,15 @@
33 PersistentCacheStats::PersistentCacheStats(PersistentCacheStats&& other) noexcept
34 : internal_(false)
35 {
36- // The cache always passes the internal instance to the event
37- // handler by const ref, so it is not possible to move construct from it.
38- assert(!other.internal_);
39-
40- p_ = other.p_; // Move must leave the instance in a usable state, so we just copy the shared_ptr.
41+ if (other.internal_)
42+ {
43+ // Source is pointing at the internal instance, so we make a copy here to de-couple from it.
44+ p_ = make_shared<internal::PersistentStringCacheStats>(*other.p_);
45+ }
46+ else
47+ {
48+ p_ = other.p_; // Move must leave the instance in a usable state, so we just copy the shared_ptr.
49+ }
50 }
51
52 PersistentCacheStats& PersistentCacheStats::operator=(PersistentCacheStats const& rhs)
53
54=== modified file 'tests/core/persistent_string_cache/persistent_string_cache_test.cpp'
55--- tests/core/persistent_string_cache/persistent_string_cache_test.cpp 2015-08-05 00:11:19 +0000
56+++ tests/core/persistent_string_cache/persistent_string_cache_test.cpp 2015-12-10 06:07:16 +0000
57@@ -363,6 +363,26 @@
58 EXPECT_EQ(miss_run_time, s3.longest_miss_run_time());
59
60 s2.cache_path(); // Moved-from instance must be usable.
61+
62+ // Move constructor from internal instance.
63+ PersistentCacheStats s4(move(c->stats()));
64+ EXPECT_EQ(test_db, s4.cache_path());
65+ EXPECT_EQ(CacheDiscardPolicy::lru_ttl, s4.policy());
66+ EXPECT_EQ(1, s4.size());
67+ EXPECT_EQ(2, s4.size_in_bytes());
68+ EXPECT_EQ(1024, s4.max_size_in_bytes());
69+ EXPECT_EQ(4, s4.hits());
70+ EXPECT_EQ(5, s4.misses());
71+ EXPECT_EQ(1, s4.hits_since_last_miss());
72+ EXPECT_EQ(0, s4.misses_since_last_hit());
73+ EXPECT_EQ(3, s.longest_hit_run());
74+ EXPECT_EQ(4, s.longest_miss_run());
75+ EXPECT_EQ(last_hit_time, s4.most_recent_hit_time());
76+ EXPECT_EQ(last_miss_time, s4.most_recent_miss_time());
77+ EXPECT_EQ(hit_run_time, s4.longest_hit_run_time());
78+ EXPECT_EQ(miss_run_time, s4.longest_miss_run_time());
79+
80+ s.cache_path(); // Moved-from instance must be usable.
81 }
82
83 // To get coverage for copying and moving from the internal instance,

Subscribers

People subscribed via source and target branches

to all changes: