github.com/tailscale/sqlite@v0.0.0-20240515181108-c667cbe57c66/cgosqlite/walcallback.go (about) 1 package cgosqlite 2 3 // #include <sqlite3.h> 4 import "C" 5 import ( 6 "sync" 7 "unsafe" 8 ) 9 10 type walHookCb func(dbName string, pages int) 11 12 var walHookFunc sync.Map // from *C.sqlite3 to walHookCb 13 14 //export walCallbackGo 15 func walCallbackGo(db *C.sqlite3, dbNameC *C.char, dbNameLen C.int, pages C.int) C.int { 16 v, _ := walHookFunc.Load(db) 17 hook, _ := v.(walHookCb) 18 if hook == nil { 19 return C.int(0) 20 } 21 22 dbNameB := unsafe.Slice((*byte)(unsafe.Pointer(dbNameC)), dbNameLen) 23 dbName := internStringFromBytes(dbNameB) 24 hook(dbName, int(pages)) 25 return C.int(0) // result's kinda useless 26 }