aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShenghou Ma <minux@golang.org>2015-02-16 23:43:40 -0500
committerAndrew Gerrand <adg@golang.org>2015-02-17 06:51:18 +0000
commit3124622303cd50e9b5965ea4dd68ef294e1a4404 (patch)
treecef78fd596f942871ee03ef552156782831cfc55
parenta25564577071b7c8592356620f2dcbf53eeca9bb (diff)
downloadgo-3124622303cd50e9b5965ea4dd68ef294e1a4404.tar.gz
go-3124622303cd50e9b5965ea4dd68ef294e1a4404.zip
[release-branch.go1.4] runtime: don't panic when given a callback with no input params on windows
Fixes #9871 for Go 1.4. Change-Id: I550a5bdb29e9a872652e0dd468a434227d7d9502 Reviewed-on: https://go-review.googlesource.com/4937 Run-TryBot: Minux Ma <minux@golang.org> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Andrew Gerrand <adg@golang.org>
-rw-r--r--src/runtime/syscall_windows.go10
-rw-r--r--src/runtime/syscall_windows_test.go8
2 files changed, 14 insertions, 4 deletions
diff --git a/src/runtime/syscall_windows.go b/src/runtime/syscall_windows.go
index 5b76ad573c3..51004b78a02 100644
--- a/src/runtime/syscall_windows.go
+++ b/src/runtime/syscall_windows.go
@@ -54,11 +54,13 @@ func compileCallback(fn eface, cleanstack bool) (code uintptr) {
panic("compilecallback: output parameter size is wrong")
}
argsize := uintptr(0)
- for _, t := range (*[1024](*_type))(unsafe.Pointer(&ft.in[0]))[:len(ft.in)] {
- if (*t).size > uintptrSize {
- panic("compilecallback: input parameter size is wrong")
+ if len(ft.in) > 0 {
+ for _, t := range (*[1024](*_type))(unsafe.Pointer(&ft.in[0]))[:len(ft.in)] {
+ if (*t).size > uintptrSize {
+ panic("compilecallback: input parameter size is wrong")
+ }
+ argsize += uintptrSize
}
- argsize += uintptrSize
}
lock(&cbs.lock)
diff --git a/src/runtime/syscall_windows_test.go b/src/runtime/syscall_windows_test.go
index ce8a9ec1ba9..126bef62eff 100644
--- a/src/runtime/syscall_windows_test.go
+++ b/src/runtime/syscall_windows_test.go
@@ -533,3 +533,11 @@ func main() {
println(z)
}
`
+
+func TestCallbackWithNoInputParameters(t *testing.T) {
+ // Test that NewCallback and NewCallbackCDecl can accept functions without
+ // input parameters, see issue 9871.
+ cb := func() uintptr { return 0 }
+ _ = syscall.NewCallback(cb)
+ _ = syscall.NewCallbackCDecl(cb)
+}