From 457b0205450ea8fdb557ebef19a148378715289e Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Fri, 9 Apr 2021 15:28:17 +0100 Subject: [PATCH] Documentation, fixes. --- file_windows.go | 5 +++-- list.go | 4 ++-- msg_windows.go | 2 ++ util_windows.go | 10 ++++------ 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/file_windows.go b/file_windows.go index 2c0d2d9..4ee3478 100644 --- a/file_windows.go +++ b/file_windows.go @@ -3,6 +3,7 @@ package zenity import ( "path/filepath" "reflect" + "runtime" "syscall" "unicode/utf16" "unsafe" @@ -311,14 +312,14 @@ func browseForFolder(opts options) (string, []string, error) { args.Title = syscall.StringToUTF16Ptr(*opts.title) } if opts.filename != "" { - ptr := syscall.StringToUTF16Ptr(opts.filename) - args.LParam = uintptr(unsafe.Pointer(ptr)) + args.LParam = strptr(opts.filename) args.CallbackFunc = syscall.NewCallback(func(wnd uintptr, msg uint32, lparam, data uintptr) uintptr { if msg == 1 { // BFFM_INITIALIZED sendMessage.Call(wnd, 1024+103 /* BFFM_SETSELECTIONW */, 1 /* TRUE */, data) } return 0 }) + defer runtime.KeepAlive(opts.filename) } if opts.ctx != nil { diff --git a/list.go b/list.go index 4363e49..d3acebd 100644 --- a/list.go +++ b/list.go @@ -27,14 +27,14 @@ func ListMultiple(text string, items []string, options ...Option) ([]string, err return listMultiple(text, items, applyOptions(options)) } -// ListMultiple displays the list dialog, allowing multiple items to be selected. +// ListMultipleItems displays the list dialog, allowing multiple items to be selected. // // Returns a nil slice on cancel, or ErrExtraButton. func ListMultipleItems(text string, items ...string) ([]string, error) { return ListMultiple(text, items) } -// DefaultItems returns an Option to set the items to initally select (macOS only). +// DefaultItems returns an Option to set the items to initially select (macOS only). func DefaultItems(items ...string) Option { return funcOption(func(o *options) { o.defaultItems = items }) } diff --git a/msg_windows.go b/msg_windows.go index 33e082e..0f4214e 100644 --- a/msg_windows.go +++ b/msg_windows.go @@ -2,6 +2,7 @@ package zenity import ( "context" + "runtime" "syscall" "unsafe" ) @@ -55,6 +56,7 @@ func message(kind messageKind, text string, opts options) (bool, error) { var title uintptr if opts.title != nil { title = strptr(*opts.title) + defer runtime.KeepAlive(*opts.title) } s, _, err := messageBox.Call(0, strptr(text), title, flags) diff --git a/util_windows.go b/util_windows.go index 0f32ae5..c199bd7 100644 --- a/util_windows.go +++ b/util_windows.go @@ -409,15 +409,13 @@ func uuid(s string) uintptr { type _COMObject struct{} func (o *_COMObject) Call(trap uintptr, a ...uintptr) (r1, r2 uintptr, lastErr error) { - self := uintptr(unsafe.Pointer(o)) - nargs := uintptr(len(a)) - switch nargs { + switch nargs := uintptr(len(a)); nargs { case 0: - return syscall.Syscall(trap, nargs+1, self, 0, 0) + return syscall.Syscall(trap, nargs+1, uintptr(unsafe.Pointer(o)), 0, 0) case 1: - return syscall.Syscall(trap, nargs+1, self, a[0], 0) + return syscall.Syscall(trap, nargs+1, uintptr(unsafe.Pointer(o)), a[0], 0) case 2: - return syscall.Syscall(trap, nargs+1, self, a[0], a[1]) + return syscall.Syscall(trap, nargs+1, uintptr(unsafe.Pointer(o)), a[0], a[1]) default: panic("COM call with too many arguments.") }