4 ms·
It's not really pure go, it's transpiled using https://gitlab.com/cznic/ccgo https://gitlab.com/cznic/ccgo Just about all the code looks like this: // Call
by justinsaccount 5y ago
It's not really pure go, it's transpiled using https://gitlab.com/cznic/ccgo https://gitlab.com/cznic/ccgo
Just about all the code looks like this:
// 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
}
}
}
- psanford 5y agoBeing 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.
- throwaway894345 5y agoOP 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.
- tgv 5y agoEspecially for portability/cross compiling.
- justinsaccount 5y agoNope, note their readme says: These combinations of GOOS and GOARCH are currently supported darwin amd64, darwin arm64, freebsd amd64, linux 386, linux amd64, linux arm, linux arm64, windows amd64 and if you look at their source tree https://gitlab.com/cznic/sqlite/-/tree/master/lib https://gitlab.com/cznic/sqlite/-/tree/master/lib you can see they have sqlite_darwin_amd64.go sqlite_darwin_arm64.go sqlite_freebsd_amd64.go sqlite_linux_386.go sqlite_linux_amd64.go sqlite_linux_arm.go sqlite_linux_arm64.go sqlite_linux_s390x.go sqlite_windows_386.go sqlite_windows_amd64.go
- therein 5y agoThat's nice and impressive as far as it goes for portability however on the other side, we have C.