Chromium Code Reviews| Index: third_party/sqlite/amalgamation/sqlite3.c |
| diff --git a/third_party/sqlite/amalgamation/sqlite3.c b/third_party/sqlite/amalgamation/sqlite3.c |
| index 46a2b2c30a8a2003ba8419e948ff06816d918b0c..0a9aaf5a8b89bfa1456cde0e419e87fec5818c6a 100644 |
| --- a/third_party/sqlite/amalgamation/sqlite3.c |
| +++ b/third_party/sqlite/amalgamation/sqlite3.c |
| @@ -136711,20 +136711,24 @@ SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db){ |
| /* #include <assert.h> */ |
| /* #include <ctype.h> */ |
| +/* #include <stdint.h> */ |
|
Scott Hess - ex-Googler
2016/03/02 01:12:08
This file is generated by a script from files in s
|
| /* #include <stdio.h> */ |
| /* #include <string.h> */ |
| -/* Internal SQLite things that are used: |
| - * u32, u64, i64 types. |
| - * Btree, Pager, and DbPage structs. |
| - * DbPage.pData, .pPager, and .pgno |
| - * sqlite3 struct. |
| - * sqlite3BtreePager() and sqlite3BtreeGetPageSize() |
| - * sqlite3BtreeGetOptimalReserve() |
| - * sqlite3PagerGet() and sqlite3PagerUnref() |
| - * getVarint(). |
| - */ |
| -/* #include "sqliteInt.h" */ |
| +/* #include "sqlite3.h" */ |
| + |
| +/* Some SQLite internals use, cribbed from fts5int.h. */ |
| +#ifndef SQLITE_AMALGAMATION |
| +typedef uint8_t u8; |
| +typedef uint32_t u32; |
| +typedef sqlite3_int64 i64; |
| +typedef sqlite3_uint64 u64; |
| + |
| +#define ArraySize(x) (sizeof(x) / sizeof(x[0])) |
| +#endif |
| + |
| +/* From recover_varint.c. */ |
| +u8 recoverGetVarint(const unsigned char *p, u64 *v); |
| /* For debugging. */ |
| #if 0 |
| @@ -136921,7 +136925,7 @@ static int pagerCreate(sqlite3_file *pSqliteFile, u32 nPageSize, |
| const int kExcessSpace = 128; |
| typedef struct RecoverPage RecoverPage; |
| struct RecoverPage { |
| - Pgno pgno; /* Page number for this page */ |
| + u32 pgno; /* Page number for this page */ |
| void *pData; /* Page data for pgno */ |
| RecoverPager *pPager; /* The pager this page is part of */ |
| }; |
| @@ -137959,11 +137963,11 @@ static int leafCursorCellDecode(RecoverLeafCursor *pCursor){ |
| return ValidateError(); |
| } |
| - nRead = getVarint(pCell, &nRecordBytes); |
| + nRead = recoverGetVarint(pCell, &nRecordBytes); |
| assert( iCellOffset+nRead<=pCursor->nPageSize ); |
| pCursor->nRecordBytes = nRecordBytes; |
| - nRead += getVarint(pCell + nRead, &iRowid); |
| + nRead += recoverGetVarint(pCell + nRead, &iRowid); |
| assert( iCellOffset+nRead<=pCursor->nPageSize ); |
| pCursor->iRowid = (i64)iRowid; |
| @@ -137989,7 +137993,7 @@ static int leafCursorCellDecode(RecoverLeafCursor *pCursor){ |
| } |
| } |
| - nRecordHeaderRead = getVarint(pCell + nRead, &nRecordHeaderBytes); |
| + nRecordHeaderRead = recoverGetVarint(pCell + nRead, &nRecordHeaderBytes); |
| assert( nRecordHeaderBytes<=nRecordBytes ); |
| pCursor->nRecordHeaderBytes = nRecordHeaderBytes; |
| @@ -138011,8 +138015,8 @@ static int leafCursorCellDecode(RecoverLeafCursor *pCursor){ |
| nRecordHeaderBytes - nRecordHeaderRead) ){ |
| return ValidateError(); |
| } |
| - nRecordHeaderRead += getVarint(pCursor->pRecordHeader + nRecordHeaderRead, |
| - &iSerialType); |
| + nRecordHeaderRead += recoverGetVarint( |
| + pCursor->pRecordHeader + nRecordHeaderRead, &iSerialType); |
| if( iSerialType==10 || iSerialType==11 ){ |
| return ValidateError(); |
| } |
| @@ -138078,7 +138082,7 @@ static int leafCursorCellColInfo(RecoverLeafCursor *pCursor, |
| /* Rather than caching the header size and how many bytes it took, |
| * decode it every time. |
| */ |
| - nRead = getVarint(pRecordHeader, &nRecordHeaderBytes); |
| + nRead = recoverGetVarint(pRecordHeader, &nRecordHeaderBytes); |
| assert( nRecordHeaderBytes==pCursor->nRecordHeaderBytes ); |
| /* Scan forward to the indicated column. Scans to _after_ column |
| @@ -138097,7 +138101,7 @@ static int leafCursorCellColInfo(RecoverLeafCursor *pCursor, |
| if( !checkVarint(pRecordHeader + nRead, nRecordHeaderBytes - nRead) ){ |
| return SQLITE_CORRUPT; |
| } |
| - nRead += getVarint(pRecordHeader + nRead, &iSerialType); |
| + nRead += recoverGetVarint(pRecordHeader + nRead, &iSerialType); |
| iColEndOffset += SerialTypeLength(iSerialType); |
| nColsSkipped++; |
| } |
| @@ -138730,7 +138734,7 @@ static int recoverInit( |
| /* Parse out db.table, assuming main if no dot. */ |
| zDot = strchr(argv[3], '.'); |
| if( !zDot ){ |
| - pRecover->zDb = sqlite3_strdup(db->aDb[0].zName); |
| + pRecover->zDb = sqlite3_strdup("main"); |
| pRecover->zTable = sqlite3_strdup(argv[3]); |
| }else if( zDot>argv[3] && zDot[1]!='\0' ){ |
| pRecover->zDb = sqlite3_strndup(argv[3], zDot - argv[3]); |
| @@ -138782,6 +138786,210 @@ static int recoverInit( |
| } |
| /************** End of recover.c *********************************************/ |
| +/************** Begin file recover_varint.c **********************************/ |
| +/* |
| +** 2016 Feb 29 |
| +** |
| +** The author disclaims copyright to this source code. In place of |
| +** a legal notice, here is a blessing: |
| +** |
| +** May you do good and not evil. |
| +** May you find forgiveness for yourself and forgive others. |
| +** May you share freely, never taking more than you give. |
| +** |
| +****************************************************************************** |
| +** |
| +** Copy of sqlite3Fts5GetVarint() from fts3_varint.c, which in turn is copied |
| +** from SQLite core. |
| +*/ |
| + |
| +/* #include <assert.h> */ |
| +/* #include "sqlite3.h" */ |
| + |
| +/* Copied from fts3int.h. */ |
| +#ifndef SQLITE_AMALGAMATION |
| +typedef unsigned char u8; |
| +typedef unsigned int u32; |
| +typedef sqlite3_uint64 u64; |
| +#endif |
| + |
| +/* |
| +** Bitmasks used by sqlite3GetVarint(). These precomputed constants |
| +** are defined here rather than simply putting the constant expressions |
| +** inline in order to work around bugs in the RVT compiler. |
| +** |
| +** SLOT_2_0 A mask for (0x7f<<14) | 0x7f |
| +** |
| +** SLOT_4_2_0 A mask for (0x7f<<28) | SLOT_2_0 |
| +*/ |
| +#define SLOT_2_0 0x001fc07f |
| +#define SLOT_4_2_0 0xf01fc07f |
| + |
| +/* |
| +** Read a 64-bit variable-length integer from memory starting at p[0]. |
| +** Return the number of bytes read. The value is stored in *v. |
| +*/ |
| +u8 recoverGetVarint(const unsigned char *p, u64 *v){ |
| + u32 a,b,s; |
| + |
| + a = *p; |
| + /* a: p0 (unmasked) */ |
| + if (!(a&0x80)) |
| + { |
| + *v = a; |
| + return 1; |
| + } |
| + |
| + p++; |
| + b = *p; |
| + /* b: p1 (unmasked) */ |
| + if (!(b&0x80)) |
| + { |
| + a &= 0x7f; |
| + a = a<<7; |
| + a |= b; |
| + *v = a; |
| + return 2; |
| + } |
| + |
| + /* Verify that constants are precomputed correctly */ |
| + assert( SLOT_2_0 == ((0x7f<<14) | (0x7f)) ); |
| + assert( SLOT_4_2_0 == ((0xfU<<28) | (0x7f<<14) | (0x7f)) ); |
| + |
| + p++; |
| + a = a<<14; |
| + a |= *p; |
| + /* a: p0<<14 | p2 (unmasked) */ |
| + if (!(a&0x80)) |
| + { |
| + a &= SLOT_2_0; |
| + b &= 0x7f; |
| + b = b<<7; |
| + a |= b; |
| + *v = a; |
| + return 3; |
| + } |
| + |
| + /* CSE1 from below */ |
| + a &= SLOT_2_0; |
| + p++; |
| + b = b<<14; |
| + b |= *p; |
| + /* b: p1<<14 | p3 (unmasked) */ |
| + if (!(b&0x80)) |
| + { |
| + b &= SLOT_2_0; |
| + /* moved CSE1 up */ |
| + /* a &= (0x7f<<14)|(0x7f); */ |
| + a = a<<7; |
| + a |= b; |
| + *v = a; |
| + return 4; |
| + } |
| + |
| + /* a: p0<<14 | p2 (masked) */ |
| + /* b: p1<<14 | p3 (unmasked) */ |
| + /* 1:save off p0<<21 | p1<<14 | p2<<7 | p3 (masked) */ |
| + /* moved CSE1 up */ |
| + /* a &= (0x7f<<14)|(0x7f); */ |
| + b &= SLOT_2_0; |
| + s = a; |
| + /* s: p0<<14 | p2 (masked) */ |
| + |
| + p++; |
| + a = a<<14; |
| + a |= *p; |
| + /* a: p0<<28 | p2<<14 | p4 (unmasked) */ |
| + if (!(a&0x80)) |
| + { |
| + /* we can skip these cause they were (effectively) done above in calc'ing s */ |
| + /* a &= (0x7f<<28)|(0x7f<<14)|(0x7f); */ |
| + /* b &= (0x7f<<14)|(0x7f); */ |
| + b = b<<7; |
| + a |= b; |
| + s = s>>18; |
| + *v = ((u64)s)<<32 | a; |
| + return 5; |
| + } |
| + |
| + /* 2:save off p0<<21 | p1<<14 | p2<<7 | p3 (masked) */ |
| + s = s<<7; |
| + s |= b; |
| + /* s: p0<<21 | p1<<14 | p2<<7 | p3 (masked) */ |
| + |
| + p++; |
| + b = b<<14; |
| + b |= *p; |
| + /* b: p1<<28 | p3<<14 | p5 (unmasked) */ |
| + if (!(b&0x80)) |
| + { |
| + /* we can skip this cause it was (effectively) done above in calc'ing s */ |
| + /* b &= (0x7f<<28)|(0x7f<<14)|(0x7f); */ |
| + a &= SLOT_2_0; |
| + a = a<<7; |
| + a |= b; |
| + s = s>>18; |
| + *v = ((u64)s)<<32 | a; |
| + return 6; |
| + } |
| + |
| + p++; |
| + a = a<<14; |
| + a |= *p; |
| + /* a: p2<<28 | p4<<14 | p6 (unmasked) */ |
| + if (!(a&0x80)) |
| + { |
| + a &= SLOT_4_2_0; |
| + b &= SLOT_2_0; |
| + b = b<<7; |
| + a |= b; |
| + s = s>>11; |
| + *v = ((u64)s)<<32 | a; |
| + return 7; |
| + } |
| + |
| + /* CSE2 from below */ |
| + a &= SLOT_2_0; |
| + p++; |
| + b = b<<14; |
| + b |= *p; |
| + /* b: p3<<28 | p5<<14 | p7 (unmasked) */ |
| + if (!(b&0x80)) |
| + { |
| + b &= SLOT_4_2_0; |
| + /* moved CSE2 up */ |
| + /* a &= (0x7f<<14)|(0x7f); */ |
| + a = a<<7; |
| + a |= b; |
| + s = s>>4; |
| + *v = ((u64)s)<<32 | a; |
| + return 8; |
| + } |
| + |
| + p++; |
| + a = a<<15; |
| + a |= *p; |
| + /* a: p4<<29 | p6<<15 | p8 (unmasked) */ |
| + |
| + /* moved CSE2 up */ |
| + /* a &= (0x7f<<29)|(0x7f<<15)|(0xff); */ |
| + b &= SLOT_2_0; |
| + b = b<<8; |
| + a |= b; |
| + |
| + s = s<<4; |
| + b = p[-4]; |
| + b &= 0x7f; |
| + b = b>>3; |
| + s |= b; |
| + |
| + *v = ((u64)s)<<32 | a; |
| + |
| + return 9; |
| +} |
| + |
| + |
| +/************** End of recover_varint.c **************************************/ |
| /************** Begin file fts3.c ********************************************/ |
| /* |
| ** 2006 Oct 10 |