]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.4] runtime: don't panic when given a callback with no input param...
authorShenghou Ma <minux@golang.org>
Tue, 17 Feb 2015 04:43:40 +0000 (23:43 -0500)
committerAndrew Gerrand <adg@golang.org>
Tue, 17 Feb 2015 06:51:18 +0000 (06:51 +0000)
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>
src/runtime/syscall_windows.go
src/runtime/syscall_windows_test.go

index 5b76ad573c31df384ee5d00a21424e11ba0f5958..51004b78a0271a5ce535568c26f5a11756a2f9ee 100644 (file)
@@ -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)
index ce8a9ec1ba9e974b9f270fa2f59c331b42df74ff..126bef62eff950683f4234bc2122c99763d3d467 100644 (file)
@@ -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)
+}