Skip to content

Commit 20bee3c

Browse files
authored
Update golangci-lint action. (jchv#42)
* Update golangci-lint action. * Update comproc for Go 1.18.
1 parent fa41ec7 commit 20bee3c

File tree

5 files changed

+85
-56
lines changed

5 files changed

+85
-56
lines changed

.github/workflows/go.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ jobs:
3333
runs-on: windows-latest
3434
steps:
3535
- uses: actions/checkout@v2
36+
- uses: actions/setup-go@v3
37+
with:
38+
go-version: 1.18
3639
- name: Lint
37-
uses: golangci/golangci-lint-action@v2
40+
uses: golangci/golangci-lint-action@v3
3841
with:
39-
version: v1.44
42+
version: v1.45

pkg/edge/comproc.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package edge
2+
3+
import (
4+
"golang.org/x/sys/windows"
5+
)
6+
7+
// ComProc stores a COM procedure.
8+
type ComProc uintptr
9+
10+
// NewComProc creates a new COM proc from a Go function.
11+
func NewComProc(fn interface{}) ComProc {
12+
return ComProc(windows.NewCallback(fn))
13+
}

pkg/edge/comproc_go17.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//go:build !go1.18
2+
// +build !go1.18
3+
4+
package edge
5+
6+
import "syscall"
7+
8+
//go:uintptrescapes
9+
// Call calls a COM procedure.
10+
func (p ComProc) Call(a ...uintptr) (r1, r2 uintptr, lastErr error) {
11+
// The magic uintptrescapes comment is needed to prevent moving uintptr(unsafe.Pointer(p)) so calls to .Call() also
12+
// satisfy the unsafe.Pointer rule "(4) Conversion of a Pointer to a uintptr when calling syscall.Syscall."
13+
// Otherwise it might be that pointers get moved, especially pointer onto the Go stack which might grow dynamically.
14+
// See https://pkg.go.dev/unsafe#Pointer and https://github.com/golang/go/issues/34474
15+
switch len(a) {
16+
case 0:
17+
return syscall.Syscall(uintptr(p), 0, 0, 0, 0)
18+
case 1:
19+
return syscall.Syscall(uintptr(p), 1, a[0], 0, 0)
20+
case 2:
21+
return syscall.Syscall(uintptr(p), 2, a[0], a[1], 0)
22+
case 3:
23+
return syscall.Syscall(uintptr(p), 3, a[0], a[1], a[2])
24+
case 4:
25+
return syscall.Syscall6(uintptr(p), 4, a[0], a[1], a[2], a[3], 0, 0)
26+
case 5:
27+
return syscall.Syscall6(uintptr(p), 5, a[0], a[1], a[2], a[3], a[4], 0)
28+
case 6:
29+
return syscall.Syscall6(uintptr(p), 6, a[0], a[1], a[2], a[3], a[4], a[5])
30+
case 7:
31+
return syscall.Syscall9(uintptr(p), 7, a[0], a[1], a[2], a[3], a[4], a[5], a[6], 0, 0)
32+
case 8:
33+
return syscall.Syscall9(uintptr(p), 8, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], 0)
34+
case 9:
35+
return syscall.Syscall9(uintptr(p), 9, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8])
36+
case 10:
37+
return syscall.Syscall12(uintptr(p), 10, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], 0, 0)
38+
case 11:
39+
return syscall.Syscall12(uintptr(p), 11, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], 0)
40+
case 12:
41+
return syscall.Syscall12(uintptr(p), 12, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11])
42+
case 13:
43+
return syscall.Syscall15(uintptr(p), 13, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], 0, 0)
44+
case 14:
45+
return syscall.Syscall15(uintptr(p), 14, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], 0)
46+
case 15:
47+
return syscall.Syscall15(uintptr(p), 15, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14])
48+
default:
49+
panic("too many arguments")
50+
}
51+
}

pkg/edge/comproc_go18.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//go:build go1.18
2+
// +build go1.18
3+
4+
package edge
5+
6+
import "syscall"
7+
8+
//go:uintptrescapes
9+
// Call calls a COM procedure.
10+
func (p ComProc) Call(a ...uintptr) (r1, r2 uintptr, lastErr error) {
11+
// The magic uintptrescapes comment is needed to prevent moving uintptr(unsafe.Pointer(p)) so calls to .Call() also
12+
// satisfy the unsafe.Pointer rule "(4) Conversion of a Pointer to a uintptr when calling syscall.Syscall."
13+
// Otherwise it might be that pointers get moved, especially pointer onto the Go stack which might grow dynamically.
14+
// See https://pkg.go.dev/unsafe#Pointer and https://github.com/golang/go/issues/34474
15+
return syscall.SyscallN(uintptr(p), a...)
16+
}

pkg/edge/corewebview2.go

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package edge
66
import (
77
"log"
88
"runtime"
9-
"syscall"
109
"unsafe"
1110

1211
"github.com/jchv/go-webview2/internal/w32"
@@ -57,59 +56,6 @@ func createCoreWebView2EnvironmentWithOptions(browserExecutableFolder, userDataF
5756
)
5857
}
5958

60-
// ComProc stores a COM procedure.
61-
type ComProc uintptr
62-
63-
// NewComProc creates a new COM proc from a Go function.
64-
func NewComProc(fn interface{}) ComProc {
65-
return ComProc(windows.NewCallback(fn))
66-
}
67-
68-
//go:uintptrescapes
69-
// Call calls a COM procedure.
70-
func (p ComProc) Call(a ...uintptr) (r1, r2 uintptr, lastErr error) {
71-
// The magic uintptrescapes comment is needed to prevent moving uintptr(unsafe.Pointer(p)) so calls to .Call() also
72-
// satisfy the unsafe.Pointer rule "(4) Conversion of a Pointer to a uintptr when calling syscall.Syscall."
73-
// Otherwise it might be that pointers get moved, especially pointer onto the Go stack which might grow dynamically.
74-
// See https://pkg.go.dev/unsafe#Pointer and https://github.com/golang/go/issues/34474
75-
switch len(a) {
76-
case 0:
77-
return syscall.Syscall(uintptr(p), 0, 0, 0, 0)
78-
case 1:
79-
return syscall.Syscall(uintptr(p), 1, a[0], 0, 0)
80-
case 2:
81-
return syscall.Syscall(uintptr(p), 2, a[0], a[1], 0)
82-
case 3:
83-
return syscall.Syscall(uintptr(p), 3, a[0], a[1], a[2])
84-
case 4:
85-
return syscall.Syscall6(uintptr(p), 4, a[0], a[1], a[2], a[3], 0, 0)
86-
case 5:
87-
return syscall.Syscall6(uintptr(p), 5, a[0], a[1], a[2], a[3], a[4], 0)
88-
case 6:
89-
return syscall.Syscall6(uintptr(p), 6, a[0], a[1], a[2], a[3], a[4], a[5])
90-
case 7:
91-
return syscall.Syscall9(uintptr(p), 7, a[0], a[1], a[2], a[3], a[4], a[5], a[6], 0, 0)
92-
case 8:
93-
return syscall.Syscall9(uintptr(p), 8, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], 0)
94-
case 9:
95-
return syscall.Syscall9(uintptr(p), 9, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8])
96-
case 10:
97-
return syscall.Syscall12(uintptr(p), 10, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], 0, 0)
98-
case 11:
99-
return syscall.Syscall12(uintptr(p), 11, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], 0)
100-
case 12:
101-
return syscall.Syscall12(uintptr(p), 12, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11])
102-
case 13:
103-
return syscall.Syscall15(uintptr(p), 13, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], 0, 0)
104-
case 14:
105-
return syscall.Syscall15(uintptr(p), 14, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], 0)
106-
case 15:
107-
return syscall.Syscall15(uintptr(p), 15, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14])
108-
default:
109-
panic("too many arguments")
110-
}
111-
}
112-
11359
// IUnknown
11460

11561
type _IUnknownVtbl struct {

0 commit comments

Comments
 (0)