Skip to content

Commit 18ebb97

Browse files
committed
Update to go1.21.1
Signed-off-by: Allen Ray <alray@redhat.com>
1 parent ead6b85 commit 18ebb97

File tree

7 files changed

+13
-29
lines changed

7 files changed

+13
-29
lines changed

.github/workflows/failpoint_test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- uses: actions/checkout@v4
1212
- uses: actions/setup-go@v4
1313
with:
14-
go-version: "1.20.7"
14+
go-version: "1.21.1"
1515
- run: |
1616
make gofail-enable
1717
make test-failpoint

.github/workflows/tests.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/checkout@v4
1616
- uses: actions/setup-go@v4
1717
with:
18-
go-version: "1.20.7"
18+
go-version: "1.21.1"
1919
- run: make fmt
2020
- env:
2121
TARGET: ${{ matrix.target }}
@@ -66,7 +66,7 @@ jobs:
6666
- uses: actions/checkout@v4
6767
- uses: actions/setup-go@v4
6868
with:
69-
go-version: "1.20.7"
69+
go-version: "1.21.1"
7070
- run: make fmt
7171
- env:
7272
TARGET: ${{ matrix.target }}
@@ -94,6 +94,6 @@ jobs:
9494
- uses: actions/checkout@v4
9595
- uses: actions/setup-go@v4
9696
with:
97-
go-version: "1.20.7"
97+
go-version: "1.21.1"
9898
- run: make coverage
9999

cmd/bbolt/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
```bash
7373
$bbolt version
7474
bbolt version: 1.3.7
75-
Go Version: go1.20.7
75+
Go Version: go1.21.1
7676
Go OS/Arch: darwin/arm64
7777
```
7878

freelist.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,13 @@ func (f *freelist) write(p *common.Page) error {
311311
p.SetCount(uint16(l))
312312
} else if l < 0xFFFF {
313313
p.SetCount(uint16(l))
314-
var ids []common.Pgid
315314
data := common.UnsafeAdd(unsafe.Pointer(p), unsafe.Sizeof(*p))
316-
common.UnsafeSlice(unsafe.Pointer(&ids), data, l)
315+
ids := unsafe.Slice((*common.Pgid)(data), l)
317316
f.copyall(ids)
318317
} else {
319318
p.SetCount(0xFFFF)
320-
var ids []common.Pgid
321319
data := common.UnsafeAdd(unsafe.Pointer(p), unsafe.Sizeof(*p))
322-
common.UnsafeSlice(unsafe.Pointer(&ids), data, l+1)
320+
ids := unsafe.Slice((*common.Pgid)(data), l+1)
323321
ids[0] = common.Pgid(l)
324322
f.copyall(ids[1:])
325323
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module go.etcd.io/bbolt
22

3-
go 1.20
3+
go 1.21
44

55
require (
66
github.com/spf13/cobra v1.7.0

internal/common/page.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const MinKeysPerPage = 2
1313

1414
const BranchPageElementSize = unsafe.Sizeof(branchPageElement{})
1515
const LeafPageElementSize = unsafe.Sizeof(leafPageElement{})
16+
const pgidSize = unsafe.Sizeof(Pgid(0))
1617

1718
const (
1819
BranchPageFlag = 0x01
@@ -99,9 +100,8 @@ func (p *Page) LeafPageElements() []leafPageElement {
99100
if p.count == 0 {
100101
return nil
101102
}
102-
var elems []leafPageElement
103103
data := UnsafeAdd(unsafe.Pointer(p), unsafe.Sizeof(*p))
104-
UnsafeSlice(unsafe.Pointer(&elems), data, int(p.count))
104+
elems := unsafe.Slice((*leafPageElement)(data), int(p.count))
105105
return elems
106106
}
107107

@@ -116,9 +116,8 @@ func (p *Page) BranchPageElements() []branchPageElement {
116116
if p.count == 0 {
117117
return nil
118118
}
119-
var elems []branchPageElement
120119
data := UnsafeAdd(unsafe.Pointer(p), unsafe.Sizeof(*p))
121-
UnsafeSlice(unsafe.Pointer(&elems), data, int(p.count))
120+
elems := unsafe.Slice((*branchPageElement)(data), int(p.count))
122121
return elems
123122
}
124123

@@ -149,9 +148,8 @@ func (p *Page) FreelistPageIds() []Pgid {
149148
return nil
150149
}
151150

152-
var ids []Pgid
153-
data := UnsafeIndex(unsafe.Pointer(p), unsafe.Sizeof(*p), unsafe.Sizeof(ids[0]), idx)
154-
UnsafeSlice(unsafe.Pointer(&ids), data, count)
151+
data := UnsafeIndex(unsafe.Pointer(p), unsafe.Sizeof(*p), pgidSize, idx)
152+
ids := unsafe.Slice((*Pgid)(data), count)
155153

156154
return ids
157155
}

internal/common/unsafe.go

-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package common
22

33
import (
4-
"reflect"
54
"unsafe"
65
)
76

@@ -26,14 +25,3 @@ func UnsafeByteSlice(base unsafe.Pointer, offset uintptr, i, j int) []byte {
2625
// all), so this is believed to be correct.
2726
return (*[pageMaxAllocSize]byte)(UnsafeAdd(base, offset))[i:j:j]
2827
}
29-
30-
// UnsafeSlice modifies the data, len, and cap of a slice variable pointed to by
31-
// the slice parameter. This helper should be used over other direct
32-
// manipulation of reflect.SliceHeader to prevent misuse, namely, converting
33-
// from reflect.SliceHeader to a Go slice type.
34-
func UnsafeSlice(slice, data unsafe.Pointer, len int) {
35-
s := (*reflect.SliceHeader)(slice)
36-
s.Data = uintptr(data)
37-
s.Cap = len
38-
s.Len = len
39-
}

0 commit comments

Comments
 (0)