summaryrefslogtreecommitdiff
path: root/vendor/modernc.org/sqlite/generator.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-11-28 11:19:39 +0100
committerLibravatar GitHub <noreply@github.com>2022-11-28 11:19:39 +0100
commitdaf44ac2b709922512cfee3cde686b84b4868775 (patch)
tree2967df466f8d4515d32c05cf520ba3e7a19d4fae /vendor/modernc.org/sqlite/generator.go
parent[chore]: Bump codeberg.org/gruf/go-store/v2 from 2.0.9 to 2.0.10 (#1160) (diff)
downloadgotosocial-daf44ac2b709922512cfee3cde686b84b4868775.tar.xz
[chore] Bump database dependencies (#1164)
github.com/uptrace/bun v1.1.8 -> v1.1.9 github.com/uptrace/bun/pgdialect v1.1.8 -> v1.1.9 github.com/uptrace/bun/sqlitedialect v1.1.8 -> v1.1.9 modernc.org/sqlite v1.18.2 -> v1.19.5
Diffstat (limited to 'vendor/modernc.org/sqlite/generator.go')
-rw-r--r--vendor/modernc.org/sqlite/generator.go75
1 files changed, 67 insertions, 8 deletions
diff --git a/vendor/modernc.org/sqlite/generator.go b/vendor/modernc.org/sqlite/generator.go
index 9b8379175..6805e75df 100644
--- a/vendor/modernc.org/sqlite/generator.go
+++ b/vendor/modernc.org/sqlite/generator.go
@@ -10,6 +10,7 @@ package main
import (
"archive/zip"
"bufio"
+ "bytes"
"flag"
"fmt"
"io"
@@ -18,6 +19,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
+ "sort"
"strings"
"modernc.org/ccgo/v3/lib"
@@ -145,7 +147,7 @@ import (
// -lpthread
const (
- volatiles = "-volatile=sqlite3_io_error_pending,sqlite3_open_file_count,sqlite3_pager_readdb_count,sqlite3_pager_writedb_count,sqlite3_pager_writej_count,sqlite3_search_count,sqlite3_sort_count,saved_cnt"
+ volatiles = "-volatile=sqlite3_io_error_pending,sqlite3_open_file_count,sqlite3_pager_readdb_count,sqlite3_pager_writedb_count,sqlite3_pager_writej_count,sqlite3_search_count,sqlite3_sort_count,saved_cnt,randomnessPid"
)
var (
@@ -253,12 +255,12 @@ var (
sz int
dev bool
}{
- {sqliteDir, "https://www.sqlite.org/2022/sqlite-amalgamation-3390300.zip", 2457, false},
- {sqliteSrcDir, "https://www.sqlite.org/2022/sqlite-src-3390300.zip", 12814, false},
+ {sqliteDir, "https://www.sqlite.org/2022/sqlite-amalgamation-3390400.zip", 2457, false},
+ {sqliteSrcDir, "https://www.sqlite.org/2022/sqlite-src-3390400.zip", 12814, false},
}
- sqliteDir = filepath.FromSlash("testdata/sqlite-amalgamation-3390300")
- sqliteSrcDir = filepath.FromSlash("testdata/sqlite-src-3390300")
+ sqliteDir = filepath.FromSlash("testdata/sqlite-amalgamation-3390400")
+ sqliteSrcDir = filepath.FromSlash("testdata/sqlite-src-3390400")
)
func download() {
@@ -708,7 +710,8 @@ func makeMpTest(goos, goarch string, more []string) {
"-ignore-unsupported-alignment",
"-o", filepath.FromSlash(fmt.Sprintf("internal/mptest/main_%s_%s.go", goos, goarch)),
"-trace-translation-units",
- filepath.Join(sqliteSrcDir, "mptest", "mptest.c"),
+ // filepath.Join(sqliteSrcDir, "mptest", "mptest.c"),
+ filepath.Join("testdata", "mptest.c"),
fmt.Sprintf("-I%s", sqliteDir),
"-l", "modernc.org/sqlite/lib",
},
@@ -725,6 +728,7 @@ func makeMpTest(goos, goarch string, more []string) {
}
func makeSqliteProduction(goos, goarch string, more []string) {
+ fn := filepath.FromSlash(fmt.Sprintf("lib/sqlite_%s_%s.go", goos, goarch))
task := ccgo.NewTask(
join(
[]string{
@@ -737,7 +741,8 @@ func makeSqliteProduction(goos, goarch string, more []string) {
"-export-typedefs", "",
"-ignore-unsupported-alignment",
"-pkgname", "sqlite3",
- "-o", filepath.FromSlash(fmt.Sprintf("lib/sqlite_%s_%s.go", goos, goarch)),
+ volatiles,
+ "-o", fn,
"-trace-translation-units",
filepath.Join(sqliteDir, "sqlite3.c"),
},
@@ -751,9 +756,14 @@ func makeSqliteProduction(goos, goarch string, more []string) {
if err := task.Main(); err != nil {
fail("%s\n", err)
}
+
+ if err := patchXsqlite3_initialize(fn); err != nil {
+ fail("%s\n", err)
+ }
}
func makeSqliteTest(goos, goarch string, more []string) {
+ fn := filepath.FromSlash(fmt.Sprintf("libtest/sqlite_%s_%s.go", goos, goarch))
task := ccgo.NewTask(
join(
[]string{
@@ -766,7 +776,8 @@ func makeSqliteTest(goos, goarch string, more []string) {
"-export-typedefs", "",
"-ignore-unsupported-alignment",
"-pkgname", "sqlite3",
- "-o", filepath.FromSlash(fmt.Sprintf("libtest/sqlite_%s_%s.go", goos, goarch)),
+ volatiles,
+ "-o", fn,
"-trace-translation-units",
volatiles,
filepath.Join(sqliteDir, "sqlite3.c"),
@@ -781,6 +792,10 @@ func makeSqliteTest(goos, goarch string, more []string) {
if err := task.Main(); err != nil {
fail("%s\n", err)
}
+
+ if err := patchXsqlite3_initialize(fn); err != nil {
+ fail("%s\n", err)
+ }
}
func join(a ...[]string) (r []string) {
@@ -794,3 +809,47 @@ func join(a ...[]string) (r []string) {
}
return r
}
+
+func patchXsqlite3_initialize(fn string) error {
+ const s = "func Xsqlite3_initialize(tls *libc.TLS) int32 {"
+ return patch(fn, func(b []byte) []diff {
+ x := bytes.Index(b, []byte(s))
+ return []diff{{x, x + len(s), `
+var mu mutex
+
+func init() { mu.recursive = true }
+
+func Xsqlite3_initialize(tls *libc.TLS) int32 {
+ mu.enter(tls.ID)
+ defer mu.leave(tls.ID)
+
+`}}
+ })
+}
+
+type diff struct {
+ from, to int // byte offsets
+ replace string // replaces b[from:to]
+}
+
+func patch(fn string, f func([]byte) []diff) error {
+ b, err := os.ReadFile(fn)
+ if err != nil {
+ return err
+ }
+
+ diffs := f(b)
+ sort.Slice(diffs, func(i, j int) bool { return diffs[i].from < diffs[j].from })
+ var patched [][]byte
+ off := 0
+ for _, diff := range diffs {
+ from := diff.from - off
+ to := diff.to - off
+ patched = append(patched, b[:from])
+ patched = append(patched, []byte(diff.replace))
+ b = b[to:]
+ off += to
+ }
+ patched = append(patched, b)
+ return os.WriteFile(fn, bytes.Join(patched, nil), 0660)
+}