From 813aa1a2f72f8fb98e6df693c13328a8aa2e82c8 Mon Sep 17 00:00:00 2001 From: Eric Kidd Date: Tue, 3 Aug 2010 09:23:05 -0400 Subject: [PATCH] Fix alignment of bth_nonleaf_entry under 32-bit Mac GCC 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. --- pstsdk/disk/disk.h | 8 +++++--- pstsdk/ltp/heap.h | 3 ++- pstsdk/util/primitives.h | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pstsdk/disk/disk.h b/pstsdk/disk/disk.h index b3058d7..60c08b1 100644 --- a/pstsdk/disk/disk.h +++ b/pstsdk/disk/disk.h @@ -1341,12 +1341,14 @@ struct bth_header template 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) == 6, "bth_nonleaf_entry incorrect size"); +static_assert(offsetof(bth_nonleaf_entry, key) == 0, "bth_nonleaf_entry key at incorrect offset"); +static_assert(offsetof(bth_nonleaf_entry, page) == 2, "bth_nonleaf_entry page at incorrect offset"); //! \endcond //! \brief Entries which make up a "leaf" BTH allocation diff --git a/pstsdk/ltp/heap.h b/pstsdk/ltp/heap.h index 6d3128e..9d6512a 100644 --- a/pstsdk/ltp/heap.h +++ b/pstsdk/ltp/heap.h @@ -468,7 +468,8 @@ inline std::tr1::shared_ptr > pstsdk::bth_nodeentries[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 diff --git a/pstsdk/util/primitives.h b/pstsdk/util/primitives.h index 0fad923..6121ccd 100644 --- a/pstsdk/util/primitives.h +++ b/pstsdk/util/primitives.h @@ -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