diff options
author | EuAndreh <eu@euandre.org> | 2024-09-12 19:33:20 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-09-12 19:35:34 -0300 |
commit | 03583c961cee000b3a71fc748bda5cb1c33b1d0c (patch) | |
tree | 0d7bce56e83d4ade9c6b7b8aee1f0b825de67169 | |
parent | tests/golite.go: Use in-memory database on more tests (diff) | |
download | golite-03583c961cee000b3a71fc748bda5cb1c33b1d0c.tar.gz golite-03583c961cee000b3a71fc748bda5cb1c33b1d0c.tar.xz |
src/golite.go: Re-introduce {commit,rollback,update}HookTrampoline CFFI functions
-rw-r--r-- | src/golite.go | 36 | ||||
-rw-r--r-- | tests/golite.go | 3 |
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 }, |