From f063685079e709c5c20235b1324babff9c0a0334 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 21 Mar 2015 02:58:20 +0000 Subject: [PATCH 01/63] If a column is both UNIQUE and a PRIMARY KEY, make sure the PRIMARY KEY designation takes precedence. FossilOrigin-Name: d871a7921722bb0fef6d51e1110a9703ddff78c8 --- manifest | 16 ++++----- manifest.uuid | 2 +- src/build.c | 1 + test/without_rowid6.test | 76 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index e2d910ce70..6b5b474365 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\ssuperfluous\sdefine\sfrom\sthe\sMSVC\smakefile. -D 2015-03-21T02:25:29.401 +C If\sa\scolumn\sis\sboth\sUNIQUE\sand\sa\sPRIMARY\sKEY,\smake\ssure\sthe\sPRIMARY\sKEY\ndesignation\stakes\sprecedence. +D 2015-03-21T02:58:20.771 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -176,7 +176,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c d4d52fb14e863cff9dbc7c746e9048ec0967a555 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 -F src/build.c ba45ebd02904e84d98839a6ea74c3eb948596587 +F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 @@ -1190,7 +1190,7 @@ F test/without_rowid2.test af260339f79d13cb220288b67cd287fbcf81ad99 F test/without_rowid3.test 1081aabf60a1e1123b7f9a8f6ae19954351843b0 F test/without_rowid4.test 4e08bcbaee0399f35d58b5581881e7a6243d458a F test/without_rowid5.test 61256715b686359df48ca1742db50cc7e3e7b862 -F test/without_rowid6.test deddb78ef539c355bddec00cdfaea6c56efd8b3f +F test/without_rowid6.test db0dbf03c49030aa3c1ba5f618620334bd2baf5f F test/wordcount.c 9915e06cb33d8ca8109b8700791afe80d305afda F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688 F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 737630b87314283b2c38790ace9d25ec05f81f4a -R bbf7713d7bc160a26b464271593d133d -U mistachkin -Z d79979d0d3fded9d4339ee09acdaf62b +P 880d2513a0fb084fae82080401b108fb13e61478 +R 705f61dec20eb9df7c2db39aa0eef35e +U drh +Z 19c081d9e2a5c29193a61d5955352cbc diff --git a/manifest.uuid b/manifest.uuid index 81fc012beb..46bb30739d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -880d2513a0fb084fae82080401b108fb13e61478 \ No newline at end of file +d871a7921722bb0fef6d51e1110a9703ddff78c8 \ No newline at end of file diff --git a/src/build.c b/src/build.c index 54dd526b56..fcf96bd42c 100644 --- a/src/build.c +++ b/src/build.c @@ -3183,6 +3183,7 @@ Index *sqlite3CreateIndex( pIdx->onError = pIndex->onError; } } + pRet = pIdx; goto exit_create_index; } } diff --git a/test/without_rowid6.test b/test/without_rowid6.test index e827ccab90..8ca78ba63a 100644 --- a/test/without_rowid6.test +++ b/test/without_rowid6.test @@ -37,5 +37,81 @@ do_execsql_test without_rowid6-140 { SELECT c FROM t1 ORDER BY b LIMIT 5; } {x1y x2y x3y x4y x5y} +# Column t1.b starts out as a unique index, but that index is +# subsequently converted into a PRIMARY KEY. +# +do_execsql_test without_rowid6-200 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1( + a UNIQUE, + b UNIQUE, + c UNIQUE, + PRIMARY KEY(b) + ) WITHOUT ROWID; + INSERT INTO t1(a,b,c) VALUES(1,8,3),(4,5,6),(7,2,9); + SELECT a FROM t1 WHERE b>3 ORDER BY b; +} {4 1} +do_execsql_test without_rowid6-210 { + EXPLAIN QUERY PLAN + SELECT a FROM t1 WHERE b>3 ORDER BY b; +} {/SEARCH TABLE t1 USING PRIMARY KEY .b>../} +do_execsql_test without_rowid6-220 { + PRAGMA index_list(t1); +} {/sqlite_autoindex_t1_2 1 pk/} + +do_execsql_test without_rowid6-300 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1( + a UNIQUE, + b PRIMARY KEY, + c UNIQUE, + UNIQUE(b) + ) WITHOUT ROWID; + INSERT INTO t1(a,b,c) VALUES(1,8,3),(4,5,6),(7,2,9); + SELECT a FROM t1 WHERE b>3 ORDER BY b; +} {4 1} +do_execsql_test without_rowid6-310 { + EXPLAIN QUERY PLAN + SELECT a FROM t1 WHERE b>3 ORDER BY b; +} {/SEARCH TABLE t1 USING PRIMARY KEY .b>../} +do_execsql_test without_rowid6-320 { + PRAGMA index_list(t1); +} {/sqlite_autoindex_t1_2 1 pk/} + +do_execsql_test without_rowid6-400 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1( + a UNIQUE, + b UNIQUE PRIMARY KEY, + c UNIQUE + ) WITHOUT ROWID; + INSERT INTO t1(a,b,c) VALUES(1,8,3),(4,5,6),(7,2,9); + SELECT a FROM t1 WHERE b>3 ORDER BY b; +} {4 1} +do_execsql_test without_rowid6-410 { + EXPLAIN QUERY PLAN + SELECT a FROM t1 WHERE b>3 ORDER BY b; +} {/SEARCH TABLE t1 USING PRIMARY KEY .b>../} +do_execsql_test without_rowid6-420 { + PRAGMA index_list(t1); +} {/sqlite_autoindex_t1_2 1 pk/} + +do_execsql_test without_rowid6-500 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a,b,c, + UNIQUE(b,c), + PRIMARY KEY(b,c) + ) WITHOUT ROWID; + INSERT INTO t1(a,b,c) VALUES(1,8,3),(4,5,6),(7,2,9); + SELECT a FROM t1 WHERE b>3 ORDER BY b; +} {4 1} +do_execsql_test without_rowid6-510 { + EXPLAIN QUERY PLAN + SELECT a FROM t1 WHERE b>3 ORDER BY b; +} {/SEARCH TABLE t1 USING PRIMARY KEY .b>../} +do_execsql_test without_rowid6-520 { + PRAGMA index_list(t1); +} {/sqlite_autoindex_t1_1 1 pk/} + finish_test From 8f9d0b2b2513311770b7c9bd23d0eb7ceaeb587e Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 21 Mar 2015 03:18:22 +0000 Subject: [PATCH 02/63] Correctly detect the error of having a "*" wildcard on a SELECT without a FROM clause on the left-hand side of a recursive CTE. FossilOrigin-Name: b11d1793a06a44931edcbf12a615b49794d53a62 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 2 +- test/with1.test | 15 +++++++++++++++ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 6b5b474365..537a662c65 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sa\scolumn\sis\sboth\sUNIQUE\sand\sa\sPRIMARY\sKEY,\smake\ssure\sthe\sPRIMARY\sKEY\ndesignation\stakes\sprecedence. -D 2015-03-21T02:58:20.771 +C Correctly\sdetect\sthe\serror\sof\shaving\sa\s"*"\swildcard\son\sa\sSELECT\swithout\na\sFROM\sclause\son\sthe\sleft-hand\sside\sof\sa\srecursive\sCTE. +D 2015-03-21T03:18:22.783 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -230,7 +230,7 @@ F src/printf.c 8da9a2687a396daa19860f4dc90975d319304744 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 94e016b6733b1d39a2f4c8d431155b4c2897d907 +F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 F src/shell.c 9c1589c8271c04c02d23cdbc2c07bb40752fa9eb F src/sqlite.h.in c7c9111477b76c82c46bf851b619df4dd35cc095 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1182,7 +1182,7 @@ F test/wild001.test bca33f499866f04c24510d74baf1e578d4e44b1c F test/win32heap.test ea19770974795cff26e11575e12d422dbd16893c F test/win32lock.test 71642fa56e9b06e5cfffe6bad67cb8c1eb2c555a F test/win32longpath.test 169c75a3b2e43481f4a62122510210c67b08f26d -F test/with1.test 268081a6b14817a262ced4d0ee34d4d2a1dd2068 +F test/with1.test 9df5cd8a62148b3d9ef8597aea563e3863018bcd F test/with2.test ee227a663586aa09771cafd4fa269c5217eaf775 F test/withM.test e97f2a8c506ab3ea9eab94e6f6072f6cc924c991 F test/without_rowid1.test 7862e605753c8d25329f665fa09072e842183151 @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 880d2513a0fb084fae82080401b108fb13e61478 -R 705f61dec20eb9df7c2db39aa0eef35e +P d871a7921722bb0fef6d51e1110a9703ddff78c8 +R abf39ccde1b147748baa7108926922a2 U drh -Z 19c081d9e2a5c29193a61d5955352cbc +Z f5732dddfb21185ad5af5f2eb0f9450a diff --git a/manifest.uuid b/manifest.uuid index 46bb30739d..3fc8b41ecb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d871a7921722bb0fef6d51e1110a9703ddff78c8 \ No newline at end of file +b11d1793a06a44931edcbf12a615b49794d53a62 \ No newline at end of file diff --git a/src/select.c b/src/select.c index a9cecaa390..8fd0f15918 100644 --- a/src/select.c +++ b/src/select.c @@ -4035,7 +4035,7 @@ static int withExpand( for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior); pEList = pLeft->pEList; if( pCte->pCols ){ - if( pEList->nExpr!=pCte->pCols->nExpr ){ + if( pEList && pEList->nExpr!=pCte->pCols->nExpr ){ sqlite3ErrorMsg(pParse, "table %s has %d values for %d columns", pCte->zName, pEList->nExpr, pCte->pCols->nExpr ); diff --git a/test/with1.test b/test/with1.test index 42d2277aef..ad88a67c22 100644 --- a/test/with1.test +++ b/test/with1.test @@ -827,5 +827,20 @@ WITH RECURSIVE SELECT x FROM t1 EXCEPT SELECT y FROM t2 ORDER BY 1; } {2 4 8 10 14 16 20} +# 2015-03-21 +# Column wildcards on the LHS of a recursive table expression +# +do_catchsql_test 13.1 { + WITH RECURSIVE c(i) AS (SELECT * UNION ALL SELECT i+1 FROM c WHERE i<10) + SELECT i FROM c; +} {1 {no tables specified}} +do_catchsql_test 13.2 { + WITH RECURSIVE c(i) AS (SELECT 5,* UNION ALL SELECT i+1 FROM c WHERE i<10) + SELECT i FROM c; +} {1 {no tables specified}} +do_catchsql_test 13.3 { + WITH RECURSIVE c(i,j) AS (SELECT 5,* UNION ALL SELECT i+1,11 FROM c WHERE i<10) + SELECT i FROM c; +} {1 {table c has 1 values for 2 columns}} finish_test From e56f53ef7c808ab4e1425edaf6106daf0ef5cca6 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 21 Mar 2015 10:53:01 +0000 Subject: [PATCH 03/63] Add a missing "ifcapable fts3" to a test case in vtab2.test. FossilOrigin-Name: d845b0f69093178517d66e1fc5060e8f62c681c7 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/vtab2.test | 24 +++++++++++++----------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 537a662c65..666fc38ffc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Correctly\sdetect\sthe\serror\sof\shaving\sa\s"*"\swildcard\son\sa\sSELECT\swithout\na\sFROM\sclause\son\sthe\sleft-hand\sside\sof\sa\srecursive\sCTE. -D 2015-03-21T03:18:22.783 +C Add\sa\smissing\s"ifcapable\sfts3"\sto\sa\stest\scase\sin\svtab2.test. +D 2015-03-21T10:53:01.184 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1112,7 +1112,7 @@ F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 F test/view.test f311691d696a5cc27e3c1b875cec1b0866b4ccd9 F test/vtab1.test 1cef14310144718812351a61c5cfb4ba8494a171 -F test/vtab2.test 366256bee644d034cbe078fbe1ec5bbe6b13fe42 +F test/vtab2.test 3644649aa8d1daac57fd541f6a5f914cac59203e F test/vtab3.test b45f47d20f225ccc9c28dc915d92740c2dee311e F test/vtab4.test 942f8b8280b3ea8a41dae20e7822d065ca1cb275 F test/vtab5.test 889f444970393c73f1e077e2bdc5d845e157a391 @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P d871a7921722bb0fef6d51e1110a9703ddff78c8 -R abf39ccde1b147748baa7108926922a2 -U drh -Z f5732dddfb21185ad5af5f2eb0f9450a +P b11d1793a06a44931edcbf12a615b49794d53a62 +R 55729177793663a0c48c1beb22d1dc2b +U dan +Z c52b93c6a8110abb696022d137cc00a4 diff --git a/manifest.uuid b/manifest.uuid index 3fc8b41ecb..435dcf9c12 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b11d1793a06a44931edcbf12a615b49794d53a62 \ No newline at end of file +d845b0f69093178517d66e1fc5060e8f62c681c7 \ No newline at end of file diff --git a/test/vtab2.test b/test/vtab2.test index 42b9da4670..3884ec57df 100644 --- a/test/vtab2.test +++ b/test/vtab2.test @@ -135,19 +135,21 @@ do_test vtab2-4.5 { #------------------------------------------------------------------------- # -reset_db -do_execsql_test 5.1 { - PRAGMA encoding='UTF16'; +ifcapable fts3 { + reset_db + do_execsql_test 5.1 { + PRAGMA encoding='UTF16'; + } + + do_test 5.2 { + sqlite3_exec_hex db { CREATE VIRTUAL TABLE %C8 USING fts3 } + } {0 {}} + + do_test 5.3 { + sqlite3_exec_hex db { CREATE VIRTUAL TABLE %C9 USING s } + } {/1 {malformed database schema.* already exists}/} } -do_test 5.2 { - sqlite3_exec_hex db { CREATE VIRTUAL TABLE %C8 USING fts3 } -} {0 {}} - -do_test 5.3 { - sqlite3_exec_hex db { CREATE VIRTUAL TABLE %C9 USING s } -} {/1 {malformed database schema.* already exists}/} - finish_test From 474640638da26ee9a22447a37839d333e8285bf0 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 21 Mar 2015 12:22:16 +0000 Subject: [PATCH 04/63] Remove an unreachable branch from the OP_VCreate opcode. FossilOrigin-Name: 5fca41a3811766b48f5f23d5d49cc4e6e79fa867 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbe.c | 17 +++++++++++------ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 666fc38ffc..05da0070b5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\smissing\s"ifcapable\sfts3"\sto\sa\stest\scase\sin\svtab2.test. -D 2015-03-21T10:53:01.184 +C Remove\san\sunreachable\sbranch\sfrom\sthe\sOP_VCreate\sopcode. +D 2015-03-21T12:22:16.937 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -293,7 +293,7 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec -F src/vdbe.c 3d96875d883c2bf53a4806c9d4c5abff18511da4 +F src/vdbe.c bd793ed436edccaf264ec969ac92c9b5f4b41d64 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P b11d1793a06a44931edcbf12a615b49794d53a62 -R 55729177793663a0c48c1beb22d1dc2b -U dan -Z c52b93c6a8110abb696022d137cc00a4 +P d845b0f69093178517d66e1fc5060e8f62c681c7 +R 33e37ff5951445c194f8f62b65ec1d8a +U drh +Z f47a30263eba86ab7824497d08f8b218 diff --git a/manifest.uuid b/manifest.uuid index 435dcf9c12..9d0d2f5b15 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d845b0f69093178517d66e1fc5060e8f62c681c7 \ No newline at end of file +5fca41a3811766b48f5f23d5d49cc4e6e79fa867 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 8eb7721085..7d6d2b4f5d 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -6033,15 +6033,20 @@ case OP_VBegin: { */ case OP_VCreate: { Mem sMem; /* For storing the record being decoded */ + const char *zTab; /* Name of the virtual table */ + memset(&sMem, 0, sizeof(sMem)); sMem.db = db; + /* Because P2 is always a static string, it is impossible for the + ** sqlite3VdbeMemCopy() to fail */ + assert( (aMem[pOp->p2].flags & MEM_Str)!=0 ); + assert( (aMem[pOp->p2].flags & MEM_Static)!=0 ); rc = sqlite3VdbeMemCopy(&sMem, &aMem[pOp->p2]); - if( rc==SQLITE_OK ){ - const char *zTab = (const char*)sqlite3_value_text(&sMem); - assert( zTab || db->mallocFailed ); - if( zTab ){ - rc = sqlite3VtabCallCreate(db, pOp->p1, zTab, &p->zErrMsg); - } + assert( rc==SQLITE_OK ); + zTab = (const char*)sqlite3_value_text(&sMem); + assert( zTab || db->mallocFailed ); + if( zTab ){ + rc = sqlite3VtabCallCreate(db, pOp->p1, zTab, &p->zErrMsg); } sqlite3VdbeMemRelease(&sMem); break; From 998aaa03ea52f20804ce9bec5a2920ff9583877e Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 21 Mar 2015 12:22:51 +0000 Subject: [PATCH 05/63] Avoid an integer overflow in fts3 causing gcc 4.7.1 with -O2 to behave counter-intuitively (perhaps because the behaviour is undefined). Add an "ifcapable trace" to a test in shell4.test. FossilOrigin-Name: e3e234649616f20610abce9ae9da1c572d3a4377 --- ext/fts3/fts3.c | 10 ++++++++-- manifest | 14 +++++++------- manifest.uuid | 2 +- test/shell4.test | 2 ++ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 3c229403b4..3c2e5adc01 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -910,11 +910,16 @@ static char *fts3WriteExprList(Fts3Table *p, const char *zFunc, int *pRc){ ** This function is used when parsing the "prefix=" FTS4 parameter. */ static int fts3GobbleInt(const char **pp, int *pnOut){ + const MAX_NPREFIX = 10000000; const char *p; /* Iterator pointer */ int nInt = 0; /* Output value */ for(p=*pp; p[0]>='0' && p[0]<='9'; p++){ nInt = nInt * 10 + (p[0] - '0'); + if( nInt>MAX_NPREFIX ){ + nInt = 0; + break; + } } if( p==*pp ) return SQLITE_ERROR; *pnOut = nInt; @@ -966,9 +971,10 @@ static int fts3PrefixParameter( const char *p = zParam; int i; for(i=1; i=0 ); + if( nPrefix==0 ){ nIndex--; i--; }else{ diff --git a/manifest b/manifest index 666fc38ffc..b682535cbf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\smissing\s"ifcapable\sfts3"\sto\sa\stest\scase\sin\svtab2.test. -D 2015-03-21T10:53:01.184 +C Avoid\san\sinteger\soverflow\sin\sfts3\scausing\sgcc\s4.7.1\swith\s-O2\sto\sbehave\scounter-intuitively\s(perhaps\sbecause\sthe\sbehaviour\sis\sundefined).\sAdd\san\s"ifcapable\strace"\sto\sa\stest\sin\sshell4.test. +D 2015-03-21T12:22:51.140 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,7 +78,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c 022915f30538b40b584c5abb27cae47d07cb3465 +F ext/fts3/fts3.c e2c7e61d676ce7b9383d1078c9774a2f22947d57 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 394858c12a17740f7a1f6bd372c4606d4425a8d1 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 @@ -866,7 +866,7 @@ F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304 F test/shell1.test ca88b14a8fc8b1f3543a24e519d019585ac9c903 F test/shell2.test 12b8bf901b0e3a8ac58cf5c0c63a0a388d4d1862 F test/shell3.test 5e8545ec72c4413a0e8d4c6be56496e3c257ca29 -F test/shell4.test 4cd3bd50200bf2efd6a74175d98da65aa86daf26 +F test/shell4.test ddf0a99044e2245a87fc17423e3aaa1445b3243b F test/shell5.test c04e9f9f948305706b88377c464c7f08ce7479f9 F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3 F test/show_speedtest1_rtree.tcl 32e6c5f073d7426148a6936a0408f4b5b169aba5 @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P b11d1793a06a44931edcbf12a615b49794d53a62 -R 55729177793663a0c48c1beb22d1dc2b +P d845b0f69093178517d66e1fc5060e8f62c681c7 +R 7a07a789329b4f516d02a691b70e458c U dan -Z c52b93c6a8110abb696022d137cc00a4 +Z 3ae65dad7900f82b42a270fbfd21fd80 diff --git a/manifest.uuid b/manifest.uuid index 435dcf9c12..2e8412f795 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d845b0f69093178517d66e1fc5060e8f62c681c7 \ No newline at end of file +e3e234649616f20610abce9ae9da1c572d3a4377 \ No newline at end of file diff --git a/test/shell4.test b/test/shell4.test index d1466f638c..fcb0b2b715 100644 --- a/test/shell4.test +++ b/test/shell4.test @@ -122,6 +122,7 @@ do_test shell4-2.2 { do_test shell4-2.3 { catchcmd ":memory:" ".trace stdout\n.trace\n.trace off\n.dump\n" } {/^1 {PRAGMA.*Usage:.*}$/} +ifcapable trace { do_test shell4-2.4 { catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;" } {0 {CREATE TABLE t1(x); @@ -129,6 +130,7 @@ SELECT * FROM t1;}} do_test shell4-2.5 { catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;" } {0 {SELECT * FROM t1;}} +} finish_test From c435cf75a57292833696920189f416e923e4a85d Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 21 Mar 2015 16:36:03 +0000 Subject: [PATCH 06/63] Fix the blocking WAL lock so that it works and so that it compiles on a Mac. FossilOrigin-Name: 67d69d21de32816894be53e4b446656d4174eb0d --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/os_unix.c | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 75771530bb..1277a25997 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sunreachable\sbranch\sfrom\sthe\sOP_VCreate\sopcode\s(merge\saccidental\sfork\sin\strunk). -D 2015-03-21T12:25:23.115 +C Fix\sthe\sblocking\sWAL\slock\sso\sthat\sit\sworks\sand\sso\sthat\sit\scompiles\son\sa\sMac. +D 2015-03-21T16:36:03.990 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,7 +214,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c cc903ecc6ebda90ef703d043ddaa7f33de0cab0f +F src/os_unix.c e68c8e77e47ce38865ebf8e1a0e877ac955f469c F src/os_win.c 8223e7db5b7c4a81d8b161098ac3959400434cdb F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P e3e234649616f20610abce9ae9da1c572d3a4377 5fca41a3811766b48f5f23d5d49cc4e6e79fa867 -R f330fb6722b7e402dae00a81353077df -U dan -Z 1c256b7cca05bea8c4676944e04ddeb4 +P 2fbfec62fc03d42ee240dfefaa0aeb59a3f04d88 +R 5a3409f8ffa9923877231407f3215215 +U drh +Z 15a1523db948e8ebecc44c81b8244965 diff --git a/manifest.uuid b/manifest.uuid index d71396b19d..a82805b710 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2fbfec62fc03d42ee240dfefaa0aeb59a3f04d88 \ No newline at end of file +67d69d21de32816894be53e4b446656d4174eb0d \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 16cb935dec..d0924a511b 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -3782,6 +3782,10 @@ static int unixGetTempname(int nBuf, char *zBuf); static int unixFileControl(sqlite3_file *id, int op, void *pArg){ unixFile *pFile = (unixFile*)id; switch( op ){ + case SQLITE_FCNTL_WAL_BLOCK: { + pFile->ctrlFlags |= UNIXFILE_BLOCK; + return SQLITE_OK; + } case SQLITE_FCNTL_LOCKSTATE: { *(int*)pArg = pFile->eFileLock; return SQLITE_OK; @@ -7228,10 +7232,6 @@ static int proxyTransformUnixFile(unixFile *pFile, const char *path) { */ static int proxyFileControl(sqlite3_file *id, int op, void *pArg){ switch( op ){ - case SQLITE_FCNTL_WAL_BLOCK: { - id->ctrlFlags |= UNIXFILE_BLOCK; - return SQLITE_OK; - } case SQLITE_FCNTL_GET_LOCKPROXYFILE: { unixFile *pFile = (unixFile*)id; if( pFile->pMethod == &proxyIoMethods ){ From d2f99333cfb8a2589c8ea56e62a668ce881bbd6f Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 21 Mar 2015 16:40:24 +0000 Subject: [PATCH 07/63] Change walblock.test to block an external process for 10 seconds, not 5. 5 seconds is not long enough to tell the difference between a blocking lock and a series of retries. FossilOrigin-Name: 717335fcdb15430ed977cbc98d30345b71728b66 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/walblock.test | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 1277a25997..227d2396bf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sblocking\sWAL\slock\sso\sthat\sit\sworks\sand\sso\sthat\sit\scompiles\son\sa\sMac. -D 2015-03-21T16:36:03.990 +C Change\swalblock.test\sto\sblock\san\sexternal\sprocess\sfor\s10\sseconds,\snot\s5.\s5\sseconds\sis\snot\slong\senough\sto\stell\sthe\sdifference\sbetween\sa\sblocking\slock\sand\sa\sseries\sof\sretries. +D 2015-03-21T16:40:24.176 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1142,7 +1142,7 @@ F test/wal9.test 378e76a9ad09cd9bee06c172ad3547b0129a6750 F test/wal_common.tcl a98f17fba96206122eff624db0ab13ec377be4fe F test/walbak.test b9f68e39646375c2b877be906babcc15d38b4877 F test/walbig.test f437473a16cfb314867c6b5d1dbcd519e73e3434 -F test/walblock.test f1290524714232c109fb0b14db28f14d81c3ddd0 +F test/walblock.test ffc761cd467a93ccd8cd998a23be2f21b95a83b1 F test/walcksum.test 9afeb96240296c08c72fc524d199c912cfe34daa F test/walcrash.test 451d79e528add5c42764cea74aa2750754171b25 F test/walcrash2.test a0edab4e5390f03b99a790de89aad15d6ec70b36 @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 2fbfec62fc03d42ee240dfefaa0aeb59a3f04d88 -R 5a3409f8ffa9923877231407f3215215 -U drh -Z 15a1523db948e8ebecc44c81b8244965 +P 67d69d21de32816894be53e4b446656d4174eb0d +R fd1744ba13eb7ca730963f1f28c9bbe1 +U dan +Z 766817d70f1d0d42f94e17731574ace5 diff --git a/manifest.uuid b/manifest.uuid index a82805b710..183e639eed 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -67d69d21de32816894be53e4b446656d4174eb0d \ No newline at end of file +717335fcdb15430ed977cbc98d30345b71728b66 \ No newline at end of file diff --git a/test/walblock.test b/test/walblock.test index 9a85ea4acc..0b0b2241e6 100644 --- a/test/walblock.test +++ b/test/walblock.test @@ -92,9 +92,9 @@ proc barrier_callback {method args} { set ::out "" testfixture $::C { db eval { SELECT * FROM t1 } } {set ::out} - do_test "1.2.2.(blocking 5 seconds)" { + do_test "1.2.2.(blocking 10 seconds)" { set ::continue 0 - after 5000 {set ::continue 1} + after 10000 {set ::continue 1} vwait ::continue set ::out } {} From e10d87f65a8642957fd302a5522f90062620bf71 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 21 Mar 2015 19:35:09 +0000 Subject: [PATCH 08/63] Avoid a segfault if NULL is passed as the first argument to SQL scalar function fts3_tokenizer(). FossilOrigin-Name: 6d0989695b486275824c14d5f88357267c1e8104 --- ext/fts3/fts3_tokenizer.c | 6 ++++-- manifest | 14 +++++++------- manifest.uuid | 2 +- test/fts3atoken.test | 10 ++++++++++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/ext/fts3/fts3_tokenizer.c b/ext/fts3/fts3_tokenizer.c index 8bb8b178ba..2b985f5f33 100644 --- a/ext/fts3/fts3_tokenizer.c +++ b/ext/fts3/fts3_tokenizer.c @@ -69,7 +69,7 @@ static void scalarFunc( if( argc==2 ){ void *pOld; int n = sqlite3_value_bytes(argv[1]); - if( n!=sizeof(pPtr) ){ + if( zName==0 || n!=sizeof(pPtr) ){ sqlite3_result_error(context, "argument type mismatch", -1); return; } @@ -80,7 +80,9 @@ static void scalarFunc( return; } }else{ - pPtr = sqlite3Fts3HashFind(pHash, zName, nName); + if( zName ){ + pPtr = sqlite3Fts3HashFind(pHash, zName, nName); + } if( !pPtr ){ char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName); sqlite3_result_error(context, zErr, -1); diff --git a/manifest b/manifest index 227d2396bf..c02318a20e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\swalblock.test\sto\sblock\san\sexternal\sprocess\sfor\s10\sseconds,\snot\s5.\s5\sseconds\sis\snot\slong\senough\sto\stell\sthe\sdifference\sbetween\sa\sblocking\slock\sand\sa\sseries\sof\sretries. -D 2015-03-21T16:40:24.176 +C Avoid\sa\ssegfault\sif\sNULL\sis\spassed\sas\sthe\sfirst\sargument\sto\sSQL\sscalar\sfunction\sfts3_tokenizer(). +D 2015-03-21T19:35:09.439 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -91,7 +91,7 @@ F ext/fts3/fts3_snippet.c 52c2dcf410b1f9af5a44d81a2cf8c68ed1cb5283 F ext/fts3/fts3_term.c a521f75132f9a495bdca1bdd45949b3191c52763 F ext/fts3/fts3_test.c 8a3a78c4458b2d7c631fcf4b152a5cd656fa7038 F ext/fts3/fts3_tokenize_vtab.c becc661223db7898b213f9e8a23d75bac02408c9 -F ext/fts3/fts3_tokenizer.c 0f9e6e01de1e1fe2e79074e3cf70ed1b1ea848b7 +F ext/fts3/fts3_tokenizer.c b7e586baeb8d0a061cf01a0f7081d88f3935eecf F ext/fts3/fts3_tokenizer.h 64c6ef6c5272c51ebe60fc607a896e84288fcbc3 F ext/fts3/fts3_tokenizer1.c 5c98225a53705e5ee34824087478cf477bdb7004 F ext/fts3/fts3_unicode.c a93f5edc0aff44ef8b06d7cb55b52026541ca145 @@ -564,7 +564,7 @@ F test/fts3al.test 07d64326e79bbdbab20ee87fc3328fbf01641c9f F test/fts3am.test 218aa6ba0dfc50c7c16b2022aac5c6be593d08d8 F test/fts3an.test a49ccadc07a2f7d646ec1b81bc09da2d85a85b18 F test/fts3ao.test 3e4e3d5e75c076520341d0bdf4eb17c00e8cbde2 -F test/fts3atoken.test 95c721d71acb141eb754701b15a8e60bb6eb4263 +F test/fts3atoken.test e3a126365131a6db52efc20a9a6053cd44e5f289 F test/fts3auto.test b981fea19b132b4e6878f50d7c1f369b28f68eb9 F test/fts3aux1.test f8f287a4a73f381f8fa15b6a70f36245f903d221 F test/fts3aux2.test 7ae2b2c13aefdf4169279a27a5f51780ce57f6ba @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 67d69d21de32816894be53e4b446656d4174eb0d -R fd1744ba13eb7ca730963f1f28c9bbe1 +P 717335fcdb15430ed977cbc98d30345b71728b66 +R 9a44cfc186a78e5b971a0e9f8c3b76c2 U dan -Z 766817d70f1d0d42f94e17731574ace5 +Z 068927d1dd3aa367e2b9f4f743992531 diff --git a/manifest.uuid b/manifest.uuid index 183e639eed..98bf637961 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -717335fcdb15430ed977cbc98d30345b71728b66 \ No newline at end of file +6d0989695b486275824c14d5f88357267c1e8104 \ No newline at end of file diff --git a/test/fts3atoken.test b/test/fts3atoken.test index 904a9a3fc3..88e3d4f72b 100644 --- a/test/fts3atoken.test +++ b/test/fts3atoken.test @@ -203,5 +203,15 @@ do_catchsql_test 6.1.3 { CREATE VIRTUAL TABLE t3 USING fts4(tokenize=" "); } {1 {unknown tokenizer: }} +do_catchsql_test 6.2.1 { + SELECT fts3_tokenizer(NULL); +} {1 {unknown tokenizer: }} +do_catchsql_test 6.2.2 { + SELECT fts3_tokenizer(NULL, X'1234567812345678'); +} {1 {argument type mismatch}} +do_catchsql_test 6.2.3 { + SELECT fts3_tokenizer(NULL, X'12345678'); +} {1 {argument type mismatch}} + finish_test From 3858cb44b64efd781481e377a045ba50dba94894 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 21 Mar 2015 20:50:58 +0000 Subject: [PATCH 09/63] Add a missing "int" on a constant declaration. FossilOrigin-Name: 235157de5113ac4c750e36a498e2a1f1cf461751 --- ext/fts3/fts3.c | 2 +- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 3c2e5adc01..c92463204c 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -910,7 +910,7 @@ static char *fts3WriteExprList(Fts3Table *p, const char *zFunc, int *pRc){ ** This function is used when parsing the "prefix=" FTS4 parameter. */ static int fts3GobbleInt(const char **pp, int *pnOut){ - const MAX_NPREFIX = 10000000; + const int MAX_NPREFIX = 10000000; const char *p; /* Iterator pointer */ int nInt = 0; /* Output value */ diff --git a/manifest b/manifest index c02318a20e..ec5a2a710e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sa\ssegfault\sif\sNULL\sis\spassed\sas\sthe\sfirst\sargument\sto\sSQL\sscalar\sfunction\sfts3_tokenizer(). -D 2015-03-21T19:35:09.439 +C Add\sa\smissing\s"int"\son\sa\sconstant\sdeclaration. +D 2015-03-21T20:50:58.948 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,7 +78,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c e2c7e61d676ce7b9383d1078c9774a2f22947d57 +F ext/fts3/fts3.c 2a1cf23133d0c75ce296d17440c44115f8413ec7 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 394858c12a17740f7a1f6bd372c4606d4425a8d1 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 717335fcdb15430ed977cbc98d30345b71728b66 -R 9a44cfc186a78e5b971a0e9f8c3b76c2 -U dan -Z 068927d1dd3aa367e2b9f4f743992531 +P 6d0989695b486275824c14d5f88357267c1e8104 +R f4c5c38b537072acd0ef8cbe1e26c753 +U drh +Z c60ff55e80e06532c78f97fe504967fd diff --git a/manifest.uuid b/manifest.uuid index 98bf637961..7d077b0af4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6d0989695b486275824c14d5f88357267c1e8104 \ No newline at end of file +235157de5113ac4c750e36a498e2a1f1cf461751 \ No newline at end of file From 5ac936529c2a828acb809525c15af87ebdba6944 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 21 Mar 2015 20:59:43 +0000 Subject: [PATCH 10/63] Do not invoke a C preprocessor macro with an empty argument, as (reportedly) some versions of GCC are unable to deal with that. FossilOrigin-Name: de9da317d4df3efefe9a1a48f954af8a19e7d098 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_unix.c | 36 ++++++++++++++++++------------------ 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/manifest b/manifest index ec5a2a710e..4a0ca3ea20 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\smissing\s"int"\son\sa\sconstant\sdeclaration. -D 2015-03-21T20:50:58.948 +C Do\snot\sinvoke\sa\sC\spreprocessor\smacro\swith\san\sempty\sargument,\sas\s(reportedly)\nsome\sversions\sof\sGCC\sare\sunable\sto\sdeal\swith\sthat. +D 2015-03-21T20:59:43.779 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,7 +214,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c e68c8e77e47ce38865ebf8e1a0e877ac955f469c +F src/os_unix.c a4dadbc2da41599e99093e91e276c38c17a73b89 F src/os_win.c 8223e7db5b7c4a81d8b161098ac3959400434cdb F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 6d0989695b486275824c14d5f88357267c1e8104 -R f4c5c38b537072acd0ef8cbe1e26c753 +P 235157de5113ac4c750e36a498e2a1f1cf461751 +R 4027cff60803cc3b440b57484c5f02d8 U drh -Z c60ff55e80e06532c78f97fe504967fd +Z 5a82a26aab899b185210ad558ba95050 diff --git a/manifest.uuid b/manifest.uuid index 7d077b0af4..9a937f472e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -235157de5113ac4c750e36a498e2a1f1cf461751 \ No newline at end of file +de9da317d4df3efefe9a1a48f954af8a19e7d098 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index d0924a511b..a9c883a935 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -1536,7 +1536,7 @@ static int unixLock(sqlite3_file *id, int eFileLock){ OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h, azFileLock(eFileLock), azFileLock(pFile->eFileLock), azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared, - osGetpid())); + osGetpid(0))); /* If there is already a lock of this type or more restrictive on the ** unixFile, do nothing. Don't use the end_lock: exit path, as @@ -1744,7 +1744,7 @@ static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){ assert( pFile ); OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock, pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared, - osGetpid())); + osGetpid(0))); assert( eFileLock<=SHARED_LOCK ); if( pFile->eFileLock<=eFileLock ){ @@ -2171,7 +2171,7 @@ static int dotlockUnlock(sqlite3_file *id, int eFileLock) { assert( pFile ); OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock, - pFile->eFileLock, osGetpid())); + pFile->eFileLock, osGetpid(0))); assert( eFileLock<=SHARED_LOCK ); /* no-op if possible */ @@ -2389,7 +2389,7 @@ static int flockUnlock(sqlite3_file *id, int eFileLock) { assert( pFile ); OSTRACE(("UNLOCK %d %d was %d pid=%d (flock)\n", pFile->h, eFileLock, - pFile->eFileLock, osGetpid())); + pFile->eFileLock, osGetpid(0))); assert( eFileLock<=SHARED_LOCK ); /* no-op if possible */ @@ -2557,7 +2557,7 @@ static int semXUnlock(sqlite3_file *id, int eFileLock) { assert( pFile ); assert( pSem ); OSTRACE(("UNLOCK %d %d was %d pid=%d (sem)\n", pFile->h, eFileLock, - pFile->eFileLock, osGetpid())); + pFile->eFileLock, osGetpid(0))); assert( eFileLock<=SHARED_LOCK ); /* no-op if possible */ @@ -2771,7 +2771,7 @@ static int afpLock(sqlite3_file *id, int eFileLock){ assert( pFile ); OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (afp)\n", pFile->h, azFileLock(eFileLock), azFileLock(pFile->eFileLock), - azFileLock(pInode->eFileLock), pInode->nShared , osGetpid())); + azFileLock(pInode->eFileLock), pInode->nShared , osGetpid(0))); /* If there is already a lock of this type or more restrictive on the ** unixFile, do nothing. Don't use the afp_end_lock: exit path, as @@ -2957,7 +2957,7 @@ static int afpUnlock(sqlite3_file *id, int eFileLock) { assert( pFile ); OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (afp)\n", pFile->h, eFileLock, pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared, - osGetpid())); + osGetpid(0))); assert( eFileLock<=SHARED_LOCK ); if( pFile->eFileLock<=eFileLock ){ @@ -4636,7 +4636,7 @@ static int unixShmLock( } sqlite3_mutex_leave(pShmNode->mutex); OSTRACE(("SHM-LOCK shmid-%d, pid-%d got %03x,%03x\n", - p->id, osGetpid(), p->sharedMask, p->exclMask)); + p->id, osGetpid(0), p->sharedMask, p->exclMask)); return rc; } @@ -5731,8 +5731,8 @@ static int unixOpen( ** the same instant might all reset the PRNG. But multiple resets ** are harmless. */ - if( randomnessPid!=osGetpid() ){ - randomnessPid = osGetpid(); + if( randomnessPid!=osGetpid(0) ){ + randomnessPid = osGetpid(0); sqlite3_randomness(0,0); } @@ -6123,7 +6123,7 @@ static int unixRandomness(sqlite3_vfs *NotUsed, int nBuf, char *zBuf){ ** tests repeatable. */ memset(zBuf, 0, nBuf); - randomnessPid = osGetpid(); + randomnessPid = osGetpid(0); #if !defined(SQLITE_TEST) { int fd, got; @@ -6444,7 +6444,7 @@ static int proxyGetLockPath(const char *dbPath, char *lPath, size_t maxLen){ { if( !confstr(_CS_DARWIN_USER_TEMP_DIR, lPath, maxLen) ){ OSTRACE(("GETLOCKPATH failed %s errno=%d pid=%d\n", - lPath, errno, osGetpid())); + lPath, errno, osGetpid(0))); return SQLITE_IOERR_LOCK; } len = strlcat(lPath, "sqliteplocks", maxLen); @@ -6466,7 +6466,7 @@ static int proxyGetLockPath(const char *dbPath, char *lPath, size_t maxLen){ } lPath[i+len]='\0'; strlcat(lPath, ":auto:", maxLen); - OSTRACE(("GETLOCKPATH proxy lock path=%s pid=%d\n", lPath, osGetpid())); + OSTRACE(("GETLOCKPATH proxy lock path=%s pid=%d\n", lPath, osGetpid(0))); return SQLITE_OK; } @@ -6493,7 +6493,7 @@ static int proxyCreateLockPath(const char *lockPath){ if( err!=EEXIST ) { OSTRACE(("CREATELOCKPATH FAILED creating %s, " "'%s' proxy lock path=%s pid=%d\n", - buf, strerror(err), lockPath, osGetpid())); + buf, strerror(err), lockPath, osGetpid(0))); return err; } } @@ -6502,7 +6502,7 @@ static int proxyCreateLockPath(const char *lockPath){ } buf[i] = lockPath[i]; } - OSTRACE(("CREATELOCKPATH proxy lock path=%s pid=%d\n", lockPath, osGetpid())); + OSTRACE(("CREATELOCKPATH proxy lock path=%s pid=%d\n", lockPath, osGetpid(0))); return 0; } @@ -6808,7 +6808,7 @@ static int proxyTakeConch(unixFile *pFile){ OSTRACE(("TAKECONCH %d for %s pid=%d\n", conchFile->h, (pCtx->lockProxyPath ? pCtx->lockProxyPath : ":auto:"), - osGetpid())); + osGetpid(0))); rc = proxyGetHostID(myHostID, &pError); if( (rc&0xff)==SQLITE_IOERR ){ @@ -7018,7 +7018,7 @@ static int proxyReleaseConch(unixFile *pFile){ conchFile = pCtx->conchFile; OSTRACE(("RELEASECONCH %d for %s pid=%d\n", conchFile->h, (pCtx->lockProxyPath ? pCtx->lockProxyPath : ":auto:"), - osGetpid())); + osGetpid(0))); if( pCtx->conchHeld>0 ){ rc = conchFile->pMethod->xUnlock((sqlite3_file*)conchFile, NO_LOCK); } @@ -7160,7 +7160,7 @@ static int proxyTransformUnixFile(unixFile *pFile, const char *path) { } OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h, - (lockPath ? lockPath : ":auto:"), osGetpid())); + (lockPath ? lockPath : ":auto:"), osGetpid(0))); pCtx = sqlite3_malloc( sizeof(*pCtx) ); if( pCtx==0 ){ From 082be63b1772e3f752a694de8e51c4b963b95dbf Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 21 Mar 2015 22:13:47 +0000 Subject: [PATCH 11/63] Increase the debugging level for the debug configuration in the MSVC batch build tool. FossilOrigin-Name: 041484ff91fd4615368ccb2257ab50acc2cd4fea --- manifest | 14 +++++++------- manifest.uuid | 2 +- tool/build-all-msvc.bat | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 4a0ca3ea20..9bcf1897b9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\sinvoke\sa\sC\spreprocessor\smacro\swith\san\sempty\sargument,\sas\s(reportedly)\nsome\sversions\sof\sGCC\sare\sunable\sto\sdeal\swith\sthat. -D 2015-03-21T20:59:43.779 +C Increase\sthe\sdebugging\slevel\sfor\sthe\sdebug\sconfiguration\sin\sthe\sMSVC\sbatch\sbuild\stool. +D 2015-03-21T22:13:47.750 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1194,7 +1194,7 @@ F test/without_rowid6.test db0dbf03c49030aa3c1ba5f618620334bd2baf5f F test/wordcount.c 9915e06cb33d8ca8109b8700791afe80d305afda F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688 F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac -F tool/build-all-msvc.bat 62785b25bf7ea82dc016b3233a896151c786cfbb x +F tool/build-all-msvc.bat 6e2c65d4c694ad3bdcbf8d813d18336c378ef642 x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 235157de5113ac4c750e36a498e2a1f1cf461751 -R 4027cff60803cc3b440b57484c5f02d8 -U drh -Z 5a82a26aab899b185210ad558ba95050 +P de9da317d4df3efefe9a1a48f954af8a19e7d098 +R 2dc59230e8af71c6a1b496cc05325870 +U mistachkin +Z bebf96c7eb7dba0d54e717c5ef7df7e1 diff --git a/manifest.uuid b/manifest.uuid index 9a937f472e..c20999f107 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -de9da317d4df3efefe9a1a48f954af8a19e7d098 \ No newline at end of file +041484ff91fd4615368ccb2257ab50acc2cd4fea \ No newline at end of file diff --git a/tool/build-all-msvc.bat b/tool/build-all-msvc.bat index 2ae202620a..1751fb4d12 100755 --- a/tool/build-all-msvc.bat +++ b/tool/build-all-msvc.bat @@ -321,7 +321,7 @@ FOR %%P IN (%PLATFORMS%) DO ( %_AECHO% Building the %%B configuration for platform %%P with name %%D... IF /I "%%B" == "Debug" ( - SET DEBUG=2 + SET DEBUG=3 SET MEMDEBUG=1 ) ELSE ( CALL :fn_UnsetVariable DEBUG From 774f42b6c62f938119248bc28a8426bcd3e7a416 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 21 Mar 2015 22:23:46 +0000 Subject: [PATCH 12/63] Add more comments to the MSVC batch build tool. FossilOrigin-Name: 03522da37821958c647d49bf8189a5affa3f6720 --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/build-all-msvc.bat | 11 +++++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 9bcf1897b9..9b298f9b65 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Increase\sthe\sdebugging\slevel\sfor\sthe\sdebug\sconfiguration\sin\sthe\sMSVC\sbatch\sbuild\stool. -D 2015-03-21T22:13:47.750 +C Add\smore\scomments\sto\sthe\sMSVC\sbatch\sbuild\stool. +D 2015-03-21T22:23:46.412 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1194,7 +1194,7 @@ F test/without_rowid6.test db0dbf03c49030aa3c1ba5f618620334bd2baf5f F test/wordcount.c 9915e06cb33d8ca8109b8700791afe80d305afda F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688 F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac -F tool/build-all-msvc.bat 6e2c65d4c694ad3bdcbf8d813d18336c378ef642 x +F tool/build-all-msvc.bat 72e05bc8deca39a547884485c086b915f50a91ed x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P de9da317d4df3efefe9a1a48f954af8a19e7d098 -R 2dc59230e8af71c6a1b496cc05325870 +P 041484ff91fd4615368ccb2257ab50acc2cd4fea +R b4cd923d8d74f09bebb5c4ffebc6ac77 U mistachkin -Z bebf96c7eb7dba0d54e717c5ef7df7e1 +Z 35bbc2e7e7719fcfdf895530fad162a8 diff --git a/manifest.uuid b/manifest.uuid index c20999f107..fa6b8b4a5b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -041484ff91fd4615368ccb2257ab50acc2cd4fea \ No newline at end of file +03522da37821958c647d49bf8189a5affa3f6720 \ No newline at end of file diff --git a/tool/build-all-msvc.bat b/tool/build-all-msvc.bat index 1751fb4d12..728183629b 100755 --- a/tool/build-all-msvc.bat +++ b/tool/build-all-msvc.bat @@ -321,7 +321,18 @@ FOR %%P IN (%PLATFORMS%) DO ( %_AECHO% Building the %%B configuration for platform %%P with name %%D... IF /I "%%B" == "Debug" ( + REM + REM NOTE: Using this level for the DEBUG environment variable should + REM disable all compiler optimizations and prevent use of the + REM NDEBUG define. Additionally, both SQLITE_ENABLE_API_ARMOR + REM and SQLITE_DEBUG defines should be enabled. + REM SET DEBUG=3 + + REM + REM NOTE: Setting this to non-zero should enable the SQLITE_MEMDEBUG + REM define. + REM SET MEMDEBUG=1 ) ELSE ( CALL :fn_UnsetVariable DEBUG From d425864d3359806fa5096103bda390917a28ea0b Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 21 Mar 2015 23:38:59 +0000 Subject: [PATCH 13/63] Fix harmless compiler warnings with MSVC when assert() and SQLITE_MEMDEBUG are both enabled. FossilOrigin-Name: 9513dbd4860c8dd391f831982d09aff227d16f5c --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/malloc.c | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 9b298f9b65..3552ab570d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\smore\scomments\sto\sthe\sMSVC\sbatch\sbuild\stool. -D 2015-03-21T22:23:46.412 +C Fix\sharmless\scompiler\swarnings\swith\sMSVC\swhen\sassert()\sand\sSQLITE_MEMDEBUG\sare\sboth\senabled. +D 2015-03-21T23:38:59.970 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -196,7 +196,7 @@ F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 F src/main.c fa997fa27d95febc16d57095299384b667a7f762 -F src/malloc.c 740db54387204c9a2eb67c6d98e68b08e9ef4eab +F src/malloc.c 13f3f1cdc0c9990c79cefaf0ceba24da983ce8cd F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 041484ff91fd4615368ccb2257ab50acc2cd4fea -R b4cd923d8d74f09bebb5c4ffebc6ac77 +P 03522da37821958c647d49bf8189a5affa3f6720 +R ec24cc7ca49e734053f58e4e5ed37882 U mistachkin -Z 35bbc2e7e7719fcfdf895530fad162a8 +Z e2c3eeafcd54988dc26d14970176c977 diff --git a/manifest.uuid b/manifest.uuid index fa6b8b4a5b..73b0fff7f2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -03522da37821958c647d49bf8189a5affa3f6720 \ No newline at end of file +9513dbd4860c8dd391f831982d09aff227d16f5c \ No newline at end of file diff --git a/src/malloc.c b/src/malloc.c index 4960f91e02..8046fb2089 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -414,7 +414,7 @@ void sqlite3ScratchFree(void *p){ }else{ /* Release memory back to the heap */ assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) ); - assert( sqlite3MemdebugNoType(p, ~MEMTYPE_SCRATCH) ); + assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_SCRATCH) ); sqlite3MemdebugSetType(p, MEMTYPE_HEAP); if( sqlite3GlobalConfig.bMemstat ){ int iSize = sqlite3MallocSize(p); @@ -452,7 +452,7 @@ int sqlite3MallocSize(void *p){ } int sqlite3DbMallocSize(sqlite3 *db, void *p){ if( db==0 ){ - assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) ); + assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); return sqlite3MallocSize(p); }else{ @@ -461,13 +461,13 @@ int sqlite3DbMallocSize(sqlite3 *db, void *p){ return db->lookaside.sz; }else{ assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); - assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); + assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); return sqlite3GlobalConfig.m.xSize(p); } } } sqlite3_uint64 sqlite3_msize(void *p){ - assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) ); + assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p); } @@ -478,7 +478,7 @@ sqlite3_uint64 sqlite3_msize(void *p){ void sqlite3_free(void *p){ if( p==0 ) return; /* IMP: R-49053-54554 */ assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); - assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) ); + assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); if( sqlite3GlobalConfig.bMemstat ){ sqlite3_mutex_enter(mem0.mutex); sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p)); @@ -523,7 +523,7 @@ void sqlite3DbFree(sqlite3 *db, void *p){ } } assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); - assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); + assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) ); sqlite3MemdebugSetType(p, MEMTYPE_HEAP); sqlite3_free(p); @@ -536,7 +536,7 @@ void *sqlite3Realloc(void *pOld, u64 nBytes){ int nOld, nNew, nDiff; void *pNew; assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) ); - assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) ); + assert( sqlite3MemdebugNoType(pOld, (u8)~MEMTYPE_HEAP) ); if( pOld==0 ){ return sqlite3Malloc(nBytes); /* IMP: R-04300-56712 */ } @@ -703,7 +703,7 @@ void *sqlite3DbRealloc(sqlite3 *db, void *p, u64 n){ } }else{ assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); - assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); + assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); sqlite3MemdebugSetType(p, MEMTYPE_HEAP); pNew = sqlite3_realloc64(p, n); if( !pNew ){ From 74893a4cdb556804dc4a31615be90fc8a69b3686 Mon Sep 17 00:00:00 2001 From: drh Date: Sun, 22 Mar 2015 10:23:17 +0000 Subject: [PATCH 14/63] Fix a potential NULL pointer dereference following a syntax error. FossilOrigin-Name: 8d27e3e16a9be79fe227e833f4770ebe09a9d90b --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/expr.c | 1 + test/misc1.test | 10 +++++++++- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 3552ab570d..012f08e737 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings\swith\sMSVC\swhen\sassert()\sand\sSQLITE_MEMDEBUG\sare\sboth\senabled. -D 2015-03-21T23:38:59.970 +C Fix\sa\spotential\sNULL\spointer\sdereference\sfollowing\sa\ssyntax\serror. +D 2015-03-22T10:23:17.264 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -182,7 +182,7 @@ F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac F src/delete.c 37964e6c1d73ff49cbea9ff690c9605fb15f600e -F src/expr.c eb4d795abca1e876726aecc7aeb95ceb29e73fe7 +F src/expr.c d09dac67d53c78880ba31d56e8ba2be3a6490553 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c e0444b61bed271a76840cbe6182df93a9baa3f12 F src/func.c 1414c24c873c48796ad45942257a179a423ba42f @@ -741,7 +741,7 @@ F test/minmax.test 42fbad0e81afaa6e0de41c960329f2b2c3526efd F test/minmax2.test b44bae787fc7b227597b01b0ca5575c7cb54d3bc F test/minmax3.test cc1e8b010136db0d01a6f2a29ba5a9f321034354 F test/minmax4.test 936941484ebdceb8adec7c86b6cd9b6e5e897c1f -F test/misc1.test 4864f2834b203cad7f688df8a5f725e4bab08029 +F test/misc1.test f3f59b3941c84a10860c06c07e86ad367a74ec92 F test/misc2.test 00d7de54eda90e237fc9a38b9e5ccc769ebf6d4d F test/misc3.test cf3dda47d5dda3e53fc5804a100d3c82be736c9d F test/misc4.test 9c078510fbfff05a9869a0b6d8b86a623ad2c4f6 @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 03522da37821958c647d49bf8189a5affa3f6720 -R ec24cc7ca49e734053f58e4e5ed37882 -U mistachkin -Z e2c3eeafcd54988dc26d14970176c977 +P 9513dbd4860c8dd391f831982d09aff227d16f5c +R e779bfe0488c17857ae1dcf614dd348f +U drh +Z ca73f5b3867dd7a4dfc248e6290c5b53 diff --git a/manifest.uuid b/manifest.uuid index 73b0fff7f2..223b936105 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9513dbd4860c8dd391f831982d09aff227d16f5c \ No newline at end of file +8d27e3e16a9be79fe227e833f4770ebe09a9d90b \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index fe09b4b50b..e6ac0f6796 100644 --- a/src/expr.c +++ b/src/expr.c @@ -397,6 +397,7 @@ static void exprSetHeight(Expr *p){ ** Expr.flags. */ void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){ + if( pParse->nErr ) return; exprSetHeight(p); sqlite3ExprCheckHeight(pParse, p->nHeight); } diff --git a/test/misc1.test b/test/misc1.test index d18223e67b..0f4881fb61 100644 --- a/test/misc1.test +++ b/test/misc1.test @@ -13,7 +13,6 @@ # This file implements tests for miscellanous features that were # left out of other test files. # -# $Id: misc1.test,v 1.42 2007/11/05 14:58:23 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -631,4 +630,13 @@ do_execsql_test misc1-20.1 { SELECT rowid, quote(x) FROM t0; } {1 ''} +# 2015-03-22: NULL pointer dereference after a syntax error +# +do_catchsql_test misc1-21.1 { + select''like''like''like#0; +} {1 {near "#0": syntax error}} +do_catchsql_test misc1-21.2 { + VALUES(0,0x0MATCH#0; +} {1 {near ";": syntax error}} + finish_test From af89fe66eae40a520e370e634da59aefe688d06f Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 23 Mar 2015 17:25:18 +0000 Subject: [PATCH 15/63] Add the sqlite3_status64() interface. Make the new interface and the legacy sqlite3_status() both atomic and threadsafe. Check threadsafety using assert()s. FossilOrigin-Name: 1ce8e8fa4b866aafa12b1da0eb4d02321af9293e --- manifest | 25 +++++++------- manifest.uuid | 2 +- src/malloc.c | 33 +++++++++++-------- src/pcache1.c | 19 ++++++++--- src/sqlite.h.in | 23 +++++++------ src/sqliteInt.h | 9 ++++-- src/status.c | 86 +++++++++++++++++++++++++++++++++++++++++-------- src/tokenize.c | 2 ++ 8 files changed, 144 insertions(+), 55 deletions(-) diff --git a/manifest b/manifest index 012f08e737..362bf302a3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\spotential\sNULL\spointer\sdereference\sfollowing\sa\ssyntax\serror. -D 2015-03-22T10:23:17.264 +C Add\sthe\ssqlite3_status64()\sinterface.\s\sMake\sthe\snew\sinterface\sand\sthe\slegacy\nsqlite3_status()\sboth\satomic\sand\sthreadsafe.\s\sCheck\sthreadsafety\susing\nassert()s. +D 2015-03-23T17:25:18.212 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -196,7 +196,7 @@ F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 F src/main.c fa997fa27d95febc16d57095299384b667a7f762 -F src/malloc.c 13f3f1cdc0c9990c79cefaf0ceba24da983ce8cd +F src/malloc.c e818a0db9ac0898f9dc74002f3a5baca32232d05 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 @@ -222,7 +222,7 @@ F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 F src/parse.y 1299c66e7b1707322ccd8af43a359b8fb0d46d72 F src/pcache.c 10539fb959849ad6efff80050541cab3d25089d4 F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 -F src/pcache1.c 1e77432b40b7d3288327d9cdf399dcdfd2b6d3bf +F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 F src/pragma.c ac4f3f856b4234e85f55b0f069698a4766011100 F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 @@ -232,12 +232,12 @@ F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 F src/shell.c 9c1589c8271c04c02d23cdbc2c07bb40752fa9eb -F src/sqlite.h.in c7c9111477b76c82c46bf851b619df4dd35cc095 +F src/sqlite.h.in df180ecc3215e4b87dbd536507869511bec88841 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h f2300529f3592323a98fd7acccec63d0e9082dc5 +F src/sqliteInt.h de9d20aa5757925a3cd26283d9e34a6ef49904fd F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 -F src/status.c 81712116e826b0089bb221b018929536b2b5406f +F src/status.c 35d02aaf02600dfeade53d2adf2455186dfd741e F src/table.c e7a09215315a978057fb42c640f890160dbcc45e F src/tclsqlite.c fa72a7c5278662357c105ba7925c1d0972506ff9 F src/test1.c 90fbedce75330d48d99eadb7d5f4223e86969585 @@ -287,7 +287,7 @@ F src/test_vfs.c b7e6831e6fcf04c5090accff30640ec5c9630739 F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 6bbcc9fe50c917864d48287b4792d46d6e873481 -F src/tokenize.c 05e52378c46efbc1fd63cbbbf7f3c555f840f4bf +F src/tokenize.c a8d270b06e5f709930f7b67cf70a847969cb5bf3 F src/trigger.c 25571661fdeae8c7f975ff40ffec205520a3f92f F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c @@ -1246,7 +1246,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 9513dbd4860c8dd391f831982d09aff227d16f5c -R e779bfe0488c17857ae1dcf614dd348f +P 8d27e3e16a9be79fe227e833f4770ebe09a9d90b +R 2bfdb46ae6ff687a8efb07761e076d30 +T *branch * status64 +T *sym-status64 * +T -sym-trunk * U drh -Z ca73f5b3867dd7a4dfc248e6290c5b53 +Z 89310d97b168ea333a94dce0bcc0bc9f diff --git a/manifest.uuid b/manifest.uuid index 223b936105..e93a4dbdf2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8d27e3e16a9be79fe227e833f4770ebe09a9d90b \ No newline at end of file +1ce8e8fa4b866aafa12b1da0eb4d02321af9293e \ No newline at end of file diff --git a/src/malloc.c b/src/malloc.c index 8046fb2089..264d046ec8 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -75,6 +75,13 @@ static SQLITE_WSD struct Mem0Global { #define mem0 GLOBAL(struct Mem0Global, mem0) +/* +** Return the memory allocator mutex. sqlite3_status() needs it. +*/ +sqlite3_mutex *sqlite3MallocMutex(void){ + return mem0.mutex; +} + /* ** This routine runs when the memory allocator sees that the ** total memory allocation is about to exceed the soft heap @@ -97,7 +104,7 @@ static int sqlite3MemoryAlarm( void *pArg, sqlite3_int64 iThreshold ){ - int nUsed; + sqlite3_int64 nUsed; sqlite3_mutex_enter(mem0.mutex); mem0.alarmCallback = xCallback; mem0.alarmArg = pArg; @@ -266,7 +273,7 @@ static int mallocWithAlarm(int n, void **pp){ nFull = sqlite3GlobalConfig.m.xRoundup(n); sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n); if( mem0.alarmCallback!=0 ){ - int nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); + sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); if( nUsed >= mem0.alarmThreshold - nFull ){ mem0.nearlyFull = 1; sqlite3MallocAlarm(nFull); @@ -283,8 +290,8 @@ static int mallocWithAlarm(int n, void **pp){ #endif if( p ){ nFull = sqlite3MallocSize(p); - sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nFull); - sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, 1); + sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nFull); + sqlite3StatusUp(SQLITE_STATUS_MALLOC_COUNT, 1); } *pp = p; return nFull; @@ -361,14 +368,14 @@ void *sqlite3ScratchMalloc(int n){ p = mem0.pScratchFree; mem0.pScratchFree = mem0.pScratchFree->pNext; mem0.nScratchFree--; - sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, 1); + sqlite3StatusUp(SQLITE_STATUS_SCRATCH_USED, 1); sqlite3_mutex_leave(mem0.mutex); }else{ sqlite3_mutex_leave(mem0.mutex); p = sqlite3Malloc(n); if( sqlite3GlobalConfig.bMemstat && p ){ sqlite3_mutex_enter(mem0.mutex); - sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, sqlite3MallocSize(p)); + sqlite3StatusUp(SQLITE_STATUS_SCRATCH_OVERFLOW, sqlite3MallocSize(p)); sqlite3_mutex_leave(mem0.mutex); } sqlite3MemdebugSetType(p, MEMTYPE_SCRATCH); @@ -409,7 +416,7 @@ void sqlite3ScratchFree(void *p){ mem0.pScratchFree = pSlot; mem0.nScratchFree++; assert( mem0.nScratchFree <= (u32)sqlite3GlobalConfig.nScratch ); - sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1); + sqlite3StatusDown(SQLITE_STATUS_SCRATCH_USED, 1); sqlite3_mutex_leave(mem0.mutex); }else{ /* Release memory back to the heap */ @@ -419,9 +426,9 @@ void sqlite3ScratchFree(void *p){ if( sqlite3GlobalConfig.bMemstat ){ int iSize = sqlite3MallocSize(p); sqlite3_mutex_enter(mem0.mutex); - sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, -iSize); - sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize); - sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1); + sqlite3StatusDown(SQLITE_STATUS_SCRATCH_OVERFLOW, iSize); + sqlite3StatusDown(SQLITE_STATUS_MEMORY_USED, iSize); + sqlite3StatusDown(SQLITE_STATUS_MALLOC_COUNT, 1); sqlite3GlobalConfig.m.xFree(p); sqlite3_mutex_leave(mem0.mutex); }else{ @@ -481,8 +488,8 @@ void sqlite3_free(void *p){ assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); if( sqlite3GlobalConfig.bMemstat ){ sqlite3_mutex_enter(mem0.mutex); - sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p)); - sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1); + sqlite3StatusDown(SQLITE_STATUS_MEMORY_USED, sqlite3MallocSize(p)); + sqlite3StatusDown(SQLITE_STATUS_MALLOC_COUNT, 1); sqlite3GlobalConfig.m.xFree(p); sqlite3_mutex_leave(mem0.mutex); }else{ @@ -570,7 +577,7 @@ void *sqlite3Realloc(void *pOld, u64 nBytes){ } if( pNew ){ nNew = sqlite3MallocSize(pNew); - sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld); + sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nNew-nOld); } sqlite3_mutex_leave(mem0.mutex); }else{ diff --git a/src/pcache1.c b/src/pcache1.c index f5f7893714..a8755a3141 100644 --- a/src/pcache1.c +++ b/src/pcache1.c @@ -195,7 +195,6 @@ void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){ static void *pcache1Alloc(int nByte){ void *p = 0; assert( sqlite3_mutex_notheld(pcache1.grp.mutex) ); - sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte); if( nByte<=pcache1.szSlot ){ sqlite3_mutex_enter(pcache1.mutex); p = (PgHdr1 *)pcache1.pFree; @@ -204,7 +203,8 @@ static void *pcache1Alloc(int nByte){ pcache1.nFreeSlot--; pcache1.bUnderPressure = pcache1.nFreeSlot=0 ); - sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1); + sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte); + sqlite3StatusUp(SQLITE_STATUS_PAGECACHE_USED, 1); } sqlite3_mutex_leave(pcache1.mutex); } @@ -217,7 +217,8 @@ static void *pcache1Alloc(int nByte){ if( p ){ int sz = sqlite3MallocSize(p); sqlite3_mutex_enter(pcache1.mutex); - sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz); + sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte); + sqlite3StatusUp(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz); sqlite3_mutex_leave(pcache1.mutex); } #endif @@ -235,7 +236,7 @@ static int pcache1Free(void *p){ if( p>=pcache1.pStart && ppNext = pcache1.pFree; pcache1.pFree = pSlot; @@ -249,7 +250,7 @@ static int pcache1Free(void *p){ nFreed = sqlite3MallocSize(p); #ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS sqlite3_mutex_enter(pcache1.mutex); - sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -nFreed); + sqlite3StatusDown(SQLITE_STATUS_PAGECACHE_OVERFLOW, nFreed); sqlite3_mutex_leave(pcache1.mutex); #endif sqlite3_free(p); @@ -986,6 +987,14 @@ void sqlite3PCacheSetDefault(void){ */ int sqlite3HeaderSizePcache1(void){ return ROUND8(sizeof(PgHdr1)); } +/* +** Return the global mutex used by this PCACHE implementation. The +** sqlite3_status() routine needs access to this mutex. +*/ +sqlite3_mutex *sqlite3Pcache1Mutex(void){ + return pcache1.mutex; +} + #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT /* ** This function is called to free superfluous dynamically allocated memory diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 9e48620c66..8419392cfa 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -1550,7 +1550,7 @@ struct sqlite3_mem_methods { **
  • [sqlite3_memory_used()] **
  • [sqlite3_memory_highwater()] **
  • [sqlite3_soft_heap_limit64()] -**
  • [sqlite3_status()] +**
  • [sqlite3_status64()] ** )^ ** ^Memory allocation statistics are enabled by default unless SQLite is ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory @@ -6305,7 +6305,7 @@ int sqlite3_test_control(int op, ...); /* ** CAPI3REF: SQLite Runtime Status ** -** ^This interface is used to retrieve runtime status information +** ^These interfaces are used to retrieve runtime status information ** about the performance of SQLite, and optionally to reset various ** highwater marks. ^The first argument is an integer code for ** the specific parameter to measure. ^(Recognized integer codes @@ -6319,19 +6319,22 @@ int sqlite3_test_control(int op, ...); ** ^(Other parameters record only the highwater mark and not the current ** value. For these latter parameters nothing is written into *pCurrent.)^ ** -** ^The sqlite3_status() routine returns SQLITE_OK on success and a -** non-zero [error code] on failure. +** ^The sqlite3_status() and sqlite3_status64() routines return +** SQLITE_OK on success and a non-zero [error code] on failure. ** -** This routine is threadsafe but is not atomic. This routine can be -** called while other threads are running the same or different SQLite -** interfaces. However the values returned in *pCurrent and -** *pHighwater reflect the status of SQLite at different points in time -** and it is possible that another thread might change the parameter -** in between the times when *pCurrent and *pHighwater are written. +** If either the current value or the highwater mark is too large to +** be represented by a 32-bit integer, then the values returned by +** sqlite3_status() are undefined. ** ** See also: [sqlite3_db_status()] */ int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); +int sqlite3_status64( + int op, + sqlite3_int64 *pCurrent, + sqlite3_int64 *pHighwater, + int resetFlag +); /* diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 9e174d6f4c..78945c1dde 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3097,10 +3097,15 @@ const sqlite3_mem_methods *sqlite3MemGetMemsys5(void); int sqlite3MutexEnd(void); #endif -int sqlite3StatusValue(int); -void sqlite3StatusAdd(int, int); +sqlite3_int64 sqlite3StatusValue(int); +void sqlite3StatusUp(int, int); +void sqlite3StatusDown(int, int); void sqlite3StatusSet(int, int); +/* Access to mutexes used by sqlite3_status() */ +sqlite3_mutex *sqlite3Pcache1Mutex(void); +sqlite3_mutex *sqlite3MallocMutex(void); + #ifndef SQLITE_OMIT_FLOATING_POINT int sqlite3IsNaN(double); #else diff --git a/src/status.c b/src/status.c index 4c2eabb661..0f6328318a 100644 --- a/src/status.c +++ b/src/status.c @@ -21,10 +21,27 @@ */ typedef struct sqlite3StatType sqlite3StatType; static SQLITE_WSD struct sqlite3StatType { - int nowValue[10]; /* Current value */ - int mxValue[10]; /* Maximum value */ + sqlite3_int64 nowValue[10]; /* Current value */ + sqlite3_int64 mxValue[10]; /* Maximum value */ } sqlite3Stat = { {0,}, {0,} }; +/* +** Elements of sqlite3Stat[] are protected by either the memory allocator +** mutex, or by the pcache1 mutex. The following array determines which. +*/ +static const char statMutex[] = { + 0, /* SQLITE_STATUS_MEMORY_USED */ + 1, /* SQLITE_STATUS_PAGECACHE_USED */ + 1, /* SQLITE_STATUS_PAGECACHE_OVERFLOW */ + 0, /* SQLITE_STATUS_SCRATCH_USED */ + 0, /* SQLITE_STATUS_SCRATCH_OVERFLOW */ + 0, /* SQLITE_STATUS_MALLOC_SIZE */ + 0, /* SQLITE_STATUS_PARSER_STACK */ + 1, /* SQLITE_STATUS_PAGECACHE_SIZE */ + 0, /* SQLITE_STATUS_SCRATCH_SIZE */ + 0, /* SQLITE_STATUS_MALLOC_COUNT */ +}; + /* The "wsdStat" macro will resolve to the status information ** state vector. If writable static data is unsupported on the target, @@ -41,33 +58,60 @@ static SQLITE_WSD struct sqlite3StatType { #endif /* -** Return the current value of a status parameter. +** Return the current value of a status parameter. The caller must +** be holding the appropriate mutex. */ -int sqlite3StatusValue(int op){ +sqlite3_int64 sqlite3StatusValue(int op){ wsdStatInit; assert( op>=0 && op=0 && op=0 && op=0 && opwsdStat.mxValue[op] ){ wsdStat.mxValue[op] = wsdStat.nowValue[op]; } } +void sqlite3StatusDown(int op, int N){ + wsdStatInit; + assert( N>=0 ); + assert( op>=0 && op=0 && op=0 && op=0 && opwsdStat.mxValue[op] ){ wsdStat.mxValue[op] = wsdStat.nowValue[op]; @@ -76,26 +120,42 @@ void sqlite3StatusSet(int op, int X){ /* ** Query status information. -** -** This implementation assumes that reading or writing an aligned -** 32-bit integer is an atomic operation. If that assumption is not true, -** then this routine is not threadsafe. */ -int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){ +int sqlite3_status64( + int op, + sqlite3_int64 *pCurrent, + sqlite3_int64 *pHighwater, + int resetFlag +){ wsdStatInit; + sqlite3_mutex *pMutex; if( op<0 || op>=ArraySize(wsdStat.nowValue) ){ return SQLITE_MISUSE_BKPT; } #ifdef SQLITE_ENABLE_API_ARMOR if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; #endif + pMutex = statMutex[op] ? sqlite3Pcache1Mutex() : sqlite3MallocMutex(); + sqlite3_mutex_enter(pMutex); *pCurrent = wsdStat.nowValue[op]; *pHighwater = wsdStat.mxValue[op]; if( resetFlag ){ wsdStat.mxValue[op] = wsdStat.nowValue[op]; } + sqlite3_mutex_leave(pMutex); return SQLITE_OK; } +int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){ + sqlite3_int64 iCur, iHwtr; + int rc; +#ifdef SQLITE_ENABLE_API_ARMOR + if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; +#endif + rc = sqlite3_status64(op, &iCur, &iHwtr, resetFlag); + *pCurrent = (int)iCur; + *pHighwater = (int)iHwtr; + return rc; +} /* ** Query status information for a single database connection diff --git a/src/tokenize.c b/src/tokenize.c index 6fb5a35c3d..5068742f31 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -459,9 +459,11 @@ abort_parse: sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse); } #ifdef YYTRACKMAXSTACKDEPTH + sqlite3_mutex_enter(sqlite3MallocMutex()); sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK, sqlite3ParserStackPeak(pEngine) ); + sqlite3_mutex_leave(sqlite3MallocMutex()); #endif /* YYDEBUG */ sqlite3ParserFree(pEngine, sqlite3_free); db->lookaside.bEnabled = enableLookaside; From 2b4905c81fc1ee72c85f8bab318cc72735a34419 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 23 Mar 2015 18:52:56 +0000 Subject: [PATCH 16/63] Add the SQLITE_PTRSIZE macro. Use it to help sqlite3_status() run faster on 32-bit systems. FossilOrigin-Name: c742bd6047bc6d0319a5a8c31d97f6b9229507f6 --- manifest | 19 ++++++++----------- manifest.uuid | 2 +- src/main.c | 5 +++++ src/sqliteInt.h | 14 ++++++++++++++ src/status.c | 11 +++++++++-- 5 files changed, 37 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 362bf302a3..014d5df5b4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\ssqlite3_status64()\sinterface.\s\sMake\sthe\snew\sinterface\sand\sthe\slegacy\nsqlite3_status()\sboth\satomic\sand\sthreadsafe.\s\sCheck\sthreadsafety\susing\nassert()s. -D 2015-03-23T17:25:18.212 +C Add\sthe\sSQLITE_PTRSIZE\smacro.\s\sUse\sit\sto\shelp\ssqlite3_status()\srun\sfaster\non\s32-bit\ssystems. +D 2015-03-23T18:52:56.780 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -195,7 +195,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 -F src/main.c fa997fa27d95febc16d57095299384b667a7f762 +F src/main.c 569d45ba9eb4fbdd631d53f440bcdb4a35ab1505 F src/malloc.c e818a0db9ac0898f9dc74002f3a5baca32232d05 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 @@ -235,9 +235,9 @@ F src/shell.c 9c1589c8271c04c02d23cdbc2c07bb40752fa9eb F src/sqlite.h.in df180ecc3215e4b87dbd536507869511bec88841 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h de9d20aa5757925a3cd26283d9e34a6ef49904fd +F src/sqliteInt.h e22a2bfbeed55ed3addff5e0ef34366e93ad0874 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 -F src/status.c 35d02aaf02600dfeade53d2adf2455186dfd741e +F src/status.c 8ccd03e35ac98e44b3df51cbc94a81119c6ab0dd F src/table.c e7a09215315a978057fb42c640f890160dbcc45e F src/tclsqlite.c fa72a7c5278662357c105ba7925c1d0972506ff9 F src/test1.c 90fbedce75330d48d99eadb7d5f4223e86969585 @@ -1246,10 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 8d27e3e16a9be79fe227e833f4770ebe09a9d90b -R 2bfdb46ae6ff687a8efb07761e076d30 -T *branch * status64 -T *sym-status64 * -T -sym-trunk * +P 1ce8e8fa4b866aafa12b1da0eb4d02321af9293e +R 0b9a82d5d161d745ba0c858230f2a6bc U drh -Z 89310d97b168ea333a94dce0bcc0bc9f +Z e9a2419ecec514dae3eef3cef6e74ea6 diff --git a/manifest.uuid b/manifest.uuid index e93a4dbdf2..db394d0c85 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1ce8e8fa4b866aafa12b1da0eb4d02321af9293e \ No newline at end of file +c742bd6047bc6d0319a5a8c31d97f6b9229507f6 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 092cbf8415..6967131143 100644 --- a/src/main.c +++ b/src/main.c @@ -128,6 +128,11 @@ int sqlite3_initialize(void){ } #endif + /* If the following assert() fails on some obscure processor/compiler + ** combination, the work-around is to set the correct pointer + ** size at compile-time using -DSQLITE_PTRSIZE=n compile-time option */ + assert( SQLITE_PTRSIZE==sizeof(char*) ); + /* If SQLite is already completely initialized, then this call ** to sqlite3_initialize() should be a no-op. But the initialization ** must be complete. So isInit must not be set until the very end diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 78945c1dde..2b1d7ebc6e 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -594,6 +594,20 @@ typedef INT8_TYPE i8; /* 1-byte signed integer */ */ typedef INT16_TYPE LogEst; +/* +** Set the SQLITE_PTRSIZE macro to the number of bytes in a pointer +*/ +#ifndef SQLITE_PTRSIZE +# if defined(__SIZEOF_POINTER__) +# define SQLITE_PTRSIZE __SIZEOF_POINTER__ +# elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \ + defined(_M_ARM) || defined(__arm__) || defined(__x86) +# define SQLITE_PTRSIZE 4 +# else +# define SQLITE_PTRSIZE 8 +# endif +#endif + /* ** Macros to determine whether the machine is big or little endian, ** and whether or not that determination is run-time or compile-time. diff --git a/src/status.c b/src/status.c index 0f6328318a..739249ec22 100644 --- a/src/status.c +++ b/src/status.c @@ -21,8 +21,13 @@ */ typedef struct sqlite3StatType sqlite3StatType; static SQLITE_WSD struct sqlite3StatType { +#if SQLITE_PTRSIZE>4 sqlite3_int64 nowValue[10]; /* Current value */ sqlite3_int64 mxValue[10]; /* Maximum value */ +#else + u32 nowValue[10]; /* Current value */ + u32 mxValue[10]; /* Maximum value */ +#endif } sqlite3Stat = { {0,}, {0,} }; /* @@ -152,8 +157,10 @@ int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){ if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; #endif rc = sqlite3_status64(op, &iCur, &iHwtr, resetFlag); - *pCurrent = (int)iCur; - *pHighwater = (int)iHwtr; + if( rc==0 ){ + *pCurrent = (int)iCur; + *pHighwater = (int)iHwtr; + } return rc; } From 062cf27d0014afc0ec0b00dee2a821111a0ef121 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 23 Mar 2015 19:03:51 +0000 Subject: [PATCH 17/63] Fix datetype size asserts in btree.c. FossilOrigin-Name: ff4812d0e8e6322ca8b6992925fd4ef4aee463e6 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 012f08e737..8ca7814754 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\spotential\sNULL\spointer\sdereference\sfollowing\sa\ssyntax\serror. -D 2015-03-22T10:23:17.264 +C Fix\sdatetype\ssize\sasserts\sin\sbtree.c. +D 2015-03-23T19:03:51.368 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c d4d52fb14e863cff9dbc7c746e9048ec0967a555 +F src/btree.c 3e320cac836546c905bd90007074d887980aa70e F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 9513dbd4860c8dd391f831982d09aff227d16f5c -R e779bfe0488c17857ae1dcf614dd348f +P 8d27e3e16a9be79fe227e833f4770ebe09a9d90b +R b5413ce9e25a08fe53ff3be92a646869 U drh -Z ca73f5b3867dd7a4dfc248e6290c5b53 +Z 5fbc203b6eb85f868f3432b74d400822 diff --git a/manifest.uuid b/manifest.uuid index 223b936105..16d4f53715 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8d27e3e16a9be79fe227e833f4770ebe09a9d90b \ No newline at end of file +ff4812d0e8e6322ca8b6992925fd4ef4aee463e6 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 1d82a2b625..ac0c877317 100644 --- a/src/btree.c +++ b/src/btree.c @@ -2017,8 +2017,8 @@ int sqlite3BtreeOpen( ** the right size. This is to guard against size changes that result ** when compiling on a different architecture. */ - assert( sizeof(i64)==8 || sizeof(i64)==4 ); - assert( sizeof(u64)==8 || sizeof(u64)==4 ); + assert( sizeof(i64)==8 ); + assert( sizeof(u64)==8 ); assert( sizeof(u32)==4 ); assert( sizeof(u16)==2 ); assert( sizeof(Pgno)==4 ); From 2493870d9c15769e5dbeaacd30809728e4571bbf Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 23 Mar 2015 19:16:30 +0000 Subject: [PATCH 18/63] Fix a non-C89 variable declaration that causes problems for MSVC. FossilOrigin-Name: 3de085eab2fbe491f2242b340851e8af8f61ad13 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/status.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 014d5df5b4..4799c31f3a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sSQLITE_PTRSIZE\smacro.\s\sUse\sit\sto\shelp\ssqlite3_status()\srun\sfaster\non\s32-bit\ssystems. -D 2015-03-23T18:52:56.780 +C Fix\sa\snon-C89\svariable\sdeclaration\sthat\scauses\sproblems\sfor\sMSVC. +D 2015-03-23T19:16:30.885 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -237,7 +237,7 @@ F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h e22a2bfbeed55ed3addff5e0ef34366e93ad0874 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 -F src/status.c 8ccd03e35ac98e44b3df51cbc94a81119c6ab0dd +F src/status.c 2e5c86866ff2f30988ce10ddbaa7ba2eaf6d4146 F src/table.c e7a09215315a978057fb42c640f890160dbcc45e F src/tclsqlite.c fa72a7c5278662357c105ba7925c1d0972506ff9 F src/test1.c 90fbedce75330d48d99eadb7d5f4223e86969585 @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 1ce8e8fa4b866aafa12b1da0eb4d02321af9293e -R 0b9a82d5d161d745ba0c858230f2a6bc +P c742bd6047bc6d0319a5a8c31d97f6b9229507f6 +R 7eaa072c7f96e653ea839c906764b0b8 U drh -Z e9a2419ecec514dae3eef3cef6e74ea6 +Z 211fd8daf94b9f843731a45e101ebe58 diff --git a/manifest.uuid b/manifest.uuid index db394d0c85..c73dc87d68 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c742bd6047bc6d0319a5a8c31d97f6b9229507f6 \ No newline at end of file +3de085eab2fbe491f2242b340851e8af8f61ad13 \ No newline at end of file diff --git a/src/status.c b/src/status.c index 739249ec22..aa27f70efc 100644 --- a/src/status.c +++ b/src/status.c @@ -132,8 +132,8 @@ int sqlite3_status64( sqlite3_int64 *pHighwater, int resetFlag ){ - wsdStatInit; sqlite3_mutex *pMutex; + wsdStatInit; if( op<0 || op>=ArraySize(wsdStat.nowValue) ){ return SQLITE_MISUSE_BKPT; } From ada3f2b14f1f9e9625f8e8f0e6b5a367bc0c9773 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 23 Mar 2015 21:32:50 +0000 Subject: [PATCH 19/63] Disable loadable extensions in the command-line shell on VxWorks user-space. FossilOrigin-Name: 0ee2d38deb35aefc55395e86984a9a773caf6218 --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/shell.c | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 53a9cfe78a..9bc4020219 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Track\stotal\smemory\susage\susing\sa\s64-bit\sinteger\son\s64-bit\ssystems.\s\sAdd\nthe\ssqlite3_status64()\sinterface.\s\sMake\sthe\ssqlite3_status()\sand\nsqlite3_status64()\sinterfaces\satomic\susing\smutexes\sand\sverify\scorrect\nmutex\soperation\susing\sassert()\sstatements. -D 2015-03-23T19:55:21.641 +C Disable\sloadable\sextensions\sin\sthe\scommand-line\sshell\son\sVxWorks\suser-space. +D 2015-03-23T21:32:50.879 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -231,7 +231,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 -F src/shell.c 9c1589c8271c04c02d23cdbc2c07bb40752fa9eb +F src/shell.c 3ae1e53878d2804fe77b8c8f1f6ca287a0e5d80e F src/sqlite.h.in df180ecc3215e4b87dbd536507869511bec88841 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -1246,8 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P ff4812d0e8e6322ca8b6992925fd4ef4aee463e6 3de085eab2fbe491f2242b340851e8af8f61ad13 -R fa228592c968c6dd60a3ff76053c22f4 -T +closed 3de085eab2fbe491f2242b340851e8af8f61ad13 +P 6fc4e79a2350295a15ac464593ad39d904953041 +R f88d42f63f5075e0fafdf77b9c8623bb U drh -Z 5ddc58556d6343081a340eb577f95e29 +Z b5778fea5ecdfe311fd40aa2979f5026 diff --git a/manifest.uuid b/manifest.uuid index dc77af1006..4f62d697cb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6fc4e79a2350295a15ac464593ad39d904953041 \ No newline at end of file +0ee2d38deb35aefc55395e86984a9a773caf6218 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index d5a8a3fe95..b31ea16333 100644 --- a/src/shell.c +++ b/src/shell.c @@ -27,7 +27,7 @@ /* ** No support for loadable extensions in VxWorks. */ -#if defined(_WRS_KERNEL) && !SQLITE_OMIT_LOAD_EXTENSION +#if (defined(__RTP__) || defined(_WRS_KERNEL)) && !SQLITE_OMIT_LOAD_EXTENSION # define SQLITE_OMIT_LOAD_EXTENSION 1 #endif From 086723a4a8a5490b46603554445a6e6d0e1c03e8 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Mar 2015 12:51:52 +0000 Subject: [PATCH 20/63] Replace the Vdbe.inVtabMethod field with the sqlite3.nVDestroy counter. FossilOrigin-Name: 9faefb96272967e731e83ef516a8c1e1b876391b --- manifest | 21 ++++++++++++--------- manifest.uuid | 2 +- src/sqliteInt.h | 1 + src/vdbe.c | 25 +++---------------------- src/vdbeInt.h | 9 --------- src/vdbeaux.c | 2 -- 6 files changed, 17 insertions(+), 43 deletions(-) diff --git a/manifest b/manifest index 9bc4020219..5c9a4c0330 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Disable\sloadable\sextensions\sin\sthe\scommand-line\sshell\son\sVxWorks\suser-space. -D 2015-03-23T21:32:50.879 +C Replace\sthe\sVdbe.inVtabMethod\sfield\swith\sthe\ssqlite3.nVDestroy\scounter. +D 2015-03-24T12:51:52.656 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -235,7 +235,7 @@ F src/shell.c 3ae1e53878d2804fe77b8c8f1f6ca287a0e5d80e F src/sqlite.h.in df180ecc3215e4b87dbd536507869511bec88841 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h e22a2bfbeed55ed3addff5e0ef34366e93ad0874 +F src/sqliteInt.h bedf15914c09bfb5fe3ec4e3f211a4a6fc42cd33 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 2e5c86866ff2f30988ce10ddbaa7ba2eaf6d4146 F src/table.c e7a09215315a978057fb42c640f890160dbcc45e @@ -293,11 +293,11 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec -F src/vdbe.c bd793ed436edccaf264ec969ac92c9b5f4b41d64 +F src/vdbe.c 884faa91c44023891d0992311fd0feed0df060fc F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 -F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a +F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 -F src/vdbeaux.c 23390670e64f011f3fed8f38a2f25aaccacb74d2 +F src/vdbeaux.c d62823d72b8f69a3e64deb03c30e959af285e488 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 919717d7599fa31d343ec28bffd0f9e91a4ff5f6 @@ -1246,7 +1246,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 6fc4e79a2350295a15ac464593ad39d904953041 -R f88d42f63f5075e0fafdf77b9c8623bb +P 0ee2d38deb35aefc55395e86984a9a773caf6218 +R 8a156978483ce9f9262ab29d0045e64e +T *branch * nVDestroy +T *sym-nVDestroy * +T -sym-trunk * U drh -Z b5778fea5ecdfe311fd40aa2979f5026 +Z 795f6417c17436a4fbd09f9a73f096f4 diff --git a/manifest.uuid b/manifest.uuid index 4f62d697cb..9e51355abe 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0ee2d38deb35aefc55395e86984a9a773caf6218 \ No newline at end of file +9faefb96272967e731e83ef516a8c1e1b876391b \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 2b1d7ebc6e..9df6d1bc4e 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1112,6 +1112,7 @@ struct sqlite3 { int nVdbeRead; /* Number of active VDBEs that read or write */ int nVdbeWrite; /* Number of active VDBEs that read and write */ int nVdbeExec; /* Number of nested calls to VdbeExec() */ + int nVDestroy; /* Number of active OP_VDestroy operations */ int nExtension; /* Number of loaded extensions */ void **aExtension; /* Array of shared library handles */ void (*xTrace)(void*,const char*); /* Trace function */ diff --git a/src/vdbe.c b/src/vdbe.c index 7d6d2b4f5d..bba6a90bf4 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -4946,30 +4946,15 @@ case OP_IdxGE: { /* jump */ */ case OP_Destroy: { /* out2-prerelease */ int iMoved; - int iCnt; - Vdbe *pVdbe; int iDb; assert( p->readOnly==0 ); -#ifndef SQLITE_OMIT_VIRTUALTABLE - iCnt = 0; - for(pVdbe=db->pVdbe; pVdbe; pVdbe = pVdbe->pNext){ - if( pVdbe->magic==VDBE_MAGIC_RUN && pVdbe->bIsReader - && pVdbe->inVtabMethod<2 && pVdbe->pc>=0 - ){ - iCnt++; - } - } -#else - iCnt = db->nVdbeRead; -#endif pOut->flags = MEM_Null; - if( iCnt>1 ){ + if( db->nVdbeRead > db->nVDestroy+1 ){ rc = SQLITE_LOCKED; p->errorAction = OE_Abort; }else{ iDb = pOp->p3; - assert( iCnt==1 ); assert( DbMaskTest(p->btreeMask, iDb) ); iMoved = 0; /* Not needed. Only to silence a warning. */ rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved); @@ -6060,9 +6045,9 @@ case OP_VCreate: { ** of that table. */ case OP_VDestroy: { - p->inVtabMethod = 2; + db->nVDestroy++; rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z); - p->inVtabMethod = 0; + db->nVDestroy--; break; } #endif /* SQLITE_OMIT_VIRTUALTABLE */ @@ -6161,9 +6146,7 @@ case OP_VFilter: { /* jump */ apArg[i] = &pArgc[i+1]; } - p->inVtabMethod = 1; rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg); - p->inVtabMethod = 0; sqlite3VtabImportErrmsg(p, pVtab); if( rc==SQLITE_OK ){ res = pModule->xEof(pVtabCursor); @@ -6253,9 +6236,7 @@ case OP_VNext: { /* jump */ ** data is available) and the error code returned when xColumn or ** some other method is next invoked on the save virtual table cursor. */ - p->inVtabMethod = 1; rc = pModule->xNext(pCur->pVtabCursor); - p->inVtabMethod = 0; sqlite3VtabImportErrmsg(p, pVtab); if( rc==SQLITE_OK ){ res = pModule->xEof(pCur->pVtabCursor); diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 877da1143c..d3955af31e 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -313,14 +313,6 @@ struct ScanStatus { ** ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare() ** is really a pointer to an instance of this structure. -** -** The Vdbe.inVtabMethod variable is set to non-zero for the duration of -** any virtual table method invocations made by the vdbe program. It is -** set to 2 for xDestroy method calls and 1 for all other methods. This -** variable is used for two purposes: to allow xDestroy methods to execute -** "DROP TABLE" statements and to prevent some nasty side effects of -** malloc failure when SQLite is invoked recursively by a virtual table -** method function. */ struct Vdbe { sqlite3 *db; /* The database connection that owns this statement */ @@ -351,7 +343,6 @@ struct Vdbe { u8 errorAction; /* Recovery action to do in case of an error */ u8 minWriteFileFormat; /* Minimum file format for writable database files */ bft explain:2; /* True if EXPLAIN present on SQL command */ - bft inVtabMethod:2; /* See comments above */ bft changeCntOn:1; /* True to update the change-counter */ bft expired:1; /* True if the VM needs to be recompiled */ bft runOnlyOnce:1; /* Automatically expire on reset */ diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 9c105cc9e7..8397fbc10d 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1782,9 +1782,7 @@ void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){ else if( pCx->pVtabCursor ){ sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor; const sqlite3_module *pModule = pVtabCursor->pVtab->pModule; - p->inVtabMethod = 1; pModule->xClose(pVtabCursor); - p->inVtabMethod = 0; } #endif } From a68d62829134f97df079b7b9c25fce44e1984f8f Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Mar 2015 13:32:53 +0000 Subject: [PATCH 21/63] Prevent a virtual table from being destroyed while it is in use. FossilOrigin-Name: fba674c083286dabb37fed9357b67593b56ed3a5 --- manifest | 21 +++++++++------------ manifest.uuid | 2 +- src/sqlite.h.in | 2 +- src/vdbe.c | 1 + src/vdbeaux.c | 2 ++ src/vtab.c | 12 ++++++++---- 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index 5c9a4c0330..3cbfeae1e3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Replace\sthe\sVdbe.inVtabMethod\sfield\swith\sthe\ssqlite3.nVDestroy\scounter. -D 2015-03-24T12:51:52.656 +C Prevent\sa\svirtual\stable\sfrom\sbeing\sdestroyed\swhile\sit\sis\sin\suse. +D 2015-03-24T13:32:53.812 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -232,7 +232,7 @@ F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 F src/shell.c 3ae1e53878d2804fe77b8c8f1f6ca287a0e5d80e -F src/sqlite.h.in df180ecc3215e4b87dbd536507869511bec88841 +F src/sqlite.h.in 2f9606a682af372415ce9d1f244183c5cc8385aa F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h bedf15914c09bfb5fe3ec4e3f211a4a6fc42cd33 @@ -293,16 +293,16 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec -F src/vdbe.c 884faa91c44023891d0992311fd0feed0df060fc +F src/vdbe.c 1524e1db29a85d8e376d0f4ef2109c5296dcd83b F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 -F src/vdbeaux.c d62823d72b8f69a3e64deb03c30e959af285e488 +F src/vdbeaux.c 741cccd410f75f6dcd9dde66c1e0601c956a42ae F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 919717d7599fa31d343ec28bffd0f9e91a4ff5f6 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 -F src/vtab.c 1680f58978ae014a331d99b4c87316d079056c5e +F src/vtab.c 62d49237bd8f3be4863815a39387b0f9897fa5e1 F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 878c8e1a51cb2ec45c395d26b7d5cd9e1a098e4a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 @@ -1246,10 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0ee2d38deb35aefc55395e86984a9a773caf6218 -R 8a156978483ce9f9262ab29d0045e64e -T *branch * nVDestroy -T *sym-nVDestroy * -T -sym-trunk * +P 9faefb96272967e731e83ef516a8c1e1b876391b +R 281e744f7b786f4abb8205e460d3cd79 U drh -Z 795f6417c17436a4fbd09f9a73f096f4 +Z 8d74d67cd7bcd5c907dded9ec155ff27 diff --git a/manifest.uuid b/manifest.uuid index 9e51355abe..cd8c7c5fbd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9faefb96272967e731e83ef516a8c1e1b876391b \ No newline at end of file +fba674c083286dabb37fed9357b67593b56ed3a5 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 8419392cfa..8e2727f6ae 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -5627,7 +5627,7 @@ int sqlite3_create_module_v2( */ struct sqlite3_vtab { const sqlite3_module *pModule; /* The module for this virtual table */ - int nRef; /* NO LONGER USED */ + int nRef; /* Number of open cursors */ char *zErrMsg; /* Error message from sqlite3_mprintf() */ /* Virtual table implementations will typically add additional fields */ }; diff --git a/src/vdbe.c b/src/vdbe.c index bba6a90bf4..82c313a2d9 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -6081,6 +6081,7 @@ case OP_VOpen: { pCur = allocateCursor(p, pOp->p1, 0, -1, 0); if( pCur ){ pCur->pVtabCursor = pVtabCursor; + pVtab->nRef++; }else{ db->mallocFailed = 1; pModule->xClose(pVtabCursor); diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 8397fbc10d..bd00786ebc 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1782,6 +1782,8 @@ void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){ else if( pCx->pVtabCursor ){ sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor; const sqlite3_module *pModule = pVtabCursor->pVtab->pModule; + assert( pVtabCursor->pVtab->nRef>0 ); + pVtabCursor->pVtab->nRef--; pModule->xClose(pVtabCursor); } #endif diff --git a/src/vtab.c b/src/vtab.c index 4631a7d0d0..23f49bafce 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -780,11 +780,15 @@ int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){ pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName); if( ALWAYS(pTab!=0 && pTab->pVTable!=0) ){ - VTable *p = vtabDisconnectAll(db, pTab); - - assert( rc==SQLITE_OK ); + VTable *p; + for(p=pTab->pVTable; p; p=p->pNext){ + assert( p->pVtab ); + if( p->pVtab->nRef>0 ){ + return SQLITE_LOCKED; + } + } + p = vtabDisconnectAll(db, pTab); rc = p->pMod->pModule->xDestroy(p->pVtab); - /* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */ if( rc==SQLITE_OK ){ assert( pTab->pVTable==p && p->pNext==0 ); From f496a7dc81dd0b2cc0c823a13a836f6a22001a4f Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Mar 2015 14:05:50 +0000 Subject: [PATCH 22/63] More defenses against virtual table being deleted out from under a running statement. FossilOrigin-Name: 116c99823022c017946b6088878a2d46759deb6e --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbe.c | 17 ++++++++++++----- src/vdbeaux.c | 3 ++- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 3cbfeae1e3..faa3a9efb1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Prevent\sa\svirtual\stable\sfrom\sbeing\sdestroyed\swhile\sit\sis\sin\suse. -D 2015-03-24T13:32:53.812 +C More\sdefenses\sagainst\svirtual\stable\sbeing\sdeleted\sout\sfrom\sunder\sa\srunning\nstatement. +D 2015-03-24T14:05:50.045 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -293,11 +293,11 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec -F src/vdbe.c 1524e1db29a85d8e376d0f4ef2109c5296dcd83b +F src/vdbe.c bbfede5a8a6908b3ddcd55fdb0b2301288dd4754 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 -F src/vdbeaux.c 741cccd410f75f6dcd9dde66c1e0601c956a42ae +F src/vdbeaux.c 056eefd33ef4457240b6d3156a96201579face0a F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 919717d7599fa31d343ec28bffd0f9e91a4ff5f6 @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 9faefb96272967e731e83ef516a8c1e1b876391b -R 281e744f7b786f4abb8205e460d3cd79 +P fba674c083286dabb37fed9357b67593b56ed3a5 +R 6651e18da796c17c1ca503ba6b1b311c U drh -Z 8d74d67cd7bcd5c907dded9ec155ff27 +Z 91702967a80a94e761fcc487487cb422 diff --git a/manifest.uuid b/manifest.uuid index cd8c7c5fbd..625bb648cf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fba674c083286dabb37fed9357b67593b56ed3a5 \ No newline at end of file +116c99823022c017946b6088878a2d46759deb6e \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 82c313a2d9..ec5e6d7442 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -6063,14 +6063,17 @@ case OP_VOpen: { VdbeCursor *pCur; sqlite3_vtab_cursor *pVtabCursor; sqlite3_vtab *pVtab; - sqlite3_module *pModule; + const sqlite3_module *pModule; assert( p->bIsReader ); pCur = 0; pVtabCursor = 0; pVtab = pOp->p4.pVtab->pVtab; - pModule = (sqlite3_module *)pVtab->pModule; - assert(pVtab && pModule); + if( pVtab==0 || NEVER(pVtab->pModule==0) ){ + rc = SQLITE_LOCKED; + break; + } + pModule = pVtab->pModule; rc = pModule->xOpen(pVtab, &pVtabCursor); sqlite3VtabImportErrmsg(p, pVtab); if( SQLITE_OK==rc ){ @@ -6312,7 +6315,7 @@ case OP_VRename: { */ case OP_VUpdate: { sqlite3_vtab *pVtab; - sqlite3_module *pModule; + const sqlite3_module *pModule; int nArg; int i; sqlite_int64 rowid; @@ -6324,7 +6327,11 @@ case OP_VUpdate: { ); assert( p->readOnly==0 ); pVtab = pOp->p4.pVtab->pVtab; - pModule = (sqlite3_module *)pVtab->pModule; + if( pVtab==0 || NEVER(pVtab->pModule==0) ){ + rc = SQLITE_LOCKED; + break; + } + pModule = pVtab->pModule; nArg = pOp->p2; assert( pOp->p4type==P4_VTAB ); if( ALWAYS(pModule->xUpdate) ){ diff --git a/src/vdbeaux.c b/src/vdbeaux.c index bd00786ebc..25840ccde8 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1118,7 +1118,8 @@ static char *displayP4(Op *pOp, char *zTemp, int nTemp){ #ifndef SQLITE_OMIT_VIRTUALTABLE case P4_VTAB: { sqlite3_vtab *pVtab = pOp->p4.pVtab->pVtab; - sqlite3_snprintf(nTemp, zTemp, "vtab:%p:%p", pVtab, pVtab->pModule); + sqlite3_snprintf(nTemp, zTemp, "vtab:%p:%p", + pVtab, pVtab ? pVtab->pModule : (sqlite3_module*)0); break; } #endif From 466fd815fbdfce266f33ee61c8d06751a6170dc0 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Mar 2015 14:57:02 +0000 Subject: [PATCH 23/63] Simplify the EXPLAIN output of virtual table P4 parameters to only show the pointer to the sqlite3_vtab object and omit the sqlite3_module object. FossilOrigin-Name: 85610bbbc60cb4a6ec856123447fdb2ba948e52f --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbeaux.c | 3 +-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index faa3a9efb1..e76179efbf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\sdefenses\sagainst\svirtual\stable\sbeing\sdeleted\sout\sfrom\sunder\sa\srunning\nstatement. -D 2015-03-24T14:05:50.045 +C Simplify\sthe\sEXPLAIN\soutput\sof\svirtual\stable\sP4\sparameters\sto\sonly\sshow\sthe\npointer\sto\sthe\ssqlite3_vtab\sobject\sand\somit\sthe\ssqlite3_module\sobject. +D 2015-03-24T14:57:02.437 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -297,7 +297,7 @@ F src/vdbe.c bbfede5a8a6908b3ddcd55fdb0b2301288dd4754 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 -F src/vdbeaux.c 056eefd33ef4457240b6d3156a96201579face0a +F src/vdbeaux.c 413dc496248ac18eb0c19e35e86bb1ffd47b8907 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c c0dc81285b7571b0a31c40f17846fe2397ec1cd9 F src/vdbesort.c 919717d7599fa31d343ec28bffd0f9e91a4ff5f6 @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P fba674c083286dabb37fed9357b67593b56ed3a5 -R 6651e18da796c17c1ca503ba6b1b311c +P 116c99823022c017946b6088878a2d46759deb6e +R 5f471e8babb874f26a1b4c65b62f02f6 U drh -Z 91702967a80a94e761fcc487487cb422 +Z ffb5a79aea5fc49ed872d8dd5ea0b00b diff --git a/manifest.uuid b/manifest.uuid index 625bb648cf..445a1dff5e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -116c99823022c017946b6088878a2d46759deb6e \ No newline at end of file +85610bbbc60cb4a6ec856123447fdb2ba948e52f \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 25840ccde8..9c5d9acca9 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1118,8 +1118,7 @@ static char *displayP4(Op *pOp, char *zTemp, int nTemp){ #ifndef SQLITE_OMIT_VIRTUALTABLE case P4_VTAB: { sqlite3_vtab *pVtab = pOp->p4.pVtab->pVtab; - sqlite3_snprintf(nTemp, zTemp, "vtab:%p:%p", - pVtab, pVtab ? pVtab->pModule : (sqlite3_module*)0); + sqlite3_snprintf(nTemp, zTemp, "vtab:%p", pVtab); break; } #endif From 428630cfcf50de48828f9f878ea0a13fc305dc7f Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 24 Mar 2015 14:57:21 +0000 Subject: [PATCH 24/63] Add tests to check that attempting to DROP a virtual table while it is use does not cause problems. FossilOrigin-Name: 5ee625b1980f9fab6294d308349dfd9ba960b60b --- manifest | 14 ++++++------- manifest.uuid | 2 +- test/vtab1.test | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index faa3a9efb1..f7fe0c8224 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\sdefenses\sagainst\svirtual\stable\sbeing\sdeleted\sout\sfrom\sunder\sa\srunning\nstatement. -D 2015-03-24T14:05:50.045 +C Add\stests\sto\scheck\sthat\sattempting\sto\sDROP\sa\svirtual\stable\swhile\sit\sis\suse\sdoes\snot\scause\sproblems. +D 2015-03-24T14:57:21.959 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1111,7 +1111,7 @@ F test/vacuum4.test d3f8ecff345f166911568f397d2432c16d2867d9 F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 F test/view.test f311691d696a5cc27e3c1b875cec1b0866b4ccd9 -F test/vtab1.test 1cef14310144718812351a61c5cfb4ba8494a171 +F test/vtab1.test c9dc2a73e93331d70b37ce4b246ef6dc18412fef F test/vtab2.test 3644649aa8d1daac57fd541f6a5f914cac59203e F test/vtab3.test b45f47d20f225ccc9c28dc915d92740c2dee311e F test/vtab4.test 942f8b8280b3ea8a41dae20e7822d065ca1cb275 @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P fba674c083286dabb37fed9357b67593b56ed3a5 -R 6651e18da796c17c1ca503ba6b1b311c -U drh -Z 91702967a80a94e761fcc487487cb422 +P 116c99823022c017946b6088878a2d46759deb6e +R 791eb1db9d6d4dcf9879622b22bdbc4e +U dan +Z 5721bb8cdc400d9869a3df977b6ecfb6 diff --git a/manifest.uuid b/manifest.uuid index 625bb648cf..5b0b4a1607 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -116c99823022c017946b6088878a2d46759deb6e \ No newline at end of file +5ee625b1980f9fab6294d308349dfd9ba960b60b \ No newline at end of file diff --git a/test/vtab1.test b/test/vtab1.test index 2929b1e54d..dfc989a643 100644 --- a/test/vtab1.test +++ b/test/vtab1.test @@ -1437,4 +1437,58 @@ ifcapable fts3 { } {SQLITE_OK} } + +#------------------------------------------------------------------------- +# The following tests verify that a DROP TABLE command on a virtual +# table does not cause other operations to crash. +# +# 23.1: Dropping a vtab while a SELECT is running on it. +# +# 23.2: Dropping a vtab while a SELECT that will, but has not yet, +# open a cursor on the vtab, is running. In this case the +# DROP TABLE succeeds and the SELECT hits an error. +# +# 23.3: Dropping a vtab from within a user-defined-function callback +# in the middle of an "INSERT INTO vtab SELECT ..." statement. +# +reset_db +load_static_extension db wholenumber +load_static_extension db eval +register_echo_module db + +do_test 23.1 { + execsql { CREATE VIRTUAL TABLE t1 USING wholenumber } + set res "" + db eval { SELECT value FROM t1 WHERE value<10 } { + if {$value == 5} { + set res [catchsql { DROP TABLE t1 }] + } + } + set res +} {1 {database table is locked}} + +do_test 23.2 { + execsql { + CREATE TABLE t2(value); + INSERT INTO t2 VALUES(1), (2), (3); + } + + set res2 [list [catch { + db eval { + SELECT value FROM t2 UNION ALL + SELECT value FROM t1 WHERE value<10 + } { + if {$value == 2} { set res1 [catchsql { DROP TABLE t1 }] } + } + } msg] $msg] + list $res1 $res2 +} {{0 {}} {1 {database table is locked}}} + +do_test 23.3.1 { + execsql { CREATE VIRTUAL TABLE t1e USING echo(t2) } + execsql { INSERT INTO t1e SELECT 4 } + catchsql { INSERT INTO t1e SELECT eval('DROP TABLE t1e') } +} {1 {database table is locked}} +do_execsql_test 23.3.2 { SELECT * FROM t1e } {1 2 3 4} + finish_test From 475640484729bbaf2510dc8798880ce51e901228 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Mar 2015 18:19:39 +0000 Subject: [PATCH 25/63] Suppress a compiler warning that was appearing with SQLITE_THREADSAFE=0. FossilOrigin-Name: 436314b5728c9413f9ac2d837e1c19364f31be72 --- manifest | 14 ++++++-------- manifest.uuid | 2 +- src/status.c | 1 + 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index d1020a6d13..2022595ba2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Prevent\sa\svirtual\stable\sfrom\sbeing\sdestroyed\swhile\sit\sis\sin\suse.\nAlso:\sreplace\sVdbe.inVtabMethod\swith\ssqlite3.nVDestroy.\s\sSimplify\sthe\nEXPLAIN\soutput\sfor\sP4.pVtab\sto\sonly\sshow\sthe\ssqlite3_vtab\spointer. -D 2015-03-24T16:43:34.928 +C Suppress\sa\scompiler\swarning\sthat\swas\sappearing\swith\sSQLITE_THREADSAFE=0. +D 2015-03-24T18:19:39.691 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -237,7 +237,7 @@ F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h bedf15914c09bfb5fe3ec4e3f211a4a6fc42cd33 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 -F src/status.c 2e5c86866ff2f30988ce10ddbaa7ba2eaf6d4146 +F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 F src/table.c e7a09215315a978057fb42c640f890160dbcc45e F src/tclsqlite.c fa72a7c5278662357c105ba7925c1d0972506ff9 F src/test1.c 90fbedce75330d48d99eadb7d5f4223e86969585 @@ -1246,9 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0ee2d38deb35aefc55395e86984a9a773caf6218 85610bbbc60cb4a6ec856123447fdb2ba948e52f 5ee625b1980f9fab6294d308349dfd9ba960b60b -R 5e10f0a3ec239c969328e02883201fd9 -T +closed 5ee625b1980f9fab6294d308349dfd9ba960b60b -T +closed 85610bbbc60cb4a6ec856123447fdb2ba948e52f +P cbeb9a1aed8ce3fb569a7717ad03c7c058b68de6 +R 1df40f85f677c47017b13b63b82a97b5 U drh -Z 4c6da71fa5b7897deec943a0cbeb333e +Z 408df2ac27dc537c38335d50565b918f diff --git a/manifest.uuid b/manifest.uuid index 83e3226971..b639b7d8cc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cbeb9a1aed8ce3fb569a7717ad03c7c058b68de6 \ No newline at end of file +436314b5728c9413f9ac2d837e1c19364f31be72 \ No newline at end of file diff --git a/src/status.c b/src/status.c index aa27f70efc..ac32753a22 100644 --- a/src/status.c +++ b/src/status.c @@ -148,6 +148,7 @@ int sqlite3_status64( wsdStat.mxValue[op] = wsdStat.nowValue[op]; } sqlite3_mutex_leave(pMutex); + (void)pMutex; /* Prevent warning when SQLITE_THREADSAFE=0 */ return SQLITE_OK; } int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){ From 59b9b02c1fa889a4f4e83f2a5597bf62baca4ccb Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 24 Mar 2015 21:27:27 +0000 Subject: [PATCH 26/63] Add SQLITE_STDCALL and SQLITE_CDECL macros on public function definitions. FossilOrigin-Name: 242f09d4d1c92ee9058857a5e780442f4b7bad55 --- Makefile.msc | 8 ++--- manifest | 23 ++++++++------ manifest.uuid | 2 +- src/sqlite.h.in | 7 ----- tool/mksqlite3c.tcl | 74 ++++++++++++++++++++++++++++++++++----------- tool/mksqlite3h.tcl | 41 ++++++++++++++++++++++--- 6 files changed, 112 insertions(+), 43 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 249e3c284d..837fc003c0 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -312,12 +312,12 @@ RCC = $(RC) -DSQLITE_OS_WIN=1 -I$(TOP) -I$(TOP)\src # !IF $(USE_STDCALL)!=0 !IF "$(PLATFORM)"=="x86" -CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl +CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall +SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall !ELSE !IFNDEF PLATFORM -CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl +CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall +SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall !ELSE CORE_CCONV_OPTS = SHELL_CCONV_OPTS = diff --git a/manifest b/manifest index 2022595ba2..8a9bcb9667 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Suppress\sa\scompiler\swarning\sthat\swas\sappearing\swith\sSQLITE_THREADSAFE=0. -D 2015-03-24T18:19:39.691 +C Add\sSQLITE_STDCALL\sand\sSQLITE_CDECL\smacros\son\spublic\sfunction\sdefinitions. +D 2015-03-24T21:27:27.369 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc cd626b52ebeec0e2c0dd929243bdd25b0df19a71 +F Makefile.msc 3481e2dd260968742c715542db178c2bdd5db99f F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION 319eb1ced4b4d17a67730f2b7b85f15c1346cb60 @@ -232,7 +232,7 @@ F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 F src/shell.c 3ae1e53878d2804fe77b8c8f1f6ca287a0e5d80e -F src/sqlite.h.in 2f9606a682af372415ce9d1f244183c5cc8385aa +F src/sqlite.h.in 82977ae32ba5f5a115d4434418087c9c1088f643 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h bedf15914c09bfb5fe3ec4e3f211a4a6fc42cd33 @@ -1213,8 +1213,8 @@ F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e F tool/mkpragmatab.tcl 94f196c9961e0ca3513e29f57125a3197808be2d F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 F tool/mksqlite3c-noext.tcl 9ef48e1748dce7b844f67e2450ff9dfeb0fb4ab5 -F tool/mksqlite3c.tcl 95ab31eda659e7ffb091e04bd83178f260d8edfd -F tool/mksqlite3h.tcl ba24038056f51fde07c0079c41885ab85e2cff12 +F tool/mksqlite3c.tcl ab2cfb2191f1edaea0e72b6ad3bc3f71aa61a6b9 +F tool/mksqlite3h.tcl c02e391f595bf91528341ffaa53e5084d8b595ce F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b F tool/mkvsix.tcl 52a4c613707ac34ae9c226e5ccc69cb948556105 F tool/offsets.c fe4262fdfa378e8f5499a42136d17bf3b98f6091 @@ -1246,7 +1246,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P cbeb9a1aed8ce3fb569a7717ad03c7c058b68de6 -R 1df40f85f677c47017b13b63b82a97b5 -U drh -Z 408df2ac27dc537c38335d50565b918f +P 436314b5728c9413f9ac2d837e1c19364f31be72 +R 887ef727abd3a9965cbccad906bf79e4 +T *branch * stdcall +T *sym-stdcall * +T -sym-trunk * +U mistachkin +Z cb11de2c68ebf434af7cc941e8219588 diff --git a/manifest.uuid b/manifest.uuid index b639b7d8cc..d35f197244 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -436314b5728c9413f9ac2d837e1c19364f31be72 \ No newline at end of file +242f09d4d1c92ee9058857a5e780442f4b7bad55 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 8e2727f6ae..6d2cc146dc 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -49,13 +49,6 @@ extern "C" { # define SQLITE_EXTERN extern #endif -/* -** Add the ability to override 'cdecl' -*/ -#ifndef SQLITE_CDECL -# define SQLITE_CDECL -#endif - /* ** These no-op macros are used in front of interfaces to mark those ** interfaces as either deprecated or experimental. New applications diff --git a/tool/mksqlite3c.tcl b/tool/mksqlite3c.tcl index fd823385b3..b33eef8f1a 100644 --- a/tool/mksqlite3c.tcl +++ b/tool/mksqlite3c.tcl @@ -83,6 +83,12 @@ if {$addstatic} { #endif #ifndef SQLITE_API # define SQLITE_API +#endif +#ifndef SQLITE_CDECL +# define SQLITE_CDECL +#endif +#ifndef SQLITE_STDCALL +# define SQLITE_STDCALL #endif} } @@ -127,6 +133,23 @@ foreach hdr { } set available_hdr(sqliteInt.h) 0 +# These headers should be copied into the amalgamation without modifying any +# of their function declarations or definitions. +set varonly_hdr(sqlite3.h) 1 + +# These are the functions that accept a variable number of arguments. They +# always need to use the "cdecl" calling convention even when another calling +# convention (e.g. "stcall") is being used for the rest of the library. +set cdecllist { + sqlite3_config + sqlite3_db_config + sqlite3_log + sqlite3_mprintf + sqlite3_snprintf + sqlite3_test_control + sqlite3_vtab_config +} + # 78 stars used for comment formatting. set s78 \ {*****************************************************************************} @@ -146,18 +169,18 @@ proc section_comment {text} { # process them appropriately. # proc copy_file {filename} { - global seen_hdr available_hdr out addstatic linemacros + global seen_hdr available_hdr varonly_hdr cdecllist out addstatic linemacros set ln 0 set tail [file tail $filename] section_comment "Begin file $tail" if {$linemacros} {puts $out "#line 1 \"$filename\""} set in [open $filename r] set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)} - set declpattern {[a-zA-Z][a-zA-Z_0-9 ]+ \**(sqlite3[_a-zA-Z0-9]+)\(} + set declpattern {([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3[_a-zA-Z0-9]+)(\(.*)} if {[file extension $filename]==".h"} { set declpattern " *$declpattern" } - set declpattern ^$declpattern + set declpattern ^$declpattern\$ while {![eof $in]} { set line [gets $in] incr ln @@ -191,32 +214,49 @@ proc copy_file {filename} { } elseif {!$linemacros && [regexp {^#line} $line]} { # Skip #line directives. } elseif {$addstatic && ![regexp {^(static|typedef)} $line]} { - regsub {^SQLITE_API } $line {} line - if {[regexp $declpattern $line all funcname]} { + # Skip adding the SQLITE_PRIVATE or SQLITE_API keyword before + # functions if this header file does not need it. + if {![info exists varonly_hdr($tail)] + && [regexp $declpattern $line all rettype funcname rest]} { + regsub {^SQLITE_API } $line {} line # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions. # so that linkage can be modified at compile-time. if {[regexp {^sqlite3_} $funcname]} { - puts $out "SQLITE_API $line" + set line SQLITE_API + append line " " [string trim $rettype] + if {[string index $rettype end] ne "*"} { + append line " " + } + if {[lsearch -exact $cdecllist $funcname] >= 0} { + append line SQLITE_CDECL + } else { + append line SQLITE_STDCALL + } + append line " " $funcname $rest + puts $out $line } else { puts $out "SQLITE_PRIVATE $line" } } elseif {[regexp $varpattern $line all varname]} { - # Add the SQLITE_PRIVATE before variable declarations or - # definitions for internal use - if {![regexp {^sqlite3_} $varname]} { - regsub {^extern } $line {} line - puts $out "SQLITE_PRIVATE $line" - } else { - if {[regexp {const char sqlite3_version\[\];} $line]} { - set line {const char sqlite3_version[] = SQLITE_VERSION;} + # Add the SQLITE_PRIVATE before variable declarations or + # definitions for internal use + regsub {^SQLITE_API } $line {} line + if {![regexp {^sqlite3_} $varname]} { + regsub {^extern } $line {} line + puts $out "SQLITE_PRIVATE $line" + } else { + if {[regexp {const char sqlite3_version\[\];} $line]} { + set line {const char sqlite3_version[] = SQLITE_VERSION;} + } + regsub {^SQLITE_EXTERN } $line {} line + puts $out "SQLITE_API $line" } - regsub {^SQLITE_EXTERN } $line {} line - puts $out "SQLITE_API $line" - } } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} { + regsub {^SQLITE_API } $line {} line regsub {^SQLITE_EXTERN } $line {} line puts $out $line } elseif {[regexp {^void \(\*sqlite3Os} $line]} { + regsub {^SQLITE_API } $line {} line puts $out "SQLITE_PRIVATE $line" } else { puts $out $line diff --git a/tool/mksqlite3h.tcl b/tool/mksqlite3h.tcl index a89b9f9beb..9ed74c3f4b 100644 --- a/tool/mksqlite3h.tcl +++ b/tool/mksqlite3h.tcl @@ -63,7 +63,7 @@ close $in # Set up patterns for recognizing API declarations. # set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+sqlite3_[_a-zA-Z0-9]+(\[|;| =)} -set declpattern {^ *[a-zA-Z][a-zA-Z_0-9 ]+ \**sqlite3_[_a-zA-Z0-9]+\(} +set declpattern {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3_[_a-zA-Z0-9]+)(\(.*)$} # Force the output to use unix line endings, even on Windows. fconfigure stdout -translation lf @@ -73,6 +73,19 @@ set filelist [subst { $TOP/ext/rtree/sqlite3rtree.h }] +# These are the functions that accept a variable number of arguments. They +# always need to use the "cdecl" calling convention even when another calling +# convention (e.g. "stcall") is being used for the rest of the library. +set cdecllist { + sqlite3_config + sqlite3_db_config + sqlite3_log + sqlite3_mprintf + sqlite3_snprintf + sqlite3_test_control + sqlite3_vtab_config +} + # Process the source files. # foreach file $filelist { @@ -97,13 +110,33 @@ foreach file $filelist { puts "#ifndef SQLITE_API" puts "# define SQLITE_API" puts "#endif" + puts "" + puts "#ifndef SQLITE_CDECL" + puts "# define SQLITE_CDECL" + puts "#endif" + puts "" + puts "#ifndef SQLITE_STDCALL" + puts "# define SQLITE_STDCALL" + puts "#endif" set line "" } - if {([regexp $varpattern $line] && ![regexp {^ *typedef} $line]) - || ([regexp $declpattern $line]) - } { + if {[regexp $varpattern $line] && ![regexp {^ *typedef} $line]} { set line "SQLITE_API $line" + } else { + if {[regexp $declpattern $line all rettype funcname rest]} { + set line SQLITE_API + append line " " [string trim $rettype] + if {[string index $rettype end] ne "*"} { + append line " " + } + if {[lsearch -exact $cdecllist $funcname] >= 0} { + append line SQLITE_CDECL + } else { + append line SQLITE_STDCALL + } + append line " " $funcname $rest + } } puts $line } From 26bbfaa59d58b1da578e83cf79c310a8695f0c45 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 24 Mar 2015 21:34:53 +0000 Subject: [PATCH 27/63] Fix a couple comment typos in a tool script. No changes to code. FossilOrigin-Name: 83421af67063825981f6051eb415944d90e9b2f6 --- manifest | 14 +++++++------- manifest.uuid | 2 +- tool/mksqlite3c-noext.tcl | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 2022595ba2..3ba7e5627e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Suppress\sa\scompiler\swarning\sthat\swas\sappearing\swith\sSQLITE_THREADSAFE=0. -D 2015-03-24T18:19:39.691 +C Fix\sa\scouple\scomment\stypos\sin\sa\stool\sscript.\s\sNo\schanges\sto\scode. +D 2015-03-24T21:34:53.280 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1212,7 +1212,7 @@ F tool/mkkeywordhash.c dfff09dbbfaf950e89af294f48f902181b144670 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e F tool/mkpragmatab.tcl 94f196c9961e0ca3513e29f57125a3197808be2d F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 -F tool/mksqlite3c-noext.tcl 9ef48e1748dce7b844f67e2450ff9dfeb0fb4ab5 +F tool/mksqlite3c-noext.tcl f8a6223bebc9e3e9dc2700484c602f159b84c8aa F tool/mksqlite3c.tcl 95ab31eda659e7ffb091e04bd83178f260d8edfd F tool/mksqlite3h.tcl ba24038056f51fde07c0079c41885ab85e2cff12 F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P cbeb9a1aed8ce3fb569a7717ad03c7c058b68de6 -R 1df40f85f677c47017b13b63b82a97b5 -U drh -Z 408df2ac27dc537c38335d50565b918f +P 436314b5728c9413f9ac2d837e1c19364f31be72 +R 8395df004ed39c3d4f3903ab69f7e9ed +U mistachkin +Z b92e1717d71c68278e3b78541d6aeae8 diff --git a/manifest.uuid b/manifest.uuid index b639b7d8cc..4601dfd81c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -436314b5728c9413f9ac2d837e1c19364f31be72 \ No newline at end of file +83421af67063825981f6051eb415944d90e9b2f6 \ No newline at end of file diff --git a/tool/mksqlite3c-noext.tcl b/tool/mksqlite3c-noext.tcl index 27522265bb..6a2fc2feeb 100644 --- a/tool/mksqlite3c-noext.tcl +++ b/tool/mksqlite3c-noext.tcl @@ -17,13 +17,13 @@ # After the "tsrc" directory has been created and populated, run # this script: # -# tclsh mksqlite3c.tcl +# tclsh mksqlite3c-noext.tcl # # The amalgamated SQLite code will be written into sqlite3.c # # Begin by reading the "sqlite3.h" header file. Extract the version number -# from in this file. The versioon number is needed to generate the header +# from in this file. The version number is needed to generate the header # comment of the amalgamation. # if {[lsearch $argv --nostatic]>=0} { From 8de1250638a76287cd94cbe8e4f312fbe77f9dd1 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 24 Mar 2015 21:52:12 +0000 Subject: [PATCH 28/63] Update the 'mksqlite3c-noext' tool as well. FossilOrigin-Name: a532256688c3a7a6385e041ec73913842e2c3ab3 --- manifest | 15 +++---- manifest.uuid | 2 +- tool/mksqlite3c-noext.tcl | 93 ++++++++++++++++++++++++++++++--------- 3 files changed, 79 insertions(+), 31 deletions(-) diff --git a/manifest b/manifest index 8a9bcb9667..8d1f543c39 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sSQLITE_STDCALL\sand\sSQLITE_CDECL\smacros\son\spublic\sfunction\sdefinitions. -D 2015-03-24T21:27:27.369 +C Update\sthe\s'mksqlite3c-noext'\stool\sas\swell. +D 2015-03-24T21:52:12.248 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1212,7 +1212,7 @@ F tool/mkkeywordhash.c dfff09dbbfaf950e89af294f48f902181b144670 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e F tool/mkpragmatab.tcl 94f196c9961e0ca3513e29f57125a3197808be2d F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 -F tool/mksqlite3c-noext.tcl 9ef48e1748dce7b844f67e2450ff9dfeb0fb4ab5 +F tool/mksqlite3c-noext.tcl 46dad185f91829a25b10291b244d2440ad4a88f4 F tool/mksqlite3c.tcl ab2cfb2191f1edaea0e72b6ad3bc3f71aa61a6b9 F tool/mksqlite3h.tcl c02e391f595bf91528341ffaa53e5084d8b595ce F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b @@ -1246,10 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 436314b5728c9413f9ac2d837e1c19364f31be72 -R 887ef727abd3a9965cbccad906bf79e4 -T *branch * stdcall -T *sym-stdcall * -T -sym-trunk * +P 242f09d4d1c92ee9058857a5e780442f4b7bad55 +R 4e80129117aa4b372475de5cd1490c7f U mistachkin -Z cb11de2c68ebf434af7cc941e8219588 +Z 6bcda5d8184063ac5fc3f1cb05a00dcd diff --git a/manifest.uuid b/manifest.uuid index d35f197244..52602f40c4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -242f09d4d1c92ee9058857a5e780442f4b7bad55 \ No newline at end of file +a532256688c3a7a6385e041ec73913842e2c3ab3 \ No newline at end of file diff --git a/tool/mksqlite3c-noext.tcl b/tool/mksqlite3c-noext.tcl index 27522265bb..35c14093e9 100644 --- a/tool/mksqlite3c-noext.tcl +++ b/tool/mksqlite3c-noext.tcl @@ -83,6 +83,12 @@ if {$addstatic} { #endif #ifndef SQLITE_API # define SQLITE_API +#endif +#ifndef SQLITE_CDECL +# define SQLITE_CDECL +#endif +#ifndef SQLITE_STDCALL +# define SQLITE_STDCALL #endif} } @@ -106,6 +112,7 @@ foreach hdr { pager.h parse.h pcache.h + pragma.h sqlite3ext.h sqlite3.h sqliteicu.h @@ -113,12 +120,31 @@ foreach hdr { sqliteLimit.h vdbe.h vdbeInt.h + vxworks.h wal.h + whereInt.h } { set available_hdr($hdr) 1 } set available_hdr(sqliteInt.h) 0 +# These headers should be copied into the amalgamation without modifying any +# of their function declarations or definitions. +set varonly_hdr(sqlite3.h) 1 + +# These are the functions that accept a variable number of arguments. They +# always need to use the "cdecl" calling convention even when another calling +# convention (e.g. "stcall") is being used for the rest of the library. +set cdecllist { + sqlite3_config + sqlite3_db_config + sqlite3_log + sqlite3_mprintf + sqlite3_snprintf + sqlite3_test_control + sqlite3_vtab_config +} + # 78 stars used for comment formatting. set s78 \ {*****************************************************************************} @@ -135,21 +161,21 @@ proc section_comment {text} { # Read the source file named $filename and write it into the # sqlite3.c output file. If any #include statements are seen, -# process them approprately. +# process them appropriately. # proc copy_file {filename} { - global seen_hdr available_hdr out addstatic linemacros + global seen_hdr available_hdr varonly_hdr cdecllist out addstatic linemacros set ln 0 set tail [file tail $filename] section_comment "Begin file $tail" if {$linemacros} {puts $out "#line 1 \"$filename\""} set in [open $filename r] set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)} - set declpattern {[a-zA-Z][a-zA-Z_0-9 ]+ \**(sqlite3[_a-zA-Z0-9]+)\(} + set declpattern {([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3[_a-zA-Z0-9]+)(\(.*)} if {[file extension $filename]==".h"} { set declpattern " *$declpattern" } - set declpattern ^$declpattern + set declpattern ^$declpattern\$ while {![eof $in]} { set line [gets $in] incr ln @@ -165,42 +191,67 @@ proc copy_file {filename} { if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""} } } elseif {![info exists seen_hdr($hdr)]} { - set seen_hdr($hdr) 1 + if {![regexp {/\*\s+amalgamator:\s+dontcache\s+\*/} $line]} { + set seen_hdr($hdr) 1 + } + puts $out $line + } elseif {[regexp {/\*\s+amalgamator:\s+keep\s+\*/} $line]} { + # This include file must be kept because there was a "keep" + # directive inside of a line comment. puts $out $line } else { - puts $out "/* $line */" + # Comment out the entire line, replacing any nested comment + # begin/end markers with the harmless substring "**". + puts $out "/* [string map [list /* ** */ **] $line] */" } } elseif {[regexp {^#ifdef __cplusplus} $line]} { puts $out "#if 0" } elseif {!$linemacros && [regexp {^#line} $line]} { # Skip #line directives. } elseif {$addstatic && ![regexp {^(static|typedef)} $line]} { - regsub {^SQLITE_API } $line {} line - if {[regexp $declpattern $line all funcname]} { + # Skip adding the SQLITE_PRIVATE or SQLITE_API keyword before + # functions if this header file does not need it. + if {![info exists varonly_hdr($tail)] + && [regexp $declpattern $line all rettype funcname rest]} { + regsub {^SQLITE_API } $line {} line # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions. # so that linkage can be modified at compile-time. if {[regexp {^sqlite3_} $funcname]} { - puts $out "SQLITE_API $line" + set line SQLITE_API + append line " " [string trim $rettype] + if {[string index $rettype end] ne "*"} { + append line " " + } + if {[lsearch -exact $cdecllist $funcname] >= 0} { + append line SQLITE_CDECL + } else { + append line SQLITE_STDCALL + } + append line " " $funcname $rest + puts $out $line } else { puts $out "SQLITE_PRIVATE $line" } } elseif {[regexp $varpattern $line all varname]} { - # Add the SQLITE_PRIVATE before variable declarations or - # definitions for internal use - if {![regexp {^sqlite3_} $varname]} { - regsub {^extern } $line {} line - puts $out "SQLITE_PRIVATE $line" - } else { - if {[regexp {const char sqlite3_version\[\];} $line]} { - set line {const char sqlite3_version[] = SQLITE_VERSION;} + # Add the SQLITE_PRIVATE before variable declarations or + # definitions for internal use + regsub {^SQLITE_API } $line {} line + if {![regexp {^sqlite3_} $varname]} { + regsub {^extern } $line {} line + puts $out "SQLITE_PRIVATE $line" + } else { + if {[regexp {const char sqlite3_version\[\];} $line]} { + set line {const char sqlite3_version[] = SQLITE_VERSION;} + } + regsub {^SQLITE_EXTERN } $line {} line + puts $out "SQLITE_API $line" } - regsub {^SQLITE_EXTERN } $line {} line - puts $out "SQLITE_API $line" - } } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} { + regsub {^SQLITE_API } $line {} line regsub {^SQLITE_EXTERN } $line {} line - puts $out "SQLITE_PRIVATE $line" + puts $out $line } elseif {[regexp {^void \(\*sqlite3Os} $line]} { + regsub {^SQLITE_API } $line {} line puts $out "SQLITE_PRIVATE $line" } else { puts $out $line From 790fa6ec30a31b3bcb3f4a15c2b98eea6c8063d4 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Mar 2015 21:54:42 +0000 Subject: [PATCH 29/63] Further simplifications to the amalgamation builder. FossilOrigin-Name: e826cd7db6b3ab010533d81a759794c2470343d2 --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/sqlite.h.in | 11 ++++++++++- tool/mksqlite3c-noext.tcl | 9 --------- tool/mksqlite3c.tcl | 9 --------- tool/mksqlite3h.tcl | 20 +------------------- 6 files changed, 22 insertions(+), 49 deletions(-) diff --git a/manifest b/manifest index 8d1f543c39..6b34425f06 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sthe\s'mksqlite3c-noext'\stool\sas\swell. -D 2015-03-24T21:52:12.248 +C Further\ssimplifications\sto\sthe\samalgamation\sbuilder. +D 2015-03-24T21:54:42.913 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -232,7 +232,7 @@ F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 F src/shell.c 3ae1e53878d2804fe77b8c8f1f6ca287a0e5d80e -F src/sqlite.h.in 82977ae32ba5f5a115d4434418087c9c1088f643 +F src/sqlite.h.in 278602140d49575e8708e643161f4263e428a02a F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqliteInt.h bedf15914c09bfb5fe3ec4e3f211a4a6fc42cd33 @@ -1212,9 +1212,9 @@ F tool/mkkeywordhash.c dfff09dbbfaf950e89af294f48f902181b144670 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e F tool/mkpragmatab.tcl 94f196c9961e0ca3513e29f57125a3197808be2d F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 -F tool/mksqlite3c-noext.tcl 46dad185f91829a25b10291b244d2440ad4a88f4 -F tool/mksqlite3c.tcl ab2cfb2191f1edaea0e72b6ad3bc3f71aa61a6b9 -F tool/mksqlite3h.tcl c02e391f595bf91528341ffaa53e5084d8b595ce +F tool/mksqlite3c-noext.tcl 274d4243bd7c8b5b280a02ec50280d73f80a9d89 +F tool/mksqlite3c.tcl 52a3352f7aa15f1db851e45ac3a5e2173d6fe93c +F tool/mksqlite3h.tcl 44730d586c9031638cdd2eb443b801c0d2dbd9f8 F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b F tool/mkvsix.tcl 52a4c613707ac34ae9c226e5ccc69cb948556105 F tool/offsets.c fe4262fdfa378e8f5499a42136d17bf3b98f6091 @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 242f09d4d1c92ee9058857a5e780442f4b7bad55 -R 4e80129117aa4b372475de5cd1490c7f -U mistachkin -Z 6bcda5d8184063ac5fc3f1cb05a00dcd +P a532256688c3a7a6385e041ec73913842e2c3ab3 +R 82569f0fcef6344e8c55e30ea4294bbd +U drh +Z 70d7caefbc05dc10c257a925b1d49a53 diff --git a/manifest.uuid b/manifest.uuid index 52602f40c4..ae9df8a883 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a532256688c3a7a6385e041ec73913842e2c3ab3 \ No newline at end of file +e826cd7db6b3ab010533d81a759794c2470343d2 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 6d2cc146dc..acc3c51404 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -43,11 +43,20 @@ extern "C" { /* -** Add the ability to override 'extern' +** Provide the ability to override linkage features of the interface. */ #ifndef SQLITE_EXTERN # define SQLITE_EXTERN extern #endif +#ifndef SQLITE_API +# define SQLITE_API +#endif +#ifndef SQLITE_CDECL +# define SQLITE_CDECL +#endif +#ifndef SQLITE_STDCALL +# define SQLITE_STDCALL +#endif /* ** These no-op macros are used in front of interfaces to mark those diff --git a/tool/mksqlite3c-noext.tcl b/tool/mksqlite3c-noext.tcl index 35c14093e9..24462fc29e 100644 --- a/tool/mksqlite3c-noext.tcl +++ b/tool/mksqlite3c-noext.tcl @@ -80,15 +80,6 @@ if {$addstatic} { puts $out \ {#ifndef SQLITE_PRIVATE # define SQLITE_PRIVATE static -#endif -#ifndef SQLITE_API -# define SQLITE_API -#endif -#ifndef SQLITE_CDECL -# define SQLITE_CDECL -#endif -#ifndef SQLITE_STDCALL -# define SQLITE_STDCALL #endif} } diff --git a/tool/mksqlite3c.tcl b/tool/mksqlite3c.tcl index b33eef8f1a..136155089c 100644 --- a/tool/mksqlite3c.tcl +++ b/tool/mksqlite3c.tcl @@ -80,15 +80,6 @@ if {$addstatic} { puts $out \ {#ifndef SQLITE_PRIVATE # define SQLITE_PRIVATE static -#endif -#ifndef SQLITE_API -# define SQLITE_API -#endif -#ifndef SQLITE_CDECL -# define SQLITE_CDECL -#endif -#ifndef SQLITE_STDCALL -# define SQLITE_STDCALL #endif} } diff --git a/tool/mksqlite3h.tcl b/tool/mksqlite3h.tcl index 9ed74c3f4b..cabce1f50b 100644 --- a/tool/mksqlite3h.tcl +++ b/tool/mksqlite3h.tcl @@ -102,25 +102,7 @@ foreach file $filelist { regsub -- --VERS-- $line $zVersion line regsub -- --VERSION-NUMBER-- $line $nVersion line regsub -- --SOURCE-ID-- $line "$zDate $zUuid" line - - if {[regexp {define SQLITE_EXTERN extern} $line]} { - puts $line - puts [gets $in] - puts "" - puts "#ifndef SQLITE_API" - puts "# define SQLITE_API" - puts "#endif" - puts "" - puts "#ifndef SQLITE_CDECL" - puts "# define SQLITE_CDECL" - puts "#endif" - puts "" - puts "#ifndef SQLITE_STDCALL" - puts "# define SQLITE_STDCALL" - puts "#endif" - set line "" - } - + if {[regexp $varpattern $line] && ![regexp {^ *typedef} $line]} { set line "SQLITE_API $line" } else { From f94c9485ef21dd1bd48c869374846e66231ba576 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 25 Mar 2015 12:05:49 +0000 Subject: [PATCH 30/63] Add two new assert()s to the sqlite3BtreeDataSize() method. FossilOrigin-Name: 42d1793d6516e285a8925bbfd96b3d3375603d15 --- manifest | 15 +++++++-------- manifest.uuid | 2 +- src/btree.c | 2 ++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 384fa980e4..e78289f594 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sSQLITE_STDCALL\sand\sSQLITE_CDECL\smacros\son\spublic\sfunction\sdefinitions. -D 2015-03-24T22:00:26.504 +C Add\stwo\snew\sassert()s\sto\sthe\ssqlite3BtreeDataSize()\smethod. +D 2015-03-25T12:05:49.756 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 3e320cac836546c905bd90007074d887980aa70e +F src/btree.c 8d92800add6e237c883b286845d8159911acdf54 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a @@ -1246,8 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 83421af67063825981f6051eb415944d90e9b2f6 e826cd7db6b3ab010533d81a759794c2470343d2 -R 00893342a7c77a3a3db8feef49e96714 -T +closed e826cd7db6b3ab010533d81a759794c2470343d2 -U mistachkin -Z 1978375717c0fca1b1a377840034ad4e +P cae3239aa58b4f7016fc9dcac3966fe6ef833879 +R 9d1846f3cd769389c238477907eb38ab +U drh +Z 681e7b9df0d47c3c796413431bb9a3b2 diff --git a/manifest.uuid b/manifest.uuid index 53bd3257f9..484d3c2181 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cae3239aa58b4f7016fc9dcac3966fe6ef833879 \ No newline at end of file +42d1793d6516e285a8925bbfd96b3d3375603d15 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index ac0c877317..1e0e57fe2e 100644 --- a/src/btree.c +++ b/src/btree.c @@ -4031,6 +4031,8 @@ int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){ int sqlite3BtreeDataSize(BtCursor *pCur, u32 *pSize){ assert( cursorHoldsMutex(pCur) ); assert( pCur->eState==CURSOR_VALID ); + assert( pCur->iPage>=0 ); + assert( pCur->iPageapPage[pCur->iPage]->intKeyLeaf==1 ); getCellInfo(pCur); *pSize = pCur->info.nPayload; From cbd3349ab956b3d0eb028ba2344caa3e772daaf2 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 25 Mar 2015 13:06:54 +0000 Subject: [PATCH 31/63] Reactivate an older assert() (adding an "|| CORRUPT_DB" term) and add a new assert() in btree.c. FossilOrigin-Name: 1e96520ac1d12ca83f019a60482efa0a074f2f94 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 13 ++++--------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index e78289f594..a0f706c635 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stwo\snew\sassert()s\sto\sthe\ssqlite3BtreeDataSize()\smethod. -D 2015-03-25T12:05:49.756 +C Reactivate\san\solder\sassert()\s(adding\san\s"||\sCORRUPT_DB"\sterm)\sand\sadd\sa\nnew\sassert()\sin\sbtree.c. +D 2015-03-25T13:06:54.837 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 8d92800add6e237c883b286845d8159911acdf54 +F src/btree.c 3634c2ee748bbbb2488cdca9dc8fc8c7bdc2f66f F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a @@ -1246,7 +1246,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P cae3239aa58b4f7016fc9dcac3966fe6ef833879 -R 9d1846f3cd769389c238477907eb38ab +P 42d1793d6516e285a8925bbfd96b3d3375603d15 +R 90535e28cf02760b75aa0324ce2f944c U drh -Z 681e7b9df0d47c3c796413431bb9a3b2 +Z 7ee968129b9c07925188972da6333faa diff --git a/manifest.uuid b/manifest.uuid index 484d3c2181..d4bfb47acf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -42d1793d6516e285a8925bbfd96b3d3375603d15 \ No newline at end of file +1e96520ac1d12ca83f019a60482efa0a074f2f94 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 1e0e57fe2e..ac350ac92f 100644 --- a/src/btree.c +++ b/src/btree.c @@ -4511,7 +4511,7 @@ static int moveToChild(BtCursor *pCur, u32 newPgno){ return SQLITE_OK; } -#if 0 +#if SQLITE_DEBUG /* ** Page pParent is an internal (non-leaf) tree page. This function ** asserts that page number iChild is the left-child if the iIdx'th @@ -4520,6 +4520,8 @@ static int moveToChild(BtCursor *pCur, u32 newPgno){ ** the page. */ static void assertParentIndex(MemPage *pParent, int iIdx, Pgno iChild){ + if( CORRUPT_DB ) return; /* The conditions tested below might not be true + ** in a corrupt database */ assert( iIdx<=pParent->nCell ); if( iIdx==pParent->nCell ){ assert( get4byte(&pParent->aData[pParent->hdrOffset+8])==iChild ); @@ -4544,19 +4546,11 @@ static void moveToParent(BtCursor *pCur){ assert( pCur->eState==CURSOR_VALID ); assert( pCur->iPage>0 ); assert( pCur->apPage[pCur->iPage] ); - - /* UPDATE: It is actually possible for the condition tested by the assert - ** below to be untrue if the database file is corrupt. This can occur if - ** one cursor has modified page pParent while a reference to it is held - ** by a second cursor. Which can only happen if a single page is linked - ** into more than one b-tree structure in a corrupt database. */ -#if 0 assertParentIndex( pCur->apPage[pCur->iPage-1], pCur->aiIdx[pCur->iPage-1], pCur->apPage[pCur->iPage]->pgno ); -#endif testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell ); releasePage(pCur->apPage[pCur->iPage]); @@ -7504,6 +7498,7 @@ static int balance(BtCursor *pCur){ /* The next iteration of the do-loop balances the parent page. */ releasePage(pPage); pCur->iPage--; + assert( pCur->iPage>=0 ); } }while( rc==SQLITE_OK ); From d2f83139f3774c61f545095c813a28a859320b39 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 25 Mar 2015 17:35:01 +0000 Subject: [PATCH 32/63] Fix the saveCursorPosition() routine in btree.c so that it works correctly for a eState=CURSOR_SKIPNEXT cursor. FossilOrigin-Name: 37866b4d483296ab9b7fcb9f5486695d4c2b8ddd --- manifest | 13 ++++++------ manifest.uuid | 2 +- src/btree.c | 17 +++++++++++----- test/btree02.test | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 test/btree02.test diff --git a/manifest b/manifest index a0f706c635..48427f05a3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Reactivate\san\solder\sassert()\s(adding\san\s"||\sCORRUPT_DB"\sterm)\sand\sadd\sa\nnew\sassert()\sin\sbtree.c. -D 2015-03-25T13:06:54.837 +C Fix\sthe\ssaveCursorPosition()\sroutine\sin\sbtree.c\sso\sthat\sit\sworks\ncorrectly\sfor\sa\seState=CURSOR_SKIPNEXT\scursor. +D 2015-03-25T17:35:01.825 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 3634c2ee748bbbb2488cdca9dc8fc8c7bdc2f66f +F src/btree.c 933ab4ad883546193f5fd55f840299165adb8069 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a @@ -384,6 +384,7 @@ F test/boundary3.test 56ef82096b4329aca2be74fa1e2b0f762ea0eb45 F test/boundary4.tcl 0bb4b1a94f4fc5ae59b79b9a2b7a140c405e2983 F test/boundary4.test 89e02fa66397b8a325d5eb102b5806f961f8ec4b F test/btree01.test e08b3613540145b353f20c81cb18ead54ff12e0f +F test/btree02.test fe69453d474d8154d19b904157ff1db4812fed99 F test/btreefault.test c2bcb542685eea44621275cfedbd8a13f65201e3 F test/busy.test 76b4887f8b9160ba903c1ac22e8ff406ad6ae2f0 F test/cache.test 13bc046b26210471ca6f2889aceb1ea52dc717de @@ -1246,7 +1247,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 42d1793d6516e285a8925bbfd96b3d3375603d15 -R 90535e28cf02760b75aa0324ce2f944c +P 1e96520ac1d12ca83f019a60482efa0a074f2f94 +R 0d2b32f8ac05ffe0443a79d106bd4efe U drh -Z 7ee968129b9c07925188972da6333faa +Z 2f58ba8b67469927a3c7d533210b0ef3 diff --git a/manifest.uuid b/manifest.uuid index d4bfb47acf..90856bf9ee 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1e96520ac1d12ca83f019a60482efa0a074f2f94 \ No newline at end of file +37866b4d483296ab9b7fcb9f5486695d4c2b8ddd \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index ac350ac92f..dd10f6a09a 100644 --- a/src/btree.c +++ b/src/btree.c @@ -600,10 +600,15 @@ static void btreeReleaseAllCursorPages(BtCursor *pCur){ static int saveCursorPosition(BtCursor *pCur){ int rc; - assert( CURSOR_VALID==pCur->eState ); + assert( CURSOR_VALID==pCur->eState || CURSOR_SKIPNEXT==pCur->eState ); assert( 0==pCur->pKey ); assert( cursorHoldsMutex(pCur) ); + if( pCur->eState==CURSOR_SKIPNEXT ){ + pCur->eState = CURSOR_VALID; + }else{ + pCur->skipNext = 0; + } rc = sqlite3BtreeKeySize(pCur, &pCur->nKey); assert( rc==SQLITE_OK ); /* KeySize() cannot fail */ @@ -674,7 +679,7 @@ static int SQLITE_NOINLINE saveCursorsOnList( ){ do{ if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ){ - if( p->eState==CURSOR_VALID ){ + if( p->eState==CURSOR_VALID || p->eState==CURSOR_SKIPNEXT ){ int rc = saveCursorPosition(p); if( SQLITE_OK!=rc ){ return rc; @@ -746,17 +751,19 @@ static int btreeMoveto( */ static int btreeRestoreCursorPosition(BtCursor *pCur){ int rc; + int skipNext; assert( cursorHoldsMutex(pCur) ); assert( pCur->eState>=CURSOR_REQUIRESEEK ); if( pCur->eState==CURSOR_FAULT ){ return pCur->skipNext; } pCur->eState = CURSOR_INVALID; - rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &pCur->skipNext); + rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext); if( rc==SQLITE_OK ){ sqlite3_free(pCur->pKey); pCur->pKey = 0; assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID ); + pCur->skipNext |= skipNext; if( pCur->skipNext && pCur->eState==CURSOR_VALID ){ pCur->eState = CURSOR_SKIPNEXT; } @@ -808,7 +815,7 @@ int sqlite3BtreeCursorRestore(BtCursor *pCur, int *pDifferentRow){ *pDifferentRow = 1; return rc; } - if( pCur->eState!=CURSOR_VALID || NEVER(pCur->skipNext!=0) ){ + if( pCur->eState!=CURSOR_VALID || pCur->skipNext!=0 ){ *pDifferentRow = 1; }else{ *pDifferentRow = 0; @@ -3625,7 +3632,7 @@ int sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode, int writeOnly){ for(p=pBtree->pBt->pCursor; p; p=p->pNext){ int i; if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ){ - if( p->eState==CURSOR_VALID ){ + if( p->eState==CURSOR_VALID || p->eState==CURSOR_SKIPNEXT ){ rc = saveCursorPosition(p); if( rc!=SQLITE_OK ){ (void)sqlite3BtreeTripAllCursors(pBtree, rc, 0); diff --git a/test/btree02.test b/test/btree02.test new file mode 100644 index 0000000000..de7c06d442 --- /dev/null +++ b/test/btree02.test @@ -0,0 +1,52 @@ +# 2015-03-25 +# +# 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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# The focus of this script is making multiple calls to saveCursorPosition() +# and restoreCursorPosition() when cursors have eState==CURSOR_SKIPNEXT +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +load_static_extension db eval +do_execsql_test btree02-100 { + CREATE TABLE t1(a TEXT, ax INTEGER, b INT, PRIMARY KEY(a,ax)) WITHOUT ROWID; + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<10) + INSERT INTO t1(a,ax,b) SELECT printf('%02x',i), random(), i FROM c; + CREATE INDEX t1a ON t1(a); + CREATE TABLE t2(x,y); + CREATE TABLE t3(cnt); + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<4) + INSERT INTO t3(cnt) SELECT i FROM c; + SELECT count(*) FROM t1; +} {10} +do_test btree02-110 { + db eval BEGIN + set i 0 + db eval {SELECT a, ax, b, cnt FROM t1 CROSS JOIN t3 WHERE b IS NOT NULL} { + db eval {INSERT INTO t2(x,y) VALUES($b,$cnt)} + # puts "a,b,cnt = ($a,$b,$cnt)" + incr i + if {$i%2==1} { + set bx [expr {$b+1000}] + # puts "INSERT ($a),$bx" + db eval {INSERT INTO t1(a,ax,b) VALUES(printf('(%s)',$a),random(),$bx)} + } else { + # puts "DELETE a=$a" + db eval {DELETE FROM t1 WHERE a=$a} + } + db eval {COMMIT; BEGIN} + } + db one {COMMIT; SELECT count(*) FROM t1;} +} {20} + +finish_test From 606a357288884b2666948fe518948f96fdab2b3d Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 25 Mar 2015 18:29:10 +0000 Subject: [PATCH 33/63] Change an unreachable branch into an assert(). FossilOrigin-Name: fb076b28c36975ff2e41440f22fe5de115c195da --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 48427f05a3..6fdfb0ad40 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\ssaveCursorPosition()\sroutine\sin\sbtree.c\sso\sthat\sit\sworks\ncorrectly\sfor\sa\seState=CURSOR_SKIPNEXT\scursor. -D 2015-03-25T17:35:01.825 +C Change\san\sunreachable\sbranch\sinto\san\sassert(). +D 2015-03-25T18:29:10.982 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 933ab4ad883546193f5fd55f840299165adb8069 +F src/btree.c 4f305e554d7d207375c3e29ab0335bd5a473a125 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a @@ -1247,7 +1247,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 1e96520ac1d12ca83f019a60482efa0a074f2f94 -R 0d2b32f8ac05ffe0443a79d106bd4efe +P 37866b4d483296ab9b7fcb9f5486695d4c2b8ddd +R 6f3611ab9d4988693f727ae20dc9c9e5 U drh -Z 2f58ba8b67469927a3c7d533210b0ef3 +Z 3f028f44e21ab0b1619e9687cba7cf7a diff --git a/manifest.uuid b/manifest.uuid index 90856bf9ee..849f782137 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -37866b4d483296ab9b7fcb9f5486695d4c2b8ddd \ No newline at end of file +fb076b28c36975ff2e41440f22fe5de115c195da \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index dd10f6a09a..52f29428f7 100644 --- a/src/btree.c +++ b/src/btree.c @@ -815,9 +815,10 @@ int sqlite3BtreeCursorRestore(BtCursor *pCur, int *pDifferentRow){ *pDifferentRow = 1; return rc; } - if( pCur->eState!=CURSOR_VALID || pCur->skipNext!=0 ){ + if( pCur->eState!=CURSOR_VALID ){ *pDifferentRow = 1; }else{ + assert( pCur->skipNext==0 ); *pDifferentRow = 0; } return SQLITE_OK; From f3e874868356277074833bb2e0f97ed5c689e58d Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 26 Mar 2015 14:29:51 +0000 Subject: [PATCH 34/63] Fix a harmless compiler warning in FTS3. FossilOrigin-Name: 1688f60c08cc9270948402d98a2333382aa32681 --- ext/fts3/fts3.c | 2 +- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index c92463204c..46b499e96b 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -1108,7 +1108,7 @@ static int fts3InitVtab( const char **aCol; /* Array of column names */ sqlite3_tokenizer *pTokenizer = 0; /* Tokenizer for this table */ - int nIndex; /* Size of aIndex[] array */ + int nIndex = 0; /* Size of aIndex[] array */ struct Fts3Index *aIndex = 0; /* Array of indexes for this table */ /* The results of parsing supported FTS4 key=value options: */ diff --git a/manifest b/manifest index 6fdfb0ad40..c1312f1107 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\san\sunreachable\sbranch\sinto\san\sassert(). -D 2015-03-25T18:29:10.982 +C Fix\sa\sharmless\scompiler\swarning\sin\sFTS3. +D 2015-03-26T14:29:51.209 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,7 +78,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c 2a1cf23133d0c75ce296d17440c44115f8413ec7 +F ext/fts3/fts3.c d3f6f0e95d366f3c2028d916c36a0844bf805840 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 394858c12a17740f7a1f6bd372c4606d4425a8d1 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 @@ -1247,7 +1247,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 37866b4d483296ab9b7fcb9f5486695d4c2b8ddd -R 6f3611ab9d4988693f727ae20dc9c9e5 +P fb076b28c36975ff2e41440f22fe5de115c195da +R 8441601541e00ddcb253d7949a1f1256 U drh -Z 3f028f44e21ab0b1619e9687cba7cf7a +Z efb1de4d37ca897d2a6769bd7d529518 diff --git a/manifest.uuid b/manifest.uuid index 849f782137..5d911793d5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fb076b28c36975ff2e41440f22fe5de115c195da \ No newline at end of file +1688f60c08cc9270948402d98a2333382aa32681 \ No newline at end of file From 21aa6a1acbdd445284f4126178dff4ab078ac7db Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 26 Mar 2015 15:27:32 +0000 Subject: [PATCH 35/63] Provide source code line numbers for errors in the Windows VFS generated by the winLogIoerr() routine. FossilOrigin-Name: b5da0d93cd1a3c0917399af3775a32327b883c8e --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_win.c | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index c1312f1107..d6bf4d8b95 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sharmless\scompiler\swarning\sin\sFTS3. -D 2015-03-26T14:29:51.209 +C Provide\ssource\scode\sline\snumbers\sfor\serrors\sin\sthe\sWindows\sVFS\sgenerated\nby\sthe\swinLogIoerr()\sroutine. +D 2015-03-26T15:27:32.905 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -215,7 +215,7 @@ F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c a4dadbc2da41599e99093e91e276c38c17a73b89 -F src/os_win.c 8223e7db5b7c4a81d8b161098ac3959400434cdb +F src/os_win.c f65255fdc30c90bab195989776797e98dc89d709 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 @@ -1247,7 +1247,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P fb076b28c36975ff2e41440f22fe5de115c195da -R 8441601541e00ddcb253d7949a1f1256 +P 1688f60c08cc9270948402d98a2333382aa32681 +R 24f2e5bf8513d160bb9262017e93ddbd U drh -Z efb1de4d37ca897d2a6769bd7d529518 +Z d3e192564f0add8f7dcb502142bd9b66 diff --git a/manifest.uuid b/manifest.uuid index 5d911793d5..fb109a572d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1688f60c08cc9270948402d98a2333382aa32681 \ No newline at end of file +b5da0d93cd1a3c0917399af3775a32327b883c8e \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index 7463778a2f..7a95b77a58 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -1966,11 +1966,11 @@ static int winRetryIoerr(int *pnRetry, DWORD *pError){ /* ** Log a I/O error retry episode. */ -static void winLogIoerr(int nRetry){ +static void winLogIoerr(int nRetry, int lineno){ if( nRetry ){ sqlite3_log(SQLITE_IOERR, - "delayed %dms for lock/sharing conflict", - winIoerrRetryDelay*nRetry*(nRetry+1)/2 + "delayed %dms for lock/sharing conflict at line %d", + winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno ); } } @@ -2548,7 +2548,7 @@ static int winRead( return winLogError(SQLITE_IOERR_READ, pFile->lastErrno, "winRead", pFile->zPath); } - winLogIoerr(nRetry); + winLogIoerr(nRetry, __LINE__); if( nRead<(DWORD)amt ){ /* Unread parts of the buffer must be zero-filled */ memset(&((char*)pBuf)[nRead], 0, amt-nRead); @@ -2659,7 +2659,7 @@ static int winWrite( return winLogError(SQLITE_IOERR_WRITE, pFile->lastErrno, "winWrite2", pFile->zPath); }else{ - winLogIoerr(nRetry); + winLogIoerr(nRetry, __LINE__); } OSTRACE(("WRITE file=%p, rc=SQLITE_OK\n", pFile->h)); return SQLITE_OK; @@ -4752,7 +4752,7 @@ static int winOpen( } } #endif - winLogIoerr(cnt); + winLogIoerr(cnt, __LINE__); OSTRACE(("OPEN file=%p, name=%s, access=%lx, rc=%s\n", h, zUtf8Name, dwDesiredAccess, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok")); @@ -4936,7 +4936,7 @@ static int winDelete( if( rc && rc!=SQLITE_IOERR_DELETE_NOENT ){ rc = winLogError(SQLITE_IOERR_DELETE, lastErrno, "winDelete", zFilename); }else{ - winLogIoerr(cnt); + winLogIoerr(cnt, __LINE__); } sqlite3_free(zConverted); OSTRACE(("DELETE name=%s, rc=%s\n", zFilename, sqlite3ErrName(rc))); @@ -4986,7 +4986,7 @@ static int winAccess( attr = sAttrData.dwFileAttributes; } }else{ - winLogIoerr(cnt); + winLogIoerr(cnt, __LINE__); if( lastErrno!=ERROR_FILE_NOT_FOUND && lastErrno!=ERROR_PATH_NOT_FOUND ){ sqlite3_free(zConverted); return winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess", From 592f0cb15e44e69577d1f72b4586093ca48ea7e6 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 26 Mar 2015 17:04:23 +0000 Subject: [PATCH 36/63] Avoid leaving the malloc subsystem in a partially initialized state if the low-level initialization callback fails. FossilOrigin-Name: 3e872011ff5e27738c282f46d2b5803d94fe4b76 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/malloc.c | 5 ++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index d6bf4d8b95..2e013a57eb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Provide\ssource\scode\sline\snumbers\sfor\serrors\sin\sthe\sWindows\sVFS\sgenerated\nby\sthe\swinLogIoerr()\sroutine. -D 2015-03-26T15:27:32.905 +C Avoid\sleaving\sthe\smalloc\ssubsystem\sin\sa\spartially\sinitialized\sstate\sif\nthe\slow-level\sinitialization\scallback\sfails. +D 2015-03-26T17:04:23.798 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -196,7 +196,7 @@ F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 F src/main.c 569d45ba9eb4fbdd631d53f440bcdb4a35ab1505 -F src/malloc.c e818a0db9ac0898f9dc74002f3a5baca32232d05 +F src/malloc.c 6a370b83d54e4bbf6f94021221c2a311cff26a18 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 @@ -1247,7 +1247,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 1688f60c08cc9270948402d98a2333382aa32681 -R 24f2e5bf8513d160bb9262017e93ddbd +P b5da0d93cd1a3c0917399af3775a32327b883c8e +R 9e8f7450055b4cee99317e6c8db6583a U drh -Z d3e192564f0add8f7dcb502142bd9b66 +Z af5a15dd737e6e7d08dff92682723060 diff --git a/manifest.uuid b/manifest.uuid index fb109a572d..22f0d978f9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b5da0d93cd1a3c0917399af3775a32327b883c8e \ No newline at end of file +3e872011ff5e27738c282f46d2b5803d94fe4b76 \ No newline at end of file diff --git a/src/malloc.c b/src/malloc.c index 264d046ec8..f06e27d846 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -162,6 +162,7 @@ void sqlite3_soft_heap_limit(int n){ ** Initialize the memory allocation subsystem. */ int sqlite3MallocInit(void){ + int rc; if( sqlite3GlobalConfig.m.xMalloc==0 ){ sqlite3MemSetDefault(); } @@ -197,7 +198,9 @@ int sqlite3MallocInit(void){ sqlite3GlobalConfig.szPage = 0; sqlite3GlobalConfig.nPage = 0; } - return sqlite3GlobalConfig.m.xInit(sqlite3GlobalConfig.m.pAppData); + rc = sqlite3GlobalConfig.m.xInit(sqlite3GlobalConfig.m.pAppData); + if( rc!=SQLITE_OK ) memset(&mem0, 0, sizeof(mem0)); + return rc; } /* From 56d89cbee327dcd97a129d4c77f01046b20e295a Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 26 Mar 2015 18:24:26 +0000 Subject: [PATCH 37/63] Revise Win32 locking test to account for recent log message changes. FossilOrigin-Name: 1bc76339e8542770bff7829a3dd346680950c0a5 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/win32lock.test | 2 ++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 2e013a57eb..8c7cd354d7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sleaving\sthe\smalloc\ssubsystem\sin\sa\spartially\sinitialized\sstate\sif\nthe\slow-level\sinitialization\scallback\sfails. -D 2015-03-26T17:04:23.798 +C Revise\sWin32\slocking\stest\sto\saccount\sfor\srecent\slog\smessage\schanges. +D 2015-03-26T18:24:26.716 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1181,7 +1181,7 @@ F test/whereK.test f8e3cf26a8513ecc7f514f54df9f0572c046c42b F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31 F test/wild001.test bca33f499866f04c24510d74baf1e578d4e44b1c F test/win32heap.test ea19770974795cff26e11575e12d422dbd16893c -F test/win32lock.test 71642fa56e9b06e5cfffe6bad67cb8c1eb2c555a +F test/win32lock.test fbf107c91d8f5512be5a5b87c4c42ab9fdd54972 F test/win32longpath.test 169c75a3b2e43481f4a62122510210c67b08f26d F test/with1.test 9df5cd8a62148b3d9ef8597aea563e3863018bcd F test/with2.test ee227a663586aa09771cafd4fa269c5217eaf775 @@ -1247,7 +1247,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P b5da0d93cd1a3c0917399af3775a32327b883c8e -R 9e8f7450055b4cee99317e6c8db6583a -U drh -Z af5a15dd737e6e7d08dff92682723060 +P 3e872011ff5e27738c282f46d2b5803d94fe4b76 +R 72196f1f01590aeab1e66e07214515fd +U mistachkin +Z 13c90271975eca10437167897808ec14 diff --git a/manifest.uuid b/manifest.uuid index 22f0d978f9..1084c3d448 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3e872011ff5e27738c282f46d2b5803d94fe4b76 \ No newline at end of file +1bc76339e8542770bff7829a3dd346680950c0a5 \ No newline at end of file diff --git a/test/win32lock.test b/test/win32lock.test index cff1ed3d87..d1f3d1a06e 100644 --- a/test/win32lock.test +++ b/test/win32lock.test @@ -64,6 +64,7 @@ while {1} { if {[info exists ::log] && $::log!=""} { do_test win32lock-1.2-$delay1-log1 { regsub {\d+} $::log # x + regsub { at line \d+} $x "" x set x } {{delayed #ms for lock/sharing conflict}} } @@ -112,6 +113,7 @@ while {1} { if {[info exists ::log] && $::log!=""} { do_test win32lock-2.2-$delay1-log1 { regsub {\d+} $::log # x + regsub { at line \d+} $x "" x set x } {{delayed #ms for lock/sharing conflict}} } From ccb43714da0768fc44aa666208236505e5703f53 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 26 Mar 2015 23:36:35 +0000 Subject: [PATCH 38/63] When syncing a memory mapped file on Windows, flush the mapped view as well. FossilOrigin-Name: df204049b9ec8dd3e43ed7dc251eaecedc05af4b --- manifest | 15 +++++++++------ manifest.uuid | 2 +- src/os_win.c | 47 +++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 8c7cd354d7..8ca2cb9aa2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Revise\sWin32\slocking\stest\sto\saccount\sfor\srecent\slog\smessage\schanges. -D 2015-03-26T18:24:26.716 +C When\ssyncing\sa\smemory\smapped\sfile\son\sWindows,\sflush\sthe\smapped\sview\sas\swell. +D 2015-03-26T23:36:35.332 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -215,7 +215,7 @@ F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c a4dadbc2da41599e99093e91e276c38c17a73b89 -F src/os_win.c f65255fdc30c90bab195989776797e98dc89d709 +F src/os_win.c af359cc1f0acc6b091c971ef0cf77c1280048cd3 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 @@ -1247,7 +1247,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 3e872011ff5e27738c282f46d2b5803d94fe4b76 -R 72196f1f01590aeab1e66e07214515fd +P 1bc76339e8542770bff7829a3dd346680950c0a5 +R 8fcf9359fa4528c262f390ec8d494656 +T *branch * winViewFlush +T *sym-winViewFlush * +T -sym-trunk * U mistachkin -Z 13c90271975eca10437167897808ec14 +Z 96541edc57aab968aa95035dbba0935a diff --git a/manifest.uuid b/manifest.uuid index 1084c3d448..e3897a191f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1bc76339e8542770bff7829a3dd346680950c0a5 \ No newline at end of file +df204049b9ec8dd3e43ed7dc251eaecedc05af4b \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index 7a95b77a58..3fd310fc17 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -197,8 +197,10 @@ WINBASEAPI LPVOID WINAPI MapViewOfFile(HANDLE, DWORD, DWORD, DWORD, SIZE_T); #endif /* SQLITE_OS_WINRT */ /* -** This file mapping API is common to both Win32 and WinRT. +** These file mapping APIs are common to both Win32 and WinRT. */ + +WINBASEAPI BOOL WINAPI FlushViewOfFile(LPCVOID, SIZE_T); WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID); #endif /* SQLITE_WIN32_FILEMAPPING_API */ @@ -1083,6 +1085,15 @@ static struct win_syscall { #define osUuidCreateSequential \ ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[78].pCurrent) +#if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0 + { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 }, +#else + { "FlushViewOfFile", (SYSCALL)0, 0 }, +#endif + +#define osFlushViewOfFile \ + ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[79].pCurrent) + }; /* End of the overrideable system calls */ /* @@ -2753,8 +2764,9 @@ static int winSync(sqlite3_file *id, int flags){ */ SimulateDiskfullError( return SQLITE_FULL ); - OSTRACE(("SYNC file=%p, flags=%x, lock=%d\n", - pFile->h, flags, pFile->locktype)); + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, flags=%x, lock=%d\n", + osGetCurrentProcessId(), pFile, pFile->h, flags, + pFile->locktype)); #ifndef SQLITE_TEST UNUSED_PARAMETER(flags); @@ -2769,19 +2781,38 @@ static int winSync(sqlite3_file *id, int flags){ ** no-op */ #ifdef SQLITE_NO_SYNC - OSTRACE(("SYNC-NOP file=%p, rc=SQLITE_OK\n", pFile->h)); + OSTRACE(("SYNC-NOP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_OK; #else +#if SQLITE_MAX_MMAP_SIZE>0 + if( pFile->pMapRegion ){ + if( osFlushViewOfFile(pFile->pMapRegion, 0) ){ + OSTRACE(("SYNC-MMAP pid=%lu, pFile=%p, pMapRegion=%p, " + "rc=SQLITE_OK\n", osGetCurrentProcessId(), + pFile, pFile->pMapRegion)); + }else{ + pFile->lastErrno = osGetLastError(); + OSTRACE(("SYNC-MMAP pid=%lu, pFile=%p, pMapRegion=%p, " + "rc=SQLITE_IOERR_MMAP\n", osGetCurrentProcessId(), + pFile, pFile->pMapRegion)); + return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno, + "winSync1", pFile->zPath); + } + } +#endif rc = osFlushFileBuffers(pFile->h); SimulateIOError( rc=FALSE ); if( rc ){ - OSTRACE(("SYNC file=%p, rc=SQLITE_OK\n", pFile->h)); + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_OK; }else{ pFile->lastErrno = osGetLastError(); - OSTRACE(("SYNC file=%p, rc=SQLITE_IOERR_FSYNC\n", pFile->h)); + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_FSYNC\n", + osGetCurrentProcessId(), pFile, pFile->h)); return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno, - "winSync", pFile->zPath); + "winSync2", pFile->zPath); } #endif } @@ -5555,7 +5586,7 @@ int sqlite3_os_init(void){ /* Double-check that the aSyscall[] array has been constructed ** correctly. See ticket [bb3a86e890c8e96ab] */ - assert( ArraySize(aSyscall)==79 ); + assert( ArraySize(aSyscall)==80 ); /* get memory map allocation granularity */ memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); From 34a8065f495147ace8564548a97c91579d0b7028 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 27 Mar 2015 00:19:31 +0000 Subject: [PATCH 39/63] In the MSVC Makefile, make the DYNAMIC_SHELL option work without USE_STDCALL. FossilOrigin-Name: 25b46a9c7e03a84bee2ffddc6d7fd6ae280e9d7b --- Makefile.msc | 6 +++--- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 837fc003c0..7e6a077ffb 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -331,7 +331,7 @@ SHELL_CCONV_OPTS = # These are additional compiler options used for the core library. # !IFNDEF CORE_COMPILE_OPTS -!IF $(USE_STDCALL)!=0 +!IF $(DYNAMIC_SHELL)!=0 CORE_COMPILE_OPTS = $(CORE_CCONV_OPTS) -DSQLITE_API=__declspec(dllexport) !ELSE CORE_COMPILE_OPTS = $(CORE_CCONV_OPTS) @@ -342,7 +342,7 @@ CORE_COMPILE_OPTS = $(CORE_CCONV_OPTS) # when linking. # !IFNDEF CORE_LINK_DEP -!IF $(USE_STDCALL)!=0 +!IF $(DYNAMIC_SHELL)!=0 CORE_LINK_DEP = !ELSE CORE_LINK_DEP = sqlite3.def @@ -352,7 +352,7 @@ CORE_LINK_DEP = sqlite3.def # These are additional linker options used for the core library. # !IFNDEF CORE_LINK_OPTS -!IF $(USE_STDCALL)!=0 +!IF $(DYNAMIC_SHELL)!=0 CORE_LINK_OPTS = !ELSE CORE_LINK_OPTS = /DEF:sqlite3.def diff --git a/manifest b/manifest index 8c7cd354d7..f180feac72 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Revise\sWin32\slocking\stest\sto\saccount\sfor\srecent\slog\smessage\schanges. -D 2015-03-26T18:24:26.716 +C In\sthe\sMSVC\sMakefile,\smake\sthe\sDYNAMIC_SHELL\soption\swork\swithout\sUSE_STDCALL. +D 2015-03-27T00:19:31.300 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc 3481e2dd260968742c715542db178c2bdd5db99f +F Makefile.msc 23e6eaa84569829c3e7f409513caa136e5bcaf2a F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION 319eb1ced4b4d17a67730f2b7b85f15c1346cb60 @@ -1247,7 +1247,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 3e872011ff5e27738c282f46d2b5803d94fe4b76 -R 72196f1f01590aeab1e66e07214515fd +P 1bc76339e8542770bff7829a3dd346680950c0a5 +R 0d57eafd4468edd6e6285fb5978d1b4c U mistachkin -Z 13c90271975eca10437167897808ec14 +Z 9f68da42d0682346a204d1bd4bb0b359 diff --git a/manifest.uuid b/manifest.uuid index 1084c3d448..44cdf4be9e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1bc76339e8542770bff7829a3dd346680950c0a5 \ No newline at end of file +25b46a9c7e03a84bee2ffddc6d7fd6ae280e9d7b \ No newline at end of file From 9871a933c143dfe61281aaa6d8107dee7aab4650 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 27 Mar 2015 00:21:52 +0000 Subject: [PATCH 40/63] Using MSVC, get the sqlite3IoTrace variable working with the USE_STDCALL and/or DYNAMIC_SHELL options. FossilOrigin-Name: fe976c9130f6eecfa0a10347ee3f800f32051b89 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/main.c | 2 +- src/shell.c | 4 ++-- src/sqliteInt.h | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index f180feac72..3a717ccebb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sthe\sMSVC\sMakefile,\smake\sthe\sDYNAMIC_SHELL\soption\swork\swithout\sUSE_STDCALL. -D 2015-03-27T00:19:31.300 +C Using\sMSVC,\sget\sthe\ssqlite3IoTrace\svariable\sworking\swith\sthe\sUSE_STDCALL\sand/or\sDYNAMIC_SHELL\soptions. +D 2015-03-27T00:21:52.785 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -195,7 +195,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660 -F src/main.c 569d45ba9eb4fbdd631d53f440bcdb4a35ab1505 +F src/main.c 40e333960d53f7d50ee8ce09d40431c87ea653f2 F src/malloc.c 6a370b83d54e4bbf6f94021221c2a311cff26a18 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 @@ -231,11 +231,11 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 -F src/shell.c 3ae1e53878d2804fe77b8c8f1f6ca287a0e5d80e +F src/shell.c f21e91ab78e7b681e5c3c8d7f7a5b92f5583ed7a F src/sqlite.h.in 278602140d49575e8708e643161f4263e428a02a F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h bedf15914c09bfb5fe3ec4e3f211a4a6fc42cd33 +F src/sqliteInt.h d02d2b85cb02a38bc442cf9302ec8209baf6771d F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 F src/table.c e7a09215315a978057fb42c640f890160dbcc45e @@ -1247,7 +1247,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 1bc76339e8542770bff7829a3dd346680950c0a5 -R 0d57eafd4468edd6e6285fb5978d1b4c +P 25b46a9c7e03a84bee2ffddc6d7fd6ae280e9d7b +R a3ab1f66556079c5bd7cf506cd3f9f92 U mistachkin -Z 9f68da42d0682346a204d1bd4bb0b359 +Z 0ec554b2258cca84ae33b3fc6f4637d7 diff --git a/manifest.uuid b/manifest.uuid index 44cdf4be9e..88bef69794 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -25b46a9c7e03a84bee2ffddc6d7fd6ae280e9d7b \ No newline at end of file +fe976c9130f6eecfa0a10347ee3f800f32051b89 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 6967131143..d9ee77fab2 100644 --- a/src/main.c +++ b/src/main.c @@ -62,7 +62,7 @@ int sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; } ** I/O active are written using this function. These messages ** are intended for debugging activity only. */ -/* not-private */ void (*sqlite3IoTrace)(const char*, ...) = 0; +SQLITE_API void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...) = 0; #endif /* diff --git a/src/shell.c b/src/shell.c index b31ea16333..14ac9bc72d 100644 --- a/src/shell.c +++ b/src/shell.c @@ -370,7 +370,7 @@ static FILE *iotrace = 0; ** is written to iotrace. */ #ifdef SQLITE_ENABLE_IOTRACE -static void iotracePrintf(const char *zFormat, ...){ +static void SQLITE_CDECL iotracePrintf(const char *zFormat, ...){ va_list ap; char *z; if( iotrace==0 ) return; @@ -3144,7 +3144,7 @@ static int do_meta_command(char *zLine, ShellState *p){ #ifdef SQLITE_ENABLE_IOTRACE if( c=='i' && strncmp(azArg[0], "iotrace", n)==0 ){ - extern void (*sqlite3IoTrace)(const char*, ...); + SQLITE_API extern void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...); if( iotrace && iotrace!=stdout ) fclose(iotrace); iotrace = 0; if( nArg<2 ){ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 9df6d1bc4e..3841c91f14 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3803,7 +3803,7 @@ void sqlite3Put4byte(u8*, u32); #ifdef SQLITE_ENABLE_IOTRACE # define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; } void sqlite3VdbeIOTraceSql(Vdbe*); -SQLITE_EXTERN void (*sqlite3IoTrace)(const char*,...); +SQLITE_API SQLITE_EXTERN void (SQLITE_CDECL *sqlite3IoTrace)(const char*,...); #else # define IOTRACE(A) # define sqlite3VdbeIOTraceSql(X) From 6f5a37a4649b800203006f23dbc63b0514d49517 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 27 Mar 2015 02:27:20 +0000 Subject: [PATCH 41/63] Fix the ".testctrl imposter" command in the command-line shell to be consistent in error reporting and results with the other .testctrl commands. FossilOrigin-Name: 0ec08ba8a0fa188146b071a489908332693ba59a --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 3a717ccebb..ddfb25e98b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Using\sMSVC,\sget\sthe\ssqlite3IoTrace\svariable\sworking\swith\sthe\sUSE_STDCALL\sand/or\sDYNAMIC_SHELL\soptions. -D 2015-03-27T00:21:52.785 +C Fix\sthe\s".testctrl\simposter"\scommand\sin\sthe\scommand-line\sshell\sto\sbe\nconsistent\sin\serror\sreporting\sand\sresults\swith\sthe\sother\s.testctrl\ncommands. +D 2015-03-27T02:27:20.756 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -231,7 +231,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 -F src/shell.c f21e91ab78e7b681e5c3c8d7f7a5b92f5583ed7a +F src/shell.c 84a1593bd86aaa14f4da8a8f9b16fbc239d262aa F src/sqlite.h.in 278602140d49575e8708e643161f4263e428a02a F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -1247,7 +1247,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 25b46a9c7e03a84bee2ffddc6d7fd6ae280e9d7b -R a3ab1f66556079c5bd7cf506cd3f9f92 -U mistachkin -Z 0ec554b2258cca84ae33b3fc6f4637d7 +P fe976c9130f6eecfa0a10347ee3f800f32051b89 +R 13326ac5b127e703532d322e93f2a662 +U drh +Z b2f8062e547cfe60af29856c986c54f4 diff --git a/manifest.uuid b/manifest.uuid index 88bef69794..980d7d833a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fe976c9130f6eecfa0a10347ee3f800f32051b89 \ No newline at end of file +0ec08ba8a0fa188146b071a489908332693ba59a \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 14ac9bc72d..7ff3eb6cb0 100644 --- a/src/shell.c +++ b/src/shell.c @@ -3803,9 +3803,9 @@ static int do_meta_command(char *zLine, ShellState *p){ azArg[2], integerValue(azArg[3]), integerValue(azArg[4])); + fprintf(p->out, "%d (0x%08x)\n", rc, rc); }else{ - fprintf(stderr,"Usage: .testctrl initmode dbName onoff tnum\n"); - rc = 1; + fprintf(stderr,"Usage: .testctrl imposter dbName onoff tnum\n"); } break; From ad1e55e55a869106c181ab278f89cc1bd6705b19 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 27 Mar 2015 18:20:25 +0000 Subject: [PATCH 42/63] Enhancements to OSTRACE usage in the Win32 VFS. FossilOrigin-Name: ab5800291e1908b5b51d912feeacf748dc9be14b --- manifest | 14 ++++++------ manifest.uuid | 2 +- src/os_win.c | 60 +++++++++++++++++++++++++++++++++------------------ 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/manifest b/manifest index ddfb25e98b..98c814021d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\s".testctrl\simposter"\scommand\sin\sthe\scommand-line\sshell\sto\sbe\nconsistent\sin\serror\sreporting\sand\sresults\swith\sthe\sother\s.testctrl\ncommands. -D 2015-03-27T02:27:20.756 +C Enhancements\sto\sOSTRACE\susage\sin\sthe\sWin32\sVFS. +D 2015-03-27T18:20:25.776 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -215,7 +215,7 @@ F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c a4dadbc2da41599e99093e91e276c38c17a73b89 -F src/os_win.c f65255fdc30c90bab195989776797e98dc89d709 +F src/os_win.c 865ba15878eded98bb29a97ac898f2a799dc481a F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 @@ -1247,7 +1247,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P fe976c9130f6eecfa0a10347ee3f800f32051b89 -R 13326ac5b127e703532d322e93f2a662 -U drh -Z b2f8062e547cfe60af29856c986c54f4 +P 0ec08ba8a0fa188146b071a489908332693ba59a +R 5fa56a67857aa9aa0bfe9c8eabbd7f2b +U mistachkin +Z 22e64f81a05ea0084d0b656c0478e6e9 diff --git a/manifest.uuid b/manifest.uuid index 980d7d833a..50a77b66aa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0ec08ba8a0fa188146b071a489908332693ba59a \ No newline at end of file +ab5800291e1908b5b51d912feeacf748dc9be14b \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index 7a95b77a58..e40114000d 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -2450,7 +2450,8 @@ static int winClose(sqlite3_file *id){ assert( pFile->pShm==0 ); #endif assert( pFile->h!=NULL && pFile->h!=INVALID_HANDLE_VALUE ); - OSTRACE(("CLOSE file=%p\n", pFile->h)); + OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p\n", + osGetCurrentProcessId(), pFile, pFile->h)); #if SQLITE_MAX_MMAP_SIZE>0 winUnmapfile(pFile); @@ -2479,7 +2480,8 @@ static int winClose(sqlite3_file *id){ pFile->h = NULL; } OpenCounter(-1); - OSTRACE(("CLOSE file=%p, rc=%s\n", pFile->h, rc ? "ok" : "failed")); + OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p, rc=%s\n", + osGetCurrentProcessId(), pFile, pFile->h, rc ? "ok" : "failed")); return rc ? SQLITE_OK : winLogError(SQLITE_IOERR_CLOSE, osGetLastError(), "winClose", pFile->zPath); @@ -2507,7 +2509,8 @@ static int winRead( assert( amt>0 ); assert( offset>=0 ); SimulateIOError(return SQLITE_IOERR_READ); - OSTRACE(("READ file=%p, buffer=%p, amount=%d, offset=%lld, lock=%d\n", + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " + "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, pFile->h, pBuf, amt, offset, pFile->locktype)); #if SQLITE_MAX_MMAP_SIZE>0 @@ -2516,7 +2519,8 @@ static int winRead( if( offsetmmapSize ){ if( offset+amt <= pFile->mmapSize ){ memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt); - OSTRACE(("READ-MMAP file=%p, rc=SQLITE_OK\n", pFile->h)); + OSTRACE(("READ-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_OK; }else{ int nCopy = (int)(pFile->mmapSize - offset); @@ -2530,7 +2534,8 @@ static int winRead( #if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED) if( winSeekFile(pFile, offset) ){ - OSTRACE(("READ file=%p, rc=SQLITE_FULL\n", pFile->h)); + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_FULL; } while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){ @@ -2544,7 +2549,8 @@ static int winRead( DWORD lastErrno; if( winRetryIoerr(&nRetry, &lastErrno) ) continue; pFile->lastErrno = lastErrno; - OSTRACE(("READ file=%p, rc=SQLITE_IOERR_READ\n", pFile->h)); + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_READ\n", + osGetCurrentProcessId(), pFile, pFile->h)); return winLogError(SQLITE_IOERR_READ, pFile->lastErrno, "winRead", pFile->zPath); } @@ -2552,11 +2558,13 @@ static int winRead( if( nRead<(DWORD)amt ){ /* Unread parts of the buffer must be zero-filled */ memset(&((char*)pBuf)[nRead], 0, amt-nRead); - OSTRACE(("READ file=%p, rc=SQLITE_IOERR_SHORT_READ\n", pFile->h)); + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_SHORT_READ\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_IOERR_SHORT_READ; } - OSTRACE(("READ file=%p, rc=SQLITE_OK\n", pFile->h)); + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_OK; } @@ -2579,7 +2587,8 @@ static int winWrite( SimulateIOError(return SQLITE_IOERR_WRITE); SimulateDiskfullError(return SQLITE_FULL); - OSTRACE(("WRITE file=%p, buffer=%p, amount=%d, offset=%lld, lock=%d\n", + OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " + "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, pFile->h, pBuf, amt, offset, pFile->locktype)); #if SQLITE_MAX_MMAP_SIZE>0 @@ -2588,7 +2597,8 @@ static int winWrite( if( offsetmmapSize ){ if( offset+amt <= pFile->mmapSize ){ memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt); - OSTRACE(("WRITE-MMAP file=%p, rc=SQLITE_OK\n", pFile->h)); + OSTRACE(("WRITE-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_OK; }else{ int nCopy = (int)(pFile->mmapSize - offset); @@ -2651,17 +2661,20 @@ static int winWrite( if( rc ){ if( ( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ) || ( pFile->lastErrno==ERROR_DISK_FULL )){ - OSTRACE(("WRITE file=%p, rc=SQLITE_FULL\n", pFile->h)); + OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n", + osGetCurrentProcessId(), pFile, pFile->h)); return winLogError(SQLITE_FULL, pFile->lastErrno, "winWrite1", pFile->zPath); } - OSTRACE(("WRITE file=%p, rc=SQLITE_IOERR_WRITE\n", pFile->h)); + OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_WRITE\n", + osGetCurrentProcessId(), pFile, pFile->h)); return winLogError(SQLITE_IOERR_WRITE, pFile->lastErrno, "winWrite2", pFile->zPath); }else{ winLogIoerr(nRetry, __LINE__); } - OSTRACE(("WRITE file=%p, rc=SQLITE_OK\n", pFile->h)); + OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_OK; } @@ -2675,8 +2688,8 @@ static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){ assert( pFile ); SimulateIOError(return SQLITE_IOERR_TRUNCATE); - OSTRACE(("TRUNCATE file=%p, size=%lld, lock=%d\n", - pFile->h, nByte, pFile->locktype)); + OSTRACE(("TRUNCATE pid=%lu, pFile=%p, file=%p, size=%lld, lock=%d\n", + osGetCurrentProcessId(), pFile, pFile->h, nByte, pFile->locktype)); /* If the user has configured a chunk-size for this file, truncate the ** file so that it consists of an integer number of chunks (i.e. the @@ -2708,7 +2721,8 @@ static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){ } #endif - OSTRACE(("TRUNCATE file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc))); + OSTRACE(("TRUNCATE pid=%lu, pFile=%p, file=%p, rc=%s\n", + osGetCurrentProcessId(), pFile, pFile->h, sqlite3ErrName(rc))); return rc; } @@ -2753,8 +2767,9 @@ static int winSync(sqlite3_file *id, int flags){ */ SimulateDiskfullError( return SQLITE_FULL ); - OSTRACE(("SYNC file=%p, flags=%x, lock=%d\n", - pFile->h, flags, pFile->locktype)); + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, flags=%x, lock=%d\n", + osGetCurrentProcessId(), pFile, pFile->h, flags, + pFile->locktype)); #ifndef SQLITE_TEST UNUSED_PARAMETER(flags); @@ -2769,17 +2784,20 @@ static int winSync(sqlite3_file *id, int flags){ ** no-op */ #ifdef SQLITE_NO_SYNC - OSTRACE(("SYNC-NOP file=%p, rc=SQLITE_OK\n", pFile->h)); + OSTRACE(("SYNC-NOP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_OK; #else rc = osFlushFileBuffers(pFile->h); SimulateIOError( rc=FALSE ); if( rc ){ - OSTRACE(("SYNC file=%p, rc=SQLITE_OK\n", pFile->h)); + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", + osGetCurrentProcessId(), pFile, pFile->h)); return SQLITE_OK; }else{ pFile->lastErrno = osGetLastError(); - OSTRACE(("SYNC file=%p, rc=SQLITE_IOERR_FSYNC\n", pFile->h)); + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_FSYNC\n", + osGetCurrentProcessId(), pFile, pFile->h)); return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno, "winSync", pFile->zPath); } From 116f0be0244e2dc92d2a54b6a994f3a080d756ac Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 30 Mar 2015 23:43:56 +0000 Subject: [PATCH 43/63] Prevent a possible infinite loop when trying to DROP a table from a corrupt database. FossilOrigin-Name: 395bb3e677a6551b06ba96fc58c393132b93d1e8 --- manifest | 15 +++++---- manifest.uuid | 2 +- src/btree.c | 7 ++-- test/corruptJ.test | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 test/corruptJ.test diff --git a/manifest b/manifest index 98c814021d..830165f1d1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhancements\sto\sOSTRACE\susage\sin\sthe\sWin32\sVFS. -D 2015-03-27T18:20:25.776 +C Prevent\sa\spossible\sinfinite\sloop\swhen\strying\sto\sDROP\sa\stable\sfrom\na\scorrupt\sdatabase. +D 2015-03-30T23:43:56.191 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 4f305e554d7d207375c3e29ab0335bd5a473a125 +F src/btree.c e565971caa0265d3cabc8b15d7017899a7814051 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a @@ -433,6 +433,7 @@ F test/corruptF.test be9fde98e4c93648f1ba52b74e5318edc8f59fe4 F test/corruptG.test 1ab3bf97ee7bdba70e0ff3ba2320657df55d1804 F test/corruptH.test 5dd4fa98c6c1ed33b178f9e8a48c4fdd3cfc9067 F test/corruptI.test 221ad8b7f0a9ac6b80fc577e73b5ad8cdea31243 +F test/corruptJ.test 8f584eb97b88e7b160d03edfe2f814c64e56b4ac F test/cost.test 19d314526616ce4473eb4e4e450fcb94499ce318 F test/count.test 42a251178e32f617eda33f76236a7f79825a50b5 F test/coveridxscan.test cdb47d01acc4a634a34fd25abe85189e0d0f1e62 @@ -1247,7 +1248,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0ec08ba8a0fa188146b071a489908332693ba59a -R 5fa56a67857aa9aa0bfe9c8eabbd7f2b -U mistachkin -Z 22e64f81a05ea0084d0b656c0478e6e9 +P ab5800291e1908b5b51d912feeacf748dc9be14b +R 7b7ce803eb05ad2f210c6eb94fdd8e1c +U drh +Z 53c46ef4969a0037acc3578044ba6e9e diff --git a/manifest.uuid b/manifest.uuid index 50a77b66aa..b562506b7f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ab5800291e1908b5b51d912feeacf748dc9be14b \ No newline at end of file +395bb3e677a6551b06ba96fc58c393132b93d1e8 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 52f29428f7..a4eae64025 100644 --- a/src/btree.c +++ b/src/btree.c @@ -7978,6 +7978,7 @@ static int clearDatabasePage( int i; int hdr; u16 szCell; + u8 hasChildren; assert( sqlite3_mutex_held(pBt->mutex) ); if( pgno>btreePagecount(pBt) ){ @@ -7986,17 +7987,19 @@ static int clearDatabasePage( rc = getAndInitPage(pBt, pgno, &pPage, 0); if( rc ) return rc; + hasChildren = !pPage->leaf; + pPage->leaf = 1; /* Block looping if the database is corrupt */ hdr = pPage->hdrOffset; for(i=0; inCell; i++){ pCell = findCell(pPage, i); - if( !pPage->leaf ){ + if( hasChildren ){ rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange); if( rc ) goto cleardatabasepage_out; } rc = clearCell(pPage, pCell, &szCell); if( rc ) goto cleardatabasepage_out; } - if( !pPage->leaf ){ + if( hasChildren ){ rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange); if( rc ) goto cleardatabasepage_out; }else if( pnChange ){ diff --git a/test/corruptJ.test b/test/corruptJ.test new file mode 100644 index 0000000000..ec884cc9b4 --- /dev/null +++ b/test/corruptJ.test @@ -0,0 +1,80 @@ +# 2015-03-30 +# +# 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. +# +#*********************************************************************** +# +# Corruption consisting of a database page that thinks it is a child +# of itself. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix corruptJ + +if {[permutation]=="mmap"} { + finish_test + return +} + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec +database_may_be_corrupt + +# Initialize the database. +# +do_execsql_test 1.1 { + PRAGMA page_size=1024; + PRAGMA auto_vacuum=0; + CREATE TABLE t1(a,b); + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<10) + INSERT INTO t1(a,b) SELECT i, zeroblob(700) FROM c; +} {} +db close + +# Corrupt the root page of the t1 table such that the left-child pointer +# for the very first cell points back to the root. Then try to DROP the +# table. The clearDatabasePage() routine should not loop. +# +do_test 1.2 { + hexio_write test.db [expr {2*1024-2}] 02 + sqlite3 db test.db + catchsql { DROP TABLE t1 } +} {1 {database disk image is malformed}} + +# Similar test using a WITHOUT ROWID table +# +do_test 2.1 { + db close + forcedelete test.db + sqlite3 db test.db + db eval { + PRAGMA page_size=1024; + PRAGMA auto_vacuum=0; + CREATE TABLE t1(a,b,PRIMARY KEY(a,b)) WITHOUT ROWID; + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<100) + INSERT INTO t1(a,b) SELECT i, zeroblob(200) FROM c; + } +} {} + +# The table is three levels deep. Corrupt the left child of an intermediate +# page so that it points back to the root page. +# +do_test 2.2 { + db close + hexio_read test.db [expr {9*1024+391}] 8 +} {00000008814D0401} +do_test 2.2b { + hexio_write test.db [expr {9*1024+391}] 00000002 + sqlite3 db test.db + catchsql { DROP TABLE t1 } +} {0 {}} + +finish_test From bc8a6b31b69b202cd66e6c4f51beb27cf01d9c11 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 31 Mar 2015 11:42:23 +0000 Subject: [PATCH 44/63] Ensure that comparison operators do not mess up the MEM_Dyn flag on registers when reverting affinity changes. FossilOrigin-Name: 02e3c88fbf6abdcf3975fb0fb71972b0ab30da30 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 6 ++++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 830165f1d1..8a2a10e6c4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Prevent\sa\spossible\sinfinite\sloop\swhen\strying\sto\sDROP\sa\stable\sfrom\na\scorrupt\sdatabase. -D 2015-03-30T23:43:56.191 +C Ensure\sthat\scomparison\soperators\sdo\snot\smess\sup\sthe\sMEM_Dyn\sflag\son\sregisters\nwhen\sreverting\saffinity\schanges. +D 2015-03-31T11:42:23.599 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -293,7 +293,7 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec -F src/vdbe.c bbfede5a8a6908b3ddcd55fdb0b2301288dd4754 +F src/vdbe.c 86ae6f4774410868af41bd839b72b7081ff03e78 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h 9cbaa84f53ddd2d09a0cf61a94337a3a035d08a0 F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 @@ -1248,7 +1248,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P ab5800291e1908b5b51d912feeacf748dc9be14b -R 7b7ce803eb05ad2f210c6eb94fdd8e1c +P 395bb3e677a6551b06ba96fc58c393132b93d1e8 +R 32fb3cc594bfc0fa1b6de17fb4714420 U drh -Z 53c46ef4969a0037acc3578044ba6e9e +Z 6c9b38c06aabdc797714a509c4f32228 diff --git a/manifest.uuid b/manifest.uuid index b562506b7f..b6c886cfee 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -395bb3e677a6551b06ba96fc58c393132b93d1e8 \ No newline at end of file +02e3c88fbf6abdcf3975fb0fb71972b0ab30da30 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index ec5e6d7442..f2de90d14c 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -1920,11 +1920,15 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ testcase( pIn1->flags & MEM_Int ); testcase( pIn1->flags & MEM_Real ); sqlite3VdbeMemStringify(pIn1, encoding, 1); + testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) ); + flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask); } if( (pIn3->flags & MEM_Str)==0 && (pIn3->flags & (MEM_Int|MEM_Real))!=0 ){ testcase( pIn3->flags & MEM_Int ); testcase( pIn3->flags & MEM_Real ); sqlite3VdbeMemStringify(pIn3, encoding, 1); + testcase( (flags3&MEM_Dyn) != (pIn3->flags&MEM_Dyn) ); + flags3 = (pIn3->flags & ~MEM_TypeMask) | (flags3 & MEM_TypeMask); } } assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 ); @@ -1961,7 +1965,9 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ } } /* Undo any changes made by applyAffinity() to the input registers. */ + assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) ); pIn1->flags = flags1; + assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) ); pIn3->flags = flags3; break; } From fe0ba71112dc8703ba4fcc1bbef2837b635d210e Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 31 Mar 2015 13:46:13 +0000 Subject: [PATCH 45/63] Add the "mptest" target to Makefile.msc FossilOrigin-Name: 1e814e0bd116ad5a05ab9f0ebed7e21b23ed0681 --- Makefile.msc | 14 ++++++++++++++ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 7e6a077ffb..14b49082bd 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1158,6 +1158,20 @@ mptester.exe: $(TOP)\mptest\mptest.c $(SHELL_CORE_DEP) $(LIBRESOBJS) sqlite3.h $(LTLINK) $(SHELL_COMPILE_OPTS) $(TOP)\mptest\mptest.c \ /link $(LTLINKOPTS) $(LTLIBPATHS) $(SHELL_LINK_OPTS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) +MPTEST1=mptester mptest.db $(TOP)/mptest/crash01.test --repeat 20 +MPTEST2=mptester mptest.db $(TOP)/mptest/multiwrite01.test --repeat 20 +mptest: mptester.exe + del /Q mptest.db + $(MPTEST1) --journalmode DELETE + $(MPTEST2) --journalmode WAL + $(MPTEST1) --journalmode WAL + $(MPTEST2) --journalmode PERSIST + $(MPTEST1) --journalmode PERSIST + $(MPTEST2) --journalmode TRUNCATE + $(MPTEST1) --journalmode TRUNCATE + $(MPTEST2) --journalmode DELETE + + # This target creates a directory named "tsrc" and fills it with # copies of all of the C source code and header files needed to # build on the target system. Some of the C source code and header diff --git a/manifest b/manifest index 8a2a10e6c4..698734f7c6 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Ensure\sthat\scomparison\soperators\sdo\snot\smess\sup\sthe\sMEM_Dyn\sflag\son\sregisters\nwhen\sreverting\saffinity\schanges. -D 2015-03-31T11:42:23.599 +C Add\sthe\s"mptest"\starget\sto\sMakefile.msc +D 2015-03-31T13:46:13.387 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc 23e6eaa84569829c3e7f409513caa136e5bcaf2a +F Makefile.msc d7e2bcf6634197e69628e632d441646a84bfdca8 F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION 319eb1ced4b4d17a67730f2b7b85f15c1346cb60 @@ -1248,7 +1248,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 395bb3e677a6551b06ba96fc58c393132b93d1e8 -R 32fb3cc594bfc0fa1b6de17fb4714420 +P 02e3c88fbf6abdcf3975fb0fb71972b0ab30da30 +R d91812f133db0a587c3c0ca8a4eb33d5 U drh -Z 6c9b38c06aabdc797714a509c4f32228 +Z 3c6ff9ce8b6355a815c81088cec6c2b3 diff --git a/manifest.uuid b/manifest.uuid index b6c886cfee..37ec8cea3c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -02e3c88fbf6abdcf3975fb0fb71972b0ab30da30 \ No newline at end of file +1e814e0bd116ad5a05ab9f0ebed7e21b23ed0681 \ No newline at end of file From 8773b858e1f59737c2c958a17f67569fd8319254 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 31 Mar 2015 14:18:29 +0000 Subject: [PATCH 46/63] Additional logging information output by mptester. FossilOrigin-Name: 0cbbf6e4571ffef102c0e515f29166f2f2022126 --- manifest | 12 ++++++------ manifest.uuid | 2 +- mptest/mptest.c | 6 ++++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 698734f7c6..34569201a8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s"mptest"\starget\sto\sMakefile.msc -D 2015-03-31T13:46:13.387 +C Additional\slogging\sinformation\soutput\sby\smptester. +D 2015-03-31T14:18:29.822 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -160,7 +160,7 @@ F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 F mptest/crash01.test 61e61469e257df0850df4293d7d4d6c2af301421 F mptest/crash02.subtest f4ef05adcd15d60e5d2bd654204f2c008b519df8 -F mptest/mptest.c 1e464f41f1bbc6578d6925043da56170f83aea96 +F mptest/mptest.c 4691e08e1fc114edd8e1875f88393718f70ba480 F mptest/multiwrite01.test dab5c5f8f9534971efce679152c5146da265222d F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b @@ -1248,7 +1248,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 02e3c88fbf6abdcf3975fb0fb71972b0ab30da30 -R d91812f133db0a587c3c0ca8a4eb33d5 +P 1e814e0bd116ad5a05ab9f0ebed7e21b23ed0681 +R bfc4505f6e856cbd418142922d77fee6 U drh -Z 3c6ff9ce8b6355a815c81088cec6c2b3 +Z 6eef793d1a736aa92f954ef3555b0150 diff --git a/manifest.uuid b/manifest.uuid index 37ec8cea3c..e135de6357 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1e814e0bd116ad5a05ab9f0ebed7e21b23ed0681 \ No newline at end of file +0cbbf6e4571ffef102c0e515f29166f2f2022126 \ No newline at end of file diff --git a/mptest/mptest.c b/mptest/mptest.c index 40c14bc87a..1efdc0319a 100644 --- a/mptest/mptest.c +++ b/mptest/mptest.c @@ -1312,6 +1312,9 @@ int SQLITE_CDECL main(int argc, char **argv){ GETPID(), iClient); }else{ if( g.iTrace>0 ){ + printf("BEGIN: %s", argv[0]); + for(i=1; i0; } From 96e285692a92a82597736c5a89f03ed032b2c0e3 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 31 Mar 2015 14:31:41 +0000 Subject: [PATCH 47/63] Fix the corruptJ.test case so that it works with and without SQLITE_SECURE_DELETE. FossilOrigin-Name: 0c0ecfd68573957553b966229a67bfcd10ce4b99 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/corruptJ.test | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 34569201a8..64f10f7deb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Additional\slogging\sinformation\soutput\sby\smptester. -D 2015-03-31T14:18:29.822 +C Fix\sthe\scorruptJ.test\scase\sso\sthat\sit\sworks\swith\sand\swithout\nSQLITE_SECURE_DELETE. +D 2015-03-31T14:31:41.936 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -433,7 +433,7 @@ F test/corruptF.test be9fde98e4c93648f1ba52b74e5318edc8f59fe4 F test/corruptG.test 1ab3bf97ee7bdba70e0ff3ba2320657df55d1804 F test/corruptH.test 5dd4fa98c6c1ed33b178f9e8a48c4fdd3cfc9067 F test/corruptI.test 221ad8b7f0a9ac6b80fc577e73b5ad8cdea31243 -F test/corruptJ.test 8f584eb97b88e7b160d03edfe2f814c64e56b4ac +F test/corruptJ.test 9e29e7a81ee3b6ac50f77ea7a9e2f3fa03f32d91 F test/cost.test 19d314526616ce4473eb4e4e450fcb94499ce318 F test/count.test 42a251178e32f617eda33f76236a7f79825a50b5 F test/coveridxscan.test cdb47d01acc4a634a34fd25abe85189e0d0f1e62 @@ -1248,7 +1248,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 1e814e0bd116ad5a05ab9f0ebed7e21b23ed0681 -R bfc4505f6e856cbd418142922d77fee6 +P 0cbbf6e4571ffef102c0e515f29166f2f2022126 +R 855ca787fb7bd1ab9ab088557a4f09bc U drh -Z 6eef793d1a736aa92f954ef3555b0150 +Z 3d4ee993730e7b33e6803497c50a3fdc diff --git a/manifest.uuid b/manifest.uuid index e135de6357..5400bc696e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0cbbf6e4571ffef102c0e515f29166f2f2022126 \ No newline at end of file +0c0ecfd68573957553b966229a67bfcd10ce4b99 \ No newline at end of file diff --git a/test/corruptJ.test b/test/corruptJ.test index ec884cc9b4..c08e628e2d 100644 --- a/test/corruptJ.test +++ b/test/corruptJ.test @@ -74,7 +74,7 @@ do_test 2.2 { do_test 2.2b { hexio_write test.db [expr {9*1024+391}] 00000002 sqlite3 db test.db - catchsql { DROP TABLE t1 } -} {0 {}} + catchsql { PRAGMA secure_delete=ON; DROP TABLE t1; } +} {1 {database disk image is malformed}} finish_test From 1cc0d11a167a1d25a1784c3ef4a6896636889299 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 31 Mar 2015 15:15:48 +0000 Subject: [PATCH 48/63] Fix harmless compiler warnings in lemon.c FossilOrigin-Name: bbe7dcda689a25860f2104804f00ba0a720c1372 --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/lemon.c | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 64f10f7deb..f76a238037 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\scorruptJ.test\scase\sso\sthat\sit\sworks\swith\sand\swithout\nSQLITE_SECURE_DELETE. -D 2015-03-31T14:31:41.936 +C Fix\sharmless\scompiler\swarnings\sin\slemon.c +D 2015-03-31T15:15:48.726 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1206,7 +1206,7 @@ F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439 F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4 F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5 F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce -F tool/lemon.c 1864c4fe4a72b1bb28f1792b60504804fe82c5d2 +F tool/lemon.c ae5f61e3b164d35955777b20d6febcbaf0950702 F tool/lempar.c 01ca97f87610d1dac6d8cd96ab109ab1130e76dc F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh d1a2da0e15b2ed33d60af35c7e9d483f13a8eb9f @@ -1248,7 +1248,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0cbbf6e4571ffef102c0e515f29166f2f2022126 -R 855ca787fb7bd1ab9ab088557a4f09bc +P 0c0ecfd68573957553b966229a67bfcd10ce4b99 +R f295c13e7a998be1a5a78140716d3389 U drh -Z 3d4ee993730e7b33e6803497c50a3fdc +Z 1c953be9eacdcbbbb1c665e7b3932b7e diff --git a/manifest.uuid b/manifest.uuid index 5400bc696e..544169567d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0c0ecfd68573957553b966229a67bfcd10ce4b99 \ No newline at end of file +bbe7dcda689a25860f2104804f00ba0a720c1372 \ No newline at end of file diff --git a/tool/lemon.c b/tool/lemon.c index 4ada425d69..cc3066bec0 100644 --- a/tool/lemon.c +++ b/tool/lemon.c @@ -1731,7 +1731,7 @@ static char *msort( char *ep; char *set[LISTSIZE]; int i; - offset = (unsigned long)next - (unsigned long)list; + offset = (unsigned long)((char*)next - (char*)list); for(i=0; i Date: Tue, 31 Mar 2015 16:33:08 +0000 Subject: [PATCH 49/63] Handle very large URI pathnames for in-memory shared-cache databases. FossilOrigin-Name: 586a94e85bc13700a2093734711c1367fa814b8c --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/btree.c | 6 ++++-- test/attach.test | 12 ++++++++++++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index f76a238037..a38babcf26 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings\sin\slemon.c -D 2015-03-31T15:15:48.726 +C Handle\svery\slarge\sURI\spathnames\sfor\sin-memory\sshared-cache\sdatabases. +D 2015-03-31T16:33:08.816 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c e565971caa0265d3cabc8b15d7017899a7814051 +F src/btree.c 525f19f01d5976dbc12e83e7339e41488de79183 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a @@ -340,7 +340,7 @@ F test/async3.test d73a062002376d7edc1fe3edff493edbec1fc2f7 F test/async4.test 1787e3952128aa10238bf39945126de7ca23685a F test/async5.test 383ab533fdb9f7ad228cc99ee66e1acb34cc0dc0 F test/atof1.test 08a61df9365c341f334a65f4348897312d8f3db7 -F test/attach.test 0d112b7713611fdf0340260192749737135fda5f +F test/attach.test 437107943f14d131cf5efc2ae5305a94d7cb1d58 F test/attach2.test 0ec5defa340363de6cd50fd595046465e9aaba2d F test/attach3.test 359eb65d00102cdfcef6fa4e81dc1648f8f80b27 F test/attach4.test 53bf502f17647c6d6c5add46dda6bac8b6f4665c @@ -1248,7 +1248,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0c0ecfd68573957553b966229a67bfcd10ce4b99 -R f295c13e7a998be1a5a78140716d3389 +P bbe7dcda689a25860f2104804f00ba0a720c1372 +R 6f0e4814d1e4f882b35ba2b9dccc56cc U drh -Z 1c953be9eacdcbbbb1c665e7b3932b7e +Z d85481fb8858c2d74f205f2246e5afa6 diff --git a/manifest.uuid b/manifest.uuid index 544169567d..7c14a1b036 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bbe7dcda689a25860f2104804f00ba0a720c1372 \ No newline at end of file +586a94e85bc13700a2093734711c1367fa814b8c \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index a4eae64025..b497cd7468 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1959,16 +1959,18 @@ int sqlite3BtreeOpen( */ if( isTempDb==0 && (isMemdb==0 || (vfsFlags&SQLITE_OPEN_URI)!=0) ){ if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){ + int nFilename = sqlite3Strlen30(zFilename)+1; int nFullPathname = pVfs->mxPathname+1; - char *zFullPathname = sqlite3Malloc(nFullPathname); + char *zFullPathname = sqlite3Malloc(MAX(nFullPathname,nFilename)); MUTEX_LOGIC( sqlite3_mutex *mutexShared; ) + p->sharable = 1; if( !zFullPathname ){ sqlite3_free(p); return SQLITE_NOMEM; } if( isMemdb ){ - memcpy(zFullPathname, zFilename, sqlite3Strlen30(zFilename)+1); + memcpy(zFullPathname, zFilename, nFilename); }else{ rc = sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname); diff --git a/test/attach.test b/test/attach.test index be5f9881c3..31c24e61d9 100644 --- a/test/attach.test +++ b/test/attach.test @@ -859,4 +859,16 @@ do_test attach-10.2 { }] 9 end } {4 noname {} 5 inmem {}} +# Attach with a very long URI filename. +# +db close +sqlite3 db test.db -uri 1 +do_execsql_test attach-11.1 { + ATTACH printf('file:%09000x/x.db?mode=memory&cache=shared',1) AS aux1; + CREATE TABLE aux1.t1(x,y); + INSERT INTO aux1.t1(x,y) VALUES(1,2),(3,4); + SELECT * FROM aux1.t1; +} {1 2 3 4} + + finish_test From 4d2daba467b1d1c53cb1d1d471df9126ae4b6873 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 31 Mar 2015 16:42:16 +0000 Subject: [PATCH 50/63] Minor tweaks to the MSVC Makefile. FossilOrigin-Name: 7244ea59ede8aa2c7d1dc2c85268e12ddd452e27 --- Makefile.msc | 8 ++++---- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 14b49082bd..5330f8962f 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1158,10 +1158,11 @@ mptester.exe: $(TOP)\mptest\mptest.c $(SHELL_CORE_DEP) $(LIBRESOBJS) sqlite3.h $(LTLINK) $(SHELL_COMPILE_OPTS) $(TOP)\mptest\mptest.c \ /link $(LTLINKOPTS) $(LTLIBPATHS) $(SHELL_LINK_OPTS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) -MPTEST1=mptester mptest.db $(TOP)/mptest/crash01.test --repeat 20 -MPTEST2=mptester mptest.db $(TOP)/mptest/multiwrite01.test --repeat 20 +MPTEST1 = mptester mptest.db $(TOP)/mptest/crash01.test --repeat 20 +MPTEST2 = mptester mptest.db $(TOP)/mptest/multiwrite01.test --repeat 20 + mptest: mptester.exe - del /Q mptest.db + del /Q mptest.db 2>NUL $(MPTEST1) --journalmode DELETE $(MPTEST2) --journalmode WAL $(MPTEST1) --journalmode WAL @@ -1171,7 +1172,6 @@ mptest: mptester.exe $(MPTEST1) --journalmode TRUNCATE $(MPTEST2) --journalmode DELETE - # This target creates a directory named "tsrc" and fills it with # copies of all of the C source code and header files needed to # build on the target system. Some of the C source code and header diff --git a/manifest b/manifest index a38babcf26..78a4b72821 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Handle\svery\slarge\sURI\spathnames\sfor\sin-memory\sshared-cache\sdatabases. -D 2015-03-31T16:33:08.816 +C Minor\stweaks\sto\sthe\sMSVC\sMakefile. +D 2015-03-31T16:42:16.959 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc d7e2bcf6634197e69628e632d441646a84bfdca8 +F Makefile.msc a8d817fa486d8c88dfbd19ae6a6567d9d350de39 F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866 F VERSION 319eb1ced4b4d17a67730f2b7b85f15c1346cb60 @@ -1248,7 +1248,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P bbe7dcda689a25860f2104804f00ba0a720c1372 -R 6f0e4814d1e4f882b35ba2b9dccc56cc -U drh -Z d85481fb8858c2d74f205f2246e5afa6 +P 586a94e85bc13700a2093734711c1367fa814b8c +R dda30a84a02345c3ad5a29c2256cdbe0 +U mistachkin +Z 140263b8fa48f28f6823c13e70219b7f diff --git a/manifest.uuid b/manifest.uuid index 7c14a1b036..6d3dfcae53 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -586a94e85bc13700a2093734711c1367fa814b8c \ No newline at end of file +7244ea59ede8aa2c7d1dc2c85268e12ddd452e27 \ No newline at end of file From d881ce8fa74bc5bf5734cda3f045a0bc2a804574 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 31 Mar 2015 17:01:52 +0000 Subject: [PATCH 51/63] Fix configure.ac and Makefile.in so that they generate pkgIndex.tcl correctly. FossilOrigin-Name: 3deff25249c59b7fc1b6eb65dda39736955679c6 --- Makefile.in | 2 +- configure | 30 ++++++++++++++++-------------- configure.ac | 1 + manifest | 18 +++++++++--------- manifest.uuid | 2 +- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/Makefile.in b/Makefile.in index 4ac06938fd..2177488f9b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1059,7 +1059,7 @@ install: sqlite3$(BEXE) lib_install sqlite3.h sqlite3.pc ${HAVE_TCL:1=tcl_instal $(INSTALL) -m 0644 sqlite3.pc $(DESTDIR)$(pkgconfigdir) pkgIndex.tcl: - echo 'package ifneeded sqlite3 $(RELEASE) [list load $(TCLLIBDIR)/libtclsqlite3.so sqlite3]' > $@ + echo 'package ifneeded sqlite3 $(RELEASE) [list load $(TCLLIBDIR)/libtclsqlite3$(SHLIB_SUFFIX) sqlite3]' > $@ tcl_install: lib_install libtclsqlite3.la pkgIndex.tcl $(INSTALL) -d $(DESTDIR)$(TCLLIBDIR) $(LTINSTALL) libtclsqlite3.la $(DESTDIR)$(TCLLIBDIR) diff --git a/configure b/configure index 0c519e2216..d259324bdd 100755 --- a/configure +++ b/configure @@ -884,6 +884,7 @@ TCL_LIB_SPEC TCL_STUB_LIB_FILE TCL_STUB_LIB_FLAG TCL_STUB_LIB_SPEC +TCL_SHLIB_SUFFIX HAVE_TCL TARGET_READLINE_LIBS TARGET_READLINE_INC @@ -3724,13 +3725,13 @@ if test "${lt_cv_nm_interface+set}" = set; then else lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext - (eval echo "\"\$as_me:3727: $ac_compile\"" >&5) + (eval echo "\"\$as_me:3728: $ac_compile\"" >&5) (eval "$ac_compile" 2>conftest.err) cat conftest.err >&5 - (eval echo "\"\$as_me:3730: $NM \\\"conftest.$ac_objext\\\"\"" >&5) + (eval echo "\"\$as_me:3731: $NM \\\"conftest.$ac_objext\\\"\"" >&5) (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) cat conftest.err >&5 - (eval echo "\"\$as_me:3733: output\"" >&5) + (eval echo "\"\$as_me:3734: output\"" >&5) cat conftest.out >&5 if $GREP 'External.*some_variable' conftest.out > /dev/null; then lt_cv_nm_interface="MS dumpbin" @@ -4952,7 +4953,7 @@ ia64-*-hpux*) ;; *-*-irix6*) # Find out which ABI we are using. - echo '#line 4955 "configure"' > conftest.$ac_ext + echo '#line 4956 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -6821,11 +6822,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:6824: $lt_compile\"" >&5) + (eval echo "\"\$as_me:6825: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:6828: \$? = $ac_status" >&5 + echo "$as_me:6829: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -7160,11 +7161,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7163: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7164: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:7167: \$? = $ac_status" >&5 + echo "$as_me:7168: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -7265,11 +7266,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7268: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7269: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:7272: \$? = $ac_status" >&5 + echo "$as_me:7273: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -7320,11 +7321,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7323: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7324: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:7327: \$? = $ac_status" >&5 + echo "$as_me:7328: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -10133,7 +10134,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10136 "configure" +#line 10137 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -10229,7 +10230,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10232 "configure" +#line 10233 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -12827,6 +12828,7 @@ $as_echo "file not found" >&6; } + fi fi if test "${use_tcl}" = "no" ; then diff --git a/configure.ac b/configure.ac index 00ecf453af..6a1188842a 100644 --- a/configure.ac +++ b/configure.ac @@ -430,6 +430,7 @@ if test "${use_tcl}" = "yes" ; then AC_SUBST(TCL_STUB_LIB_FILE) AC_SUBST(TCL_STUB_LIB_FLAG) AC_SUBST(TCL_STUB_LIB_SPEC) + AC_SUBST(TCL_SHLIB_SUFFIX) fi fi if test "${use_tcl}" = "no" ; then diff --git a/manifest b/manifest index 78a4b72821..9e2a939d3b 100644 --- a/manifest +++ b/manifest @@ -1,7 +1,7 @@ -C Minor\stweaks\sto\sthe\sMSVC\sMakefile. -D 2015-03-31T16:42:16.959 +C Fix\sconfigure.ac\sand\sMakefile.in\sso\sthat\sthey\sgenerate\spkgIndex.tcl\scorrectly. +D 2015-03-31T17:01:52.572 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f -F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb +F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.msc a8d817fa486d8c88dfbd19ae6a6567d9d350de39 F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858 @@ -38,8 +38,8 @@ F autoconf/tea/win/rules.vc c511f222b80064096b705dbeb97060ee1d6b6d63 F config.guess 226d9a188c6196f3033ffc651cbc9dcee1a42977 F config.h.in 42b71ad3fe21c9e88fa59e8458ca1a6bc72eb0c0 F config.sub 9ebe4c3b3dab6431ece34f16828b594fb420da55 -F configure 613b220c2f2c7adcd50eb5ee4144ab581a150b47 x -F configure.ac 6a8d145aea6d81f0b90013340780e43ed74fd5f4 +F configure 8b18c2378805a1d8aaca85d293671f450dd3c723 x +F configure.ac 0b775d383c536bbaafc1e46dd3cbb81a7ea11aeb F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad F doc/lemon.html 334dbf6621b8fb8790297ec1abf3cfa4621709d1 F doc/pager-invariants.txt 27fed9a70ddad2088750c4a2b493b63853da2710 @@ -1248,7 +1248,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 586a94e85bc13700a2093734711c1367fa814b8c -R dda30a84a02345c3ad5a29c2256cdbe0 -U mistachkin -Z 140263b8fa48f28f6823c13e70219b7f +P 7244ea59ede8aa2c7d1dc2c85268e12ddd452e27 +R 975c1f85d87faa80fd42aac5b24ed9ba +U drh +Z 016bf5cf61fe366d051895307d7b2ae3 diff --git a/manifest.uuid b/manifest.uuid index 6d3dfcae53..d92c73c696 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7244ea59ede8aa2c7d1dc2c85268e12ddd452e27 \ No newline at end of file +3deff25249c59b7fc1b6eb65dda39736955679c6 \ No newline at end of file From 8237f6d180d0233a4abac22e12e5f52f6497fd8f Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 31 Mar 2015 17:32:06 +0000 Subject: [PATCH 52/63] Change the sqlite3_log() message generated on a retry after delay in os_win to be an SQLITE_NOTICE instead of SQLITE_IOERR. FossilOrigin-Name: 5d533eee049e63b3700f5ef7c28c588afccde57a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_win.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 9e2a939d3b..d5d1701f1e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sconfigure.ac\sand\sMakefile.in\sso\sthat\sthey\sgenerate\spkgIndex.tcl\scorrectly. -D 2015-03-31T17:01:52.572 +C Change\sthe\ssqlite3_log()\smessage\sgenerated\son\sa\sretry\safter\sdelay\sin\sos_win\nto\sbe\san\sSQLITE_NOTICE\sinstead\sof\sSQLITE_IOERR. +D 2015-03-31T17:32:06.290 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -215,7 +215,7 @@ F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c a4dadbc2da41599e99093e91e276c38c17a73b89 -F src/os_win.c 865ba15878eded98bb29a97ac898f2a799dc481a +F src/os_win.c 23c2d1fab9b44e728e7d3ac0c82d5ac2a96de290 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 @@ -1248,7 +1248,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 7244ea59ede8aa2c7d1dc2c85268e12ddd452e27 -R 975c1f85d87faa80fd42aac5b24ed9ba +P 3deff25249c59b7fc1b6eb65dda39736955679c6 +R 5464b14f38d360ccc6fa7360d378f7df U drh -Z 016bf5cf61fe366d051895307d7b2ae3 +Z f2a2061ec6a7f778916e1fed0b96d2ff diff --git a/manifest.uuid b/manifest.uuid index d92c73c696..1069e22d85 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3deff25249c59b7fc1b6eb65dda39736955679c6 \ No newline at end of file +5d533eee049e63b3700f5ef7c28c588afccde57a \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index e40114000d..e685e20fab 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -1968,7 +1968,7 @@ static int winRetryIoerr(int *pnRetry, DWORD *pError){ */ static void winLogIoerr(int nRetry, int lineno){ if( nRetry ){ - sqlite3_log(SQLITE_IOERR, + sqlite3_log(SQLITE_NOTICE, "delayed %dms for lock/sharing conflict at line %d", winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno ); From 4c45196a76c92309980cdbd7fd570e183c272c36 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 31 Mar 2015 18:05:49 +0000 Subject: [PATCH 53/63] Add the "mptest" target to main.mk. Change TRUNCATE and PERSIST to DELETE for mptest.c on Windows because of problems trying to delete the journal. FossilOrigin-Name: ea697e6d9ff1f4d77774589a02ba4a18feafbf03 --- main.mk | 13 +++++++++++++ manifest | 14 +++++++------- manifest.uuid | 2 +- mptest/mptest.c | 12 +++++++++++- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/main.mk b/main.mk index 7d21dbb25e..57bb35c486 100644 --- a/main.mk +++ b/main.mk @@ -408,6 +408,19 @@ mptester$(EXE): sqlite3.c $(TOP)/mptest/mptest.c $(TCCX) -o $@ -I. $(TOP)/mptest/mptest.c sqlite3.c \ $(TLIBS) $(THREADLIB) +MPTEST1=./mptester$(EXE) mptest.db $(TOP)/mptest/crash01.test --repeat 20 +MPTEST2=./mptester$(EXE) mptest.db $(TOP)/mptest/multiwrite01.test --repeat 20 +mptest: mptester$(EXE) + rm -f mptest.db + $(MPTEST1) --journalmode DELETE + $(MPTEST2) --journalmode WAL + $(MPTEST1) --journalmode WAL + $(MPTEST2) --journalmode PERSIST + $(MPTEST1) --journalmode PERSIST + $(MPTEST2) --journalmode TRUNCATE + $(MPTEST1) --journalmode TRUNCATE + $(MPTEST2) --journalmode DELETE + sqlite3.o: sqlite3.c $(TCCX) -I. -c sqlite3.c diff --git a/manifest b/manifest index d5d1701f1e..74afeab247 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\ssqlite3_log()\smessage\sgenerated\son\sa\sretry\safter\sdelay\sin\sos_win\nto\sbe\san\sSQLITE_NOTICE\sinstead\sof\sSQLITE_IOERR. -D 2015-03-31T17:32:06.290 +C Add\sthe\s"mptest"\starget\sto\smain.mk.\s\sChange\sTRUNCATE\sand\sPERSIST\sto\sDELETE\nfor\smptest.c\son\sWindows\sbecause\sof\sproblems\strying\sto\sdelete\sthe\sjournal. +D 2015-03-31T18:05:49.317 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -152,7 +152,7 @@ F ext/userauth/userauth.c 5fa3bdb492f481bbc1709fc83c91ebd13460c69e F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 -F main.mk 04c49c495795b18a7b70053eef285be1e4d43fa4 +F main.mk 997eee18387a3e69394f2f948c9c6ccf079655a4 F mkopcodec.awk c2ff431854d702cdd2d779c9c0d1f58fa16fa4ea F mkopcodeh.awk c6b3fa301db6ef7ac916b14c60868aeaec1337b5 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 @@ -160,7 +160,7 @@ F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 F mptest/crash01.test 61e61469e257df0850df4293d7d4d6c2af301421 F mptest/crash02.subtest f4ef05adcd15d60e5d2bd654204f2c008b519df8 -F mptest/mptest.c 4691e08e1fc114edd8e1875f88393718f70ba480 +F mptest/mptest.c dae6de83eddac3ef97fc4111632f6066760f939a F mptest/multiwrite01.test dab5c5f8f9534971efce679152c5146da265222d F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b @@ -1248,7 +1248,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 3deff25249c59b7fc1b6eb65dda39736955679c6 -R 5464b14f38d360ccc6fa7360d378f7df +P 5d533eee049e63b3700f5ef7c28c588afccde57a +R 9e646d8c9c851fc471bfbde27cfe2ec7 U drh -Z f2a2061ec6a7f778916e1fed0b96d2ff +Z 7401f8256f1a048a9f3296d27a2e41e1 diff --git a/manifest.uuid b/manifest.uuid index 1069e22d85..9e31354eac 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5d533eee049e63b3700f5ef7c28c588afccde57a \ No newline at end of file +ea697e6d9ff1f4d77774589a02ba4a18feafbf03 \ No newline at end of file diff --git a/mptest/mptest.c b/mptest/mptest.c index 1efdc0319a..52ff6a4c83 100644 --- a/mptest/mptest.c +++ b/mptest/mptest.c @@ -1327,6 +1327,17 @@ int SQLITE_CDECL main(int argc, char **argv){ } rc = sqlite3_open_v2(g.zDbFile, &g.db, openFlags, g.zVfs); if( rc ) fatalError("cannot open [%s]", g.zDbFile); + if( zJMode ){ +#if defined(_WIN32) + if( sqlite3_stricmp(zJMode,"persist")==0 + || sqlite3_stricmp(zJMode,"truncate")==0 + ){ + printf("Changing journal mode to DELETE from %s", zJMode); + zJMode = "DELETE"; + } +#endif + runSql("PRAGMA journal_mode=%Q;", zJMode); + } sqlite3_enable_load_extension(g.db, 1); sqlite3_busy_handler(g.db, busyHandler, 0); sqlite3_create_function(g.db, "vfsname", 0, SQLITE_UTF8, 0, @@ -1358,7 +1369,6 @@ int SQLITE_CDECL main(int argc, char **argv){ fatalError("missing script filename"); } if( n>1 ) unrecognizedArguments(argv[0], n, argv+2); - if( zJMode ) runSql("PRAGMA journal_mode=%Q;", zJMode); runSql( "DROP TABLE IF EXISTS task;\n" "DROP TABLE IF EXISTS counters;\n" From ccf46d0b9020d88fddbdc2dd9b9104b403f7d615 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 1 Apr 2015 13:21:33 +0000 Subject: [PATCH 54/63] Improved detection and suppression of endless loops in clearDatabasePage(). FossilOrigin-Name: 30011ad2f55cfcacaf23a58ebcc17b17a7b9355e --- manifest | 15 +++++++-------- manifest.uuid | 2 +- src/btree.c | 14 ++++++++------ src/btreeInt.h | 1 + 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 63d5d9eccf..83880531e8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C On\swindows,\sflush\sthe\smapping\sview\swhen\ssyncing\scontent\sto\sdisk. -D 2015-03-31T19:40:05.313 +C Improved\sdetection\sand\ssuppression\sof\sendless\sloops\sin\sclearDatabasePage(). +D 2015-04-01T13:21:33.901 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -173,9 +173,9 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 525f19f01d5976dbc12e83e7339e41488de79183 +F src/btree.c 2caf598165f3608fde8abac2b243826616ce54b7 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 -F src/btreeInt.h 2bfefc01875d8da066504c233ec259fcb3b2ef72 +F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 F src/build.c 0419bba592c22f6d00e6d57a2ca7136720d02c1a F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463 @@ -1248,8 +1248,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P ea697e6d9ff1f4d77774589a02ba4a18feafbf03 45acf6a85150839d591316418dad59ae20ce3aa4 -R 00dcdcdf447a25afe74cb2a2ac195e0b -T +closed 45acf6a85150839d591316418dad59ae20ce3aa4 +P a828e73dc1ae50189bdf73f60caeb7308738ad7a +R 9ae26e7b05df4833a239ec9186729882 U drh -Z e131d4f6392434ebe038899ef79bd289 +Z b113a7338e765a6278a4e0ffd57f1cf8 diff --git a/manifest.uuid b/manifest.uuid index 6301587c11..925ee38b4d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a828e73dc1ae50189bdf73f60caeb7308738ad7a \ No newline at end of file +30011ad2f55cfcacaf23a58ebcc17b17a7b9355e \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index b497cd7468..789796d55a 100644 --- a/src/btree.c +++ b/src/btree.c @@ -7980,28 +7980,29 @@ static int clearDatabasePage( int i; int hdr; u16 szCell; - u8 hasChildren; assert( sqlite3_mutex_held(pBt->mutex) ); if( pgno>btreePagecount(pBt) ){ return SQLITE_CORRUPT_BKPT; } - rc = getAndInitPage(pBt, pgno, &pPage, 0); if( rc ) return rc; - hasChildren = !pPage->leaf; - pPage->leaf = 1; /* Block looping if the database is corrupt */ + if( pPage->bBusy ){ + rc = SQLITE_CORRUPT_BKPT; + goto cleardatabasepage_out; + } + pPage->bBusy = 1; hdr = pPage->hdrOffset; for(i=0; inCell; i++){ pCell = findCell(pPage, i); - if( hasChildren ){ + if( !pPage->leaf ){ rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange); if( rc ) goto cleardatabasepage_out; } rc = clearCell(pPage, pCell, &szCell); if( rc ) goto cleardatabasepage_out; } - if( hasChildren ){ + if( !pPage->leaf ){ rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange); if( rc ) goto cleardatabasepage_out; }else if( pnChange ){ @@ -8015,6 +8016,7 @@ static int clearDatabasePage( } cleardatabasepage_out: + pPage->bBusy = 0; releasePage(pPage); return rc; } diff --git a/src/btreeInt.h b/src/btreeInt.h index 87d0ef1bb8..33ef641059 100644 --- a/src/btreeInt.h +++ b/src/btreeInt.h @@ -280,6 +280,7 @@ struct MemPage { u8 hdrOffset; /* 100 for page 1. 0 otherwise */ u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */ u8 max1bytePayload; /* min(maxLocal,127) */ + u8 bBusy; /* Prevent endless loops on corrupt database files */ u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */ u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */ u16 cellOffset; /* Index in aData of first cell pointer */ From 5f1731f67000d8e0c7cd9ce14ffd48e37bf42866 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 2 Apr 2015 15:24:53 +0000 Subject: [PATCH 55/63] Disable e_walauto.test on OpenBSD, as it requires a coherent cache. FossilOrigin-Name: 90701227085b8b8eb10a8eebe8d55f38b4778574 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/e_walauto.test | 8 ++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 83880531e8..e116e655ac 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\sdetection\sand\ssuppression\sof\sendless\sloops\sin\sclearDatabasePage(). -D 2015-04-01T13:21:33.901 +C Disable\se_walauto.test\son\sOpenBSD,\sas\sit\srequires\sa\scoherent\scache. +D 2015-04-02T15:24:53.782 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -485,7 +485,7 @@ F test/e_update.test 312cb8f5ccfe41515a6bb092f8ea562a9bd54d52 F test/e_uri.test 5ae33760fb2039c61aa2d90886f1664664173585 F test/e_vacuum.test 5bfbdc21b65c0abf24398d0ba31dc88d93ca77a9 F test/e_wal.test ae9a593207a77d711443ee69ffe081fda9243625 -F test/e_walauto.test ca70cf75c07a6cb1874ced101dd426da76625649 +F test/e_walauto.test 6544af03423abc61b53cfb976839385ddc2a0a70 F test/e_walckpt.test 65e29b6631e51f210f83e4ff11571e647ba93608 F test/e_walhook.test da3ea8b3483d1af72190337bda50155a91a4b664 F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea @@ -1248,7 +1248,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P a828e73dc1ae50189bdf73f60caeb7308738ad7a -R 9ae26e7b05df4833a239ec9186729882 -U drh -Z b113a7338e765a6278a4e0ffd57f1cf8 +P 30011ad2f55cfcacaf23a58ebcc17b17a7b9355e +R 0b149500fabb905b0771216875924384 +U dan +Z 259e8553f23f2ead0f4917d2e8d05aa6 diff --git a/manifest.uuid b/manifest.uuid index 925ee38b4d..67f1e1b12f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -30011ad2f55cfcacaf23a58ebcc17b17a7b9355e \ No newline at end of file +90701227085b8b8eb10a8eebe8d55f38b4778574 \ No newline at end of file diff --git a/test/e_walauto.test b/test/e_walauto.test index b624b2469c..a1f4eb7079 100644 --- a/test/e_walauto.test +++ b/test/e_walauto.test @@ -15,6 +15,14 @@ source $testdir/tester.tcl source $testdir/wal_common.tcl set testprefix e_walauto +# Do not run this test on OpenBSD, as it depends on read() and mmap both +# accessing the same coherent view of the "test.db-shm" file. This doesn't +# work on OpenBSD. +# +if {$tcl_platform(os) == "OpenBSD"} { + finish_test + return +} proc read_nbackfill {} { seek $::shmfd 96 From eaf26402370336186d8119e3130eaf050595ff44 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 3 Apr 2015 18:33:40 +0000 Subject: [PATCH 56/63] Add source code to the "showlocks" utility program in the tool/ subdirectory. FossilOrigin-Name: 6868cc66d2be67b7f03776c982962ffa4b30de11 --- manifest | 13 +++++----- manifest.uuid | 2 +- tool/showlocks.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 tool/showlocks.c diff --git a/manifest b/manifest index e116e655ac..73436f25df 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Disable\se_walauto.test\son\sOpenBSD,\sas\sit\srequires\sa\scoherent\scache. -D 2015-04-02T15:24:53.782 +C Add\ssource\scode\sto\sthe\s"showlocks"\sutility\sprogram\sin\sthe\stool/\ssubdirectory. +D 2015-04-03T18:33:40.031 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1227,6 +1227,7 @@ F tool/restore_jrnl.tcl 6957a34f8f1f0f8285e07536225ec3b292a9024a F tool/rollback-test.c 9fc98427d1e23e84429d7e6d07d9094fbdec65a5 F tool/showdb.c 63cdef19e7fbca0c164b096ef8aef3bb9e9dd222 F tool/showjournal.c 053eb1cc774710c6890b7dd6293300cc297b16a5 +F tool/showlocks.c 9920bcc64f58378ff1118caead34147201f48c68 F tool/showstat4.c 9515faa8ec176599d4a8288293ba8ec61f7b728a F tool/showwal.c 85cb36d4fe3e93e2fbd63e786e0d1ce42d0c4fad F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe @@ -1248,7 +1249,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 30011ad2f55cfcacaf23a58ebcc17b17a7b9355e -R 0b149500fabb905b0771216875924384 -U dan -Z 259e8553f23f2ead0f4917d2e8d05aa6 +P 90701227085b8b8eb10a8eebe8d55f38b4778574 +R f70ddacff9e1db6211fe7e92067ecf89 +U drh +Z 4cde991c3d8a79a805d8a208c5613c13 diff --git a/manifest.uuid b/manifest.uuid index 67f1e1b12f..1722db95be 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -90701227085b8b8eb10a8eebe8d55f38b4778574 \ No newline at end of file +6868cc66d2be67b7f03776c982962ffa4b30de11 \ No newline at end of file diff --git a/tool/showlocks.c b/tool/showlocks.c new file mode 100644 index 0000000000..752c535cc3 --- /dev/null +++ b/tool/showlocks.c @@ -0,0 +1,64 @@ +/* +** This file implements a simple command-line utility that shows all of the +** Posix Advisory Locks on a file. +** +** Usage: +** +** showlocks FILENAME +** +** To compile: gcc -o showlocks showlocks.c +*/ +#include +#include +#include +#include +#include + +/* This utility only looks for locks in the first 2 billion bytes */ +#define MX_LCK 2147483647 + +/* +** Print all locks on the inode of "fd" that occur in between +** lwr and upr, inclusive. +*/ +static int showLocksInRange(int fd, off_t lwr, off_t upr){ + int cnt = 0; + struct flock x; + + x.l_type = F_WRLCK; + x.l_whence = SEEK_SET; + x.l_start = lwr; + x.l_len = upr-lwr; + fcntl(fd, F_GETLK, &x); + if( x.l_type==F_UNLCK ) return 0; + printf("start: %-12d len: %-5d pid: %-5d type: %s\n", + (int)x.l_start, (int)x.l_len, + x.l_pid, x.l_type==F_WRLCK ? "WRLCK" : "RDLCK"); + cnt++; + if( x.l_start>lwr ){ + cnt += showLocksInRange(fd, lwr, x.l_start-1); + } + if( x.l_start+x.l_len Date: Fri, 3 Apr 2015 20:33:33 +0000 Subject: [PATCH 57/63] Disable the SQLITE_FCNTL_WAL_BLOCK feature for now. It needs more work and is not yet ready for release. FossilOrigin-Name: 4ae9a3acc4eeeb7998769eb856c97c2233476f72 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/os_unix.c | 2 +- test/walblock.test | 5 +---- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 73436f25df..31dda70760 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\ssource\scode\sto\sthe\s"showlocks"\sutility\sprogram\sin\sthe\stool/\ssubdirectory. -D 2015-04-03T18:33:40.031 +C Disable\sthe\sSQLITE_FCNTL_WAL_BLOCK\sfeature\sfor\snow.\s\sIt\sneeds\smore\swork\sand\nis\snot\syet\sready\sfor\srelease. +D 2015-04-03T20:33:33.240 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,7 +214,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c a4dadbc2da41599e99093e91e276c38c17a73b89 +F src/os_unix.c 25b80a3d167da44226a2084dc9e89a6cb1f02e2e F src/os_win.c 03d27be3a20048ef52a648d5f0a15f5edda9f2a3 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 4120a49ecd37697e28f5ed807f470b9c0b88410c @@ -1144,7 +1144,7 @@ F test/wal9.test 378e76a9ad09cd9bee06c172ad3547b0129a6750 F test/wal_common.tcl a98f17fba96206122eff624db0ab13ec377be4fe F test/walbak.test b9f68e39646375c2b877be906babcc15d38b4877 F test/walbig.test f437473a16cfb314867c6b5d1dbcd519e73e3434 -F test/walblock.test ffc761cd467a93ccd8cd998a23be2f21b95a83b1 +F test/walblock.test be48f3a75eff0b4456209f26b3ce186c2015497d F test/walcksum.test 9afeb96240296c08c72fc524d199c912cfe34daa F test/walcrash.test 451d79e528add5c42764cea74aa2750754171b25 F test/walcrash2.test a0edab4e5390f03b99a790de89aad15d6ec70b36 @@ -1249,7 +1249,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 90701227085b8b8eb10a8eebe8d55f38b4778574 -R f70ddacff9e1db6211fe7e92067ecf89 +P 6868cc66d2be67b7f03776c982962ffa4b30de11 +R f821ca69e41f19033ce555eacc91c4ed U drh -Z 4cde991c3d8a79a805d8a208c5613c13 +Z 7ec9ecc18bf834ba571fcbb8e1e49df1 diff --git a/manifest.uuid b/manifest.uuid index 1722db95be..174ac4daaf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6868cc66d2be67b7f03776c982962ffa4b30de11 \ No newline at end of file +4ae9a3acc4eeeb7998769eb856c97c2233476f72 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index a9c883a935..1d867d7cd8 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -3783,7 +3783,7 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){ unixFile *pFile = (unixFile*)id; switch( op ){ case SQLITE_FCNTL_WAL_BLOCK: { - pFile->ctrlFlags |= UNIXFILE_BLOCK; + /* pFile->ctrlFlags |= UNIXFILE_BLOCK; // Deferred feature */ return SQLITE_OK; } case SQLITE_FCNTL_LOCKSTATE: { diff --git a/test/walblock.test b/test/walblock.test index 0b0b2241e6..23167a8830 100644 --- a/test/walblock.test +++ b/test/walblock.test @@ -15,6 +15,7 @@ source $testdir/tester.tcl source $testdir/lock_common.tcl source $testdir/wal_common.tcl +finish_test; return; # Feature currently not implemented. ifcapable !wal {finish_test ; return } if {$::tcl_platform(platform)!="unix"} { finish_test ; return } set testprefix walblock @@ -111,7 +112,3 @@ do_test "1.2.3.(blocking 0.5 seconds)" { finish_test - - - - From b33c50f215b45acd1b6f47008562e64d895d3fba Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 4 Apr 2015 16:43:16 +0000 Subject: [PATCH 58/63] Fix a problem with resolving ORDER BY clauses that feature COLLATE clauses attached to compound SELECT statements. FossilOrigin-Name: 427b50fba7362e5b447e79d39050f25ed2ef10af --- manifest | 23 ++++++++++-------- manifest.uuid | 2 +- src/resolve.c | 25 ++++++++++++++++++++ src/select.c | 2 ++ src/sqliteInt.h | 1 + test/selectA.test | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 102 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 31dda70760..ad90ce9662 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Disable\sthe\sSQLITE_FCNTL_WAL_BLOCK\sfeature\sfor\snow.\s\sIt\sneeds\smore\swork\sand\nis\snot\syet\sready\sfor\srelease. -D 2015-04-03T20:33:33.240 +C Fix\sa\sproblem\swith\sresolving\sORDER\sBY\sclauses\sthat\sfeature\sCOLLATE\sclauses\sattached\sto\scompound\sSELECT\sstatements. +D 2015-04-04T16:43:16.254 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -228,14 +228,14 @@ F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 F src/printf.c 8da9a2687a396daa19860f4dc90975d319304744 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 -F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b +F src/resolve.c 41aa91af56d960e9414ce1d7c17cfb68e0d1c6cb F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 72ffb62e2879956302140e9f6e6ae88aee36b0e5 +F src/select.c c28c52e353287434fac8473e56ee4be848d12c9d F src/shell.c 84a1593bd86aaa14f4da8a8f9b16fbc239d262aa F src/sqlite.h.in 278602140d49575e8708e643161f4263e428a02a F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h d02d2b85cb02a38bc442cf9302ec8209baf6771d +F src/sqliteInt.h 107b02ed6c64162b653acc2368e982de529e14f6 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 F src/table.c e7a09215315a978057fb42c640f890160dbcc45e @@ -845,7 +845,7 @@ F test/select6.test 39eac4a5c03650b2b473c532882273283ee8b7a0 F test/select7.test 7fd2ef598cfabb6b9ff6ac13973b91d0527df49d F test/select8.test 391de11bdd52339c30580dabbbbe97e3e9a3c79d F test/select9.test aebc2bb0c3bc44606125033cbcaac2c8d1f33a95 -F test/selectA.test 64b88a80271c1710966e50e633380696b60a12a4 +F test/selectA.test e452bdb975f488ea46d091382a9185b5853ed2c7 F test/selectB.test 954e4e49cf1f896d61794e440669e03a27ceea25 F test/selectC.test 871fb55d884d3de5943c4057ebd22c2459e71977 F test/selectD.test b0f02a04ef7737decb24e08be2c39b9664b43394 @@ -1249,7 +1249,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 6868cc66d2be67b7f03776c982962ffa4b30de11 -R f821ca69e41f19033ce555eacc91c4ed -U drh -Z 7ec9ecc18bf834ba571fcbb8e1e49df1 +P 4ae9a3acc4eeeb7998769eb856c97c2233476f72 +R 0a683c8bd67cbd2be5ea29e95266b636 +T *branch * compound-order-by-fix +T *sym-compound-order-by-fix * +T -sym-trunk * +U dan +Z 235b3663512a162fe4fda68eec524b54 diff --git a/manifest.uuid b/manifest.uuid index 174ac4daaf..dcc45e2918 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4ae9a3acc4eeeb7998769eb856c97c2233476f72 \ No newline at end of file +427b50fba7362e5b447e79d39050f25ed2ef10af \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index 47df7243f8..a7b14cd005 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -1186,6 +1186,20 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ sqlite3ResolveExprNames(&sNC, p->pOffset) ){ return WRC_Abort; } + + /* If the SF_Converted flags is set, then this Select object was + ** was created by the convertCompoundSelectToSubquery() function. + ** In this case the ORDER BY clause (p->pOrderBy) should be resolved + ** as if it were part of the sub-query, not the parent. This block + ** moves the pOrderBy down to the sub-query. It will be moved back + ** after the names have been resolved. */ + if( p->selFlags & SF_Converted ){ + Select *pSub = p->pSrc->a[0].pSelect; + assert( p->pSrc->nSrc==1 && isCompound==0 && p->pOrderBy ); + assert( pSub->pPrior && pSub->pOrderBy==0 ); + pSub->pOrderBy = p->pOrderBy; + p->pOrderBy = 0; + } /* Recursively resolve names in all subqueries */ @@ -1268,6 +1282,17 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ sNC.pNext = 0; sNC.ncFlags |= NC_AllowAgg; + /* If this is a converted compound query, move the ORDER BY clause from + ** the sub-query back to the parent query. At this point each term + ** within the ORDER BY clause has been transformed to an integer value. + ** These integers will be replaced by copies of the corresponding result + ** set expressions by the call to resolveOrderGroupBy() below. */ + if( p->selFlags & SF_Converted ){ + Select *pSub = p->pSrc->a[0].pSelect; + p->pOrderBy = pSub->pOrderBy; + pSub->pOrderBy = 0; + } + /* Process the ORDER BY clause for singleton SELECT statements. ** The ORDER BY clause for compounds SELECT statements is handled ** below, after all of the result-sets for all of the elements of diff --git a/src/select.c b/src/select.c index 8fd0f15918..90aaa842a6 100644 --- a/src/select.c +++ b/src/select.c @@ -3884,6 +3884,8 @@ static int convertCompoundSelectToSubquery(Walker *pWalker, Select *p){ p->pPrior = 0; p->pNext = 0; p->selFlags &= ~SF_Compound; + assert( (p->selFlags & SF_Converted)==0 ); + p->selFlags |= SF_Converted; assert( pNew->pPrior!=0 ); pNew->pPrior->pNext = pNew; pNew->pLimit = 0; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 3841c91f14..1c0ad44e3a 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2389,6 +2389,7 @@ struct Select { #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */ #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */ #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */ +#define SF_Converted 0x2000 /* By convertCompoundSelectToSubquery() */ /* diff --git a/test/selectA.test b/test/selectA.test index 6e593e8e22..0338338902 100644 --- a/test/selectA.test +++ b/test/selectA.test @@ -1375,4 +1375,64 @@ do_execsql_test 4.2.2 { } {/2 . 3 . 4 . 5 . 6 . 7 ./} +proc strip_rnd {explain} { + regexp -all {sqlite_sq_[0123456789ABCDEF]*} $explain sqlite_sq +} + +proc do_same_test {tn q1 args} { + set r2 [strip_rnd [db eval "EXPLAIN $q1"]] + set i 1 + foreach q $args { + set tst [subst -nocommands {strip_rnd [db eval "EXPLAIN $q"]}] + uplevel do_test $tn.$i [list $tst] [list $r2] + incr i + } +} + +do_execsql_test 5.0 { + CREATE TABLE t8(a, b); + CREATE TABLE t9(c, d); +} {} + +do_same_test 5.1 { + SELECT a, b FROM t8 INTERSECT SELECT c, d FROM t9 ORDER BY a; +} { + SELECT a, b FROM t8 INTERSECT SELECT c, d FROM t9 ORDER BY t8.a; +} { + SELECT a, b FROM t8 INTERSECT SELECT c, d FROM t9 ORDER BY 1; +} { + SELECT a, b FROM t8 INTERSECT SELECT c, d FROM t9 ORDER BY c; +} { + SELECT a, b FROM t8 INTERSECT SELECT c, d FROM t9 ORDER BY t9.c; +} + +do_same_test 5.2 { + SELECT a, b FROM t8 UNION SELECT c, d FROM t9 ORDER BY a COLLATE NOCASE +} { + SELECT a, b FROM t8 UNION SELECT c, d FROM t9 ORDER BY t8.a COLLATE NOCASE +} { + SELECT a, b FROM t8 UNION SELECT c, d FROM t9 ORDER BY 1 COLLATE NOCASE +} { + SELECT a, b FROM t8 UNION SELECT c, d FROM t9 ORDER BY c COLLATE NOCASE +} { + SELECT a, b FROM t8 UNION SELECT c, d FROM t9 ORDER BY t9.c COLLATE NOCASE +} + +do_same_test 5.3 { + SELECT a, b FROM t8 EXCEPT SELECT c, d FROM t9 ORDER BY b, c COLLATE NOCASE +} { + SELECT a, b FROM t8 EXCEPT SELECT c, d FROM t9 ORDER BY 2, 1 COLLATE NOCASE +} { + SELECT a, b FROM t8 EXCEPT SELECT c, d FROM t9 ORDER BY d, a COLLATE NOCASE +} { + SELECT a, b FROM t8 EXCEPT SELECT * FROM t9 ORDER BY t9.d, c COLLATE NOCASE +} { + SELECT * FROM t8 EXCEPT SELECT c, d FROM t9 ORDER BY d, t8.a COLLATE NOCASE +} + +do_catchsql_test 5.4 { + SELECT * FROM t8 UNION SELECT * FROM t9 ORDER BY a+b COLLATE NOCASE +} {1 {1st ORDER BY term does not match any column in the result set}} + + finish_test From 4b0000c9a89800c2c7603b2fd722431776685d52 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 6 Apr 2015 09:05:29 +0000 Subject: [PATCH 59/63] Fix a problem with fts3 prefix terms within phrase queries on "order=DESC" tables with a mix of negative and positive rowids. FossilOrigin-Name: 0cdf502885ea7e5805d7ba3719f055f5d48fc78d --- ext/fts3/fts3.c | 57 ++++++++++++++++++++++++++++++++++++-------- manifest | 17 +++++++------ manifest.uuid | 2 +- test/fts3prefix.test | 18 ++++++++++++++ 4 files changed, 76 insertions(+), 18 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 46b499e96b..7a15379b83 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -2502,26 +2502,33 @@ static int fts3DoclistOrMerge( ** ** The right-hand input doclist is overwritten by this function. */ -static void fts3DoclistPhraseMerge( +static int fts3DoclistPhraseMerge( int bDescDoclist, /* True if arguments are desc */ int nDist, /* Distance from left to right (1=adjacent) */ char *aLeft, int nLeft, /* Left doclist */ - char *aRight, int *pnRight /* IN/OUT: Right/output doclist */ + char **paRight, int *pnRight /* IN/OUT: Right/output doclist */ ){ sqlite3_int64 i1 = 0; sqlite3_int64 i2 = 0; sqlite3_int64 iPrev = 0; + char *aRight = *paRight; char *pEnd1 = &aLeft[nLeft]; char *pEnd2 = &aRight[*pnRight]; char *p1 = aLeft; char *p2 = aRight; char *p; int bFirstOut = 0; - char *aOut = aRight; + char *aOut; assert( nDist>0 ); - + if( bDescDoclist ){ + aOut = sqlite3_malloc(*pnRight + FTS3_VARINT_MAX); + if( aOut==0 ) return SQLITE_NOMEM; + }else{ + aOut = aRight; + } p = aOut; + fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1); fts3GetDeltaVarint3(&p2, pEnd2, 0, &i2); @@ -2550,6 +2557,12 @@ static void fts3DoclistPhraseMerge( } *pnRight = (int)(p - aOut); + if( bDescDoclist ){ + sqlite3_free(aRight); + *paRight = aOut; + } + + return SQLITE_OK; } /* @@ -2674,8 +2687,22 @@ static int fts3TermSelectMerge( ){ if( pTS->aaOutput[0]==0 ){ /* If this is the first term selected, copy the doclist to the output - ** buffer using memcpy(). */ - pTS->aaOutput[0] = sqlite3_malloc(nDoclist); + ** buffer using memcpy(). + ** + ** Add FTS3_VARINT_MAX bytes of unused space to the end of the + ** allocation. This is so as to ensure that the buffer is big enough + ** to hold the current doclist AND'd with any other doclist. If the + ** doclists are stored in order=ASC order, this padding would not be + ** required (since the size of [doclistA AND doclistB] is always less + ** than or equal to the size of [doclistA] in that case). But this is + ** not true for order=DESC. For example, a doclist containing (1, -1) + ** may be smaller than (-1), as in the first example the -1 may be stored + ** as a single-byte delta, whereas in the second it must be stored as a + ** FTS3_VARINT_MAX byte varint. + ** + ** Similar padding is added in the fts3DoclistOrMerge() function. + */ + pTS->aaOutput[0] = sqlite3_malloc(nDoclist + FTS3_VARINT_MAX + 1); pTS->anOutput[0] = nDoclist; if( pTS->aaOutput[0] ){ memcpy(pTS->aaOutput[0], aDoclist, nDoclist); @@ -3931,14 +3958,17 @@ static void fts3EvalAllocateReaders( ** This function assumes that pList points to a buffer allocated using ** sqlite3_malloc(). This function takes responsibility for eventually ** freeing the buffer. +** +** SQLITE_OK is returned if successful, or SQLITE_NOMEM if an error occurs. */ -static void fts3EvalPhraseMergeToken( +static int fts3EvalPhraseMergeToken( Fts3Table *pTab, /* FTS Table pointer */ Fts3Phrase *p, /* Phrase to merge pList/nList into */ int iToken, /* Token pList/nList corresponds to */ char *pList, /* Pointer to doclist */ int nList /* Number of bytes in pList */ ){ + int rc = SQLITE_OK; assert( iToken!=p->iDoclistToken ); if( pList==0 ){ @@ -3977,13 +4007,16 @@ static void fts3EvalPhraseMergeToken( nDiff = p->iDoclistToken - iToken; } - fts3DoclistPhraseMerge(pTab->bDescIdx, nDiff, pLeft, nLeft, pRight,&nRight); + rc = fts3DoclistPhraseMerge( + pTab->bDescIdx, nDiff, pLeft, nLeft, &pRight, &nRight + ); sqlite3_free(pLeft); p->doclist.aAll = pRight; p->doclist.nAll = nRight; } if( iToken>p->iDoclistToken ) p->iDoclistToken = iToken; + return rc; } /* @@ -4009,7 +4042,7 @@ static int fts3EvalPhraseLoad( char *pThis = 0; rc = fts3TermSelect(pTab, pToken, p->iColumn, &nThis, &pThis); if( rc==SQLITE_OK ){ - fts3EvalPhraseMergeToken(pTab, p, iToken, pThis, nThis); + rc = fts3EvalPhraseMergeToken(pTab, p, iToken, pThis, nThis); } } assert( pToken->pSegcsr==0 ); @@ -4811,9 +4844,13 @@ static int fts3EvalSelectDeferred( char *pList = 0; rc = fts3TermSelect(pTab, pToken, pTC->iCol, &nList, &pList); assert( rc==SQLITE_OK || pList==0 ); + if( rc==SQLITE_OK ){ + rc = fts3EvalPhraseMergeToken( + pTab, pTC->pPhrase, pTC->iToken,pList,nList + ); + } if( rc==SQLITE_OK ){ int nCount; - fts3EvalPhraseMergeToken(pTab, pTC->pPhrase, pTC->iToken,pList,nList); nCount = fts3DoclistCountDocids( pTC->pPhrase->doclist.aAll, pTC->pPhrase->doclist.nAll ); diff --git a/manifest b/manifest index 762233f676..12c20e5b8a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\swith\sresolving\sORDER\sBY\sclauses\sthat\sfeature\sCOLLATE\sclauses\sattached\sto\scompound\sSELECT\sstatements. -D 2015-04-04T16:49:04.697 +C Fix\sa\sproblem\swith\sfts3\sprefix\sterms\swithin\sphrase\squeries\son\s"order=DESC"\stables\swith\sa\smix\sof\snegative\sand\spositive\srowids. +D 2015-04-06T09:05:29.052 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -78,7 +78,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c d3f6f0e95d366f3c2028d916c36a0844bf805840 +F ext/fts3/fts3.c 23bd9d37a777342f5c22a648e9b4b005dde9e58f F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 394858c12a17740f7a1f6bd372c4606d4425a8d1 F ext/fts3/fts3_aux.c 5c211e17a64885faeb16b9ba7772f9d5445c2365 @@ -594,7 +594,7 @@ F test/fts3join.test 53e66a0c21eb568580674a43b21c059acb26f499 F test/fts3malloc.test b0e4c133b8d61d4f6d112d8110f8320e9e453ef6 F test/fts3matchinfo.test 58544fa4d254000fa4e7f494b0a832f7ba61d45e F test/fts3near.test 7e3354d46f155a822b59c0e957fd2a70c1d7e905 -F test/fts3prefix.test 9f68e3598a139c23ec47d09299420e0fc4c72a83 +F test/fts3prefix.test fa794eaab0bdae466494947b0b153d7844478ab2 F test/fts3prefix2.test e1f0a822ca661dced7f12ce392e14eaf65609dce F test/fts3query.test c838b18f2b859e15fd31c64be3d79ef1556803ca F test/fts3rnd.test 1320d8826a845e38a96e769562bf83d7a92a15d0 @@ -1249,7 +1249,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 4ae9a3acc4eeeb7998769eb856c97c2233476f72 427b50fba7362e5b447e79d39050f25ed2ef10af -R 0a683c8bd67cbd2be5ea29e95266b636 +P edc1de2a588fd50c0049bb2be76d3f6783443165 +R a8252a4468bea13d638722c58d3ce9cc +T *branch * fts3-prefix-query-fix +T *sym-fts3-prefix-query-fix * +T -sym-trunk * U dan -Z c9ac74415bdb7893d918eacf5a95862c +Z 7c1c374a4c4efe674ae583b0f9d983d2 diff --git a/manifest.uuid b/manifest.uuid index ff36ec293f..2a42d14f33 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -edc1de2a588fd50c0049bb2be76d3f6783443165 \ No newline at end of file +0cdf502885ea7e5805d7ba3719f055f5d48fc78d \ No newline at end of file diff --git a/test/fts3prefix.test b/test/fts3prefix.test index 8ffabe8d65..e8d2b2b5fb 100644 --- a/test/fts3prefix.test +++ b/test/fts3prefix.test @@ -274,4 +274,22 @@ do_execsql_test 6.5.2 { SELECT md5sum(quote(root)) FROM t1_segdir; } [db eval {SELECT md5sum(quote(root)) FROM t2_segdir}] + +do_execsql_test 7.0 { + CREATE VIRTUAL TABLE t6 USING fts4(x,order=DESC); + INSERT INTO t6(docid, x) VALUES(-1,'a b'); + INSERT INTO t6(docid, x) VALUES(1, 'b'); +} +do_execsql_test 7.1 { + SELECT docid FROM t6 WHERE t6 MATCH '"a* b"'; +} {-1} +do_execsql_test 7.2 { + SELECT docid FROM t6 WHERE t6 MATCH 'a*'; +} {-1} +do_execsql_test 7.3 { + SELECT docid FROM t6 WHERE t6 MATCH 'a* b'; +} {-1} + + + finish_test From 74b42275eca70ba323730c5a1088f1baf9937383 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 7 Apr 2015 12:41:17 +0000 Subject: [PATCH 60/63] Guard against excessive width and precision in floating-point conversions in the printf routines. FossilOrigin-Name: c494171f77dc2e5e04cb6d865e688448f04e5920 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/printf.c | 7 ++++--- test/printf.test | 3 +++ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 839dc44cc6..31581470a9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\swith\sfts3\sprefix\sterms\swithin\sphrase\squeries\son\s"order=DESC"\stables\swith\sa\smix\sof\snegative\sand\spositive\srowids. -D 2015-04-06T11:04:51.176 +C Guard\sagainst\sexcessive\swidth\sand\sprecision\sin\sfloating-point\sconversions\nin\sthe\sprintf\sroutines. +D 2015-04-07T12:41:17.461 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -226,7 +226,7 @@ F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 F src/pragma.c ac4f3f856b4234e85f55b0f069698a4766011100 F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 -F src/printf.c 8da9a2687a396daa19860f4dc90975d319304744 +F src/printf.c 32f69fcba9ddfb71f9466b867f7ee7b7ffee30de F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 41aa91af56d960e9414ce1d7c17cfb68e0d1c6cb F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e @@ -797,7 +797,7 @@ F test/permutations.test f9cc1dd987986c9d4949211c7a4ed55ec9aecba1 F test/pragma.test ad99d05e411c7687302124be56f3b362204be041 F test/pragma2.test f624a496a95ee878e81e59961eade66d5c00c028 F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c -F test/printf.test ec9870c4dce8686a37818e0bf1aba6e6a1863552 +F test/printf.test 2f11179e8b7210f3ea262d96b7f7b4cb78b34500 F test/printf2.test b4acd4bf8734243257f01ddefa17c4fb090acc8a F test/progress.test a282973d1d17f08071bc58a77d6b80f2a81c354d F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc @@ -1249,7 +1249,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P edc1de2a588fd50c0049bb2be76d3f6783443165 0cdf502885ea7e5805d7ba3719f055f5d48fc78d -R 3d0aeff53f9d343a974360d23614c066 -U dan -Z ac6175e8f164395f5f3f99cbe84625aa +P 3ad829e50faca538db3abb2afb898b5521550c5c +R 1f357953eb69048c3e73348b4613f5e5 +U drh +Z 21bd74616576d30557b17c20f6eb18f9 diff --git a/manifest.uuid b/manifest.uuid index 60fdaf0098..45e0581d32 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3ad829e50faca538db3abb2afb898b5521550c5c \ No newline at end of file +c494171f77dc2e5e04cb6d865e688448f04e5920 \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index 81efa057fc..0ff9887eb7 100644 --- a/src/printf.c +++ b/src/printf.c @@ -450,7 +450,7 @@ void sqlite3VXPrintf( else prefix = 0; } if( xtype==etGENERIC && precision>0 ) precision--; - for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1){} + for(idx=precision&0xfff, rounder=0.5; idx>0; idx--, rounder*=0.1){} if( xtype==etFLOAT ) realvalue += rounder; /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */ exp = 0; @@ -505,8 +505,9 @@ void sqlite3VXPrintf( }else{ e2 = exp; } - if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){ - bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 ); + if( MAX(e2,0)+(i64)precision+(i64)width > etBUFSIZE - 15 ){ + bufpt = zExtra + = sqlite3Malloc( MAX(e2,0)+(i64)precision+(i64)width+15 ); if( bufpt==0 ){ setStrAccumError(pAccum, STRACCUM_NOMEM); return; diff --git a/test/printf.test b/test/printf.test index 73222720ab..5dfc6d06cf 100644 --- a/test/printf.test +++ b/test/printf.test @@ -526,6 +526,9 @@ do_test printf-2.1.2.8 { do_test printf-2.1.2.9 { sqlite3_mprintf_double {abc: %d %d (%1.1g) :xyz} 1 1 1.0e-20 } {abc: 1 1 (1e-20) :xyz} +do_test printf-2.1.2.10 { + sqlite3_mprintf_double {abc: %*.*f} 2000000000 1000000000 1.0e-20 +} {abc: } do_test printf-2.1.3.1 { sqlite3_mprintf_double {abc: (%*.*f) :xyz} 1 1 1.0 } {abc: (1.0) :xyz} From a30d22a7a6b1eff78d2869ab4e56782522d5a758 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 7 Apr 2015 13:28:41 +0000 Subject: [PATCH 61/63] Further changes to guard against integer overflow in the width and precision of printf() arguments. FossilOrigin-Name: 5ce4e7d7651e5c72a59f03f7aeb366291e62ab57 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/printf.c | 9 +++++++-- test/printf.test | 21 +++++++++++++++++++++ 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 31581470a9..3aa52a9c50 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Guard\sagainst\sexcessive\swidth\sand\sprecision\sin\sfloating-point\sconversions\nin\sthe\sprintf\sroutines. -D 2015-04-07T12:41:17.461 +C Further\schanges\sto\sguard\sagainst\sinteger\soverflow\sin\sthe\swidth\sand\sprecision\nof\sprintf()\sarguments. +D 2015-04-07T13:28:41.878 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -226,7 +226,7 @@ F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 F src/pragma.c ac4f3f856b4234e85f55b0f069698a4766011100 F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 -F src/printf.c 32f69fcba9ddfb71f9466b867f7ee7b7ffee30de +F src/printf.c 0f3476d9c8befc12708a3d614c22859b0cb79f19 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 41aa91af56d960e9414ce1d7c17cfb68e0d1c6cb F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e @@ -797,7 +797,7 @@ F test/permutations.test f9cc1dd987986c9d4949211c7a4ed55ec9aecba1 F test/pragma.test ad99d05e411c7687302124be56f3b362204be041 F test/pragma2.test f624a496a95ee878e81e59961eade66d5c00c028 F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c -F test/printf.test 2f11179e8b7210f3ea262d96b7f7b4cb78b34500 +F test/printf.test 5ab2b4666ca544645c4af2d78198f93b1e030d6e F test/printf2.test b4acd4bf8734243257f01ddefa17c4fb090acc8a F test/progress.test a282973d1d17f08071bc58a77d6b80f2a81c354d F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc @@ -1249,7 +1249,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 3ad829e50faca538db3abb2afb898b5521550c5c -R 1f357953eb69048c3e73348b4613f5e5 +P c494171f77dc2e5e04cb6d865e688448f04e5920 +R 7b4db908cf9a9f885bafc7fac7b1a77f U drh -Z 21bd74616576d30557b17c20f6eb18f9 +Z 16061aae0366142fcfaf02b796330263 diff --git a/manifest.uuid b/manifest.uuid index 45e0581d32..dddcbe141c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c494171f77dc2e5e04cb6d865e688448f04e5920 \ No newline at end of file +5ce4e7d7651e5c72a59f03f7aeb366291e62ab57 \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index 0ff9887eb7..13eb491cda 100644 --- a/src/printf.c +++ b/src/printf.c @@ -390,6 +390,7 @@ void sqlite3VXPrintf( if( precision0 ) precision--; + testcase( precision>0xfff ); for(idx=precision&0xfff, rounder=0.5; idx>0; idx--, rounder*=0.1){} if( xtype==etFLOAT ) realvalue += rounder; /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */ @@ -739,7 +741,7 @@ void sqlite3VXPrintf( */ static int sqlite3StrAccumEnlarge(StrAccum *p, int N){ char *zNew; - assert( p->nChar+N >= p->nAlloc ); /* Only called if really needed */ + assert( p->nChar+(i64)N >= p->nAlloc ); /* Only called if really needed */ if( p->accError ){ testcase(p->accError==STRACCUM_TOOBIG); testcase(p->accError==STRACCUM_NOMEM); @@ -788,7 +790,10 @@ static int sqlite3StrAccumEnlarge(StrAccum *p, int N){ ** Append N copies of character c to the given string buffer. */ void sqlite3AppendChar(StrAccum *p, int N, char c){ - if( p->nChar+N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ) return; + testcase( p->nChar + (i64)N > 0x7fffffff ); + if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){ + return; + } while( (N--)>0 ) p->zText[p->nChar++] = c; } diff --git a/test/printf.test b/test/printf.test index 5dfc6d06cf..dadc23194e 100644 --- a/test/printf.test +++ b/test/printf.test @@ -472,6 +472,18 @@ do_test printf-1.16.7 { sqlite3_mprintf_int {abc: (%#6d) (%#6x) (%#6o) :xyz}\ 0xff676981 0xff676981 0xff676981 } {abc: (-9999999) (0xff676981) (037731664601) :xyz} +do_test printf-1.17.1 { + sqlite3_mprintf_int {abd: %2147483647d %2147483647x %2147483647o} 1 1 1 +} {} +do_test printf-1.17.2 { + sqlite3_mprintf_int {abd: %*d %x} 2147483647 1 1 +} {} +do_test printf-1.17.3 { + sqlite3_mprintf_int {abd: %*d %x} -2147483648 1 1 +} {} +do_test printf-1.17.4 { + sqlite3_mprintf_int {abd: %.2147483648d %x %x} 1 1 1 +} {abd: 1 1 1} do_test printf-2.1.1.1 { sqlite3_mprintf_double {abc: (%*.*f) :xyz} 1 1 0.001 } {abc: (0.0) :xyz} @@ -3469,6 +3481,15 @@ do_test printf-3.5 { do_test printf-3.6 { sqlite3_mprintf_str {%d %d A String: (%-30s)} 1 2 {This is the string} } [format {%d %d A String: (%-30s)} 1 2 {This is the string}] +do_test printf-3.7 { + sqlite3_mprintf_str {%d A String: (%*s)} 1 2147483647 {This is the string} +} [] +do_test printf-3.8 { + sqlite3_mprintf_str {%d A String: (%*s)} 1 -2147483648 {This is the string} +} [] +do_test printf-3.9 { + sqlite3_mprintf_str {%d A String: (%.*s)} 1 -2147483648 {This is the string} +} {1 A String: (This is the string)} do_test snprintf-3.11 { sqlite3_snprintf_str 2 {x%d %d %s} 10 10 {This is the string} } {x} From 8c069147cecc868648b2ef701b77d74be073095f Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 7 Apr 2015 14:38:57 +0000 Subject: [PATCH 62/63] Another change to avoid a problem caused by integer overflow in the printf() code. FossilOrigin-Name: 95625ef3adc3c408d67e70f877f390445fbb8292 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/printf.c | 10 ++++++++-- test/printf.test | 9 ++++++--- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 3aa52a9c50..476d45c6a9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Further\schanges\sto\sguard\sagainst\sinteger\soverflow\sin\sthe\swidth\sand\sprecision\nof\sprintf()\sarguments. -D 2015-04-07T13:28:41.878 +C Another\schange\sto\savoid\sa\sproblem\scaused\sby\sinteger\soverflow\sin\sthe\sprintf()\scode. +D 2015-04-07T14:38:57.638 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -226,7 +226,7 @@ F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 F src/pragma.c ac4f3f856b4234e85f55b0f069698a4766011100 F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 -F src/printf.c 0f3476d9c8befc12708a3d614c22859b0cb79f19 +F src/printf.c 62f93b9276807b053e9c9625b48f4843ef82e978 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 41aa91af56d960e9414ce1d7c17cfb68e0d1c6cb F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e @@ -797,7 +797,7 @@ F test/permutations.test f9cc1dd987986c9d4949211c7a4ed55ec9aecba1 F test/pragma.test ad99d05e411c7687302124be56f3b362204be041 F test/pragma2.test f624a496a95ee878e81e59961eade66d5c00c028 F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c -F test/printf.test 5ab2b4666ca544645c4af2d78198f93b1e030d6e +F test/printf.test b38d5d81a8cc20a040667c9acad68ddf5b18ccdd F test/printf2.test b4acd4bf8734243257f01ddefa17c4fb090acc8a F test/progress.test a282973d1d17f08071bc58a77d6b80f2a81c354d F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc @@ -1249,7 +1249,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c494171f77dc2e5e04cb6d865e688448f04e5920 -R 7b4db908cf9a9f885bafc7fac7b1a77f -U drh -Z 16061aae0366142fcfaf02b796330263 +P 5ce4e7d7651e5c72a59f03f7aeb366291e62ab57 +R d822c3498c99ae588b224a89f4618062 +U dan +Z d5717f1cffb0747ad695b3c7e862b042 diff --git a/manifest.uuid b/manifest.uuid index dddcbe141c..50a22e5cce 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5ce4e7d7651e5c72a59f03f7aeb366291e62ab57 \ No newline at end of file +95625ef3adc3c408d67e70f877f390445fbb8292 \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index 13eb491cda..3eab6d47d6 100644 --- a/src/printf.c +++ b/src/printf.c @@ -270,6 +270,8 @@ void sqlite3VXPrintf( c = *++fmt; } } + if( width<0 ) width = 0; /* force to non-negative after int overflow */ + /* Get the precision */ if( c=='.' ){ precision = 0; @@ -280,7 +282,6 @@ void sqlite3VXPrintf( }else{ precision = va_arg(ap,int); } - if( precision<0 ) precision = -precision; c = *++fmt; }else{ while( c>='0' && c<='9' ){ @@ -288,6 +289,12 @@ void sqlite3VXPrintf( c = *++fmt; } } + + /* If a negative precision has been specified, use its absolute value + ** instead. This is (probably) not standard printf() behaviour, but + ** it is what sqlite3_mprintf() and friends have always done. If the + ** precision specified is -2147483648, use 0. */ + if( precision<0 ) precision = (-precision) & 0x7fffffff; }else{ precision = -1; } @@ -390,7 +397,6 @@ void sqlite3VXPrintf( if( precision Date: Tue, 7 Apr 2015 15:39:29 +0000 Subject: [PATCH 63/63] Avoid signed integer overflow when converting oversized in-line integer widths and precisions in printf(). FossilOrigin-Name: 8e4ac2ce24415926247961b00a62425ae85d6ffb --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/printf.c | 22 ++++++++++++---------- test/printf.test | 8 ++++---- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/manifest b/manifest index 476d45c6a9..aa53c43007 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Another\schange\sto\savoid\sa\sproblem\scaused\sby\sinteger\soverflow\sin\sthe\sprintf()\scode. -D 2015-04-07T14:38:57.638 +C Avoid\ssigned\sinteger\soverflow\swhen\sconverting\soversized\sin-line\sinteger\nwidths\sand\sprecisions\sin\sprintf(). +D 2015-04-07T15:39:29.937 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -226,7 +226,7 @@ F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 F src/pragma.c ac4f3f856b4234e85f55b0f069698a4766011100 F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f F src/prepare.c 173a5a499138451b2561614ecb87d78f9f4644b9 -F src/printf.c 62f93b9276807b053e9c9625b48f4843ef82e978 +F src/printf.c 8ae1fa9d30c1200a9268a390ba9e9cea9197b27a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 41aa91af56d960e9414ce1d7c17cfb68e0d1c6cb F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e @@ -797,7 +797,7 @@ F test/permutations.test f9cc1dd987986c9d4949211c7a4ed55ec9aecba1 F test/pragma.test ad99d05e411c7687302124be56f3b362204be041 F test/pragma2.test f624a496a95ee878e81e59961eade66d5c00c028 F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c -F test/printf.test b38d5d81a8cc20a040667c9acad68ddf5b18ccdd +F test/printf.test b3ff34e73d59124140eaf89f7672e21bc2ca5fcc F test/printf2.test b4acd4bf8734243257f01ddefa17c4fb090acc8a F test/progress.test a282973d1d17f08071bc58a77d6b80f2a81c354d F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc @@ -1249,7 +1249,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 5ce4e7d7651e5c72a59f03f7aeb366291e62ab57 -R d822c3498c99ae588b224a89f4618062 -U dan -Z d5717f1cffb0747ad695b3c7e862b042 +P 95625ef3adc3c408d67e70f877f390445fbb8292 +R 5875861747bb686954783d9ce4259b86 +U drh +Z e5281cee406ead55e17262e5bdbb2163 diff --git a/manifest.uuid b/manifest.uuid index 50a22e5cce..786af92027 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -95625ef3adc3c408d67e70f877f390445fbb8292 \ No newline at end of file +8e4ac2ce24415926247961b00a62425ae85d6ffb \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index 3eab6d47d6..9714fa1565 100644 --- a/src/printf.c +++ b/src/printf.c @@ -261,16 +261,18 @@ void sqlite3VXPrintf( } if( width<0 ){ flag_leftjustify = 1; - width = -width; + width = width >= -2147483647 ? -width : 0; } c = *++fmt; }else{ + unsigned wx = 0; while( c>='0' && c<='9' ){ - width = width*10 + c - '0'; + wx = wx*10 + c - '0'; c = *++fmt; } + testcase( wx>0x7fffffff ); + width = wx & 0x7fffffff; } - if( width<0 ) width = 0; /* force to non-negative after int overflow */ /* Get the precision */ if( c=='.' ){ @@ -283,18 +285,18 @@ void sqlite3VXPrintf( precision = va_arg(ap,int); } c = *++fmt; + if( precision<0 ){ + precision = precision >= -2147483647 ? -precision : -1; + } }else{ + unsigned px = 0; while( c>='0' && c<='9' ){ - precision = precision*10 + c - '0'; + px = px*10 + c - '0'; c = *++fmt; } + testcase( px>0x7fffffff ); + precision = px & 0x7fffffff; } - - /* If a negative precision has been specified, use its absolute value - ** instead. This is (probably) not standard printf() behaviour, but - ** it is what sqlite3_mprintf() and friends have always done. If the - ** precision specified is -2147483648, use 0. */ - if( precision<0 ) precision = (-precision) & 0x7fffffff; }else{ precision = -1; } diff --git a/test/printf.test b/test/printf.test index 3bf13f4eb9..6103d8acf8 100644 --- a/test/printf.test +++ b/test/printf.test @@ -483,7 +483,7 @@ do_test printf-1.17.3 { } {abd: 1 1} do_test printf-1.17.4 { sqlite3_mprintf_int {abd: %.2147483648d %x %x} 1 1 1 -} {abd: 1 1 1} +} {/.*/} do_test printf-2.1.1.1 { sqlite3_mprintf_double {abc: (%*.*f) :xyz} 1 1 0.001 } {abc: (0.0) :xyz} @@ -3489,7 +3489,7 @@ do_test printf-3.8 { } {1 A String: (This is the string)} do_test printf-3.9 { sqlite3_mprintf_str {%d A String: (%.*s)} 1 -2147483648 {This is the string} -} {1 A String: ()} +} {1 A String: (This is the string)} do_test snprintf-3.11 { sqlite3_snprintf_str 2 {x%d %d %s} 10 10 {This is the string} } {x} @@ -3710,8 +3710,8 @@ do_test printf-13.6 { sqlite3_mprintf_hexdouble %.20f fff8000000000000 } {NaN} do_test printf-13.7 { - sqlite3_mprintf_hexdouble %3000000000.10000f 4693b8b5b5056e17 -} "100000000000000000000000000000000.[string repeat 0 10000]" + sqlite3_mprintf_hexdouble %2147483648.10000f 4693b8b5b5056e17 +} {/100000000000000000000000000000000.00/} do_test printf-14.1 { sqlite3_mprintf_str {abc-%y-123} 0 0 {not used}