From a49172663cb4082dcbafa8200b70c93b1c19314a Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Thu, 5 Jul 2012 15:24:33 -0400 Subject: [PATCH] cmd/cgo: make typedef map traversal order consistent So that _cgo_gotypes.go will be the same for the same source code. R=nigeltao CC=golang-dev https://golang.org/cl/6357067 --- src/cmd/cgo/out.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index 2ab974c979..ae572d6dc6 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -14,6 +14,7 @@ import ( "go/printer" "go/token" "os" + "sort" "strings" ) @@ -57,7 +58,13 @@ func (p *Package) writeDefs() { fmt.Fprintf(fgo2, "type _ unsafe.Pointer\n\n") fmt.Fprintf(fgo2, "func _Cerrno(dst *error, x int) { *dst = syscall.Errno(x) }\n") - for name, def := range typedef { + typedefNames := make([]string, 0, len(typedef)) + for name := range typedef { + typedefNames = append(typedefNames, name) + } + sort.Strings(typedefNames) + for _, name := range typedefNames { + def := typedef[name] fmt.Fprintf(fgo2, "type %s ", name) conf.Fprint(fgo2, fset, def.Go) fmt.Fprintf(fgo2, "\n\n")