From: Gustavo Niemeyer Date: Tue, 11 Jan 2011 15:15:49 +0000 (-0500) Subject: cgo: fix enum const conflict X-Git-Tag: weekly.2011-01-12~32 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=02ff646fef25769c7ba756fcdf03f13b7afbf4f3;p=gostls13.git cgo: fix enum const conflict This change prevents enum consts from conflicting with themselves when loaded twice in different go files. Fixes #1400. R=rsc CC=golang-dev https://golang.org/cl/3849044 --- diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index 7626038c4b..be3b8fe64a 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -372,8 +372,12 @@ func (p *Package) loadDWARF(f *File, names []*Name) { } else { n.Type = conv.Type(types[i]) if enums[i] != 0 && n.Type.EnumValues != nil { + k := fmt.Sprintf("__cgo_enum__%d", i) n.Kind = "const" - n.Const = strconv.Itoa64(n.Type.EnumValues[fmt.Sprintf("__cgo_enum__%d", i)]) + n.Const = strconv.Itoa64(n.Type.EnumValues[k]) + // Remove injected enum to ensure the value will deep-compare + // equally in future loads of the same constant. + n.Type.EnumValues[k] = 0, false } } }