aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/repeated_field.h
diff options
context:
space:
mode:
authorGravatar Feng Xiao <xfxyjwf@gmail.com>2014-12-05 02:54:43 -0800
committerGravatar Feng Xiao <xfxyjwf@gmail.com>2014-12-05 02:54:43 -0800
commitbe20ae0b6975071563ecc61f8372fd7936f174ed (patch)
treeed4c27622fceb78410c74af287532379f475843e /src/google/protobuf/repeated_field.h
parent7c939bcb25bff016ca63669c203e2ebfc0834825 (diff)
Fix compile issues and test failures in VS2008.
Diffstat (limited to 'src/google/protobuf/repeated_field.h')
-rw-r--r--src/google/protobuf/repeated_field.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h
index e14dcc62..4798eeda 100644
--- a/src/google/protobuf/repeated_field.h
+++ b/src/google/protobuf/repeated_field.h
@@ -236,10 +236,11 @@ class RepeatedField {
Arena* arena;
Element elements[1];
};
- // Why not sizeof(Rep) - sizeof(Element)? Because this is not accurate w.r.t.
- // trailing padding on the struct -- e.g. if Element is int, this would yield
- // 12 on x86-64, not 8 as we want.
- static const size_t kRepHeaderSize = sizeof(Arena*);
+ // We can not use sizeof(Rep) - sizeof(Element) due to the trailing padding on
+ // the struct. We can not use sizeof(Arena*) as well because there might be
+ // a "gap" after the field arena and before the field elements (e.g., when
+ // Element is double and pointer is 32bit).
+ static const size_t kRepHeaderSize;
// Contains arena ptr and the elements array. We also keep the invariant that
// if rep_ is NULL, then arena is NULL.
Rep* rep_;
@@ -263,6 +264,10 @@ class RepeatedField {
}
};
+template<typename Element>
+const size_t RepeatedField<Element>::kRepHeaderSize =
+ reinterpret_cast<size_t>(&reinterpret_cast<Rep*>(16)->elements[0]) - 16;
+
namespace internal {
template <typename It> class RepeatedPtrIterator;
template <typename It, typename VoidPtr> class RepeatedPtrOverPtrsIterator;