Skip to content

Commit

Permalink
runtime: use EnumTimeFormatsEx instead of EnumWindows in callback tests
Browse files Browse the repository at this point in the history
Use EnumTimeFormatsEx() to test panics across callback boundaries
instead of EnumWindows(). EnumWindows() is incompatible with Go's panic
unwinding mechanism. See the associated issue for more information.

Updates #26148

Change-Id: If1dd70885d9c418b980b6827942cb1fd16c73803
Reviewed-on: https://go-review.googlesource.com/c/155923
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
  • Loading branch information
jordanrh1 authored and alexbrainman committed Dec 30, 2018
1 parent 58a17b4 commit 3e89272
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/runtime/syscall_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,18 @@ func TestEnumWindows(t *testing.T) {
}
}

func callback(hwnd syscall.Handle, lparam uintptr) uintptr {
func callback(timeFormatString unsafe.Pointer, lparam uintptr) uintptr {
(*(*func())(unsafe.Pointer(&lparam)))()
return 0 // stop enumeration
}

// nestedCall calls into Windows, back into Go, and finally to f.
func nestedCall(t *testing.T, f func()) {
c := syscall.NewCallback(callback)
d := GetDLL(t, "user32.dll")
d := GetDLL(t, "kernel32.dll")
defer d.Release()
d.Proc("EnumWindows").Call(c, uintptr(*(*unsafe.Pointer)(unsafe.Pointer(&f))))
const LOCALE_NAME_USER_DEFAULT = 0
d.Proc("EnumTimeFormatsEx").Call(c, LOCALE_NAME_USER_DEFAULT, 0, uintptr(*(*unsafe.Pointer)(unsafe.Pointer(&f))))
}

func TestCallback(t *testing.T) {
Expand Down

0 comments on commit 3e89272

Please sign in to comment.