~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to misc/cgo/test/issue7560.go

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-11-18 15:12:26 UTC
  • mfrom: (14.2.12 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20141118151226-zug7vn93mn3dtiz3
Tags: 2:1.3.2-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - Support co-installability with gccgo-go tool:
    - d/rules,golang-go.install: Rename bin/go -> bin/golang-go
    - d/golang-go.{postinst,prerm}: Install/remove /usr/bin/go using
      alternatives.
  - d/copyright: Amendments for full compiliance with copyright format.
  - d/control: Demote golang-go.tools to Suggests to support Ubuntu MIR.
  - dropped patches (now upstream):
    - d/p/issue27650045_40001_50001.diff
    - d/p/issue28050043_60001_70001.diff
    - d/p/issue54790044_100001_110001.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2014 The Go Authors.  All rights reserved.
 
2
// Use of this source code is governed by a BSD-style
 
3
// license that can be found in the LICENSE file.
 
4
 
 
5
package cgotest
 
6
 
 
7
/*
 
8
#include <stdint.h>
 
9
 
 
10
typedef struct {
 
11
        char x;
 
12
        long y;
 
13
} __attribute__((__packed__)) misaligned;
 
14
 
 
15
int
 
16
offset7560(void)
 
17
{
 
18
        return (uintptr_t)&((misaligned*)0)->y;
 
19
}
 
20
*/
 
21
import "C"
 
22
 
 
23
import (
 
24
        "reflect"
 
25
        "testing"
 
26
)
 
27
 
 
28
func test7560(t *testing.T) {
 
29
        // some mingw don't implement __packed__ correctly.
 
30
        if C.offset7560() != 1 {
 
31
                t.Skip("C compiler did not pack struct")
 
32
        }
 
33
 
 
34
        // C.misaligned should have x but then a padding field to get to the end of the struct.
 
35
        // There should not be a field named 'y'.
 
36
        var v C.misaligned
 
37
        rt := reflect.TypeOf(&v).Elem()
 
38
        if rt.NumField() != 2 || rt.Field(0).Name != "x" || rt.Field(1).Name != "_" {
 
39
                t.Errorf("unexpected fields in C.misaligned:\n")
 
40
                for i := 0; i < rt.NumField(); i++ {
 
41
                        t.Logf("%+v\n", rt.Field(i))
 
42
                }
 
43
        }
 
44
}