Commit ca264cdc authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

syscall: avoid convT2I allocs for common Windows error values

This is was already done for Unix in https://golang.org/cl/6701 +
https://golang.org/cl/8192. Do it for Windows also.

Fixes #16988

Change-Id: Ia7832b0d0d48566b0cd205652b85130df529592e
Reviewed-on: https://go-review.googlesource.com/28484
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarJosh Bleecher Snyder <josharian@gmail.com>
parent 238274df
......@@ -10,6 +10,31 @@ import (
var _ unsafe.Pointer
// Do the interface allocations only once for common
// Errno values.
const (
errnoWSAEINPROGRESS = 10036
)
var (
errWSAEINPROGRESS error = syscall.Errno(errnoWSAEINPROGRESS)
)
// errnoErr returns common boxed Errno values, to prevent
// allocations at runtime.
func errnoErr(e syscall.Errno) error {
switch e {
case 0:
return nil
case errnoWSAEINPROGRESS:
return errWSAEINPROGRESS
}
// TODO: add more here, after collecting data on the common
// error values see on Windows. (perhaps when running
// all.bat?)
return e
}
var (
modadvapi32 = syscall.NewLazyDLL(sysdll.Add("advapi32.dll"))
modkernel32 = syscall.NewLazyDLL(sysdll.Add("kernel32.dll"))
......@@ -76,7 +101,7 @@ func expandEnvironmentStrings(src *uint16, dst *uint16, size uint32) (n uint32,
n = uint32(r0)
if n == 0 {
if e1 != 0 {
err = error(e1)
err = errnoErr(e1)
} else {
err = syscall.EINVAL
}
......
......@@ -10,6 +10,31 @@ import (
var _ unsafe.Pointer
// Do the interface allocations only once for common
// Errno values.
const (
errnoWSAEINPROGRESS = 10036
)
var (
errWSAEINPROGRESS error = syscall.Errno(errnoWSAEINPROGRESS)
)
// errnoErr returns common boxed Errno values, to prevent
// allocations at runtime.
func errnoErr(e syscall.Errno) error {
switch e {
case 0:
return nil
case errnoWSAEINPROGRESS:
return errWSAEINPROGRESS
}
// TODO: add more here, after collecting data on the common
// error values see on Windows. (perhaps when running
// all.bat?)
return e
}
var (
modiphlpapi = syscall.NewLazyDLL(sysdll.Add("iphlpapi.dll"))
modkernel32 = syscall.NewLazyDLL(sysdll.Add("kernel32.dll"))
......@@ -33,7 +58,7 @@ func GetComputerNameEx(nameformat uint32, buf *uint16, n *uint32) (err error) {
r1, _, e1 := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nameformat), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)))
if r1 == 0 {
if e1 != 0 {
err = error(e1)
err = errnoErr(e1)
} else {
err = syscall.EINVAL
}
......@@ -45,7 +70,7 @@ func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) {
r1, _, e1 := syscall.Syscall(procMoveFileExW.Addr(), 3, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags))
if r1 == 0 {
if e1 != 0 {
err = error(e1)
err = errnoErr(e1)
} else {
err = syscall.EINVAL
}
......@@ -64,7 +89,7 @@ func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32,
nwrite = int32(r0)
if nwrite == 0 {
if e1 != 0 {
err = error(e1)
err = errnoErr(e1)
} else {
err = syscall.EINVAL
}
......
......@@ -281,7 +281,7 @@ func (r *Rets) SetReturnValuesCode() string {
func (r *Rets) useLongHandleErrorCode(retvar string) string {
const code = `if %s {
if e1 != 0 {
err = error(e1)
err = errnoErr(e1)
} else {
err = %sEINVAL
}
......@@ -829,6 +829,31 @@ import (
var _ unsafe.Pointer
// Do the interface allocations only once for common
// Errno values.
const (
errnoWSAEINPROGRESS = 10036
)
var (
errWSAEINPROGRESS error = {{syscalldot}}Errno(errnoWSAEINPROGRESS)
)
// errnoErr returns common boxed Errno values, to prevent
// allocations at runtime.
func errnoErr(e {{syscalldot}}Errno) error {
switch e {
case 0:
return nil
case errnoWSAEINPROGRESS:
return errWSAEINPROGRESS
}
// TODO: add more here, after collecting data on the common
// error values see on Windows. (perhaps when running
// all.bat?)
return e
}
var (
{{template "dlls" .}}
{{template "funcnames" .}})
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment