// Code generated by modernc.org/undup from the per-target sqlite_*.go files; DO NOT EDIT. //go:build (darwin && amd64) || (darwin && arm64) || (freebsd && 386) || (freebsd && amd64) || (freebsd && arm) || (freebsd && arm64) || (linux && 386) || (linux && amd64) || (linux && arm) || (linux && arm64) || (linux && loong64) || (linux && ppc64le) || (linux && riscv64) || (netbsd && amd64) || (openbsd && amd64) || (openbsd && arm64) package sqlite3 import ( "unsafe" "modernc.org/libc" ) const BYTE_ORDER = 1234 func Xsqlite3_bind_text16(tls *libc.TLS, pStmt uintptr, i int32, zData uintptr, n int32, __ccgo_fp_xDel uintptr) (r int32) { return _bindText(tls, pStmt, i, zData, libc.Int64FromUint64(libc.Uint64FromInt32(n) & ^libc.Uint64FromInt32(1)), __ccgo_fp_xDel, uint8(SQLITE_UTF16LE)) } func Xsqlite3_bind_text64(tls *libc.TLS, pStmt uintptr, i int32, zData uintptr, nData Tsqlite3_uint64, __ccgo_fp_xDel uintptr, enc uint8) (r int32) { if libc.Int32FromUint8(enc) != int32(SQLITE_UTF8) && libc.Int32FromUint8(enc) != int32(SQLITE_UTF8_ZT) { if libc.Int32FromUint8(enc) == int32(SQLITE_UTF16) { enc = uint8(SQLITE_UTF16LE) } nData = nData & ^libc.Uint64FromInt32(1) } return _bindText(tls, pStmt, i, zData, libc.Int64FromUint64(nData), __ccgo_fp_xDel, enc) } // C documentation // // /* // ** Register a new collation sequence with the database handle db. // */ func Xsqlite3_create_collation16(tls *libc.TLS, db uintptr, zName uintptr, enc int32, pCtx uintptr, __ccgo_fp_xCompare uintptr) (r int32) { var rc int32 var zName8 uintptr _, _ = rc, zName8 rc = SQLITE_OK Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex) zName8 = _sqlite3Utf16to8(tls, db, zName, -int32(1), uint8(SQLITE_UTF16LE)) if zName8 != 0 { rc = _createCollation(tls, db, zName8, libc.Uint8FromInt32(enc), pCtx, __ccgo_fp_xCompare, uintptr(0)) _sqlite3DbFree(tls, db, zName8) } rc = _sqlite3ApiExit(tls, db, rc) Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex) return rc } func Xsqlite3_result_text16(tls *libc.TLS, pCtx uintptr, z uintptr, n int32, __ccgo_fp_xDel uintptr) { _setResultStrOrError(tls, pCtx, z, libc.Int32FromUint64(libc.Uint64FromInt32(n) & ^libc.Uint64FromInt32(1)), uint8(SQLITE_UTF16LE), __ccgo_fp_xDel) } func Xsqlite3_result_text64(tls *libc.TLS, pCtx uintptr, z uintptr, n Tsqlite3_uint64, __ccgo_fp_xDel uintptr, enc uint8) { if libc.Int32FromUint8(enc) != int32(SQLITE_UTF8) && libc.Int32FromUint8(enc) != int32(SQLITE_UTF8_ZT) { if libc.Int32FromUint8(enc) == int32(SQLITE_UTF16) { enc = uint8(SQLITE_UTF16LE) } n = n & ^libc.Uint64FromInt32(1) } if n > uint64(0x7fffffff) { _invokeValueDestructor(tls, z, __ccgo_fp_xDel, pCtx) } else { _setResultStrOrError(tls, pCtx, z, libc.Int32FromUint64(n), enc, __ccgo_fp_xDel) _sqlite3VdbeMemZeroTerminateIfAble(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut) } } // C documentation // // /* // ** Do additional sanity check after btreeInitPage() if // ** PRAGMA cell_size_check=ON // */ func _btreeCellSizeCheck(tls *libc.TLS, pPage uintptr) (r int32) { var cellOffset, i, iCellFirst, iCellLast, pc, sz, usableSize int32 var data uintptr _, _, _, _, _, _, _, _ = cellOffset, data, i, iCellFirst, iCellLast, pc, sz, usableSize /* Start of cell content area */ iCellFirst = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FcellOffset) + int32(2)*libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) usableSize = libc.Int32FromUint32((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize) iCellLast = usableSize - int32(4) data = (*TMemPage)(unsafe.Pointer(pPage)).FaData cellOffset = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FcellOffset) if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) { iCellLast = iCellLast - 1 } i = 0 for { if !(i < libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell)) { break } pc = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(cellOffset+i*int32(2)))))< iCellLast { return _sqlite3CorruptError(tls, int32(75424)) } sz = libc.Int32FromUint16((*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxCellSize})))(tls, pPage, data+uintptr(pc))) if pc+sz > usableSize { return _sqlite3CorruptError(tls, int32(75429)) } goto _1 _1: ; i = i + 1 } return SQLITE_OK } func _btreeParseCell(tls *libc.TLS, pPage uintptr, iCell int32, pInfo uintptr) { (*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell})))(tls, pPage, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*iCell))))<= int32(CURSOR_REQUIRESEEK) { v1 = _btreeRestoreCursorPosition(tls, pCur) } else { v1 = SQLITE_OK } rc = v1 if rc != SQLITE_OK { return rc } if int32(CURSOR_INVALID) == libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FeState) { return int32(SQLITE_DONE) } if int32(CURSOR_SKIPNEXT) == libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FeState) { (*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_VALID) if (*TBtCursor)(unsafe.Pointer(pCur)).FskipNext < 0 { return SQLITE_OK } } } pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage if _sqlite3FaultSim(tls, int32(412)) != 0 { (*TMemPage)(unsafe.Pointer(pPage)).FisInit = uint8(0) } if !((*TMemPage)(unsafe.Pointer(pPage)).FisInit != 0) { return _sqlite3CorruptError(tls, int32(79674)) } if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) { idx = libc.Int32FromUint16((*TBtCursor)(unsafe.Pointer(pCur)).Fix) rc = _moveToChild(tls, pCur, _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*idx))))<= (*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd { return int32(99) } c = (*(*func(*libc.TLS, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xRecordCompare})))(tls, nCell, pCell+1, pIdxKey) } else { if v2 = !(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pCell + 1)))&libc.Int32FromInt32(0x80) != 0); v2 { v1 = nCell&libc.Int32FromInt32(0x7f)<= (*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd { return int32(99) } c = (*(*func(*libc.TLS, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xRecordCompare})))(tls, nCell, pCell+2, pIdxKey) } else { /* If the record extends into overflow pages, do not attempt ** the optimization. */ c = int32(99) } } return c } // C documentation // // /* // ** Somewhere on pPage is a pointer to page iFrom. Modify this pointer so // ** that it points to iTo. Parameter eType describes the type of pointer to // ** be modified, as follows: // ** // ** PTRMAP_BTREE: pPage is a btree-page. The pointer points at a child // ** page of pPage. // ** // ** PTRMAP_OVERFLOW1: pPage is a btree-page. The pointer points at an overflow // ** page pointed to by one of the cells on pPage. // ** // ** PTRMAP_OVERFLOW2: pPage is an overflow-page. The pointer points at the next // ** overflow page in the list. // */ func _modifyPagePointer(tls *libc.TLS, pPage uintptr, iFrom TPgno, iTo TPgno, eType Tu8) (r int32) { bp := tls.Alloc(32) defer tls.Free(32) var i, nCell, rc, v1 int32 var pCell uintptr var _ /* info at bp+0 */ TCellInfo _, _, _, _, _ = i, nCell, pCell, rc, v1 if libc.Int32FromUint8(eType) == int32(PTRMAP_OVERFLOW2) { /* The pointer is always the first 4 bytes of the page in this case. */ if _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData) != iFrom { return _sqlite3CorruptError(tls, int32(77112)) } _sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData, iTo) } else { if (*TMemPage)(unsafe.Pointer(pPage)).FisInit != 0 { v1 = SQLITE_OK } else { v1 = _btreeInitPage(tls, pPage) } rc = v1 if rc != 0 { return rc } nCell = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) i = 0 for { if !(i < nCell) { break } pCell = (*TMemPage)(unsafe.Pointer(pPage)).FaData + uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*i))))< (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize) { return _sqlite3CorruptError(tls, int32(77131)) } if iFrom == _sqlite3Get4byte(tls, pCell+uintptr((**(**TCellInfo)(__ccgo_up(bp))).FnSize)-uintptr(4)) { _sqlite3Put4byte(tls, pCell+uintptr((**(**TCellInfo)(__ccgo_up(bp))).FnSize)-uintptr(4), iTo) break } } } else { if pCell+uintptr(4) > (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize) { return _sqlite3CorruptError(tls, int32(77140)) } if _sqlite3Get4byte(tls, pCell) == iFrom { _sqlite3Put4byte(tls, pCell, iTo) break } } goto _2 _2: ; i = i + 1 } if i == nCell { if libc.Int32FromUint8(eType) != int32(PTRMAP_BTREE) || _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8))) != iFrom { return _sqlite3CorruptError(tls, int32(77152)) } _sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8)), iTo) } } return SQLITE_OK } // C documentation // // /* // ** Move the cursor down to the left-most leaf entry beneath the // ** entry to which it is currently pointing. // ** // ** The left-most leaf is the one with the smallest key - the first // ** in ascending order. // */ func _moveToLeftmost(tls *libc.TLS, pCur uintptr) (r int32) { var pPage, v1 uintptr var pgno TPgno var rc int32 var v2 bool _, _, _, _, _ = pPage, pgno, rc, v1, v2 rc = SQLITE_OK for { if v2 = rc == SQLITE_OK; v2 { v1 = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage pPage = v1 } if !(v2 && !((*TMemPage)(unsafe.Pointer(v1)).Fleaf != 0)) { break } pgno = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*libc.Int32FromUint16((*TBtCursor)(unsafe.Pointer(pCur)).Fix)))))<0 The cursor is left pointing at an entry that // ** is larger than intKey. // */ func _sqlite3BtreeTableMoveto(tls *libc.TLS, pCur uintptr, intKey Ti64, biasRight int32, pRes uintptr) (r int32) { bp := tls.Alloc(16) defer tls.Free(16) var c, idx, lwr, rc, upr int32 var chldPg TPgno var pCell, pPage, v3 uintptr var _ /* nCellKey at bp+0 */ Ti64 _, _, _, _, _, _, _, _, _ = c, chldPg, idx, lwr, pCell, pPage, rc, upr, v3 /* If the cursor is already positioned at the point we are trying ** to move to, then just return without doing any work */ if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_VALID && libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags)&int32(BTCF_ValidNKey) != 0 { if (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey == intKey { **(**int32)(__ccgo_up(pRes)) = 0 return SQLITE_OK } if (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey < intKey { if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags)&int32(BTCF_AtLast) != 0 { **(**int32)(__ccgo_up(pRes)) = -int32(1) return SQLITE_OK } /* If the requested key is one more than the previous key, then ** try to get there using sqlite3BtreeNext() rather than a full ** binary search. This is an optimization only. The correct answer ** is still obtained without this case, only a little more slowly. */ if (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey+int64(1) == intKey { **(**int32)(__ccgo_up(pRes)) = 0 rc = _sqlite3BtreeNext(tls, pCur, 0) if rc == SQLITE_OK { _getCellInfo(tls, pCur) if (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey == intKey { return SQLITE_OK } } else { if rc != int32(SQLITE_DONE) { return rc } } } } } rc = _moveToRoot(tls, pCur) if rc != 0 { if rc == int32(SQLITE_EMPTY) { **(**int32)(__ccgo_up(pRes)) = -int32(1) return SQLITE_OK } return rc } for { pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage /* Pointer to current cell in pPage */ /* pPage->nCell must be greater than zero. If this is the root-page ** the cursor would have been INVALID above and this for(;;) loop ** not run. If this is not the root-page, then the moveToChild() routine ** would have already detected db corruption. Similarly, pPage must ** be the right kind (index or table) of b-tree page. Otherwise ** a moveToChild() or moveToRoot() call would have detected corruption. */ lwr = 0 upr = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) - int32(1) idx = upr >> (int32(1) - biasRight) /* idx = biasRight ? upr : (lwr+upr)/2; */ for { pCell = (*TMemPage)(unsafe.Pointer(pPage)).FaDataOfst + uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*idx))))<= (*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd { return _sqlite3CorruptError(tls, int32(79121)) } } } _sqlite3GetVarint(tls, pCell, bp) if **(**Ti64)(__ccgo_up(bp)) < intKey { lwr = idx + int32(1) if lwr > upr { c = -int32(1) break } } else { if **(**Ti64)(__ccgo_up(bp)) > intKey { upr = idx - int32(1) if lwr > upr { c = +libc.Int32FromInt32(1) break } } else { (*TBtCursor)(unsafe.Pointer(pCur)).Fix = libc.Uint16FromInt32(idx) if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) { lwr = idx goto moveto_table_next_layer } else { v3 = pCur + 1 *(*Tu8)(unsafe.Pointer(v3)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v3))) | libc.Int32FromInt32(BTCF_ValidNKey)) (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey = **(**Ti64)(__ccgo_up(bp)) (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = uint16(0) **(**int32)(__ccgo_up(pRes)) = 0 return SQLITE_OK } } } idx = (lwr + upr) >> int32(1) /* idx = (lwr+upr)/2; */ goto _2 _2: } if (*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0 { (*TBtCursor)(unsafe.Pointer(pCur)).Fix = libc.Uint16FromInt32(idx) **(**int32)(__ccgo_up(pRes)) = c rc = SQLITE_OK goto moveto_table_finish } goto moveto_table_next_layer moveto_table_next_layer: ; if lwr >= libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) { chldPg = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8))) } else { chldPg = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*lwr))))<> libc.Int32FromInt32(56) & int64(0xFF)) **(**Tu8)(__ccgo_up(p + 1)) = libc.Uint8FromInt64(i >> libc.Int32FromInt32(48) & int64(0xFF)) **(**Tu8)(__ccgo_up(p + 2)) = libc.Uint8FromInt64(i >> libc.Int32FromInt32(40) & int64(0xFF)) **(**Tu8)(__ccgo_up(p + 3)) = libc.Uint8FromInt64(i >> libc.Int32FromInt32(32) & int64(0xFF)) **(**Tu8)(__ccgo_up(p + 4)) = libc.Uint8FromInt64(i >> libc.Int32FromInt32(24) & int64(0xFF)) **(**Tu8)(__ccgo_up(p + 5)) = libc.Uint8FromInt64(i >> libc.Int32FromInt32(16) & int64(0xFF)) **(**Tu8)(__ccgo_up(p + 6)) = libc.Uint8FromInt64(i >> libc.Int32FromInt32(8) & int64(0xFF)) **(**Tu8)(__ccgo_up(p + 7)) = libc.Uint8FromInt64(i >> libc.Int32FromInt32(0) & int64(0xFF)) return int32(8) }