code review 6498054: syscall: extract an ExampleLoadLibrary from comment (issue 6498054)

20 views
Skip to first unread message

minu...@gmail.com

unread,
Aug 29, 2012, 8:54:53 AM8/29/12
to golan...@googlegroups.com, golan...@googlegroups.com, re...@codereview-hr.appspotmail.com
Reviewers: golang-dev_googlegroups.com,

Message:
Hello golan...@googlegroups.com (cc: golan...@googlegroups.com),

I'd like you to review this change to
https://code.google.com/p/go/


Description:
syscall: extract an ExampleLoadLibrary from comment
while we are at it, fix some out-of-date comments.

Please review this at http://codereview.appspot.com/6498054/

Affected files:
M src/pkg/syscall/asm_windows_386.s
M src/pkg/syscall/asm_windows_amd64.s
M src/pkg/syscall/syscall_windows.go
M src/pkg/syscall/syscall_windows_test.go


Index: src/pkg/syscall/asm_windows_386.s
===================================================================
--- a/src/pkg/syscall/asm_windows_386.s
+++ b/src/pkg/syscall/asm_windows_386.s
@@ -3,5 +3,5 @@
// license that can be found in the LICENSE file.

//
-// System calls for 386, Windows are implemented
in ../runtime/windows/syscall.goc
+// System calls for 386, Windows are implemented
in ../runtime/syscall_windows.goc
//
Index: src/pkg/syscall/asm_windows_amd64.s
===================================================================
--- a/src/pkg/syscall/asm_windows_amd64.s
+++ b/src/pkg/syscall/asm_windows_amd64.s
@@ -3,5 +3,5 @@
// license that can be found in the LICENSE file.

//
-// System calls for amd64, Windows are implemented
in ../runtime/windows/syscall.goc
+// System calls for amd64, Windows are implemented
in ../runtime/syscall_windows.goc
//
Index: src/pkg/syscall/syscall_windows.go
===================================================================
--- a/src/pkg/syscall/syscall_windows.go
+++ b/src/pkg/syscall/syscall_windows.go
@@ -15,43 +15,6 @@

const InvalidHandle = ^Handle(0)

-/*
-
-small demo to detect version of windows you are running:
-
-package main
-
-import (
- "syscall"
-)
-
-func abort(funcname string, err error) {
- panic(funcname + " failed: " + err.Error())
-}
-
-func print_version(v uint32) {
- major := byte(v)
- minor := uint8(v >> 8)
- build := uint16(v >> 16)
- print("windows version ", major, ".", minor, " (Build ", build, ")\n")
-}
-
-func main() {
- h, err := syscall.LoadLibrary("kernel32.dll")
- if err != nil {
- abort("LoadLibrary", err)
- }
- defer syscall.FreeLibrary(h)
- proc, err := syscall.GetProcAddress(h, "GetVersion")
- if err != nil {
- abort("GetProcAddress", err)
- }
- r, _, _ := syscall.Syscall(uintptr(proc), 0, 0, 0, 0)
- print_version(uint32(r))
-}
-
-*/
-
// StringToUTF16 is deprecated. Use UTF16FromString instead.
// If s contains a NUL byte this function panics instead of
// returning an error.
@@ -142,7 +105,7 @@
// Converts a Go function to a function pointer conforming
// to the stdcall calling convention. This is useful when
// interoperating with Windows code requiring callbacks.
-// Implemented in ../runtime/windows/syscall.goc
+// Implemented in ../runtime/syscall_windows.goc
func NewCallback(fn interface{}) uintptr

// windows api calls
Index: src/pkg/syscall/syscall_windows_test.go
===================================================================
--- a/src/pkg/syscall/syscall_windows_test.go
+++ b/src/pkg/syscall/syscall_windows_test.go
@@ -49,3 +49,24 @@
t.Fatalf("memory corruption: want=%d got=%d", want, x.got)
}
}
+
+func abort(funcname string, err error) {
+ panic(funcname + " failed: " + err.Error())
+}
+
+func ExampleLoadLibrary() {
+ h, err := syscall.LoadLibrary("kernel32.dll")
+ if err != nil {
+ abort("LoadLibrary", err)
+ }
+ defer syscall.FreeLibrary(h)
+ proc, err := syscall.GetProcAddress(h, "GetVersion")
+ if err != nil {
+ abort("GetProcAddress", err)
+ }
+ r, _, _ := syscall.Syscall(uintptr(proc), 0, 0, 0, 0)
+ major := byte(r)
+ minor := uint8(r >> 8)
+ build := uint16(r >> 16)
+ print("windows version ", major, ".", minor, " (Build ", build, ")\n")
+}


Dave Cheney

unread,
Aug 29, 2012, 9:28:02 AM8/29/12
to re...@codereview-hr.appspotmail.com, minux, golan...@googlegroups.com

LGTM. Thank you for improving this.

r...@golang.org

unread,
Aug 29, 2012, 9:38:46 AM8/29/12
to minu...@gmail.com, golan...@googlegroups.com, da...@cheney.net, golan...@googlegroups.com, re...@codereview-hr.appspotmail.com

minu...@gmail.com

unread,
Aug 29, 2012, 9:45:28 AM8/29/12
to minu...@gmail.com, golan...@googlegroups.com, da...@cheney.net, r...@golang.org, re...@codereview-hr.appspotmail.com
*** Submitted as
http://code.google.com/p/go/source/detail?r=80be10893a8b ***

syscall: extract an ExampleLoadLibrary from comment
while we are at it, fix some out-of-date comments.

R=golang-dev, dave, r
CC=golang-dev
http://codereview.appspot.com/6498054


http://codereview.appspot.com/6498054/
Reply all
Reply to author
Forward
0 new messages