2024-05-27 15:46:15 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/tetratelabs/wazero/experimental"
|
2024-10-25 16:09:18 +00:00
|
|
|
|
|
|
|
"github.com/ncruces/go-sqlite3/internal/alloc"
|
2024-05-27 15:46:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type moduleKey struct{}
|
|
|
|
type moduleState struct {
|
|
|
|
mmapState
|
|
|
|
handleState
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewContext(ctx context.Context) context.Context {
|
|
|
|
state := new(moduleState)
|
2024-10-25 16:09:18 +00:00
|
|
|
ctx = experimental.WithMemoryAllocator(ctx, experimental.MemoryAllocatorFunc(alloc.NewMemory))
|
2024-05-27 15:46:15 +00:00
|
|
|
ctx = experimental.WithCloseNotifier(ctx, state)
|
|
|
|
ctx = context.WithValue(ctx, moduleKey{}, state)
|
|
|
|
return ctx
|
|
|
|
}
|