mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[chore] bump ncruces go-sqlite3 => v0.23.0 (#3785)
* bump ncruces go-sqlite3 => v0.23.0 * whoops, add missing vendor changes...
This commit is contained in:
4
vendor/github.com/ncruces/go-sqlite3/vfs/api.go
generated
vendored
4
vendor/github.com/ncruces/go-sqlite3/vfs/api.go
generated
vendored
@ -193,7 +193,7 @@ type FileSharedMemory interface {
|
||||
// SharedMemory is a shared-memory WAL-index implementation.
|
||||
// Use [NewSharedMemory] to create a shared-memory.
|
||||
type SharedMemory interface {
|
||||
shmMap(context.Context, api.Module, int32, int32, bool) (uint32, _ErrorCode)
|
||||
shmMap(context.Context, api.Module, int32, int32, bool) (ptr_t, _ErrorCode)
|
||||
shmLock(int32, int32, _ShmFlag) _ErrorCode
|
||||
shmUnmap(bool)
|
||||
shmBarrier()
|
||||
@ -207,7 +207,7 @@ type blockingSharedMemory interface {
|
||||
|
||||
type fileControl interface {
|
||||
File
|
||||
fileControl(ctx context.Context, mod api.Module, op _FcntlOpcode, pArg uint32) _ErrorCode
|
||||
fileControl(ctx context.Context, mod api.Module, op _FcntlOpcode, pArg ptr_t) _ErrorCode
|
||||
}
|
||||
|
||||
type filePDB interface {
|
||||
|
8
vendor/github.com/ncruces/go-sqlite3/vfs/cksm.go
generated
vendored
8
vendor/github.com/ncruces/go-sqlite3/vfs/cksm.go
generated
vendored
@ -102,14 +102,14 @@ func (c cksmFile) Pragma(name string, value string) (string, error) {
|
||||
}
|
||||
|
||||
func (c cksmFile) DeviceCharacteristics() DeviceCharacteristic {
|
||||
res := c.File.DeviceCharacteristics()
|
||||
ret := c.File.DeviceCharacteristics()
|
||||
if c.verifyCksm {
|
||||
res &^= IOCAP_SUBPAGE_READ
|
||||
ret &^= IOCAP_SUBPAGE_READ
|
||||
}
|
||||
return res
|
||||
return ret
|
||||
}
|
||||
|
||||
func (c cksmFile) fileControl(ctx context.Context, mod api.Module, op _FcntlOpcode, pArg uint32) _ErrorCode {
|
||||
func (c cksmFile) fileControl(ctx context.Context, mod api.Module, op _FcntlOpcode, pArg ptr_t) _ErrorCode {
|
||||
switch op {
|
||||
case _FCNTL_CKPT_START:
|
||||
c.inCkpt = true
|
||||
|
7
vendor/github.com/ncruces/go-sqlite3/vfs/const.go
generated
vendored
7
vendor/github.com/ncruces/go-sqlite3/vfs/const.go
generated
vendored
@ -8,7 +8,12 @@ const (
|
||||
_MAX_PATHNAME = 1024
|
||||
_DEFAULT_SECTOR_SIZE = 4096
|
||||
|
||||
ptrlen = 4
|
||||
ptrlen = util.PtrLen
|
||||
)
|
||||
|
||||
type (
|
||||
stk_t = util.Stk_t
|
||||
ptr_t = util.Ptr_t
|
||||
)
|
||||
|
||||
// https://sqlite.org/rescode.html
|
||||
|
8
vendor/github.com/ncruces/go-sqlite3/vfs/file.go
generated
vendored
8
vendor/github.com/ncruces/go-sqlite3/vfs/file.go
generated
vendored
@ -186,14 +186,14 @@ func (f *vfsFile) SectorSize() int {
|
||||
}
|
||||
|
||||
func (f *vfsFile) DeviceCharacteristics() DeviceCharacteristic {
|
||||
res := IOCAP_SUBPAGE_READ
|
||||
ret := IOCAP_SUBPAGE_READ
|
||||
if osBatchAtomic(f.File) {
|
||||
res |= IOCAP_BATCH_ATOMIC
|
||||
ret |= IOCAP_BATCH_ATOMIC
|
||||
}
|
||||
if f.psow {
|
||||
res |= IOCAP_POWERSAFE_OVERWRITE
|
||||
ret |= IOCAP_POWERSAFE_OVERWRITE
|
||||
}
|
||||
return res
|
||||
return ret
|
||||
}
|
||||
|
||||
func (f *vfsFile) SizeHint(size int64) error {
|
||||
|
34
vendor/github.com/ncruces/go-sqlite3/vfs/filename.go
generated
vendored
34
vendor/github.com/ncruces/go-sqlite3/vfs/filename.go
generated
vendored
@ -16,13 +16,13 @@ import (
|
||||
type Filename struct {
|
||||
ctx context.Context
|
||||
mod api.Module
|
||||
zPath uint32
|
||||
zPath ptr_t
|
||||
flags OpenFlag
|
||||
stack [2]uint64
|
||||
stack [2]stk_t
|
||||
}
|
||||
|
||||
// GetFilename is an internal API users should not call directly.
|
||||
func GetFilename(ctx context.Context, mod api.Module, id uint32, flags OpenFlag) *Filename {
|
||||
func GetFilename(ctx context.Context, mod api.Module, id ptr_t, flags OpenFlag) *Filename {
|
||||
if id == 0 {
|
||||
return nil
|
||||
}
|
||||
@ -71,12 +71,12 @@ func (n *Filename) path(method string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
n.stack[0] = uint64(n.zPath)
|
||||
n.stack[0] = stk_t(n.zPath)
|
||||
fn := n.mod.ExportedFunction(method)
|
||||
if err := fn.CallWithStack(n.ctx, n.stack[:]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return util.ReadString(n.mod, uint32(n.stack[0]), _MAX_PATHNAME)
|
||||
return util.ReadString(n.mod, ptr_t(n.stack[0]), _MAX_PATHNAME)
|
||||
}
|
||||
|
||||
// DatabaseFile returns the main database [File] corresponding to a journal.
|
||||
@ -90,12 +90,12 @@ func (n *Filename) DatabaseFile() File {
|
||||
return nil
|
||||
}
|
||||
|
||||
n.stack[0] = uint64(n.zPath)
|
||||
n.stack[0] = stk_t(n.zPath)
|
||||
fn := n.mod.ExportedFunction("sqlite3_database_file_object")
|
||||
if err := fn.CallWithStack(n.ctx, n.stack[:]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
file, _ := vfsFileGet(n.ctx, n.mod, uint32(n.stack[0])).(File)
|
||||
file, _ := vfsFileGet(n.ctx, n.mod, ptr_t(n.stack[0])).(File)
|
||||
return file
|
||||
}
|
||||
|
||||
@ -108,13 +108,13 @@ func (n *Filename) URIParameter(key string) string {
|
||||
}
|
||||
|
||||
uriKey := n.mod.ExportedFunction("sqlite3_uri_key")
|
||||
n.stack[0] = uint64(n.zPath)
|
||||
n.stack[1] = uint64(0)
|
||||
n.stack[0] = stk_t(n.zPath)
|
||||
n.stack[1] = stk_t(0)
|
||||
if err := uriKey.CallWithStack(n.ctx, n.stack[:]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ptr := uint32(n.stack[0])
|
||||
ptr := ptr_t(n.stack[0])
|
||||
if ptr == 0 {
|
||||
return ""
|
||||
}
|
||||
@ -127,13 +127,13 @@ func (n *Filename) URIParameter(key string) string {
|
||||
if k == "" {
|
||||
return ""
|
||||
}
|
||||
ptr += uint32(len(k)) + 1
|
||||
ptr += ptr_t(len(k)) + 1
|
||||
|
||||
v := util.ReadString(n.mod, ptr, _MAX_NAME)
|
||||
if k == key {
|
||||
return v
|
||||
}
|
||||
ptr += uint32(len(v)) + 1
|
||||
ptr += ptr_t(len(v)) + 1
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,13 +146,13 @@ func (n *Filename) URIParameters() url.Values {
|
||||
}
|
||||
|
||||
uriKey := n.mod.ExportedFunction("sqlite3_uri_key")
|
||||
n.stack[0] = uint64(n.zPath)
|
||||
n.stack[1] = uint64(0)
|
||||
n.stack[0] = stk_t(n.zPath)
|
||||
n.stack[1] = stk_t(0)
|
||||
if err := uriKey.CallWithStack(n.ctx, n.stack[:]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ptr := uint32(n.stack[0])
|
||||
ptr := ptr_t(n.stack[0])
|
||||
if ptr == 0 {
|
||||
return nil
|
||||
}
|
||||
@ -167,13 +167,13 @@ func (n *Filename) URIParameters() url.Values {
|
||||
if k == "" {
|
||||
return params
|
||||
}
|
||||
ptr += uint32(len(k)) + 1
|
||||
ptr += ptr_t(len(k)) + 1
|
||||
|
||||
v := util.ReadString(n.mod, ptr, _MAX_NAME)
|
||||
if params == nil {
|
||||
params = url.Values{}
|
||||
}
|
||||
params.Add(k, v)
|
||||
ptr += uint32(len(v)) + 1
|
||||
ptr += ptr_t(len(v)) + 1
|
||||
}
|
||||
}
|
||||
|
4
vendor/github.com/ncruces/go-sqlite3/vfs/memdb/memdb.go
generated
vendored
4
vendor/github.com/ncruces/go-sqlite3/vfs/memdb/memdb.go
generated
vendored
@ -10,9 +10,11 @@ import (
|
||||
"github.com/ncruces/go-sqlite3/vfs"
|
||||
)
|
||||
|
||||
// Must be a multiple of 64K (the largest page size).
|
||||
const sectorSize = 65536
|
||||
|
||||
// Ensure sectorSize is a multiple of 64K (the largest page size).
|
||||
var _ [0]struct{} = [sectorSize & 65535]struct{}{}
|
||||
|
||||
type memVFS struct{}
|
||||
|
||||
func (memVFS) Open(name string, flags vfs.OpenFlag) (vfs.File, vfs.OpenFlag, error) {
|
||||
|
2
vendor/github.com/ncruces/go-sqlite3/vfs/shm_bsd.go
generated
vendored
2
vendor/github.com/ncruces/go-sqlite3/vfs/shm_bsd.go
generated
vendored
@ -142,7 +142,7 @@ func (s *vfsShm) shmOpen() _ErrorCode {
|
||||
return _OK
|
||||
}
|
||||
|
||||
func (s *vfsShm) shmMap(ctx context.Context, mod api.Module, id, size int32, extend bool) (uint32, _ErrorCode) {
|
||||
func (s *vfsShm) shmMap(ctx context.Context, mod api.Module, id, size int32, extend bool) (ptr_t, _ErrorCode) {
|
||||
// Ensure size is a multiple of the OS page size.
|
||||
if int(size)&(unix.Getpagesize()-1) != 0 {
|
||||
return 0, _IOERR_SHMMAP
|
||||
|
14
vendor/github.com/ncruces/go-sqlite3/vfs/shm_dotlk.go
generated
vendored
14
vendor/github.com/ncruces/go-sqlite3/vfs/shm_dotlk.go
generated
vendored
@ -35,8 +35,8 @@ type vfsShm struct {
|
||||
free api.Function
|
||||
path string
|
||||
shadow [][_WALINDEX_PGSZ]byte
|
||||
ptrs []uint32
|
||||
stack [1]uint64
|
||||
ptrs []ptr_t
|
||||
stack [1]stk_t
|
||||
lock [_SHM_NLOCK]bool
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ func (s *vfsShm) shmOpen() _ErrorCode {
|
||||
return _OK
|
||||
}
|
||||
|
||||
func (s *vfsShm) shmMap(ctx context.Context, mod api.Module, id, size int32, extend bool) (uint32, _ErrorCode) {
|
||||
func (s *vfsShm) shmMap(ctx context.Context, mod api.Module, id, size int32, extend bool) (ptr_t, _ErrorCode) {
|
||||
if size != _WALINDEX_PGSZ {
|
||||
return 0, _IOERR_SHMMAP
|
||||
}
|
||||
@ -128,15 +128,15 @@ func (s *vfsShm) shmMap(ctx context.Context, mod api.Module, id, size int32, ext
|
||||
|
||||
// Allocate local memory.
|
||||
for int(id) >= len(s.ptrs) {
|
||||
s.stack[0] = uint64(size)
|
||||
s.stack[0] = stk_t(size)
|
||||
if err := s.alloc.CallWithStack(ctx, s.stack[:]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if s.stack[0] == 0 {
|
||||
panic(util.OOMErr)
|
||||
}
|
||||
clear(util.View(s.mod, uint32(s.stack[0]), _WALINDEX_PGSZ))
|
||||
s.ptrs = append(s.ptrs, uint32(s.stack[0]))
|
||||
clear(util.View(s.mod, ptr_t(s.stack[0]), _WALINDEX_PGSZ))
|
||||
s.ptrs = append(s.ptrs, ptr_t(s.stack[0]))
|
||||
}
|
||||
|
||||
s.shadow[0][4] = 1
|
||||
@ -168,7 +168,7 @@ func (s *vfsShm) shmUnmap(delete bool) {
|
||||
defer s.Unlock()
|
||||
|
||||
for _, p := range s.ptrs {
|
||||
s.stack[0] = uint64(p)
|
||||
s.stack[0] = stk_t(p)
|
||||
if err := s.free.CallWithStack(context.Background(), s.stack[:]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
2
vendor/github.com/ncruces/go-sqlite3/vfs/shm_ofd.go
generated
vendored
2
vendor/github.com/ncruces/go-sqlite3/vfs/shm_ofd.go
generated
vendored
@ -73,7 +73,7 @@ func (s *vfsShm) shmOpen() _ErrorCode {
|
||||
return rc
|
||||
}
|
||||
|
||||
func (s *vfsShm) shmMap(ctx context.Context, mod api.Module, id, size int32, extend bool) (uint32, _ErrorCode) {
|
||||
func (s *vfsShm) shmMap(ctx context.Context, mod api.Module, id, size int32, extend bool) (ptr_t, _ErrorCode) {
|
||||
// Ensure size is a multiple of the OS page size.
|
||||
if int(size)&(unix.Getpagesize()-1) != 0 {
|
||||
return 0, _IOERR_SHMMAP
|
||||
|
14
vendor/github.com/ncruces/go-sqlite3/vfs/shm_windows.go
generated
vendored
14
vendor/github.com/ncruces/go-sqlite3/vfs/shm_windows.go
generated
vendored
@ -26,8 +26,8 @@ type vfsShm struct {
|
||||
regions []*util.MappedRegion
|
||||
shared [][]byte
|
||||
shadow [][_WALINDEX_PGSZ]byte
|
||||
ptrs []uint32
|
||||
stack [1]uint64
|
||||
ptrs []ptr_t
|
||||
stack [1]stk_t
|
||||
fileLock bool
|
||||
blocking bool
|
||||
sync.Mutex
|
||||
@ -72,7 +72,7 @@ func (s *vfsShm) shmOpen() _ErrorCode {
|
||||
return rc
|
||||
}
|
||||
|
||||
func (s *vfsShm) shmMap(ctx context.Context, mod api.Module, id, size int32, extend bool) (_ uint32, rc _ErrorCode) {
|
||||
func (s *vfsShm) shmMap(ctx context.Context, mod api.Module, id, size int32, extend bool) (_ ptr_t, rc _ErrorCode) {
|
||||
// Ensure size is a multiple of the OS page size.
|
||||
if size != _WALINDEX_PGSZ || (windows.Getpagesize()-1)&_WALINDEX_PGSZ != 0 {
|
||||
return 0, _IOERR_SHMMAP
|
||||
@ -119,15 +119,15 @@ func (s *vfsShm) shmMap(ctx context.Context, mod api.Module, id, size int32, ext
|
||||
|
||||
// Allocate local memory.
|
||||
for int(id) >= len(s.ptrs) {
|
||||
s.stack[0] = uint64(size)
|
||||
s.stack[0] = stk_t(size)
|
||||
if err := s.alloc.CallWithStack(ctx, s.stack[:]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if s.stack[0] == 0 {
|
||||
panic(util.OOMErr)
|
||||
}
|
||||
clear(util.View(s.mod, uint32(s.stack[0]), _WALINDEX_PGSZ))
|
||||
s.ptrs = append(s.ptrs, uint32(s.stack[0]))
|
||||
clear(util.View(s.mod, ptr_t(s.stack[0]), _WALINDEX_PGSZ))
|
||||
s.ptrs = append(s.ptrs, ptr_t(s.stack[0]))
|
||||
}
|
||||
|
||||
s.shadow[0][4] = 1
|
||||
@ -168,7 +168,7 @@ func (s *vfsShm) shmUnmap(delete bool) {
|
||||
|
||||
// Free local memory.
|
||||
for _, p := range s.ptrs {
|
||||
s.stack[0] = uint64(p)
|
||||
s.stack[0] = stk_t(p)
|
||||
if err := s.free.CallWithStack(context.Background(), s.stack[:]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
157
vendor/github.com/ncruces/go-sqlite3/vfs/vfs.go
generated
vendored
157
vendor/github.com/ncruces/go-sqlite3/vfs/vfs.go
generated
vendored
@ -49,7 +49,7 @@ func ExportHostFunctions(env wazero.HostModuleBuilder) wazero.HostModuleBuilder
|
||||
return env
|
||||
}
|
||||
|
||||
func vfsFind(ctx context.Context, mod api.Module, zVfsName uint32) uint32 {
|
||||
func vfsFind(ctx context.Context, mod api.Module, zVfsName ptr_t) uint32 {
|
||||
name := util.ReadString(mod, zVfsName, _MAX_NAME)
|
||||
if vfs := Find(name); vfs != nil && vfs != (vfsOS{}) {
|
||||
return 1
|
||||
@ -57,46 +57,46 @@ func vfsFind(ctx context.Context, mod api.Module, zVfsName uint32) uint32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func vfsLocaltime(ctx context.Context, mod api.Module, pTm uint32, t int64) _ErrorCode {
|
||||
func vfsLocaltime(ctx context.Context, mod api.Module, pTm ptr_t, t int64) _ErrorCode {
|
||||
tm := time.Unix(t, 0)
|
||||
var isdst int
|
||||
var isdst int32
|
||||
if tm.IsDST() {
|
||||
isdst = 1
|
||||
}
|
||||
|
||||
const size = 32 / 8
|
||||
// https://pubs.opengroup.org/onlinepubs/7908799/xsh/time.h.html
|
||||
util.WriteUint32(mod, pTm+0*size, uint32(tm.Second()))
|
||||
util.WriteUint32(mod, pTm+1*size, uint32(tm.Minute()))
|
||||
util.WriteUint32(mod, pTm+2*size, uint32(tm.Hour()))
|
||||
util.WriteUint32(mod, pTm+3*size, uint32(tm.Day()))
|
||||
util.WriteUint32(mod, pTm+4*size, uint32(tm.Month()-time.January))
|
||||
util.WriteUint32(mod, pTm+5*size, uint32(tm.Year()-1900))
|
||||
util.WriteUint32(mod, pTm+6*size, uint32(tm.Weekday()-time.Sunday))
|
||||
util.WriteUint32(mod, pTm+7*size, uint32(tm.YearDay()-1))
|
||||
util.WriteUint32(mod, pTm+8*size, uint32(isdst))
|
||||
util.Write32(mod, pTm+0*size, int32(tm.Second()))
|
||||
util.Write32(mod, pTm+1*size, int32(tm.Minute()))
|
||||
util.Write32(mod, pTm+2*size, int32(tm.Hour()))
|
||||
util.Write32(mod, pTm+3*size, int32(tm.Day()))
|
||||
util.Write32(mod, pTm+4*size, int32(tm.Month()-time.January))
|
||||
util.Write32(mod, pTm+5*size, int32(tm.Year()-1900))
|
||||
util.Write32(mod, pTm+6*size, int32(tm.Weekday()-time.Sunday))
|
||||
util.Write32(mod, pTm+7*size, int32(tm.YearDay()-1))
|
||||
util.Write32(mod, pTm+8*size, isdst)
|
||||
return _OK
|
||||
}
|
||||
|
||||
func vfsRandomness(ctx context.Context, mod api.Module, pVfs uint32, nByte int32, zByte uint32) uint32 {
|
||||
mem := util.View(mod, zByte, uint64(nByte))
|
||||
func vfsRandomness(ctx context.Context, mod api.Module, pVfs ptr_t, nByte int32, zByte ptr_t) uint32 {
|
||||
mem := util.View(mod, zByte, int64(nByte))
|
||||
n, _ := rand.Reader.Read(mem)
|
||||
return uint32(n)
|
||||
}
|
||||
|
||||
func vfsSleep(ctx context.Context, mod api.Module, pVfs uint32, nMicro int32) _ErrorCode {
|
||||
func vfsSleep(ctx context.Context, mod api.Module, pVfs ptr_t, nMicro int32) _ErrorCode {
|
||||
time.Sleep(time.Duration(nMicro) * time.Microsecond)
|
||||
return _OK
|
||||
}
|
||||
|
||||
func vfsCurrentTime64(ctx context.Context, mod api.Module, pVfs, piNow uint32) _ErrorCode {
|
||||
func vfsCurrentTime64(ctx context.Context, mod api.Module, pVfs, piNow ptr_t) _ErrorCode {
|
||||
day, nsec := julianday.Date(time.Now())
|
||||
msec := day*86_400_000 + nsec/1_000_000
|
||||
util.WriteUint64(mod, piNow, uint64(msec))
|
||||
util.Write64(mod, piNow, msec)
|
||||
return _OK
|
||||
}
|
||||
|
||||
func vfsFullPathname(ctx context.Context, mod api.Module, pVfs, zRelative uint32, nFull int32, zFull uint32) _ErrorCode {
|
||||
func vfsFullPathname(ctx context.Context, mod api.Module, pVfs, zRelative ptr_t, nFull int32, zFull ptr_t) _ErrorCode {
|
||||
vfs := vfsGet(mod, pVfs)
|
||||
path := util.ReadString(mod, zRelative, _MAX_PATHNAME)
|
||||
|
||||
@ -110,7 +110,7 @@ func vfsFullPathname(ctx context.Context, mod api.Module, pVfs, zRelative uint32
|
||||
return vfsErrorCode(err, _CANTOPEN_FULLPATH)
|
||||
}
|
||||
|
||||
func vfsDelete(ctx context.Context, mod api.Module, pVfs, zPath, syncDir uint32) _ErrorCode {
|
||||
func vfsDelete(ctx context.Context, mod api.Module, pVfs, zPath ptr_t, syncDir int32) _ErrorCode {
|
||||
vfs := vfsGet(mod, pVfs)
|
||||
path := util.ReadString(mod, zPath, _MAX_PATHNAME)
|
||||
|
||||
@ -118,21 +118,20 @@ func vfsDelete(ctx context.Context, mod api.Module, pVfs, zPath, syncDir uint32)
|
||||
return vfsErrorCode(err, _IOERR_DELETE)
|
||||
}
|
||||
|
||||
func vfsAccess(ctx context.Context, mod api.Module, pVfs, zPath uint32, flags AccessFlag, pResOut uint32) _ErrorCode {
|
||||
func vfsAccess(ctx context.Context, mod api.Module, pVfs, zPath ptr_t, flags AccessFlag, pResOut ptr_t) _ErrorCode {
|
||||
vfs := vfsGet(mod, pVfs)
|
||||
path := util.ReadString(mod, zPath, _MAX_PATHNAME)
|
||||
|
||||
ok, err := vfs.Access(path, flags)
|
||||
var res uint32
|
||||
var res int32
|
||||
if ok {
|
||||
res = 1
|
||||
}
|
||||
|
||||
util.WriteUint32(mod, pResOut, res)
|
||||
util.Write32(mod, pResOut, res)
|
||||
return vfsErrorCode(err, _IOERR_ACCESS)
|
||||
}
|
||||
|
||||
func vfsOpen(ctx context.Context, mod api.Module, pVfs, zPath, pFile uint32, flags OpenFlag, pOutFlags, pOutVFS uint32) _ErrorCode {
|
||||
func vfsOpen(ctx context.Context, mod api.Module, pVfs, zPath, pFile ptr_t, flags OpenFlag, pOutFlags, pOutVFS ptr_t) _ErrorCode {
|
||||
vfs := vfsGet(mod, pVfs)
|
||||
name := GetFilename(ctx, mod, zPath, flags)
|
||||
|
||||
@ -154,24 +153,24 @@ func vfsOpen(ctx context.Context, mod api.Module, pVfs, zPath, pFile uint32, fla
|
||||
}
|
||||
if file, ok := file.(FileSharedMemory); ok &&
|
||||
pOutVFS != 0 && file.SharedMemory() != nil {
|
||||
util.WriteUint32(mod, pOutVFS, 1)
|
||||
util.Write32(mod, pOutVFS, int32(1))
|
||||
}
|
||||
if pOutFlags != 0 {
|
||||
util.WriteUint32(mod, pOutFlags, uint32(flags))
|
||||
util.Write32(mod, pOutFlags, flags)
|
||||
}
|
||||
file = cksmWrapFile(name, flags, file)
|
||||
vfsFileRegister(ctx, mod, pFile, file)
|
||||
return _OK
|
||||
}
|
||||
|
||||
func vfsClose(ctx context.Context, mod api.Module, pFile uint32) _ErrorCode {
|
||||
func vfsClose(ctx context.Context, mod api.Module, pFile ptr_t) _ErrorCode {
|
||||
err := vfsFileClose(ctx, mod, pFile)
|
||||
return vfsErrorCode(err, _IOERR_CLOSE)
|
||||
}
|
||||
|
||||
func vfsRead(ctx context.Context, mod api.Module, pFile, zBuf uint32, iAmt int32, iOfst int64) _ErrorCode {
|
||||
func vfsRead(ctx context.Context, mod api.Module, pFile, zBuf ptr_t, iAmt int32, iOfst int64) _ErrorCode {
|
||||
file := vfsFileGet(ctx, mod, pFile).(File)
|
||||
buf := util.View(mod, zBuf, uint64(iAmt))
|
||||
buf := util.View(mod, zBuf, int64(iAmt))
|
||||
|
||||
n, err := file.ReadAt(buf, iOfst)
|
||||
if n == int(iAmt) {
|
||||
@ -184,59 +183,58 @@ func vfsRead(ctx context.Context, mod api.Module, pFile, zBuf uint32, iAmt int32
|
||||
return _IOERR_SHORT_READ
|
||||
}
|
||||
|
||||
func vfsWrite(ctx context.Context, mod api.Module, pFile, zBuf uint32, iAmt int32, iOfst int64) _ErrorCode {
|
||||
func vfsWrite(ctx context.Context, mod api.Module, pFile, zBuf ptr_t, iAmt int32, iOfst int64) _ErrorCode {
|
||||
file := vfsFileGet(ctx, mod, pFile).(File)
|
||||
buf := util.View(mod, zBuf, uint64(iAmt))
|
||||
buf := util.View(mod, zBuf, int64(iAmt))
|
||||
|
||||
_, err := file.WriteAt(buf, iOfst)
|
||||
return vfsErrorCode(err, _IOERR_WRITE)
|
||||
}
|
||||
|
||||
func vfsTruncate(ctx context.Context, mod api.Module, pFile uint32, nByte int64) _ErrorCode {
|
||||
func vfsTruncate(ctx context.Context, mod api.Module, pFile ptr_t, nByte int64) _ErrorCode {
|
||||
file := vfsFileGet(ctx, mod, pFile).(File)
|
||||
err := file.Truncate(nByte)
|
||||
return vfsErrorCode(err, _IOERR_TRUNCATE)
|
||||
}
|
||||
|
||||
func vfsSync(ctx context.Context, mod api.Module, pFile uint32, flags SyncFlag) _ErrorCode {
|
||||
func vfsSync(ctx context.Context, mod api.Module, pFile ptr_t, flags SyncFlag) _ErrorCode {
|
||||
file := vfsFileGet(ctx, mod, pFile).(File)
|
||||
err := file.Sync(flags)
|
||||
return vfsErrorCode(err, _IOERR_FSYNC)
|
||||
}
|
||||
|
||||
func vfsFileSize(ctx context.Context, mod api.Module, pFile, pSize uint32) _ErrorCode {
|
||||
func vfsFileSize(ctx context.Context, mod api.Module, pFile, pSize ptr_t) _ErrorCode {
|
||||
file := vfsFileGet(ctx, mod, pFile).(File)
|
||||
size, err := file.Size()
|
||||
util.WriteUint64(mod, pSize, uint64(size))
|
||||
util.Write64(mod, pSize, size)
|
||||
return vfsErrorCode(err, _IOERR_SEEK)
|
||||
}
|
||||
|
||||
func vfsLock(ctx context.Context, mod api.Module, pFile uint32, eLock LockLevel) _ErrorCode {
|
||||
func vfsLock(ctx context.Context, mod api.Module, pFile ptr_t, eLock LockLevel) _ErrorCode {
|
||||
file := vfsFileGet(ctx, mod, pFile).(File)
|
||||
err := file.Lock(eLock)
|
||||
return vfsErrorCode(err, _IOERR_LOCK)
|
||||
}
|
||||
|
||||
func vfsUnlock(ctx context.Context, mod api.Module, pFile uint32, eLock LockLevel) _ErrorCode {
|
||||
func vfsUnlock(ctx context.Context, mod api.Module, pFile ptr_t, eLock LockLevel) _ErrorCode {
|
||||
file := vfsFileGet(ctx, mod, pFile).(File)
|
||||
err := file.Unlock(eLock)
|
||||
return vfsErrorCode(err, _IOERR_UNLOCK)
|
||||
}
|
||||
|
||||
func vfsCheckReservedLock(ctx context.Context, mod api.Module, pFile, pResOut uint32) _ErrorCode {
|
||||
func vfsCheckReservedLock(ctx context.Context, mod api.Module, pFile, pResOut ptr_t) _ErrorCode {
|
||||
file := vfsFileGet(ctx, mod, pFile).(File)
|
||||
locked, err := file.CheckReservedLock()
|
||||
|
||||
var res uint32
|
||||
var res int32
|
||||
if locked {
|
||||
res = 1
|
||||
}
|
||||
|
||||
util.WriteUint32(mod, pResOut, res)
|
||||
util.Write32(mod, pResOut, res)
|
||||
return vfsErrorCode(err, _IOERR_CHECKRESERVEDLOCK)
|
||||
}
|
||||
|
||||
func vfsFileControl(ctx context.Context, mod api.Module, pFile uint32, op _FcntlOpcode, pArg uint32) _ErrorCode {
|
||||
func vfsFileControl(ctx context.Context, mod api.Module, pFile ptr_t, op _FcntlOpcode, pArg ptr_t) _ErrorCode {
|
||||
file := vfsFileGet(ctx, mod, pFile).(File)
|
||||
if file, ok := file.(fileControl); ok {
|
||||
return file.fileControl(ctx, mod, op, pArg)
|
||||
@ -244,62 +242,62 @@ func vfsFileControl(ctx context.Context, mod api.Module, pFile uint32, op _Fcntl
|
||||
return vfsFileControlImpl(ctx, mod, file, op, pArg)
|
||||
}
|
||||
|
||||
func vfsFileControlImpl(ctx context.Context, mod api.Module, file File, op _FcntlOpcode, pArg uint32) _ErrorCode {
|
||||
func vfsFileControlImpl(ctx context.Context, mod api.Module, file File, op _FcntlOpcode, pArg ptr_t) _ErrorCode {
|
||||
switch op {
|
||||
case _FCNTL_LOCKSTATE:
|
||||
if file, ok := file.(FileLockState); ok {
|
||||
if lk := file.LockState(); lk <= LOCK_EXCLUSIVE {
|
||||
util.WriteUint32(mod, pArg, uint32(lk))
|
||||
util.Write32(mod, pArg, lk)
|
||||
return _OK
|
||||
}
|
||||
}
|
||||
|
||||
case _FCNTL_PERSIST_WAL:
|
||||
if file, ok := file.(FilePersistWAL); ok {
|
||||
if i := util.ReadUint32(mod, pArg); int32(i) >= 0 {
|
||||
if i := util.Read32[int32](mod, pArg); i >= 0 {
|
||||
file.SetPersistWAL(i != 0)
|
||||
} else if file.PersistWAL() {
|
||||
util.WriteUint32(mod, pArg, 1)
|
||||
util.Write32(mod, pArg, int32(1))
|
||||
} else {
|
||||
util.WriteUint32(mod, pArg, 0)
|
||||
util.Write32(mod, pArg, int32(0))
|
||||
}
|
||||
return _OK
|
||||
}
|
||||
|
||||
case _FCNTL_POWERSAFE_OVERWRITE:
|
||||
if file, ok := file.(FilePowersafeOverwrite); ok {
|
||||
if i := util.ReadUint32(mod, pArg); int32(i) >= 0 {
|
||||
if i := util.Read32[int32](mod, pArg); i >= 0 {
|
||||
file.SetPowersafeOverwrite(i != 0)
|
||||
} else if file.PowersafeOverwrite() {
|
||||
util.WriteUint32(mod, pArg, 1)
|
||||
util.Write32(mod, pArg, int32(1))
|
||||
} else {
|
||||
util.WriteUint32(mod, pArg, 0)
|
||||
util.Write32(mod, pArg, int32(0))
|
||||
}
|
||||
return _OK
|
||||
}
|
||||
|
||||
case _FCNTL_CHUNK_SIZE:
|
||||
if file, ok := file.(FileChunkSize); ok {
|
||||
size := util.ReadUint32(mod, pArg)
|
||||
size := util.Read32[int32](mod, pArg)
|
||||
file.ChunkSize(int(size))
|
||||
return _OK
|
||||
}
|
||||
|
||||
case _FCNTL_SIZE_HINT:
|
||||
if file, ok := file.(FileSizeHint); ok {
|
||||
size := util.ReadUint64(mod, pArg)
|
||||
err := file.SizeHint(int64(size))
|
||||
size := util.Read64[int64](mod, pArg)
|
||||
err := file.SizeHint(size)
|
||||
return vfsErrorCode(err, _IOERR_TRUNCATE)
|
||||
}
|
||||
|
||||
case _FCNTL_HAS_MOVED:
|
||||
if file, ok := file.(FileHasMoved); ok {
|
||||
moved, err := file.HasMoved()
|
||||
var res uint32
|
||||
var val uint32
|
||||
if moved {
|
||||
res = 1
|
||||
val = 1
|
||||
}
|
||||
util.WriteUint32(mod, pArg, res)
|
||||
util.Write32(mod, pArg, val)
|
||||
return vfsErrorCode(err, _IOERR_FSTAT)
|
||||
}
|
||||
|
||||
@ -354,10 +352,10 @@ func vfsFileControlImpl(ctx context.Context, mod api.Module, file File, op _Fcnt
|
||||
|
||||
case _FCNTL_PRAGMA:
|
||||
if file, ok := file.(FilePragma); ok {
|
||||
ptr := util.ReadUint32(mod, pArg+1*ptrlen)
|
||||
ptr := util.Read32[ptr_t](mod, pArg+1*ptrlen)
|
||||
name := util.ReadString(mod, ptr, _MAX_SQL_LENGTH)
|
||||
var value string
|
||||
if ptr := util.ReadUint32(mod, pArg+2*ptrlen); ptr != 0 {
|
||||
if ptr := util.Read32[ptr_t](mod, pArg+2*ptrlen); ptr != 0 {
|
||||
value = util.ReadString(mod, ptr, _MAX_SQL_LENGTH)
|
||||
}
|
||||
|
||||
@ -369,22 +367,22 @@ func vfsFileControlImpl(ctx context.Context, mod api.Module, file File, op _Fcnt
|
||||
}
|
||||
if out != "" {
|
||||
fn := mod.ExportedFunction("sqlite3_malloc64")
|
||||
stack := [...]uint64{uint64(len(out) + 1)}
|
||||
stack := [...]stk_t{stk_t(len(out) + 1)}
|
||||
if err := fn.CallWithStack(ctx, stack[:]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
util.WriteUint32(mod, pArg, uint32(stack[0]))
|
||||
util.WriteString(mod, uint32(stack[0]), out)
|
||||
util.Write32(mod, pArg, ptr_t(stack[0]))
|
||||
util.WriteString(mod, ptr_t(stack[0]), out)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
case _FCNTL_BUSYHANDLER:
|
||||
if file, ok := file.(FileBusyHandler); ok {
|
||||
arg := util.ReadUint64(mod, pArg)
|
||||
arg := util.Read64[stk_t](mod, pArg)
|
||||
fn := mod.ExportedFunction("sqlite3_invoke_busy_handler_go")
|
||||
file.BusyHandler(func() bool {
|
||||
stack := [...]uint64{arg}
|
||||
stack := [...]stk_t{arg}
|
||||
if err := fn.CallWithStack(ctx, stack[:]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -396,7 +394,7 @@ func vfsFileControlImpl(ctx context.Context, mod api.Module, file File, op _Fcnt
|
||||
case _FCNTL_LOCK_TIMEOUT:
|
||||
if file, ok := file.(FileSharedMemory); ok {
|
||||
if shm, ok := file.SharedMemory().(blockingSharedMemory); ok {
|
||||
shm.shmEnableBlocking(util.ReadUint32(mod, pArg) != 0)
|
||||
shm.shmEnableBlocking(util.Read32[uint32](mod, pArg) != 0)
|
||||
return _OK
|
||||
}
|
||||
}
|
||||
@ -411,44 +409,45 @@ func vfsFileControlImpl(ctx context.Context, mod api.Module, file File, op _Fcnt
|
||||
return _NOTFOUND
|
||||
}
|
||||
|
||||
func vfsSectorSize(ctx context.Context, mod api.Module, pFile uint32) uint32 {
|
||||
func vfsSectorSize(ctx context.Context, mod api.Module, pFile ptr_t) uint32 {
|
||||
file := vfsFileGet(ctx, mod, pFile).(File)
|
||||
return uint32(file.SectorSize())
|
||||
}
|
||||
|
||||
func vfsDeviceCharacteristics(ctx context.Context, mod api.Module, pFile uint32) DeviceCharacteristic {
|
||||
func vfsDeviceCharacteristics(ctx context.Context, mod api.Module, pFile ptr_t) DeviceCharacteristic {
|
||||
file := vfsFileGet(ctx, mod, pFile).(File)
|
||||
return file.DeviceCharacteristics()
|
||||
}
|
||||
|
||||
func vfsShmBarrier(ctx context.Context, mod api.Module, pFile uint32) {
|
||||
func vfsShmBarrier(ctx context.Context, mod api.Module, pFile ptr_t) {
|
||||
shm := vfsFileGet(ctx, mod, pFile).(FileSharedMemory).SharedMemory()
|
||||
shm.shmBarrier()
|
||||
}
|
||||
|
||||
func vfsShmMap(ctx context.Context, mod api.Module, pFile uint32, iRegion, szRegion int32, bExtend, pp uint32) _ErrorCode {
|
||||
func vfsShmMap(ctx context.Context, mod api.Module, pFile ptr_t, iRegion, szRegion, bExtend int32, pp ptr_t) _ErrorCode {
|
||||
shm := vfsFileGet(ctx, mod, pFile).(FileSharedMemory).SharedMemory()
|
||||
p, rc := shm.shmMap(ctx, mod, iRegion, szRegion, bExtend != 0)
|
||||
util.WriteUint32(mod, pp, p)
|
||||
util.Write32(mod, pp, p)
|
||||
return rc
|
||||
}
|
||||
|
||||
func vfsShmLock(ctx context.Context, mod api.Module, pFile uint32, offset, n int32, flags _ShmFlag) _ErrorCode {
|
||||
func vfsShmLock(ctx context.Context, mod api.Module, pFile ptr_t, offset, n int32, flags _ShmFlag) _ErrorCode {
|
||||
shm := vfsFileGet(ctx, mod, pFile).(FileSharedMemory).SharedMemory()
|
||||
return shm.shmLock(offset, n, flags)
|
||||
}
|
||||
|
||||
func vfsShmUnmap(ctx context.Context, mod api.Module, pFile, bDelete uint32) _ErrorCode {
|
||||
func vfsShmUnmap(ctx context.Context, mod api.Module, pFile ptr_t, bDelete int32) _ErrorCode {
|
||||
shm := vfsFileGet(ctx, mod, pFile).(FileSharedMemory).SharedMemory()
|
||||
shm.shmUnmap(bDelete != 0)
|
||||
return _OK
|
||||
}
|
||||
|
||||
func vfsGet(mod api.Module, pVfs uint32) VFS {
|
||||
func vfsGet(mod api.Module, pVfs ptr_t) VFS {
|
||||
var name string
|
||||
if pVfs != 0 {
|
||||
const zNameOffset = 16
|
||||
name = util.ReadString(mod, util.ReadUint32(mod, pVfs+zNameOffset), _MAX_NAME)
|
||||
ptr := util.Read32[ptr_t](mod, pVfs+zNameOffset)
|
||||
name = util.ReadString(mod, ptr, _MAX_NAME)
|
||||
}
|
||||
if vfs := Find(name); vfs != nil {
|
||||
return vfs
|
||||
@ -456,21 +455,21 @@ func vfsGet(mod api.Module, pVfs uint32) VFS {
|
||||
panic(util.NoVFSErr + util.ErrorString(name))
|
||||
}
|
||||
|
||||
func vfsFileRegister(ctx context.Context, mod api.Module, pFile uint32, file File) {
|
||||
func vfsFileRegister(ctx context.Context, mod api.Module, pFile ptr_t, file File) {
|
||||
const fileHandleOffset = 4
|
||||
id := util.AddHandle(ctx, file)
|
||||
util.WriteUint32(mod, pFile+fileHandleOffset, id)
|
||||
util.Write32(mod, pFile+fileHandleOffset, id)
|
||||
}
|
||||
|
||||
func vfsFileGet(ctx context.Context, mod api.Module, pFile uint32) any {
|
||||
func vfsFileGet(ctx context.Context, mod api.Module, pFile ptr_t) any {
|
||||
const fileHandleOffset = 4
|
||||
id := util.ReadUint32(mod, pFile+fileHandleOffset)
|
||||
id := util.Read32[ptr_t](mod, pFile+fileHandleOffset)
|
||||
return util.GetHandle(ctx, id)
|
||||
}
|
||||
|
||||
func vfsFileClose(ctx context.Context, mod api.Module, pFile uint32) error {
|
||||
func vfsFileClose(ctx context.Context, mod api.Module, pFile ptr_t) error {
|
||||
const fileHandleOffset = 4
|
||||
id := util.ReadUint32(mod, pFile+fileHandleOffset)
|
||||
id := util.Read32[ptr_t](mod, pFile+fileHandleOffset)
|
||||
return util.DelHandle(ctx, id)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user