Skip to content

Commit 3bea369

Browse files
committed
Update to go 1.21
Use `atomic.Bool` stdlib instead of including our own. Include `tools\mkwinsyscall` updates from go-winio/283 to switch to `syscallN`. Note: removed `// TODO` about `print`/`ln`, since the latter adds spaces between args when printing, which is undesired. Signed-off-by: Hamza El-Saawy <[email protected]>
1 parent 008bc6e commit 3bea369

File tree

16 files changed

+83
-207
lines changed

16 files changed

+83
-207
lines changed

Diff for: .github/workflows/ci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
env:
77
GO_VERSION: "oldstable"
88
GOTESTSUM_VERSION: "latest"
9+
GOLANGCILINT_VERSION: "latest"
910

1011
jobs:
1112
lint:
@@ -26,7 +27,7 @@ jobs:
2627
- name: Run golangci-lint
2728
uses: golangci/golangci-lint-action@v3
2829
with:
29-
version: v1.53
30+
version: ${{ env.GOLANGCILINT_VERSION }}
3031
args: >-
3132
--verbose
3233
--timeout=5m

Diff for: file.go

+12-30
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,6 @@ import (
2121
//sys setFileCompletionNotificationModes(h windows.Handle, flags uint8) (err error) = SetFileCompletionNotificationModes
2222
//sys wsaGetOverlappedResult(h windows.Handle, o *windows.Overlapped, bytes *uint32, wait bool, flags *uint32) (err error) = ws2_32.WSAGetOverlappedResult
2323

24-
//todo (go1.19): switch to [atomic.Bool]
25-
26-
type atomicBool int32
27-
28-
func (b *atomicBool) isSet() bool { return atomic.LoadInt32((*int32)(b)) != 0 }
29-
func (b *atomicBool) setFalse() { atomic.StoreInt32((*int32)(b), 0) }
30-
func (b *atomicBool) setTrue() { atomic.StoreInt32((*int32)(b), 1) }
31-
32-
//revive:disable-next-line:predeclared Keep "new" to maintain consistency with "atomic" pkg
33-
func (b *atomicBool) swap(new bool) bool {
34-
var newInt int32
35-
if new {
36-
newInt = 1
37-
}
38-
return atomic.SwapInt32((*int32)(b), newInt) == 1
39-
}
40-
4124
var (
4225
ErrFileClosed = errors.New("file has already been closed")
4326
ErrTimeout = &timeoutError{}
@@ -81,7 +64,7 @@ type win32File struct {
8164
handle windows.Handle
8265
wg sync.WaitGroup
8366
wgLock sync.RWMutex
84-
closing atomicBool
67+
closing atomic.Bool
8568
socket bool
8669
readDeadline deadlineHandler
8770
writeDeadline deadlineHandler
@@ -92,7 +75,7 @@ type deadlineHandler struct {
9275
channel timeoutChan
9376
channelLock sync.RWMutex
9477
timer *time.Timer
95-
timedout atomicBool
78+
timedout atomic.Bool
9679
}
9780

9881
// makeWin32File makes a new win32File from an existing file handle.
@@ -131,7 +114,7 @@ func NewOpenFile(h windows.Handle) (io.ReadWriteCloser, error) {
131114
func (f *win32File) closeHandle() {
132115
f.wgLock.Lock()
133116
// Atomically set that we are closing, releasing the resources only once.
134-
if !f.closing.swap(true) {
117+
if !f.closing.Swap(true) {
135118
f.wgLock.Unlock()
136119
// cancel all IO and wait for it to complete
137120
_ = cancelIoEx(f.handle, nil)
@@ -152,14 +135,14 @@ func (f *win32File) Close() error {
152135

153136
// IsClosed checks if the file has been closed.
154137
func (f *win32File) IsClosed() bool {
155-
return f.closing.isSet()
138+
return f.closing.Load()
156139
}
157140

158141
// prepareIO prepares for a new IO operation.
159142
// The caller must call f.wg.Done() when the IO is finished, prior to Close() returning.
160143
func (f *win32File) prepareIO() (*ioOperation, error) {
161144
f.wgLock.RLock()
162-
if f.closing.isSet() {
145+
if f.closing.Load() {
163146
f.wgLock.RUnlock()
164147
return nil, ErrFileClosed
165148
}
@@ -193,7 +176,7 @@ func (f *win32File) asyncIO(c *ioOperation, d *deadlineHandler, bytes uint32, er
193176
return int(bytes), err
194177
}
195178

196-
if f.closing.isSet() {
179+
if f.closing.Load() {
197180
_ = cancelIoEx(f.handle, &c.o)
198181
}
199182

@@ -209,7 +192,7 @@ func (f *win32File) asyncIO(c *ioOperation, d *deadlineHandler, bytes uint32, er
209192
case r = <-c.ch:
210193
err = r.err
211194
if err == windows.ERROR_OPERATION_ABORTED { //nolint:errorlint // err is Errno
212-
if f.closing.isSet() {
195+
if f.closing.Load() {
213196
err = ErrFileClosed
214197
}
215198
} else if err != nil && f.socket {
@@ -242,7 +225,7 @@ func (f *win32File) Read(b []byte) (int, error) {
242225
}
243226
defer f.wg.Done()
244227

245-
if f.readDeadline.timedout.isSet() {
228+
if f.readDeadline.timedout.Load() {
246229
return 0, ErrTimeout
247230
}
248231

@@ -256,9 +239,8 @@ func (f *win32File) Read(b []byte) (int, error) {
256239
return 0, io.EOF
257240
} else if err == windows.ERROR_BROKEN_PIPE { //nolint:errorlint // err is Errno
258241
return 0, io.EOF
259-
} else {
260-
return n, err
261242
}
243+
return n, err
262244
}
263245

264246
// Write writes to a file handle.
@@ -269,7 +251,7 @@ func (f *win32File) Write(b []byte) (int, error) {
269251
}
270252
defer f.wg.Done()
271253

272-
if f.writeDeadline.timedout.isSet() {
254+
if f.writeDeadline.timedout.Load() {
273255
return 0, ErrTimeout
274256
}
275257

@@ -306,7 +288,7 @@ func (d *deadlineHandler) set(deadline time.Time) error {
306288
}
307289
d.timer = nil
308290
}
309-
d.timedout.setFalse()
291+
d.timedout.Store(false)
310292

311293
select {
312294
case <-d.channel:
@@ -321,7 +303,7 @@ func (d *deadlineHandler) set(deadline time.Time) error {
321303
}
322304

323305
timeoutIO := func() {
324-
d.timedout.setTrue()
306+
d.timedout.Store(true)
325307
close(d.channel)
326308
}
327309

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/Microsoft/go-winio
22

3-
go 1.17
3+
go 1.21
44

55
require (
66
github.com/sirupsen/logrus v1.9.3

Diff for: go.sum

-38
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,15 @@ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVs
88
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
99
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
1010
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
11-
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
12-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
13-
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
14-
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
15-
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
16-
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
1711
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
1812
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
19-
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
20-
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
21-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
22-
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
23-
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
24-
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
25-
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
26-
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
27-
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
2813
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
2914
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
30-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
31-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
32-
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
33-
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3415
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
35-
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
36-
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
37-
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3816
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
3917
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
40-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
41-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
42-
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
43-
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
44-
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
45-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
46-
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
47-
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
48-
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
49-
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
50-
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
51-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
52-
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
53-
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
54-
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
5518
golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8=
5619
golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8=
57-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
5820
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5921
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
6022
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

Diff for: internal/computestorage/zsyscall_windows.go

+2-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: internal/fs/zsyscall_windows.go

+1-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: internal/interop/zsyscall_windows.go

+1-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: internal/socket/socket.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,16 @@ func connectEx(
156156
bytesSent *uint32,
157157
overlapped *windows.Overlapped,
158158
) (err error) {
159-
// todo: after upgrading to 1.18, switch from syscall.Syscall9 to syscall.SyscallN
160-
r1, _, e1 := syscall.Syscall9(connectExFunc.addr,
161-
7,
159+
r1, _, e1 := syscall.SyscallN(connectExFunc.addr,
162160
uintptr(s),
163161
uintptr(name),
164162
uintptr(namelen),
165163
uintptr(unsafe.Pointer(sendBuf)),
166164
uintptr(sendDataLen),
167165
uintptr(unsafe.Pointer(bytesSent)),
168166
uintptr(unsafe.Pointer(overlapped)),
169-
0,
170-
0)
167+
)
168+
171169
if r1 == 0 {
172170
if e1 != 0 {
173171
err = error(e1)

Diff for: internal/socket/zsyscall_windows.go

+3-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pkg/bindfilter/zsyscall_windows.go

+3-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)