Skip to content

Commit

Permalink
Merge pull request #566 from dusk125/upgrade-go1.21
Browse files Browse the repository at this point in the history
Update to go1.21.1
  • Loading branch information
ahrtr authored Sep 15, 2023
2 parents ead6b85 + 18ebb97 commit e682325
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/failpoint_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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

2 changes: 1 addition & 1 deletion cmd/bbolt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
6 changes: 2 additions & 4 deletions freelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:])
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module go.etcd.io/bbolt

go 1.20
go 1.21

require (
github.com/spf13/cobra v1.7.0
Expand Down
12 changes: 5 additions & 7 deletions internal/common/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 0 additions & 12 deletions internal/common/unsafe.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package common

import (
"reflect"
"unsafe"
)

Expand All @@ -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
}

0 comments on commit e682325

Please sign in to comment.