]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: make typedef map traversal order consistent
authorShenghou Ma <minux.ma@gmail.com>
Thu, 5 Jul 2012 19:24:33 +0000 (15:24 -0400)
committerShenghou Ma <minux.ma@gmail.com>
Thu, 5 Jul 2012 19:24:33 +0000 (15:24 -0400)
        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

index 2ab974c9793ca8bb6879ed947458a659305559b3..ae572d6dc6d16af04dd482dd634e04cc7a421533 100644 (file)
@@ -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")