mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/cgo: ignore top-level qualifiers in function args/results
The top-level qualifiers are unimportant for our purposes. If a C function is defined as `const int f(const int i)`, the `const`s are meaningless to C, and we want to avoid using them in the struct we create where the `const` has a completely different meaning. This unwinds https://golang.org/cl/33097 with regard to top-level qualifiers. Change-Id: I3d66b0eb43b6d9a586d9cdedfae5a2306b46d96c Reviewed-on: https://go-review.googlesource.com/33325 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
This commit is contained in:
parent
c1e9760d4c
commit
7061dc3f6e
2 changed files with 16 additions and 3 deletions
|
|
@ -1476,6 +1476,19 @@ func base(dt dwarf.Type) dwarf.Type {
|
|||
return dt
|
||||
}
|
||||
|
||||
// unqual strips away qualifiers from a DWARF type.
|
||||
// In general we don't care about top-level qualifiers.
|
||||
func unqual(dt dwarf.Type) dwarf.Type {
|
||||
for {
|
||||
if d, ok := dt.(*dwarf.QualType); ok {
|
||||
dt = d.Type
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return dt
|
||||
}
|
||||
|
||||
// Map from dwarf text names to aliases we use in package "C".
|
||||
var dwarfToName = map[string]string{
|
||||
"long int": "long",
|
||||
|
|
@ -1930,7 +1943,7 @@ func isStructUnionClass(x ast.Expr) bool {
|
|||
// FuncArg returns a Go type with the same memory layout as
|
||||
// dtype when used as the type of a C function argument.
|
||||
func (c *typeConv) FuncArg(dtype dwarf.Type, pos token.Pos) *Type {
|
||||
t := c.Type(dtype, pos)
|
||||
t := c.Type(unqual(dtype), pos)
|
||||
switch dt := dtype.(type) {
|
||||
case *dwarf.ArrayType:
|
||||
// Arrays are passed implicitly as pointers in C.
|
||||
|
|
@ -1994,7 +2007,7 @@ func (c *typeConv) FuncType(dtype *dwarf.FuncType, pos token.Pos) *FuncType {
|
|||
if _, ok := dtype.ReturnType.(*dwarf.VoidType); ok {
|
||||
gr = []*ast.Field{{Type: c.goVoid}}
|
||||
} else if dtype.ReturnType != nil {
|
||||
r = c.Type(dtype.ReturnType, pos)
|
||||
r = c.Type(unqual(dtype.ReturnType), pos)
|
||||
gr = []*ast.Field{{Type: r.Go}}
|
||||
}
|
||||
return &FuncType{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue