Skip to content

Commit ea8c36c

Browse files
committed
Small cleanups to bucket container fix
Original fix was in cff72f1. We use a more-clearly-named method to indicate when the container is deallocated, and also update the project version.
1 parent cff72f1 commit ea8c36c

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

CMakeLists.txt

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
cmake_minimum_required(VERSION 3.1.0)
2-
project(libcuckoo LANGUAGES C CXX)
3-
4-
set(libcuckoo_VERSION_MAJOR 0)
5-
set(libcuckoo_VERSION_MINOR 3)
6-
set(libcuckoo_VERSION_PATCH 0)
2+
project(libcuckoo
3+
VERSION 0.3.1
4+
LANGUAGES C CXX)
75

86
# put these in the cache so they show up in ccmake
97
option (BUILD_EXAMPLES "build example libcuckoo programs")

libcuckoo/bucket_container.hh

+10-8
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,12 @@ public:
244244
destroy_buckets();
245245
}
246246

247-
// Checks whether the bucket container owns any memory, or if has been
248-
// deallocated. If true, the member-wise getter/setter operations will be
249-
// valid, otherwise they cannot be called safely. Object-level members (such
250-
// as hashpower and size) will remain valid after deallocation.
251-
explicit operator bool() const noexcept {
252-
return buckets_ != nullptr;
247+
// Returns true if the bucket container memory has been deallocated, or false
248+
// if it still owns any memory. If true, the member-wise getter/setter
249+
// operations cannot be called safely. Object-level members (such as
250+
// hashpower and size) will remain valid after deallocation.
251+
bool is_deallocated() const noexcept {
252+
return buckets_ == nullptr;
253253
}
254254

255255
private:
@@ -292,7 +292,7 @@ private:
292292
}
293293

294294
void destroy_buckets() noexcept {
295-
if (buckets_ == nullptr) {
295+
if (is_deallocated()) {
296296
return;
297297
}
298298
// The bucket default constructor is nothrow, so we don't have to
@@ -329,7 +329,9 @@ private:
329329
const bucket_container &>::type src,
330330
std::integral_constant<bool, B> move) {
331331
assert(dst_hp >= src.hashpower());
332-
if (!static_cast<bool>(src)) { return nullptr; }
332+
if (src.is_deallocated()) {
333+
return nullptr;
334+
}
333335
bucket_container dst(dst_hp, get_allocator());
334336
// Move/copy all occupied slots of the source buckets
335337
for (size_t i = 0; i < src.size(); ++i) {

tests/unit-tests/test_bucket_container.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,12 @@ TEST_CASE("copy assignment with throwing type is destroyed properly",
331331
TEST_CASE("copy destroyed buckets container", "[bucket container]") {
332332
std::allocator<value_type> a;
333333
TestingContainer<decltype(a)> bc(2, a);
334-
REQUIRE(static_cast<bool>(bc));
334+
REQUIRE(!bc.is_deallocated());
335335
bc.clear_and_deallocate();
336-
REQUIRE(!static_cast<bool>(bc));
336+
REQUIRE(bc.is_deallocated());
337337
auto bc2 = bc;
338-
REQUIRE(!static_cast<bool>(bc));
339-
REQUIRE(!static_cast<bool>(bc2));
338+
REQUIRE(bc.is_deallocated());
339+
REQUIRE(bc2.is_deallocated());
340340
REQUIRE(bc.size() == bc2.size());
341341
REQUIRE(bc.get_allocator() == bc2.get_allocator());
342342
}

0 commit comments

Comments
 (0)