Commit 8ae4b9f6 authored by shess's avatar shess Committed by Commit bot

[sqlite] Bring patches up-to-date with trunk.

CL https://codereview.chromium.org/1753993002 landed changes to allow
recover.c to compile outside of SQLite core.  It also neglected to
fully update the patches, so that patching according to
README.chromium resulted in something different from trunk.  Bring it
back in line with trunk.

Additionally update README.chromium with the current version, and
tweak the patch instructions to work better.

BUG=584407
TBR=michaeln@chromium.org

Review-Url: https://codereview.chromium.org/2366013002
Cr-Commit-Position: refs/heads/master@{#420744}
parent dee58c1c
Name: sqlite Name: sqlite
URL: http://sqlite.org/ URL: http://sqlite.org/
Version: 3.8.7.4 Version: 3.10.2
Included In Release: Yes Included In Release: Yes
Security Critical: Yes Security Critical: Yes
License: Public domain License: Public domain
...@@ -55,6 +55,7 @@ BASE=3080704 ...@@ -55,6 +55,7 @@ BASE=3080704
#### Create a reference branch. #### Create a reference branch.
git checkout -b sqlite_${BASE} master git checkout -b sqlite_${BASE} master
git rm -rf src git rm -rf src
rm -rf src # In case there are things git doesn't know in there.
cp -a sqlite-src-${BASE} src cp -a sqlite-src-${BASE} src
# -f includes ignored files, of which there are a couple. # -f includes ignored files, of which there are a couple.
git add -f src/ git add -f src/
......
From 31dd2fd1cdeba87223f6a46cc19bcea9eb8b2f38 Mon Sep 17 00:00:00 2001 From d176c774ba1a8b431400f38ca71459bf148f0c3a Mon Sep 17 00:00:00 2001
From: Scott Hess <shess@chromium.org> From: Scott Hess <shess@chromium.org>
Date: Sat, 20 Jul 2013 11:42:21 -0700 Date: Sat, 20 Jul 2013 11:42:21 -0700
Subject: [PATCH 05/13] Virtual table supporting recovery of corrupted Subject: [PATCH 05/13] Virtual table supporting recovery of corrupted
...@@ -15,53 +15,26 @@ listed. This patch and the top of recover.c should be considered ...@@ -15,53 +15,26 @@ listed. This patch and the top of recover.c should be considered
authoritative. The history is mostly under authoritative. The history is mostly under
third_party/sqlite/src/src/{recover,recover-alt}.c . third_party/sqlite/src/src/{recover,recover-alt}.c .
--- ---
third_party/sqlite/src/Makefile.in | 1 + third_party/sqlite/src/main.mk | 6 +-
third_party/sqlite/src/Makefile.linux-gcc | 4 + third_party/sqlite/src/src/main.c | 8 +
third_party/sqlite/src/main.mk | 5 +- third_party/sqlite/src/src/recover.c | 2270 +++++++++++++++++++++++++++
third_party/sqlite/src/src/main.c | 8 + third_party/sqlite/src/src/recover.h | 23 +
third_party/sqlite/src/src/recover.c | 2281 ++++++++++++++++++++++++++++ third_party/sqlite/src/src/recover_varint.c | 201 +++
third_party/sqlite/src/src/sqlite.h.in | 16 + third_party/sqlite/src/test/recover.test | 164 ++
third_party/sqlite/src/test/recover.test | 164 ++ third_party/sqlite/src/test/recover0.test | 532 +++++++
third_party/sqlite/src/test/recover0.test | 532 +++++++ third_party/sqlite/src/test/recover1.test | 429 +++++
third_party/sqlite/src/test/recover1.test | 429 ++++++ third_party/sqlite/src/test/recover2.test | 157 ++
third_party/sqlite/src/test/recover2.test | 157 ++ 9 files changed, 3789 insertions(+), 1 deletion(-)
third_party/sqlite/src/tool/mksqlite3c.tcl | 2 +
11 files changed, 3598 insertions(+), 1 deletion(-)
create mode 100644 third_party/sqlite/src/src/recover.c create mode 100644 third_party/sqlite/src/src/recover.c
create mode 100644 third_party/sqlite/src/src/recover.h
create mode 100644 third_party/sqlite/src/src/recover_varint.c
create mode 100644 third_party/sqlite/src/test/recover.test create mode 100644 third_party/sqlite/src/test/recover.test
create mode 100644 third_party/sqlite/src/test/recover0.test create mode 100644 third_party/sqlite/src/test/recover0.test
create mode 100644 third_party/sqlite/src/test/recover1.test create mode 100644 third_party/sqlite/src/test/recover1.test
create mode 100644 third_party/sqlite/src/test/recover2.test create mode 100644 third_party/sqlite/src/test/recover2.test
diff --git a/third_party/sqlite/src/Makefile.in b/third_party/sqlite/src/Makefile.in
index 1fe49d6..8b965c7 100644
--- a/third_party/sqlite/src/Makefile.in
+++ b/third_party/sqlite/src/Makefile.in
@@ -260,6 +260,7 @@ SRC = \
$(TOP)/src/prepare.c \
$(TOP)/src/printf.c \
$(TOP)/src/random.c \
+ $(TOP)/src/recover.c \
$(TOP)/src/resolve.c \
$(TOP)/src/rowset.c \
$(TOP)/src/select.c \
diff --git a/third_party/sqlite/src/Makefile.linux-gcc b/third_party/sqlite/src/Makefile.linux-gcc
index 952e8d1..f6291c0 100644
--- a/third_party/sqlite/src/Makefile.linux-gcc
+++ b/third_party/sqlite/src/Makefile.linux-gcc
@@ -81,6 +81,10 @@ OPTS += -DSQLITE_MEMDEBUG=1
# TODO(shess) I can't see why I need this setting.
OPTS += -DOS_UNIX=1
+# The recover virtual table is not generally enabled. Enable it for testing
+# purposes.
+OPTS += -DDEFAULT_ENABLE_RECOVER=1
+
#### The suffix to add to executable files. ".exe" for windows.
# Nothing for unix.
#
diff --git a/third_party/sqlite/src/main.mk b/third_party/sqlite/src/main.mk diff --git a/third_party/sqlite/src/main.mk b/third_party/sqlite/src/main.mk
index 6ff3bd4..a8629aa 100644 index 6ff3bd4..26f9f15 100644
--- a/third_party/sqlite/src/main.mk --- a/third_party/sqlite/src/main.mk
+++ b/third_party/sqlite/src/main.mk +++ b/third_party/sqlite/src/main.mk
@@ -67,7 +67,8 @@ LIBOBJ+= vdbe.o parse.o \ @@ -67,7 +67,8 @@ LIBOBJ+= vdbe.o parse.o \
...@@ -69,27 +42,28 @@ index 6ff3bd4..a8629aa 100644 ...@@ -69,27 +42,28 @@ index 6ff3bd4..a8629aa 100644
notify.o opcodes.o os.o os_unix.o os_win.o \ notify.o opcodes.o os.o os_unix.o os_win.o \
pager.o pcache.o pcache1.o pragma.o prepare.o printf.o \ pager.o pcache.o pcache1.o pragma.o prepare.o printf.o \
- random.o resolve.o rowset.o rtree.o select.o sqlite3rbu.o status.o \ - random.o resolve.o rowset.o rtree.o select.o sqlite3rbu.o status.o \
+ random.o recover.o resolve.o rowset.o rtree.o \ + random.o recover.o recover_varint.o resolve.o rowset.o rtree.o \
+ select.o sqlite3rbu.o status.o \ + select.o sqlite3rbu.o status.o \
table.o threads.o tokenize.o treeview.o trigger.o \ table.o threads.o tokenize.o treeview.o trigger.o \
update.o userauth.o util.o vacuum.o \ update.o userauth.o util.o vacuum.o \
vdbeapi.o vdbeaux.o vdbeblob.o vdbemem.o vdbesort.o \ vdbeapi.o vdbeaux.o vdbeblob.o vdbemem.o vdbesort.o \
@@ -140,6 +141,7 @@ SRC = \ @@ -360,6 +361,8 @@ TESTSRC2 = \
$(TOP)/src/prepare.c \
$(TOP)/src/printf.c \
$(TOP)/src/random.c \
+ $(TOP)/src/recover.c \
$(TOP)/src/resolve.c \
$(TOP)/src/rowset.c \
$(TOP)/src/select.c \
@@ -360,6 +362,7 @@ TESTSRC2 = \
$(TOP)/src/prepare.c \ $(TOP)/src/prepare.c \
$(TOP)/src/printf.c \ $(TOP)/src/printf.c \
$(TOP)/src/random.c \ $(TOP)/src/random.c \
+ $(TOP)/src/recover.c \ + $(TOP)/src/recover.c \
+ $(TOP)/src/recover_varint.c \
$(TOP)/src/pcache.c \ $(TOP)/src/pcache.c \
$(TOP)/src/pcache1.c \ $(TOP)/src/pcache1.c \
$(TOP)/src/select.c \ $(TOP)/src/select.c \
@@ -720,6 +723,7 @@ sqlite3_analyzer$(EXE): sqlite3_analyzer.c
#
TESTFIXTURE_FLAGS = -DSQLITE_TEST=1 -DSQLITE_CRASH_TEST=1
TESTFIXTURE_FLAGS += -DSQLITE_SERVER=1 -DSQLITE_PRIVATE="" -DSQLITE_CORE
+TESTFIXTURE_FLAGS += -DDEFAULT_ENABLE_RECOVER=1
testfixture$(EXE): $(TESTSRC2) libsqlite3.a $(TESTSRC) $(TOP)/src/tclsqlite.c
$(TCCX) $(TCL_FLAGS) -DTCLSH=1 $(TESTFIXTURE_FLAGS) \
diff --git a/third_party/sqlite/src/src/main.c b/third_party/sqlite/src/src/main.c diff --git a/third_party/sqlite/src/src/main.c b/third_party/sqlite/src/src/main.c
index 3be7c77..301808c 100644 index 3be7c77..301808c 100644
--- a/third_party/sqlite/src/src/main.c --- a/third_party/sqlite/src/src/main.c
...@@ -111,10 +85,10 @@ index 3be7c77..301808c 100644 ...@@ -111,10 +85,10 @@ index 3be7c77..301808c 100644
rc = sqlite3IcuInit(db); rc = sqlite3IcuInit(db);
diff --git a/third_party/sqlite/src/src/recover.c b/third_party/sqlite/src/src/recover.c diff --git a/third_party/sqlite/src/src/recover.c b/third_party/sqlite/src/src/recover.c
new file mode 100644 new file mode 100644
index 0000000..5ff6f78 index 0000000..c22fd4d
--- /dev/null --- /dev/null
+++ b/third_party/sqlite/src/src/recover.c +++ b/third_party/sqlite/src/src/recover.c
@@ -0,0 +1,2281 @@ @@ -0,0 +1,2270 @@
+/* +/*
+** 2012 Jan 11 +** 2012 Jan 11
+** +**
...@@ -327,20 +301,24 @@ index 0000000..5ff6f78 ...@@ -327,20 +301,24 @@ index 0000000..5ff6f78
+ +
+#include <assert.h> +#include <assert.h>
+#include <ctype.h> +#include <ctype.h>
+#include <stdint.h>
+#include <stdio.h> +#include <stdio.h>
+#include <string.h> +#include <string.h>
+ +
+/* Internal SQLite things that are used: +#include "sqlite3.h"
+ * u32, u64, i64 types. +
+ * Btree, Pager, and DbPage structs. +/* Some SQLite internals use, cribbed from fts5int.h. */
+ * DbPage.pData, .pPager, and .pgno +#ifndef SQLITE_AMALGAMATION
+ * sqlite3 struct. +typedef uint8_t u8;
+ * sqlite3BtreePager() and sqlite3BtreeGetPageSize() +typedef uint32_t u32;
+ * sqlite3BtreeGetOptimalReserve() +typedef sqlite3_int64 i64;
+ * sqlite3PagerGet() and sqlite3PagerUnref() +typedef sqlite3_uint64 u64;
+ * getVarint(). +
+ */ +#define ArraySize(x) (sizeof(x) / sizeof(x[0]))
+#include "sqliteInt.h" +#endif
+
+/* From recover_varint.c. */
+u8 recoverGetVarint(const unsigned char *p, u64 *v);
+ +
+/* For debugging. */ +/* For debugging. */
+#if 0 +#if 0
...@@ -365,10 +343,10 @@ index 0000000..5ff6f78 ...@@ -365,10 +343,10 @@ index 0000000..5ff6f78
+ +
+/* From section 1.5. */ +/* From section 1.5. */
+static const unsigned kiPageTypeOffset = 0; +static const unsigned kiPageTypeOffset = 0;
+static const unsigned kiPageFreeBlockOffset = 1; +/* static const unsigned kiPageFreeBlockOffset = 1; */
+static const unsigned kiPageCellCountOffset = 3; +static const unsigned kiPageCellCountOffset = 3;
+static const unsigned kiPageCellContentOffset = 5; +/* static const unsigned kiPageCellContentOffset = 5; */
+static const unsigned kiPageFragmentedBytesOffset = 7; +/* static const unsigned kiPageFragmentedBytesOffset = 7; */
+static const unsigned knPageLeafHeaderBytes = 8; +static const unsigned knPageLeafHeaderBytes = 8;
+/* Interior pages contain an additional field. */ +/* Interior pages contain an additional field. */
+static const unsigned kiPageRightChildOffset = 8; +static const unsigned kiPageRightChildOffset = 8;
...@@ -537,7 +515,7 @@ index 0000000..5ff6f78 ...@@ -537,7 +515,7 @@ index 0000000..5ff6f78
+const int kExcessSpace = 128; +const int kExcessSpace = 128;
+typedef struct RecoverPage RecoverPage; +typedef struct RecoverPage RecoverPage;
+struct RecoverPage { +struct RecoverPage {
+ Pgno pgno; /* Page number for this page */ + u32 pgno; /* Page number for this page */
+ void *pData; /* Page data for pgno */ + void *pData; /* Page data for pgno */
+ RecoverPager *pPager; /* The pager this page is part of */ + RecoverPager *pPager; /* The pager this page is part of */
+}; +};
...@@ -814,8 +792,6 @@ index 0000000..5ff6f78 ...@@ -814,8 +792,6 @@ index 0000000..5ff6f78
+ * interiorCursorDestroy - release all resources associated with the + * interiorCursorDestroy - release all resources associated with the
+ * cursor and any parent cursors. + * cursor and any parent cursors.
+ * interiorCursorCreate - create a cursor with the given parent and page. + * interiorCursorCreate - create a cursor with the given parent and page.
+ * interiorCursorEOF - returns true if neither the cursor nor the
+ * parent cursors can return any more data.
+ * interiorCursorNextPage - fetch the next child page from the cursor. + * interiorCursorNextPage - fetch the next child page from the cursor.
+ * + *
+ * Logically, interiorCursorNextPage() returns the next child page + * Logically, interiorCursorNextPage() returns the next child page
...@@ -832,11 +808,6 @@ index 0000000..5ff6f78 ...@@ -832,11 +808,6 @@ index 0000000..5ff6f78
+ * Note that while interiorCursorNextPage() will refuse to follow + * Note that while interiorCursorNextPage() will refuse to follow
+ * loops, it does not keep track of pages returned for purposes of + * loops, it does not keep track of pages returned for purposes of
+ * preventing duplication. + * preventing duplication.
+ *
+ * Note that interiorCursorEOF() could return false (not at EOF), and
+ * interiorCursorNextPage() could still return SQLITE_DONE. This
+ * could happen if there are more cells to iterate in an interior
+ * page, but those cells refer to invalid pages.
+ */ + */
+typedef struct RecoverInteriorCursor RecoverInteriorCursor; +typedef struct RecoverInteriorCursor RecoverInteriorCursor;
+struct RecoverInteriorCursor { +struct RecoverInteriorCursor {
...@@ -952,14 +923,6 @@ index 0000000..5ff6f78 ...@@ -952,14 +923,6 @@ index 0000000..5ff6f78
+ return 0; + return 0;
+} +}
+ +
+static int interiorCursorEOF(RecoverInteriorCursor *pCursor){
+ /* Find a parent with remaining children. EOF if none found. */
+ while( pCursor && pCursor->iChild>=pCursor->nChildren ){
+ pCursor = pCursor->pParent;
+ }
+ return pCursor==NULL;
+}
+
+/* Internal helper. Used to detect if iPage would cause a loop. */ +/* Internal helper. Used to detect if iPage would cause a loop. */
+static int interiorCursorPageInUse(RecoverInteriorCursor *pCursor, +static int interiorCursorPageInUse(RecoverInteriorCursor *pCursor,
+ unsigned iPage){ + unsigned iPage){
...@@ -1575,11 +1538,11 @@ index 0000000..5ff6f78 ...@@ -1575,11 +1538,11 @@ index 0000000..5ff6f78
+ return ValidateError(); + return ValidateError();
+ } + }
+ +
+ nRead = getVarint(pCell, &nRecordBytes); + nRead = recoverGetVarint(pCell, &nRecordBytes);
+ assert( iCellOffset+nRead<=pCursor->nPageSize ); + assert( iCellOffset+nRead<=pCursor->nPageSize );
+ pCursor->nRecordBytes = nRecordBytes; + pCursor->nRecordBytes = nRecordBytes;
+ +
+ nRead += getVarint(pCell + nRead, &iRowid); + nRead += recoverGetVarint(pCell + nRead, &iRowid);
+ assert( iCellOffset+nRead<=pCursor->nPageSize ); + assert( iCellOffset+nRead<=pCursor->nPageSize );
+ pCursor->iRowid = (i64)iRowid; + pCursor->iRowid = (i64)iRowid;
+ +
...@@ -1605,7 +1568,7 @@ index 0000000..5ff6f78 ...@@ -1605,7 +1568,7 @@ index 0000000..5ff6f78
+ } + }
+ } + }
+ +
+ nRecordHeaderRead = getVarint(pCell + nRead, &nRecordHeaderBytes); + nRecordHeaderRead = recoverGetVarint(pCell + nRead, &nRecordHeaderBytes);
+ assert( nRecordHeaderBytes<=nRecordBytes ); + assert( nRecordHeaderBytes<=nRecordBytes );
+ pCursor->nRecordHeaderBytes = nRecordHeaderBytes; + pCursor->nRecordHeaderBytes = nRecordHeaderBytes;
+ +
...@@ -1627,8 +1590,8 @@ index 0000000..5ff6f78 ...@@ -1627,8 +1590,8 @@ index 0000000..5ff6f78
+ nRecordHeaderBytes - nRecordHeaderRead) ){ + nRecordHeaderBytes - nRecordHeaderRead) ){
+ return ValidateError(); + return ValidateError();
+ } + }
+ nRecordHeaderRead += getVarint(pCursor->pRecordHeader + nRecordHeaderRead, + nRecordHeaderRead += recoverGetVarint(
+ &iSerialType); + pCursor->pRecordHeader + nRecordHeaderRead, &iSerialType);
+ if( iSerialType==10 || iSerialType==11 ){ + if( iSerialType==10 || iSerialType==11 ){
+ return ValidateError(); + return ValidateError();
+ } + }
...@@ -1694,7 +1657,7 @@ index 0000000..5ff6f78 ...@@ -1694,7 +1657,7 @@ index 0000000..5ff6f78
+ /* Rather than caching the header size and how many bytes it took, + /* Rather than caching the header size and how many bytes it took,
+ * decode it every time. + * decode it every time.
+ */ + */
+ nRead = getVarint(pRecordHeader, &nRecordHeaderBytes); + nRead = recoverGetVarint(pRecordHeader, &nRecordHeaderBytes);
+ assert( nRecordHeaderBytes==pCursor->nRecordHeaderBytes ); + assert( nRecordHeaderBytes==pCursor->nRecordHeaderBytes );
+ +
+ /* Scan forward to the indicated column. Scans to _after_ column + /* Scan forward to the indicated column. Scans to _after_ column
...@@ -1713,7 +1676,7 @@ index 0000000..5ff6f78 ...@@ -1713,7 +1676,7 @@ index 0000000..5ff6f78
+ if( !checkVarint(pRecordHeader + nRead, nRecordHeaderBytes - nRead) ){ + if( !checkVarint(pRecordHeader + nRead, nRecordHeaderBytes - nRead) ){
+ return SQLITE_CORRUPT; + return SQLITE_CORRUPT;
+ } + }
+ nRead += getVarint(pRecordHeader + nRead, &iSerialType); + nRead += recoverGetVarint(pRecordHeader + nRead, &iSerialType);
+ iColEndOffset += SerialTypeLength(iSerialType); + iColEndOffset += SerialTypeLength(iSerialType);
+ nColsSkipped++; + nColsSkipped++;
+ } + }
...@@ -2108,7 +2071,7 @@ index 0000000..5ff6f78 ...@@ -2108,7 +2071,7 @@ index 0000000..5ff6f78
+ 0, /* xRename - rename the table */ + 0, /* xRename - rename the table */
+}; +};
+ +
+CHROMIUM_SQLITE_API +SQLITE_API
+int recoverVtableInit(sqlite3 *db){ +int recoverVtableInit(sqlite3 *db){
+ return sqlite3_create_module_v2(db, "recover", &recoverModule, NULL, 0); + return sqlite3_create_module_v2(db, "recover", &recoverModule, NULL, 0);
+} +}
...@@ -2346,7 +2309,7 @@ index 0000000..5ff6f78 ...@@ -2346,7 +2309,7 @@ index 0000000..5ff6f78
+ /* Parse out db.table, assuming main if no dot. */ + /* Parse out db.table, assuming main if no dot. */
+ zDot = strchr(argv[3], '.'); + zDot = strchr(argv[3], '.');
+ if( !zDot ){ + if( !zDot ){
+ pRecover->zDb = sqlite3_strdup(db->aDb[0].zName); + pRecover->zDb = sqlite3_strdup("main");
+ pRecover->zTable = sqlite3_strdup(argv[3]); + pRecover->zTable = sqlite3_strdup(argv[3]);
+ }else if( zDot>argv[3] && zDot[1]!='\0' ){ + }else if( zDot>argv[3] && zDot[1]!='\0' ){
+ pRecover->zDb = sqlite3_strndup(argv[3], zDot - argv[3]); + pRecover->zDb = sqlite3_strndup(argv[3], zDot - argv[3]);
...@@ -2396,19 +2359,22 @@ index 0000000..5ff6f78 ...@@ -2396,19 +2359,22 @@ index 0000000..5ff6f78
+ *ppVtab = (sqlite3_vtab *)pRecover; + *ppVtab = (sqlite3_vtab *)pRecover;
+ return SQLITE_OK; + return SQLITE_OK;
+} +}
diff --git a/third_party/sqlite/src/src/sqlite.h.in b/third_party/sqlite/src/src/sqlite.h.in diff --git a/third_party/sqlite/src/src/recover.h b/third_party/sqlite/src/src/recover.h
index e5673fd..6829bcb 100644 new file mode 100644
--- a/third_party/sqlite/src/src/sqlite.h.in index 0000000..691f2fd
+++ b/third_party/sqlite/src/src/sqlite.h.in --- /dev/null
@@ -7411,6 +7411,22 @@ int sqlite3_strnicmp(const char *, const char *, int); +++ b/third_party/sqlite/src/src/recover.h
*/ @@ -0,0 +1,23 @@
int sqlite3_strglob(const char *zGlob, const char *zStr); +/* TODO(shess): sqliteicu.h is able to make this include without
+** trouble. It doesn't work when used with Chromium's SQLite. For
+/* Begin recover virtual table patch for Chromium */ +** now the including code must include sqlite3.h first.
+/* Our patches don't conform to SQLite's amalgamation processing. Hack it. */ +*/
+#ifndef CHROMIUM_SQLITE_API +/* #include "sqlite3.h" */
+#define CHROMIUM_SQLITE_API SQLITE_API +
+#ifdef __cplusplus
+extern "C" {
+#endif +#endif
+
+/* +/*
+** Call to initialize the recover virtual-table modules (see recover.c). +** Call to initialize the recover virtual-table modules (see recover.c).
+** +**
...@@ -2416,13 +2382,219 @@ index e5673fd..6829bcb 100644 ...@@ -2416,13 +2382,219 @@ index e5673fd..6829bcb 100644
+** virtual table available to Web SQL. Breaking it out allows only +** virtual table available to Web SQL. Breaking it out allows only
+** selected users to enable it (currently sql/recovery.cc). +** selected users to enable it (currently sql/recovery.cc).
+*/ +*/
+CHROMIUM_SQLITE_API +SQLITE_API
+int recoverVtableInit(sqlite3 *db); +int recoverVtableInit(sqlite3 *db);
+/* End recover virtual table patch for Chromium */
+ +
/* Begin WebDatabase patch for Chromium */ +#ifdef __cplusplus
/* Expose some SQLite internals for the WebDatabase vfs. +} /* End of the 'extern "C"' block */
** DO NOT EXTEND THE USE OF THIS. +#endif
diff --git a/third_party/sqlite/src/src/recover_varint.c b/third_party/sqlite/src/src/recover_varint.c
new file mode 100644
index 0000000..c111e2c
--- /dev/null
+++ b/third_party/sqlite/src/src/recover_varint.c
@@ -0,0 +1,201 @@
+/*
+** 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 recoverGetVarint(). 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;
+}
+
diff --git a/third_party/sqlite/src/test/recover.test b/third_party/sqlite/src/test/recover.test diff --git a/third_party/sqlite/src/test/recover.test b/third_party/sqlite/src/test/recover.test
new file mode 100644 new file mode 100644
index 0000000..bfb7888 index 0000000..bfb7888
...@@ -3729,19 +3901,6 @@ index 0000000..8aa4e04 ...@@ -3729,19 +3901,6 @@ index 0000000..8aa4e04
+} [list 4 1024 1 text [string length $substr] $substr] +} [list 4 1024 1 text [string length $substr] $substr]
+ +
+finish_test +finish_test
diff --git a/third_party/sqlite/src/tool/mksqlite3c.tcl b/third_party/sqlite/src/tool/mksqlite3c.tcl
index 23241e2..1113758 100644
--- a/third_party/sqlite/src/tool/mksqlite3c.tcl
+++ b/third_party/sqlite/src/tool/mksqlite3c.tcl
@@ -361,6 +361,8 @@ foreach file {
main.c
notify.c
+ recover.c
+
fts3.c
fts3_aux.c
fts3_expr.c
-- --
2.7.0 2.5.0
From a00fdd7ed25829eb5489907fc1e4a43429e0b621 Mon Sep 17 00:00:00 2001 From 5628b1aa2f0207924e6c39f46266b396a7fe374c Mon Sep 17 00:00:00 2001
From: "tc@google.com" <tc@google.com> From: "tc@google.com" <tc@google.com>
Date: Tue, 6 Jan 2009 22:39:41 +0000 Date: Tue, 6 Jan 2009 22:39:41 +0000
Subject: [PATCH 06/10] Custom shell.c helpers to load Chromium's ICU data. Subject: [PATCH 06/13] Custom shell.c helpers to load Chromium's ICU data.
History uses fts3 with an icu-based segmenter. These changes allow building a History uses fts3 with an icu-based segmenter. These changes allow building a
sqlite3 binary for Linux or Windows which can read those files. sqlite3 binary for Linux or Windows which can read those files.
...@@ -18,12 +18,12 @@ Original review URL: https://codereview.chromium.org/42250 ...@@ -18,12 +18,12 @@ Original review URL: https://codereview.chromium.org/42250
create mode 100644 third_party/sqlite/src/src/shell_icu_win.c create mode 100644 third_party/sqlite/src/src/shell_icu_win.c
diff --git a/third_party/sqlite/src/Makefile.linux-gcc b/third_party/sqlite/src/Makefile.linux-gcc diff --git a/third_party/sqlite/src/Makefile.linux-gcc b/third_party/sqlite/src/Makefile.linux-gcc
index f6291c0..17c9e00 100644 index 952e8d1..30ac8bb 100644
--- a/third_party/sqlite/src/Makefile.linux-gcc --- a/third_party/sqlite/src/Makefile.linux-gcc
+++ b/third_party/sqlite/src/Makefile.linux-gcc +++ b/third_party/sqlite/src/Makefile.linux-gcc
@@ -85,6 +85,13 @@ OPTS += -DOS_UNIX=1 @@ -81,6 +81,13 @@ OPTS += -DSQLITE_MEMDEBUG=1
# purposes. # TODO(shess) I can't see why I need this setting.
OPTS += -DDEFAULT_ENABLE_RECOVER=1 OPTS += -DOS_UNIX=1
+# Support for loading Chromium ICU data in sqlite3. +# Support for loading Chromium ICU data in sqlite3.
+ifeq ($(shell uname -s),Darwin) +ifeq ($(shell uname -s),Darwin)
...@@ -36,7 +36,7 @@ index f6291c0..17c9e00 100644 ...@@ -36,7 +36,7 @@ index f6291c0..17c9e00 100644
# Nothing for unix. # Nothing for unix.
# #
diff --git a/third_party/sqlite/src/main.mk b/third_party/sqlite/src/main.mk diff --git a/third_party/sqlite/src/main.mk b/third_party/sqlite/src/main.mk
index a8629aa..4a6d5d6 100644 index 26f9f15..3ff3647 100644
--- a/third_party/sqlite/src/main.mk --- a/third_party/sqlite/src/main.mk
+++ b/third_party/sqlite/src/main.mk +++ b/third_party/sqlite/src/main.mk
@@ -476,7 +476,7 @@ libsqlite3.a: $(LIBOBJ) @@ -476,7 +476,7 @@ libsqlite3.a: $(LIBOBJ)
...@@ -141,5 +141,5 @@ index 0000000..67ebbf4 ...@@ -141,5 +141,5 @@ index 0000000..67ebbf4
+ return 1; + return 1;
+} +}
-- --
2.7.0 2.5.0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment