Adds runtime alignment assertions, see #3267

This commit is contained in:
Daniel J. Hofmann
2016-11-09 00:23:38 +01:00
committed by Patrick Niklaus
parent 7dea7476f1
commit 559c88b36d
3 changed files with 23 additions and 2 deletions
+1
View File
@@ -106,6 +106,7 @@ struct DataLayout
template <typename T> inline void SetBlockSize(BlockID bid, uint64_t entries)
{
static_assert(sizeof(T) % alignof(T) == 0, "aligned T* can't be used as an array pointer");
num_entries[bid] = entries;
entry_size[bid] = sizeof(T);
entry_align[bid] = alignof(T);
+3 -1
View File
@@ -373,7 +373,9 @@ class StaticRTree
{
m_leaves_region.open(leaf_file);
std::size_t num_leaves = m_leaves_region.size() / sizeof(LeafNode);
m_leaves.reset(reinterpret_cast<const LeafNode *>(m_leaves_region.data()), num_leaves);
auto data_ptr = m_leaves_region.data();
BOOST_ASSERT(reinterpret_cast<uintptr_t>(data_ptr) % alignof(LeafNode) == 0);
m_leaves.reset(reinterpret_cast<const LeafNode *>(data_ptr), num_leaves);
}
catch (const std::exception &exc)
{