From d092608c065831f1984ac9d332ca5b2c95a11f57 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 16 Dec 2016 00:27:18 +0000 Subject: [PATCH] Align Group.Stats properly for 32-bit platforms. Fixes golang/go#18334 --- groupcache.go | 2 ++ groupcache_test.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/groupcache.go b/groupcache.go index c227237..316ca49 100644 --- a/groupcache.go +++ b/groupcache.go @@ -166,6 +166,8 @@ type Group struct { // concurrent callers. loadGroup flightGroup + _ int32 // force Stats to be 8-byte aligned on 32-bit platforms + // Stats are statistics on the group. Stats Stats } diff --git a/groupcache_test.go b/groupcache_test.go index 3a4ecc2..ea05cac 100644 --- a/groupcache_test.go +++ b/groupcache_test.go @@ -27,6 +27,7 @@ import ( "sync" "testing" "time" + "unsafe" "github.com/golang/protobuf/proto" @@ -443,5 +444,13 @@ func TestNoDedup(t *testing.T) { } } +func TestGroupStatsAlignment(t *testing.T) { + var g Group + off := unsafe.Offsetof(g.Stats) + if off%8 != 0 { + t.Fatal("Stats structure is not 8-byte aligned.") + } +} + // TODO(bradfitz): port the Google-internal full integration test into here, // using HTTP requests instead of our RPC system.