mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
cmd/cgo: use consistent tag for a particular struct
For #31891 Fixes #38408 Change-Id: Ie7498c2cab728ae798e66e7168425e16b063520e Reviewed-on: https://go-review.googlesource.com/c/go/+/228102 Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
This commit is contained in:
parent
cdaf8b6469
commit
33ff63da4e
@ -124,6 +124,11 @@ typedef struct {
|
|||||||
} Issue31891B;
|
} Issue31891B;
|
||||||
|
|
||||||
void callIssue31891(void);
|
void callIssue31891(void);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int i;
|
||||||
|
} Issue38408, *PIssue38408;
|
||||||
|
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
@ -552,3 +557,8 @@ func useIssue31891B(c *C.Issue31891B) {}
|
|||||||
func test31891(t *testing.T) {
|
func test31891(t *testing.T) {
|
||||||
C.callIssue31891()
|
C.callIssue31891()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// issue 38408
|
||||||
|
// A typedef pointer can be used as the element type.
|
||||||
|
// No runtime test; just make sure it compiles.
|
||||||
|
var _ C.PIssue38408 = &C.Issue38408{i: 1}
|
||||||
|
@ -2060,6 +2060,10 @@ var goIdent = make(map[string]*ast.Ident)
|
|||||||
// that may contain a pointer. This is used for cgo pointer checking.
|
// that may contain a pointer. This is used for cgo pointer checking.
|
||||||
var unionWithPointer = make(map[ast.Expr]bool)
|
var unionWithPointer = make(map[ast.Expr]bool)
|
||||||
|
|
||||||
|
// anonymousStructTag provides a consistent tag for an anonymous struct.
|
||||||
|
// The same dwarf.StructType pointer will always get the same tag.
|
||||||
|
var anonymousStructTag = make(map[*dwarf.StructType]string)
|
||||||
|
|
||||||
func (c *typeConv) Init(ptrSize, intSize int64) {
|
func (c *typeConv) Init(ptrSize, intSize int64) {
|
||||||
c.ptrSize = ptrSize
|
c.ptrSize = ptrSize
|
||||||
c.intSize = intSize
|
c.intSize = intSize
|
||||||
@ -2408,8 +2412,12 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if tag == "" {
|
if tag == "" {
|
||||||
tag = "__" + strconv.Itoa(tagGen)
|
tag = anonymousStructTag[dt]
|
||||||
tagGen++
|
if tag == "" {
|
||||||
|
tag = "__" + strconv.Itoa(tagGen)
|
||||||
|
tagGen++
|
||||||
|
anonymousStructTag[dt] = tag
|
||||||
|
}
|
||||||
} else if t.C.Empty() {
|
} else if t.C.Empty() {
|
||||||
t.C.Set(dt.Kind + " " + tag)
|
t.C.Set(dt.Kind + " " + tag)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user