summaryrefslogtreecommitdiff
path: root/vendor/github.com/ncruces/go-sqlite3/internal/util/handle.go
diff options
context:
space:
mode:
authorLibravatar Terin Stock <terinjokes@gmail.com>2025-03-09 17:47:56 +0100
committerLibravatar Terin Stock <terinjokes@gmail.com>2025-03-10 01:59:49 +0100
commit3ac1ee16f377d31a0fb80c8dae28b6239ac4229e (patch)
treef61faa581feaaeaba2542b9f2b8234a590684413 /vendor/github.com/ncruces/go-sqlite3/internal/util/handle.go
parent[chore] update URLs to forked source (diff)
downloadgotosocial-3ac1ee16f377d31a0fb80c8dae28b6239ac4229e.tar.xz
[chore] remove vendor
Diffstat (limited to 'vendor/github.com/ncruces/go-sqlite3/internal/util/handle.go')
-rw-r--r--vendor/github.com/ncruces/go-sqlite3/internal/util/handle.go70
1 files changed, 0 insertions, 70 deletions
diff --git a/vendor/github.com/ncruces/go-sqlite3/internal/util/handle.go b/vendor/github.com/ncruces/go-sqlite3/internal/util/handle.go
deleted file mode 100644
index f9f39b449..000000000
--- a/vendor/github.com/ncruces/go-sqlite3/internal/util/handle.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package util
-
-import (
- "context"
- "io"
-)
-
-type handleState struct {
- handles []any
- holes int
-}
-
-func (s *handleState) CloseNotify(ctx context.Context, exitCode uint32) {
- for _, h := range s.handles {
- if c, ok := h.(io.Closer); ok {
- c.Close()
- }
- }
- s.handles = nil
- s.holes = 0
-}
-
-func GetHandle(ctx context.Context, id Ptr_t) any {
- if id == 0 {
- return nil
- }
- s := ctx.Value(moduleKey{}).(*moduleState)
- return s.handles[^id]
-}
-
-func DelHandle(ctx context.Context, id Ptr_t) error {
- if id == 0 {
- return nil
- }
- s := ctx.Value(moduleKey{}).(*moduleState)
- a := s.handles[^id]
- s.handles[^id] = nil
- if l := Ptr_t(len(s.handles)); l == ^id {
- s.handles = s.handles[:l-1]
- } else {
- s.holes++
- }
- if c, ok := a.(io.Closer); ok {
- return c.Close()
- }
- return nil
-}
-
-func AddHandle(ctx context.Context, a any) Ptr_t {
- if a == nil {
- panic(NilErr)
- }
-
- s := ctx.Value(moduleKey{}).(*moduleState)
-
- // Find an empty slot.
- if s.holes > cap(s.handles)-len(s.handles) {
- for id, h := range s.handles {
- if h == nil {
- s.holes--
- s.handles[id] = a
- return ^Ptr_t(id)
- }
- }
- }
-
- // Add a new slot.
- s.handles = append(s.handles, a)
- return -Ptr_t(len(s.handles))
-}