windows/mkwinsyscall: deduplicate functions before printing variables

The same symbol name might be defined multiple times with different
function names or signatures. In that case, it's an error to redefine
the proc variable. So deduplicate these before printing.

Change-Id: I7a636cd44fb1ea6f51840ef3924d6316e266faa0
Reviewed-on: https://go-review.googlesource.com/c/sys/+/288332
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Jason A. Donenfeld
2021-01-30 20:42:56 +01:00
parent 134d130e1a
commit 78dc250343

View File

@@ -644,6 +644,7 @@ func (f *Fn) HelperName() string {
// Source files and functions.
type Source struct {
Funcs []*Fn
DLLFuncNames []*Fn
Files []string
StdLibImports []string
ExternalImports []string
@@ -676,6 +677,15 @@ func ParseFiles(fs []string) (*Source, error) {
return nil, err
}
}
src.DLLFuncNames = make([]*Fn, 0, len(src.Funcs))
uniq := make(map[string]bool, len(src.Funcs))
for _, fn := range src.Funcs {
name := fn.DLLFuncName()
if !uniq[name] {
src.DLLFuncNames = append(src.DLLFuncNames, fn)
uniq[name] = true
}
}
return src, nil
}
@@ -920,7 +930,7 @@ var (
{{define "dlls"}}{{range .DLLs}} mod{{.}} = {{newlazydll .}}
{{end}}{{end}}
{{define "funcnames"}}{{range .Funcs}} proc{{.DLLFuncName}} = mod{{.DLLName}}.NewProc("{{.DLLFuncName}}")
{{define "funcnames"}}{{range .DLLFuncNames}} proc{{.DLLFuncName}} = mod{{.DLLName}}.NewProc("{{.DLLFuncName}}")
{{end}}{{end}}
{{define "helperbody"}}