mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/cgo: roll back "use C exact-width integer types to represent Go types"
Roll back CL 159258 and CL 168337. Those changes broke existing code. I can't see any way to keep existing code working while also producing good error messages for types like C.ulong (such as the ones already tested for in misc/cgo/errors). This is not an exact roll back because parts of the code have changed since those CLs. Updates #29878 Fixes #31093 Change-Id: I56fe76c167ff0ab381ed273b9ca4b952402e1434 Reviewed-on: https://go-review.googlesource.com/c/go/+/180357 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
This commit is contained in:
parent
003dbc4cda
commit
ac921dad66
6 changed files with 22 additions and 76 deletions
|
|
@ -23,7 +23,6 @@ import (
|
|||
"internal/xcoff"
|
||||
"math"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
|
@ -2047,8 +2046,6 @@ type typeConv struct {
|
|||
|
||||
ptrSize int64
|
||||
intSize int64
|
||||
|
||||
exactWidthIntegerTypes map[string]*Type
|
||||
}
|
||||
|
||||
var tagGen int
|
||||
|
|
@ -2091,21 +2088,6 @@ func (c *typeConv) Init(ptrSize, intSize int64) {
|
|||
} else {
|
||||
c.goVoidPtr = c.Ident("unsafe.Pointer")
|
||||
}
|
||||
|
||||
c.exactWidthIntegerTypes = make(map[string]*Type)
|
||||
for _, t := range []ast.Expr{
|
||||
c.int8, c.int16, c.int32, c.int64,
|
||||
c.uint8, c.uint16, c.uint32, c.uint64,
|
||||
} {
|
||||
name := t.(*ast.Ident).Name
|
||||
u := new(Type)
|
||||
*u = *goTypes[name]
|
||||
if u.Align > ptrSize {
|
||||
u.Align = ptrSize
|
||||
}
|
||||
u.Go = t
|
||||
c.exactWidthIntegerTypes[name] = u
|
||||
}
|
||||
}
|
||||
|
||||
// base strips away qualifiers and typedefs to get the underlying type
|
||||
|
|
@ -2477,26 +2459,6 @@ func (c *typeConv) Type(dtype dwarf.Type, pos token.Pos) *Type {
|
|||
t.Align = c.ptrSize
|
||||
break
|
||||
}
|
||||
// Exact-width integer types. These are always compatible with
|
||||
// the corresponding Go types since the C standard requires
|
||||
// them to have no padding bit and use the two’s complement
|
||||
// representation.
|
||||
if exactWidthIntegerType.MatchString(dt.Name) {
|
||||
sub := c.Type(dt.Type, pos)
|
||||
goname := strings.TrimPrefix(dt.Name, "__")
|
||||
goname = strings.TrimSuffix(goname, "_t")
|
||||
u := c.exactWidthIntegerTypes[goname]
|
||||
if sub.Size != u.Size {
|
||||
fatalf("%s: unexpected size: %d vs. %d – %s", lineno(pos), sub.Size, u.Size, dtype)
|
||||
}
|
||||
if sub.Align != u.Align {
|
||||
fatalf("%s: unexpected alignment: %d vs. %d – %s", lineno(pos), sub.Align, u.Align, dtype)
|
||||
}
|
||||
t.Size = u.Size
|
||||
t.Align = u.Align
|
||||
t.Go = u.Go
|
||||
break
|
||||
}
|
||||
name := c.Ident("_Ctype_" + dt.Name)
|
||||
goIdent[name.Name] = name
|
||||
sub := c.Type(dt.Type, pos)
|
||||
|
|
@ -2632,8 +2594,6 @@ func (c *typeConv) Type(dtype dwarf.Type, pos token.Pos) *Type {
|
|||
return t
|
||||
}
|
||||
|
||||
var exactWidthIntegerType = regexp.MustCompile(`^(__)?u?int(8|16|32|64)_t$`)
|
||||
|
||||
// isStructUnionClass reports whether the type described by the Go syntax x
|
||||
// is a struct, union, or class with a tag.
|
||||
func isStructUnionClass(x ast.Expr) bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue