Skip to content

Commit

Permalink
Fix alignment of bth_nonleaf_entry under 32-bit Mac GCC
Browse files Browse the repository at this point in the history
The layout constraints on this structure changed in Subversion r48798,
requiring the overall structure to be 6 bytes in size.  This proves
somewhat tricky to get working on Mac GCC:

  1) We need to remove the PSTSDK_MS_STRUCT option, which overrides
     all other packing options.
  2) We need to add some new declarations to the 'page' member
     variable.
  3) We can no longer pass entry.page directly to make_pair, because
     make_pair requires an aligned reference for its second argument.
     Instead, we copy 'page' to a normally-aligned temporary variable.

With these changes, the code builds and passes all test suites again.
  • Loading branch information
emk committed Aug 4, 2010
1 parent 21c7d2d commit 813aa1a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions pstsdk/disk/disk.h
Expand Up @@ -1341,12 +1341,14 @@ struct bth_header
template<typename K>
struct bth_nonleaf_entry
{
K key; //!< Key of the lower level page
heap_id page; //!< Heap id of the lower level page
} PSTSDK_MS_STRUCT;
K key; //!< Key of the lower level page
heap_id page PSTSDK_PACK_2; //!< Heap id of the lower level page
};
#pragma pack()
//! \cond static_asserts
static_assert(sizeof(bth_nonleaf_entry<ushort>) == 6, "bth_nonleaf_entry<ushort> incorrect size");
static_assert(offsetof(bth_nonleaf_entry<ushort>, key) == 0, "bth_nonleaf_entry<ushort> key at incorrect offset");
static_assert(offsetof(bth_nonleaf_entry<ushort>, page) == 2, "bth_nonleaf_entry<ushort> page at incorrect offset");
//! \endcond

//! \brief Entries which make up a "leaf" BTH allocation
Expand Down
3 changes: 2 additions & 1 deletion pstsdk/ltp/heap.h
Expand Up @@ -468,7 +468,8 @@ inline std::tr1::shared_ptr<pstsdk::bth_nonleaf_node<K,V> > pstsdk::bth_node<K,V

for(uint i = 0; i < num_entries; ++i)
{
child_nodes.push_back(std::make_pair(pbth_nonleaf_node->entries[i].key, pbth_nonleaf_node->entries[i].page));
heap_id page = pbth_nonleaf_node->entries[i].page;
child_nodes.push_back(std::make_pair(pbth_nonleaf_node->entries[i].key, page));
}

#ifndef BOOST_NO_RVALUE_REFERENCES
Expand Down
2 changes: 2 additions & 0 deletions pstsdk/util/primitives.h
Expand Up @@ -53,8 +53,10 @@
// '#pragma ms_struct on', but it fails on at least some Linux systems.
#ifdef __GNUC__
#define PSTSDK_MS_STRUCT __attribute__((ms_struct))
#define PSTSDK_PACK_2 __attribute__((packed, aligned(2)))
#else
#define PSTSDK_MS_STRUCT
#define PSTSDK_PACK_2
#endif

namespace pstsdk
Expand Down

0 comments on commit 813aa1a

Please sign in to comment.