We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
package main //sys GetForegroundWindow() (hwnd syscall.Handle) = user32.GetForegroundWindow func main() { }
C:\temp>go run c:/go/src/syscall/mksyscall_windows.go -output bar.go foo.go
C:\temp>go build .\bar.go:5: imported and not used: "unsafe"
Since mksyscall_windows.go uses template, we should handle whether parameters has pointer before execute template. Most easy ways to fix this:
diff --git a/src/syscall/mksyscall_windows.go b/src/syscall/mksyscall_windows.go index cb540d3..3e29901 100644 --- a/src/syscall/mksyscall_windows.go +++ b/src/syscall/mksyscall_windows.go @@ -65,6 +65,7 @@ import ( var ( filename = flag.String("output", "", "output file name (standard output if omitted)") printTraceFlag = flag.Bool("trace", false, "generate print statement after every syscall") + hasUnsafe = false ) func trim(s string) string { @@ -171,10 +172,12 @@ func (p *Param) SyscallArgList() []string { var s string switch { case t[0] == '*': + hasUnsafe = true s = fmt.Sprintf("unsafe.Pointer(%s)", p.Name) case t == "bool": s = p.tmpVar() case strings.HasPrefix(t, "[]"): + hasUnsafe = true return []string{ fmt.Sprintf("uintptr(unsafe.Pointer(%s))", p.tmpVar()), fmt.Sprintf("uintptr(len(%s))", p.Name), @@ -306,6 +309,7 @@ func (r *Rets) SetErrorCode() string { s := "" switch { case r.Type[0] == '*': + hasUnsafe = true s = fmt.Sprintf("%s = (%s)(unsafe.Pointer(r0))", r.Name, r.Type) case r.Type == "bool": s = fmt.Sprintf("%s = r0 != 0", r.Name) @@ -716,6 +720,15 @@ func main() { if err != nil { log.Fatal(err) } + + // TODO: When there is pointer, unsafe package is needless. + if !hasUnsafe { + s := string(data) + if pos := strings.Index(s, "import \"unsafe\"\n"); pos >= 0 { + data = []byte(s[:pos] + s[pos+16:]) + } + } + if *filename == "" { _, err = os.Stdout.Write(data) } else {
The text was updated successfully, but these errors were encountered:
Or put dummy function which use unsafe.
Sorry, something went wrong.
The fix https://go-review.googlesource.com/5005
Alex
f208266
No branches or pull requests
Since mksyscall_windows.go uses template, we should handle whether parameters has pointer before execute template.
Most easy ways to fix this:
The text was updated successfully, but these errors were encountered: