Skip to content

Commit

Permalink
Merge branch 'gcc-4.9' into gcc-4.7
Browse files Browse the repository at this point in the history
  • Loading branch information
ony committed Nov 3, 2014
2 parents 54403c6 + 515dc5d commit 9c6a388
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ find_package(GTest REQUIRED)
find_package(LevelDB REQUIRED)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wconversion -Werror")

include_directories(include)
include_directories(${LevelDB_INCLUDE_DIRS})
Expand Down
22 changes: 13 additions & 9 deletions include/leveldb/sandwich_db.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace leveldb
}
};

template <typename Base, typename Prefix = short>
template <typename Base, typename Prefix>
class SandwichDB<Base, Prefix>::Part final : public AnyDB
{
SandwichDB *sandwich;
Expand Down Expand Up @@ -146,27 +146,30 @@ namespace leveldb
Status Get(const Slice &key, std::string &value) noexcept override
{
assert( Valid() );
char buf[prefix.size() + key.size()];
const size_t buf_size = prefix.size() + key.size();
char buf[buf_size];
(void) memcpy(buf, prefix.data(), prefix.size());
(void) memcpy(buf + sizeof(prefix), key.data(), key.size());
return sandwich->base.Get(Slice(buf, sizeof(buf)), value);
return sandwich->base.Get(Slice(buf, buf_size), value);
}

Status Put(const Slice &key, const Slice &value) noexcept override
{
assert( Valid() );
char buf[prefix.size() + key.size()];
const size_t buf_size = prefix.size() + key.size();
char buf[buf_size];
(void) memcpy(buf, prefix.data(), prefix.size());
(void) memcpy(buf + prefix.size(), key.data(), key.size());
return sandwich->base.Put(Slice(buf, sizeof(buf)), value);
return sandwich->base.Put(Slice(buf, buf_size), value);
}
Status Delete(const Slice &key) noexcept override
{
assert( Valid() );
const size_t buf_size = prefix.size() + key.size();
char buf[prefix.size() + key.size()];
(void) memcpy(buf, prefix.data(), prefix.size());
(void) memcpy(buf + prefix.size(), key.data(), key.size());
return sandwich->base.Delete(Slice(buf, sizeof(buf)));
return sandwich->base.Delete(Slice(buf, buf_size));
}

class Walker;
Expand All @@ -178,7 +181,7 @@ namespace leveldb
}
};

template <typename Base, typename Prefix = short>
template <typename Base, typename Prefix>
class SandwichDB<Base, Prefix>::Part::Walker
{
host_order<Prefix> prefix;
Expand Down Expand Up @@ -227,10 +230,11 @@ namespace leveldb

void Seek(const Slice &target)
{
char buf[prefix.size() + target.size()];
const size_t buf_size = prefix.size() + target.size();
char buf[buf_size];
(void) memcpy(buf, prefix.data(), prefix.size());
(void) memcpy(buf + sizeof(prefix), target.data(), target.size());
impl.Seek(Slice(buf, sizeof(buf)));
impl.Seek(Slice(buf, buf_size));
}
};
}
6 changes: 4 additions & 2 deletions include/leveldb/sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace leveldb
{ return s.size() != size(); }
};

template <typename T, size_t PAGE_SIZE = 10>
template <typename T, T PAGE_SIZE = 10>
class Sequence
{
AnyDB &base;
Expand Down Expand Up @@ -180,7 +180,9 @@ namespace leveldb
return s;
}

const host_order<T> nextAllocated = std::min(size_t(allocated.max()), allocated + PAGE_SIZE);
// to avoid overflow we'll use:
// min(max, x + p) ~ min(max - p, x) + p
const host_order<T> nextAllocated = T(std::min(T(allocated.max() - PAGE_SIZE), T(allocated)) + PAGE_SIZE);
if (nextAllocated == allocated) // overflow
{
(void) base.Put(key, host_order<T>{0}); // mark as overflow
Expand Down

0 comments on commit 9c6a388

Please sign in to comment.