// Call this routine to record the fact that an OOM (out-of-memory) error
// has happened. This routine will set db->mallocFailed, and also
// temporarily disable the lookaside memory allocator and interrupt
// any running VDBEs.
func Xsqlite3OomFault(tls *libc.TLS, db uintptr) { /* sqlite3.c:28548:21: */
if (int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0) &&
(int32((*Sqlite3)(unsafe.Pointer(db)).FbBenignMalloc) == 0) {
(*Sqlite3)(unsafe.Pointer(db)).FmallocFailed = U8(1)
if (*Sqlite3)(unsafe.Pointer(db)).FnVdbeExec > 0 {
libc.AtomicStoreNInt32((db + 400 /* &.u1 */ /* &.isInterrupted */), int32(1), 0)
}
(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable++
(*Sqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = U16(0)
if (*Sqlite3)(unsafe.Pointer(db)).FpParse != 0 {
(*Parse)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FpParse)).Frc = SQLITE_NOMEM
}
}
}
Being translated means it doesn't have the normal cgo calling overhead. It also means you can cross compile it for every platform that the Go toolchain supports without any external compilers.
OP mentioned that the pure-Go version is ~6 times slower, so the cgo calling overhead is clearly made up for by C. Also, I've heard that sqlite is the rare piece of C software that is actually bulletproof, so I don't think the pure-Go version can make the usual boasts about correctness and security in this particular case.
Not needing extra external compilers is still a nice proposition, however.
Just about all the code looks like this: