From 18ebb974510c2c48f905fd4721f07a20173c6962 Mon Sep 17 00:00:00 2001 From: Allen Ray Date: Wed, 13 Sep 2023 11:00:29 -0400 Subject: [PATCH] Update to go1.21.1 Signed-off-by: Allen Ray --- .github/workflows/failpoint_test.yaml | 2 +- .github/workflows/tests.yaml | 6 +++--- cmd/bbolt/README.md | 2 +- freelist.go | 6 ++---- go.mod | 2 +- internal/common/page.go | 12 +++++------- internal/common/unsafe.go | 12 ------------ 7 files changed, 13 insertions(+), 29 deletions(-) diff --git a/.github/workflows/failpoint_test.yaml b/.github/workflows/failpoint_test.yaml index 02074ba45..41da8afe5 100644 --- a/.github/workflows/failpoint_test.yaml +++ b/.github/workflows/failpoint_test.yaml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: - go-version: "1.20.7" + go-version: "1.21.1" - run: | make gofail-enable make test-failpoint diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 6e2743fdb..8b4d41e6b 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: - go-version: "1.20.7" + go-version: "1.21.1" - run: make fmt - env: TARGET: ${{ matrix.target }} @@ -66,7 +66,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: - go-version: "1.20.7" + go-version: "1.21.1" - run: make fmt - env: TARGET: ${{ matrix.target }} @@ -94,6 +94,6 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: - go-version: "1.20.7" + go-version: "1.21.1" - run: make coverage diff --git a/cmd/bbolt/README.md b/cmd/bbolt/README.md index 8c7785456..a3e7c169f 100644 --- a/cmd/bbolt/README.md +++ b/cmd/bbolt/README.md @@ -72,7 +72,7 @@ ```bash $bbolt version bbolt version: 1.3.7 - Go Version: go1.20.7 + Go Version: go1.21.1 Go OS/Arch: darwin/arm64 ``` diff --git a/freelist.go b/freelist.go index 2b09e7626..29ac16c72 100644 --- a/freelist.go +++ b/freelist.go @@ -311,15 +311,13 @@ func (f *freelist) write(p *common.Page) error { p.SetCount(uint16(l)) } else if l < 0xFFFF { p.SetCount(uint16(l)) - var ids []common.Pgid data := common.UnsafeAdd(unsafe.Pointer(p), unsafe.Sizeof(*p)) - common.UnsafeSlice(unsafe.Pointer(&ids), data, l) + ids := unsafe.Slice((*common.Pgid)(data), l) f.copyall(ids) } else { p.SetCount(0xFFFF) - var ids []common.Pgid data := common.UnsafeAdd(unsafe.Pointer(p), unsafe.Sizeof(*p)) - common.UnsafeSlice(unsafe.Pointer(&ids), data, l+1) + ids := unsafe.Slice((*common.Pgid)(data), l+1) ids[0] = common.Pgid(l) f.copyall(ids[1:]) } diff --git a/go.mod b/go.mod index 50262c34e..7445c9559 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module go.etcd.io/bbolt -go 1.20 +go 1.21 require ( github.com/spf13/cobra v1.7.0 diff --git a/internal/common/page.go b/internal/common/page.go index 808484c19..ee808967c 100644 --- a/internal/common/page.go +++ b/internal/common/page.go @@ -13,6 +13,7 @@ const MinKeysPerPage = 2 const BranchPageElementSize = unsafe.Sizeof(branchPageElement{}) const LeafPageElementSize = unsafe.Sizeof(leafPageElement{}) +const pgidSize = unsafe.Sizeof(Pgid(0)) const ( BranchPageFlag = 0x01 @@ -99,9 +100,8 @@ func (p *Page) LeafPageElements() []leafPageElement { if p.count == 0 { return nil } - var elems []leafPageElement data := UnsafeAdd(unsafe.Pointer(p), unsafe.Sizeof(*p)) - UnsafeSlice(unsafe.Pointer(&elems), data, int(p.count)) + elems := unsafe.Slice((*leafPageElement)(data), int(p.count)) return elems } @@ -116,9 +116,8 @@ func (p *Page) BranchPageElements() []branchPageElement { if p.count == 0 { return nil } - var elems []branchPageElement data := UnsafeAdd(unsafe.Pointer(p), unsafe.Sizeof(*p)) - UnsafeSlice(unsafe.Pointer(&elems), data, int(p.count)) + elems := unsafe.Slice((*branchPageElement)(data), int(p.count)) return elems } @@ -149,9 +148,8 @@ func (p *Page) FreelistPageIds() []Pgid { return nil } - var ids []Pgid - data := UnsafeIndex(unsafe.Pointer(p), unsafe.Sizeof(*p), unsafe.Sizeof(ids[0]), idx) - UnsafeSlice(unsafe.Pointer(&ids), data, count) + data := UnsafeIndex(unsafe.Pointer(p), unsafe.Sizeof(*p), pgidSize, idx) + ids := unsafe.Slice((*Pgid)(data), count) return ids } diff --git a/internal/common/unsafe.go b/internal/common/unsafe.go index c1970ba3c..9b77dd7b2 100644 --- a/internal/common/unsafe.go +++ b/internal/common/unsafe.go @@ -1,7 +1,6 @@ package common import ( - "reflect" "unsafe" ) @@ -26,14 +25,3 @@ func UnsafeByteSlice(base unsafe.Pointer, offset uintptr, i, j int) []byte { // all), so this is believed to be correct. return (*[pageMaxAllocSize]byte)(UnsafeAdd(base, offset))[i:j:j] } - -// UnsafeSlice modifies the data, len, and cap of a slice variable pointed to by -// the slice parameter. This helper should be used over other direct -// manipulation of reflect.SliceHeader to prevent misuse, namely, converting -// from reflect.SliceHeader to a Go slice type. -func UnsafeSlice(slice, data unsafe.Pointer, len int) { - s := (*reflect.SliceHeader)(slice) - s.Data = uintptr(data) - s.Cap = len - s.Len = len -}