]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: warn not to use FormatMessage
authorAlex Brainman <alex.brainman@gmail.com>
Mon, 13 Jul 2015 00:55:49 +0000 (10:55 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Tue, 21 Jul 2015 02:26:27 +0000 (02:26 +0000)
Fixes #11147

Change-Id: Ib31160946a53f6f9b11daea211ff04d186b51b3f
Reviewed-on: https://go-review.googlesource.com/12067
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/syscall/syscall_windows.go
src/syscall/zsyscall_windows.go

index 23035ac3872f774f3d22bed63319b72edca9b6c3..1006a9b72a662f1469021160cf30d3c997a916c4 100644 (file)
@@ -82,6 +82,14 @@ type Errno uintptr
 
 func langid(pri, sub uint16) uint32 { return uint32(sub)<<10 | uint32(pri) }
 
+// FormatMessage is deprecated (msgsrc should be uintptr, not uint32, but can
+// not be changed due to the Go 1 compatibility guarantee).
+//
+// Deprecated: Use FormatMessage from golang.org/x/sys/windows instead.
+func FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
+       return formatMessage(flags, uintptr(msgsrc), msgid, langid, buf, args)
+}
+
 func (e Errno) Error() string {
        // deal with special go errors
        idx := int(e - APPLICATION_ERROR)
@@ -91,9 +99,9 @@ func (e Errno) Error() string {
        // ask windows for the remaining errors
        var flags uint32 = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_IGNORE_INSERTS
        b := make([]uint16, 300)
-       n, err := FormatMessage(flags, 0, uint32(e), langid(LANG_ENGLISH, SUBLANG_ENGLISH_US), b, nil)
+       n, err := formatMessage(flags, 0, uint32(e), langid(LANG_ENGLISH, SUBLANG_ENGLISH_US), b, nil)
        if err != nil {
-               n, err = FormatMessage(flags, 0, uint32(e), 0, b, nil)
+               n, err = formatMessage(flags, 0, uint32(e), 0, b, nil)
                if err != nil {
                        return "winapi error #" + itoa(int(e))
                }
@@ -136,7 +144,7 @@ func NewCallbackCDecl(fn interface{}) uintptr {
 //sys  FreeLibrary(handle Handle) (err error)
 //sys  GetProcAddress(module Handle, procname string) (proc uintptr, err error)
 //sys  GetVersion() (ver uint32, err error)
-//sys  FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) = FormatMessageW
+//sys  formatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) = FormatMessageW
 //sys  ExitProcess(exitcode uint32)
 //sys  CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile int32) (handle Handle, err error) [failretval==InvalidHandle] = CreateFileW
 //sys  ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error)
index ba62499f4efae3f7e76008d0afd7804e1dad783d..7879ba1aa5c4a980e526bdd5dfb592033cb00179 100644 (file)
@@ -240,7 +240,7 @@ func GetVersion() (ver uint32, err error) {
        return
 }
 
-func FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
+func formatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
        var _p0 *uint16
        if len(buf) > 0 {
                _p0 = &buf[0]