Skip to content

Commit 19bc6e3

Browse files
committed
Rename.
1 parent 3955c22 commit 19bc6e3

File tree

7 files changed

+25
-24
lines changed

7 files changed

+25
-24
lines changed

internal/alloc/alloc_other.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//go:build !(unix || windows) || sqlite3_nosys
2+
3+
package alloc
4+
5+
import "github.com/tetratelabs/wazero/experimental"
6+
7+
func Virtual(cap, max uint64) experimental.LinearMemory {
8+
return Slice(cap, max)
9+
}

internal/util/alloc_slice.go renamed to internal/alloc/alloc_slice.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
//go:build !(darwin || linux) || !(amd64 || arm64 || riscv64) || sqlite3_noshm || sqlite3_nosys
22

3-
package util
3+
package alloc
44

55
import "github.com/tetratelabs/wazero/experimental"
66

7-
func sliceAlloc(cap, max uint64) experimental.LinearMemory {
8-
return &sliceBuffer{make([]byte, cap), max}
7+
func Slice(cap, _ uint64) experimental.LinearMemory {
8+
return &sliceMemory{make([]byte, 0, cap)}
99
}
1010

11-
type sliceBuffer struct {
11+
type sliceMemory struct {
1212
buf []byte
13-
max uint64
1413
}
1514

16-
func (b *sliceBuffer) Free() {}
15+
func (b *sliceMemory) Free() {}
1716

18-
func (b *sliceBuffer) Reallocate(size uint64) []byte {
17+
func (b *sliceMemory) Reallocate(size uint64) []byte {
1918
if cap := uint64(cap(b.buf)); size > cap {
2019
b.buf = append(b.buf[:cap], make([]byte, size-cap)...)
2120
} else {

internal/util/alloc_unix.go renamed to internal/alloc/alloc_unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//go:build unix && !sqlite3_nosys
22

3-
package util
3+
package alloc
44

55
import (
66
"math"
@@ -9,7 +9,7 @@ import (
99
"golang.org/x/sys/unix"
1010
)
1111

12-
func virtualAlloc(cap, max uint64) experimental.LinearMemory {
12+
func Virtual(_, max uint64) experimental.LinearMemory {
1313
// Round up to the page size.
1414
rnd := uint64(unix.Getpagesize() - 1)
1515
max = (max + rnd) &^ rnd

internal/util/alloc_windows.go renamed to internal/alloc/alloc_windows.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//go:build !sqlite3_nosys
22

3-
package util
3+
package alloc
44

55
import (
66
"math"
@@ -11,7 +11,7 @@ import (
1111
"golang.org/x/sys/windows"
1212
)
1313

14-
func virtualAlloc(cap, max uint64) experimental.LinearMemory {
14+
func Virtual(_, max uint64) experimental.LinearMemory {
1515
// Round up to the page size.
1616
rnd := uint64(windows.Getpagesize() - 1)
1717
max = (max + rnd) &^ rnd
@@ -32,7 +32,7 @@ func virtualAlloc(cap, max uint64) experimental.LinearMemory {
3232
mem := virtualMemory{addr: r}
3333
// SliceHeader, although deprecated, avoids a go vet warning.
3434
sh := (*reflect.SliceHeader)(unsafe.Pointer(&mem.buf))
35-
sh.Cap = int(max) // Not a bug.
35+
sh.Cap = int(max)
3636
sh.Data = r
3737
return &mem
3838
}

internal/util/alloc_other.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

internal/util/mmap.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import (
77
"os"
88
"unsafe"
99

10+
"github.com/ncruces/go-sqlite3/internal/alloc"
1011
"github.com/tetratelabs/wazero/api"
1112
"github.com/tetratelabs/wazero/experimental"
1213
"golang.org/x/sys/unix"
1314
)
1415

1516
func withAllocator(ctx context.Context) context.Context {
1617
return experimental.WithMemoryAllocator(ctx,
17-
experimental.MemoryAllocatorFunc(virtualAlloc))
18+
experimental.MemoryAllocatorFunc(alloc.Virtual))
1819
}
1920

2021
type mmapState struct {

internal/util/mmap_other.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package util
55
import (
66
"context"
77

8+
"github.com/ncruces/go-sqlite3/internal/alloc"
89
"github.com/tetratelabs/wazero/experimental"
910
)
1011

@@ -14,8 +15,8 @@ func withAllocator(ctx context.Context) context.Context {
1415
return experimental.WithMemoryAllocator(ctx,
1516
experimental.MemoryAllocatorFunc(func(cap, max uint64) experimental.LinearMemory {
1617
if cap == max {
17-
return virtualAlloc(cap, max)
18+
return alloc.Virtual(cap, max)
1819
}
19-
return sliceAlloc(cap, max)
20+
return alloc.Slice(cap, max)
2021
}))
2122
}

0 commit comments

Comments
 (0)