]> Cypherpunks repositories - gostls13.git/commitdiff
cgo: fix enum const conflict
authorGustavo Niemeyer <gustavo@niemeyer.net>
Tue, 11 Jan 2011 15:15:49 +0000 (10:15 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 11 Jan 2011 15:15:49 +0000 (10:15 -0500)
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

src/cmd/cgo/gcc.go

index 7626038c4babca228e515e92060c45c2e3d106b0..be3b8fe64a63eeacc374cb0eeb541dbe7868d130 100644 (file)
@@ -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
                        }
                }
        }