]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: fix struct size calculation to include terminal padding
authorDamien Neil <dneil@google.com>
Thu, 16 Oct 2014 20:58:32 +0000 (13:58 -0700)
committerRob Pike <r@golang.org>
Thu, 16 Oct 2014 20:58:32 +0000 (13:58 -0700)
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/160920045

src/reflect/all_test.go
src/reflect/type.go

index 6bdc9be9dd3b185af4708190e668ed9c68137b9f..40eae0364c09530df9f03aef9774aff5a29c0a80 100644 (file)
@@ -2678,6 +2678,26 @@ func TestFuncArg(t *testing.T) {
        }
 }
 
+func TestStructArg(t *testing.T) {
+       type padded struct {
+               B string
+               C int32
+       }
+       var (
+               gotA  padded
+               gotB  uint32
+               wantA = padded{"3", 4}
+               wantB = uint32(5)
+       )
+       f := func(a padded, b uint32) {
+               gotA, gotB = a, b
+       }
+       ValueOf(f).Call([]Value{ValueOf(wantA), ValueOf(wantB)})
+       if gotA != wantA || gotB != wantB {
+               t.Errorf("function called with (%v, %v), want (%v, %v)", gotA, gotB, wantA, wantB)
+       }
+}
+
 var tagGetTests = []struct {
        Tag   StructTag
        Key   string
index b92d524c3bab631a82a0b70c7964117aa39ec185..4ba1d4fccf85520668d55f5fc2cc8e0c569a2fc1 100644 (file)
@@ -1544,6 +1544,7 @@ func (gc *gcProg) appendProg(t *rtype) {
                for i := 0; i < c; i++ {
                        gc.appendProg(t.Field(i).Type.common())
                }
+               gc.align(uintptr(t.align))
        }
 }