aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/golite.go36
-rw-r--r--tests/golite.go3
2 files changed, 33 insertions, 6 deletions
diff --git a/src/golite.go b/src/golite.go
index 7c280a0..00cbbc7 100644
--- a/src/golite.go
+++ b/src/golite.go
@@ -453,6 +453,32 @@ func (b *SQLiteBackup) Close() error {
return nil
}
+//export commitHookTrampoline
+func commitHookTrampoline(handle unsafe.Pointer) C.int {
+ return C.int(lookupHandle(handle).(func() int)())
+}
+
+//export rollbackHookTrampoline
+func rollbackHookTrampoline(handle unsafe.Pointer) {
+ lookupHandle(handle).(func())()
+}
+
+//export updateHookTrampoline
+func updateHookTrampoline(
+ handle unsafe.Pointer,
+ op C.int,
+ db *C.char,
+ table *C.char,
+ rowid int64,
+) {
+ lookupHandle(handle).(func(int, string, string, int64))(
+ int(op),
+ C.GoString(db),
+ C.GoString(table),
+ int64(rowid),
+ )
+}
+
// Use handles to avoid passing Go pointers to C.
type handleVal struct {
db *SQLiteConn
@@ -463,14 +489,16 @@ var handleLock sync.Mutex
var handleVals = make(map[unsafe.Pointer]handleVal)
func newHandle(db *SQLiteConn, v any) unsafe.Pointer {
- handleLock.Lock()
- defer handleLock.Unlock()
val := handleVal{db: db, val: v}
- var p unsafe.Pointer = C.malloc(C.size_t(1))
+ p := C.malloc(C.size_t(1))
if p == nil {
panic("can't allocate 'cgo-pointer hack index pointer': ptr == nil")
}
- handleVals[p] = val
+ {
+ handleLock.Lock()
+ defer handleLock.Unlock()
+ handleVals[p] = val
+ }
return p
}
diff --git a/tests/golite.go b/tests/golite.go
index bb79c49..04c4f09 100644
--- a/tests/golite.go
+++ b/tests/golite.go
@@ -5102,8 +5102,7 @@ func MainTest() {
// { "TestCollationRegistration", TestCollationRegistration },
{ "TestDeclTypes", TestDeclTypes },
{ "TestPinger", TestPinger },
- // { "TestUpdateAndTransactionHooks", TestUpdateAndTransactionHooks },
- // { "TestAuthorizer", TestAuthorizer },
+ { "TestUpdateAndTransactionHooks", TestUpdateAndTransactionHooks },
{ "TestSetFileControlInt", TestSetFileControlInt },
{ "TestNonColumnString", TestNonColumnString },
{ "TestNilAndEmptyBytes", TestNilAndEmptyBytes },