diff options
-rw-r--r-- | manifest | 28 | ||||
-rw-r--r-- | manifest.uuid | 2 | ||||
-rw-r--r-- | src/build.c | 10 | ||||
-rw-r--r-- | src/callback.c | 6 | ||||
-rw-r--r-- | src/date.c | 5 | ||||
-rw-r--r-- | src/main.c | 8 | ||||
-rw-r--r-- | src/malloc.c | 4 | ||||
-rw-r--r-- | src/select.c | 3 | ||||
-rw-r--r-- | src/sqliteInt.h | 3 | ||||
-rw-r--r-- | src/test1.c | 16 | ||||
-rw-r--r-- | src/util.c | 126 |
11 files changed, 117 insertions, 94 deletions
@@ -1,5 +1,5 @@ -C More\schanges\sto\sinsert.c\sto\sfacilitate\sfull\scoverage\stesting.\s(CVS\s6596) -D 2009-05-03T01:01:00 +C Changes\sto\sfacility\sfull\scoverage\stesting\sof\sutil.c.\s(CVS\s6597) +D 2009-05-03T20:23:53 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 583e87706abc3026960ed759aff6371faf84c211 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -109,10 +109,10 @@ F src/btmutex.c 9b899c0d8df3bd68f527b0afe03088321b696d3c F src/btree.c 64ad8841aefce2ba0cb3b138e5fe8669ce5fa6db F src/btree.h 99fcc7e8c4a1e35afe271bcb38de1a698dfc904e F src/btreeInt.h df64030d632f8c8ac217ed52e8b6b3eacacb33a5 -F src/build.c 9f00cc9cc0a3e7271dad30cd11915ea1f323174d -F src/callback.c 3aff18ce7ede2baba7c7cad1f55f9d88fa0c323e +F src/build.c 894dc1b8fba81acce54133fd69a40e609248eb38 +F src/callback.c c54a923b06a17a2f965e5c3a6f87a3a963209a4c F src/complete.c 5ad5c6cd4548211867c204c41a126d73a9fbcea0 -F src/date.c d327ec7bb2f64b08d32b1035de82b9ba8675de91 +F src/date.c ab5f7137656652a48434d64f96bdcdc823bb23b3 F src/delete.c a0a0932eea77471ab243337026abbce444024c43 F src/expr.c 40b35167137c53777d15d3247d93615b4eefec2d F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff @@ -125,8 +125,8 @@ F src/insert.c 35d73660090a3b93ee6aa92a54d9dad912ac0197 F src/journal.c e00df0c0da8413ab6e1bb7d7cab5665d4a9000d0 F src/legacy.c 2ad5b52df322d0f132f66817095e0e79c8942611 F src/loadext.c 3f96631089fc4f3871a67f02f2e4fc7ea4d51edc -F src/main.c 27a22ea98931594fcd476c87066a948a2faa53b6 -F src/malloc.c a1f0f8ae110abb8eb546e259ab0eaea7e0f9b588 +F src/main.c a01115fda61971701695fe0d1487e2dfe46a8b1e +F src/malloc.c 7b3b6423f5b355e5d649b91e16ef252d610bcf19 F src/mem0.c f2f84062d1f35814d6535c9f9e33de3bfb3b132c F src/mem1.c e6d5c23941288df8191b8a98c28e3f57771e2270 F src/mem2.c d02bd6a5b34f2d59012a852615621939d9c09548 @@ -158,16 +158,16 @@ F src/printf.c ea2d76000cc5f4579d7e9cb2f5460433eec0d384 F src/random.c 676b9d7ac820fe81e6fb2394ac8c10cff7f38628 F src/resolve.c d01b53d81ab9b28ba7161c1af9e02bc90bbd685b F src/rowset.c 14d12b5e81b5907b87d511f6f4219805f96a4b55 -F src/select.c 84022ec5d41c321e98fa96e4f4d5e44de203a099 +F src/select.c 9587023e906afe2074a718d25d6a4326874fb791 F src/shell.c 0a11f831603f17fea20ca97133c0f64e716af4a7 F src/sqlite.h.in 926985a312747e284c21ab32a8e8231a3bed9bd1 F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17 -F src/sqliteInt.h a734ac9d1c5f0d2b3b1ebc8581e237d1293ae6b7 +F src/sqliteInt.h 2edb5e7e194e8083dad299e282aa0ed5022247b8 F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76 F src/table.c cc86ad3d6ad54df7c63a3e807b5783c90411a08d F src/tclsqlite.c d3195e0738c101a155404ecdb1cd9532a2fd34f2 -F src/test1.c c4d475f899e2160c686449d2b4fea7b846f5bd34 +F src/test1.c c8f9358879876660b721369f576bf6e4ac5b9210 F src/test2.c 71c22e2974f8094fe0fd1eba8f27872dde9b2a39 F src/test3.c d3115b301c6ee761b102f315fe24125f3d6c3a4d F src/test4.c f79ab52d27ff49b784b631a42e2ccd52cfd5c84c @@ -201,7 +201,7 @@ F src/tokenize.c 286ce8a4bffe5ec81ad893e6243684d8f8846ed9 F src/trigger.c 448615bec40efcd6b3a9362a060f2e7067f25be5 F src/update.c 5062f0f042f67a4da0aff69949f145e2bc96e3cd F src/utf.c 9541d28f40441812c0b40f00334372a0542c00ff -F src/util.c b19471b83b77785635172a740b55a0efead3f921 +F src/util.c 40fb962de1b00a310de4acc87c6800173e35c25f F src/vacuum.c 07121a727beeee88f27d704a00313ad6a7c9bef0 F src/vdbe.c 5fe07cce9f010cd052535463bd0348e8d513b448 F src/vdbe.h 35a648bc3279a120da24f34d9a25213ec15daf8a @@ -727,7 +727,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 8f3cac7682a0c992f95f7453aaf9a29b1fe35d6f -R 5c167e348a2d5e3ff2fee4e24ebee7ea +P 46c4ec968bc22843c65744ab4a01ec7ac605567b +R 7b0e588db84d78319007ef42e8ba55fe U drh -Z 9f1931f4a62117e3d94c8c586b5f71f4 +Z 3ad8cae0bb9ab3914b1dbd324f2667b2 diff --git a/manifest.uuid b/manifest.uuid index e173ec388..07e33f213 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -46c4ec968bc22843c65744ab4a01ec7ac605567b
\ No newline at end of file +a612299092a48b38c5f9cf430bbcaf41777cbcb3
\ No newline at end of file diff --git a/src/build.c b/src/build.c index 9dc63a440..065ef5305 100644 --- a/src/build.c +++ b/src/build.c @@ -22,7 +22,7 @@ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.534 2009/05/02 13:29:38 drh Exp $ +** $Id: build.c,v 1.535 2009/05/03 20:23:53 drh Exp $ */ #include "sqliteInt.h" @@ -261,7 +261,7 @@ Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){ int i; int nName; assert( zName!=0 ); - nName = sqlite3Strlen(db, zName); + nName = sqlite3Strlen30(zName); for(i=OMIT_TEMPDB; i<db->nDb; i++){ int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue; @@ -323,7 +323,7 @@ Table *sqlite3LocateTable( Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){ Index *p = 0; int i; - int nName = sqlite3Strlen(db, zName); + int nName = sqlite3Strlen30(zName); for(i=OMIT_TEMPDB; i<db->nDb; i++){ int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ Schema *pSchema = db->aDb[j].pSchema; @@ -375,7 +375,7 @@ void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){ int len; Hash *pHash = &db->aDb[iDb].pSchema->idxHash; - len = sqlite3Strlen(db, zIdxName); + len = sqlite3Strlen30(zIdxName); pIndex = sqlite3HashInsert(pHash, zIdxName, len, 0); if( pIndex ){ if( pIndex->pTable->pIndex==pIndex ){ @@ -1261,7 +1261,7 @@ CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName){ pColl = sqlite3GetCollSeq(db, pColl, zName, nName); if( !pColl ){ if( nName<0 ){ - nName = sqlite3Strlen(db, zName); + nName = sqlite3Strlen30(zName); } sqlite3ErrorMsg(pParse, "no such collation sequence: %.*s", nName, zName); pColl = 0; diff --git a/src/callback.c b/src/callback.c index a95969b1b..2c81c9522 100644 --- a/src/callback.c +++ b/src/callback.c @@ -13,7 +13,7 @@ ** This file contains functions used to access the internal hash tables ** of user defined functions and collation sequences. ** -** $Id: callback.c,v 1.38 2009/05/02 13:29:38 drh Exp $ +** $Id: callback.c,v 1.39 2009/05/03 20:23:53 drh Exp $ */ #include "sqliteInt.h" @@ -25,7 +25,7 @@ */ static void callCollNeeded(sqlite3 *db, const char *zName, int nName){ assert( !db->xCollNeeded || !db->xCollNeeded16 ); - if( nName<0 ) nName = sqlite3Strlen(db, zName); + if( nName<0 ) nName = sqlite3Strlen30(zName); if( db->xCollNeeded ){ char *zExternal = sqlite3DbStrNDup(db, zName, nName); if( !zExternal ) return; @@ -158,7 +158,7 @@ static CollSeq *findCollSeqEntry( int create ){ CollSeq *pColl; - if( nName<0 ) nName = sqlite3Strlen(db, zName); + if( nName<0 ) nName = sqlite3Strlen30(zName); pColl = sqlite3HashFind(&db->aCollSeq, zName, nName); if( 0==pColl && create ){ diff --git a/src/date.c b/src/date.c index a1768040f..bcd0ea86d 100644 --- a/src/date.c +++ b/src/date.c @@ -16,7 +16,7 @@ ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: date.c,v 1.106 2009/04/16 12:58:03 drh Exp $ +** $Id: date.c,v 1.107 2009/05/03 20:23:53 drh Exp $ ** ** SQLite processes all times and dates as Julian Day numbers. The ** dates and times are stored as the number of days since noon @@ -344,6 +344,7 @@ static int parseDateOrTime( const char *zDate, DateTime *p ){ + int isRealNum; /* Return from sqlite3IsNumber(). Not used */ if( parseYyyyMmDd(zDate,p)==0 ){ return 0; }else if( parseHhMmSs(zDate, p)==0 ){ @@ -351,7 +352,7 @@ static int parseDateOrTime( }else if( sqlite3StrICmp(zDate,"now")==0){ setDateTimeToCurrent(context, p); return 0; - }else if( sqlite3IsNumber(zDate, 0, SQLITE_UTF8) ){ + }else if( sqlite3IsNumber(zDate, &isRealNum, SQLITE_UTF8) ){ double r; getValue(zDate, &r); p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5); diff --git a/src/main.c b/src/main.c index cc2a81057..7a1984173 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.545 2009/05/02 13:29:38 drh Exp $ +** $Id: main.c,v 1.546 2009/05/03 20:23:53 drh Exp $ */ #include "sqliteInt.h" @@ -930,7 +930,7 @@ int sqlite3CreateFunc( (!xFunc && (xFinal && !xStep)) || (!xFunc && (!xFinal && xStep)) || (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) || - (255<(nName = sqlite3Strlen(db, zFunctionName))) ){ + (255<(nName = sqlite3Strlen30( zFunctionName))) ){ sqlite3Error(db, SQLITE_ERROR, "bad parameters"); return SQLITE_ERROR; } @@ -1056,7 +1056,7 @@ int sqlite3_overload_function( const char *zName, int nArg ){ - int nName = sqlite3Strlen(db, zName); + int nName = sqlite3Strlen30(zName); int rc; sqlite3_mutex_enter(db->mutex); if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){ @@ -1383,7 +1383,7 @@ static int createCollation( ** sequence. If so, and there are active VMs, return busy. If there ** are no active VMs, invalidate any pre-compiled statements. */ - nName = sqlite3Strlen(db, zName); + nName = sqlite3Strlen30(zName); pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, nName, 0); if( pColl && pColl->xCmp ){ if( db->activeVdbeCnt ){ diff --git a/src/malloc.c b/src/malloc.c index 92e56394e..70d691601 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -12,7 +12,7 @@ ** ** Memory allocation functions used throughout sqlite. ** -** $Id: malloc.c,v 1.61 2009/03/24 15:08:10 drh Exp $ +** $Id: malloc.c,v 1.62 2009/05/03 20:23:54 drh Exp $ */ #include "sqliteInt.h" #include <stdarg.h> @@ -651,7 +651,7 @@ char *sqlite3DbStrDup(sqlite3 *db, const char *z){ if( z==0 ){ return 0; } - n = (db ? sqlite3Strlen(db, z) : sqlite3Strlen30(z))+1; + n = sqlite3Strlen30(z) + 1; assert( (n&0x7fffffff)==n ); zNew = sqlite3DbMallocRaw(db, (int)n); if( zNew ){ diff --git a/src/select.c b/src/select.c index 54600e53d..d1c0fb44e 100644 --- a/src/select.c +++ b/src/select.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.511 2009/05/01 21:13:37 drh Exp $ +** $Id: select.c,v 1.512 2009/05/03 20:23:54 drh Exp $ */ #include "sqliteInt.h" @@ -1157,7 +1157,6 @@ static int selectColumnsFromExprList( sqlite3DbFree(db, zName); break; } - sqlite3Dequote(zName); /* Make sure the column name is unique. If the name is not unique, ** append a integer to the name so that it becomes unique. diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 52093c092..c5282b340 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.866 2009/05/02 13:29:38 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.867 2009/05/03 20:23:54 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -2294,7 +2294,6 @@ int sqlite3WalkSelectFrom(Walker*, Select*); int sqlite3StrICmp(const char *, const char *); int sqlite3StrNICmp(const char *, const char *, int); int sqlite3IsNumber(const char*, int*, u8); -int sqlite3Strlen(sqlite3*, const char*); int sqlite3Strlen30(const char*); int sqlite3MallocInit(void); diff --git a/src/test1.c b/src/test1.c index 384166e06..72eeb1ae9 100644 --- a/src/test1.c +++ b/src/test1.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test1.c,v 1.352 2009/04/28 15:35:39 danielk1977 Exp $ +** $Id: test1.c,v 1.353 2009/05/03 20:23:54 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -1218,18 +1218,6 @@ static int sqlite3_mprintf_int( } /* -** If zNum represents an integer that will fit in 64-bits, then set -** *pValue to that integer and return true. Otherwise return false. -*/ -static int sqlite3GetInt64(const char *zNum, i64 *pValue){ - if( sqlite3FitsIn64Bits(zNum, 0) ){ - sqlite3Atoi64(zNum, pValue); - return 1; - } - return 0; -} - -/* ** Usage: sqlite3_mprintf_int64 FORMAT INTEGER INTEGER INTEGER ** ** Call mprintf with three 64-bit integer arguments @@ -1249,7 +1237,7 @@ static int sqlite3_mprintf_int64( return TCL_ERROR; } for(i=2; i<5; i++){ - if( !sqlite3GetInt64(argv[i], &a[i-2]) ){ + if( !sqlite3Atoi64(argv[i], &a[i-2]) ){ Tcl_AppendResult(interp, "argument is not a valid 64-bit integer", 0); return TCL_ERROR; } diff --git a/src/util.c b/src/util.c index b2ab11101..b9d545f46 100644 --- a/src/util.c +++ b/src/util.c @@ -14,7 +14,7 @@ ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** -** $Id: util.c,v 1.252 2009/05/01 21:13:37 drh Exp $ +** $Id: util.c,v 1.253 2009/05/03 20:23:54 drh Exp $ */ #include "sqliteInt.h" #include <stdarg.h> @@ -58,6 +58,7 @@ int sqlite3Assert(void){ ** Otherwise, we have our own implementation that works on most systems. */ int sqlite3IsNaN(double x){ + int rc; /* The value return */ #if !defined(SQLITE_HAVE_ISNAN) /* ** Systems that support the isnan() library function should probably @@ -87,15 +88,21 @@ int sqlite3IsNaN(double x){ #endif volatile double y = x; volatile double z = y; - return y!=z; + rc = (y!=z); #else /* if defined(SQLITE_HAVE_ISNAN) */ - return isnan(x); + rc = isnan(x); #endif /* SQLITE_HAVE_ISNAN */ + testcase( rc ); + return rc; } /* ** Compute a string length that is limited to what can be stored in ** lower 30 bits of a 32-bit signed integer. +** +** The value returned will never be negative. Nor will it ever be greater +** than the actual length of the string. For very long strings (greater +** than 1GiB) the value returned might be less than the true string length. */ int sqlite3Strlen30(const char *z){ const char *z2 = z; @@ -104,24 +111,6 @@ int sqlite3Strlen30(const char *z){ } /* -** Return the length of a string, except do not allow the string length -** to exceed the SQLITE_LIMIT_LENGTH setting. -*/ -int sqlite3Strlen(sqlite3 *db, const char *z){ - const char *z2 = z; - int len; - int x; - while( *z2 ){ z2++; } - x = (int)(z2 - z); - len = 0x7fffffff & x; - if( len!=x || len > db->aLimit[SQLITE_LIMIT_LENGTH] ){ - return db->aLimit[SQLITE_LIMIT_LENGTH]; - }else{ - return len; - } -} - -/* ** Set the most recent error code and error string for the sqlite ** handle "db". The error code is set to "err_code". ** @@ -179,6 +168,7 @@ void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){ va_list ap; sqlite3 *db = pParse->db; pParse->nErr++; + testcase( pParse->zErrMsg!=0 ); sqlite3DbFree(db, pParse->zErrMsg); va_start(ap, zFormat); pParse->zErrMsg = sqlite3VMPrintf(db, zFormat, ap); @@ -226,7 +216,7 @@ int sqlite3Dequote(char *z){ case '[': quote = ']'; break; /* For MS SqlServer compatibility */ default: return -1; } - for(i=1, j=0; z[i]; i++){ + for(i=1, j=0; ALWAYS(z[i]); i++){ if( z[i]==quote ){ if( z[i+1]==quote ){ z[j++] = quote; @@ -265,10 +255,15 @@ int sqlite3StrNICmp(const char *zLeft, const char *zRight, int N){ } /* -** Return TRUE if z is a pure numeric string. Return FALSE if the -** string contains any character which is not part of a number. If -** the string is numeric and contains the '.' character, set *realnum -** to TRUE (otherwise FALSE). +** Return TRUE if z is a pure numeric string. Return FALSE and leave +** *realnum unchanged if the string contains any character which is not +** part of a number. +** +** If the string is pure numeric, set *realnum to TRUE if the string +** contains the '.' character or an "E+000" style exponentiation suffix. +** Otherwise set *realnum to FALSE. Note that just becaue *realnum is +** false does not mean that the number can be successfully converted into +** an integer - it might be too big. ** ** An empty string is considered non-numeric. */ @@ -280,20 +275,20 @@ int sqlite3IsNumber(const char *z, int *realnum, u8 enc){ return 0; } z += incr; - if( realnum ) *realnum = 0; + *realnum = 0; while( sqlite3Isdigit(*z) ){ z += incr; } if( *z=='.' ){ z += incr; if( !sqlite3Isdigit(*z) ) return 0; while( sqlite3Isdigit(*z) ){ z += incr; } - if( realnum ) *realnum = 1; + *realnum = 1; } if( *z=='e' || *z=='E' ){ z += incr; if( *z=='+' || *z=='-' ) z += incr; if( !sqlite3Isdigit(*z) ) return 0; while( sqlite3Isdigit(*z) ){ z += incr; } - if( realnum ) *realnum = 1; + *realnum = 1; } return *z==0; } @@ -452,25 +447,25 @@ int sqlite3Atoi64(const char *zNum, i64 *pNum){ } /* -** The string zNum represents an integer. There might be some other +** The string zNum represents an unsigned integer. There might be some other ** information following the integer too, but that part is ignored. ** If the integer that the prefix of zNum represents will fit in a ** 64-bit signed integer, return TRUE. Otherwise return FALSE. ** -** This routine returns FALSE for the string -9223372036854775808 even that -** that number will, in theory fit in a 64-bit integer. Positive -** 9223373036854775808 will not fit in 64 bits. So it seems safer to return -** false. +** If the negFlag parameter is true, that means that zNum really represents +** a negative number. (The leading "-" is omitted from zNum.) This +** parameter is needed to determine a boundary case. A string +** of "9223373036854775808" returns false if negFlag is false or true +** if negFlag is true. +** +** Leading zeros are ignored. */ int sqlite3FitsIn64Bits(const char *zNum, int negFlag){ int i, c; int neg = 0; - if( *zNum=='-' ){ - neg = 1; - zNum++; - }else if( *zNum=='+' ){ - zNum++; - } + + assert( zNum[0]>='0' && zNum[0]<='9' ); /* zNum is an unsigned number */ + if( negFlag ) neg = 1-neg; while( *zNum=='0' ){ zNum++; /* Skip leading zeros. Ticket #2454 */ @@ -775,33 +770,40 @@ u8 sqlite3GetVarint(const unsigned char *p, u64 *v){ u8 sqlite3GetVarint32(const unsigned char *p, u32 *v){ u32 a,b; + /* The 1-byte case. Overwhelmingly the most common. Handled inline + ** by the getVarin32() macro */ a = *p; /* a: p0 (unmasked) */ #ifndef getVarint32 if (!(a&0x80)) { + /* Values between 0 and 127 */ *v = a; return 1; } #endif + /* The 2-byte case */ p++; b = *p; /* b: p1 (unmasked) */ if (!(b&0x80)) { + /* Values between 128 and 16383 */ a &= 0x7f; a = a<<7; *v = a | b; return 2; } + /* The 3-byte case */ p++; a = a<<14; a |= *p; /* a: p0<<14 | p2 (unmasked) */ if (!(a&0x80)) { + /* Values between 16384 and 2097151 */ a &= (0x7f<<14)|(0x7f); b &= 0x7f; b = b<<7; @@ -809,12 +811,39 @@ u8 sqlite3GetVarint32(const unsigned char *p, u32 *v){ return 3; } + /* A 32-bit varint is used to store size information in btrees. + ** Objects are rarely larger than 2MiB limit of a 3-byte varint. + ** A 3-byte varint is sufficient, for example, to record the size + ** of a 1048569-byte BLOB or string. + ** + ** We only unroll the first 1-, 2-, and 3- byte cases. The very + ** rare larger cases can be handled by the slower 64-bit varint + ** routine. + */ +#if 1 + { + u64 v64; + u8 n; + + p -= 2; + n = sqlite3GetVarint(p, &v64); + assert( n>3 && n<=9 ); + *v = (u32)v64; + return n; + } + +#else + /* For following code (kept for historical record only) shows an + ** unrolling for the 3- and 4-byte varint cases. This code is + ** slightly faster, but it is also larger and much harder to test. + */ p++; b = b<<14; b |= *p; /* b: p1<<14 | p3 (unmasked) */ if (!(b&0x80)) { + /* Values between 2097152 and 268435455 */ b &= (0x7f<<14)|(0x7f); a &= (0x7f<<14)|(0x7f); a = a<<7; @@ -828,6 +857,7 @@ u8 sqlite3GetVarint32(const unsigned char *p, u32 *v){ /* a: p0<<28 | p2<<14 | p4 (unmasked) */ if (!(a&0x80)) { + /* Walues between 268435456 and 34359738367 */ a &= (0x1f<<28)|(0x7f<<14)|(0x7f); b &= (0x1f<<28)|(0x7f<<14)|(0x7f); b = b<<7; @@ -849,6 +879,7 @@ u8 sqlite3GetVarint32(const unsigned char *p, u32 *v){ *v = (u32)v64; return n; } +#endif } /* @@ -860,7 +891,7 @@ int sqlite3VarintLen(u64 v){ do{ i++; v >>= 7; - }while( v!=0 && i<9 ); + }while( v!=0 && ALWAYS(i<9) ); return i; } @@ -998,13 +1029,18 @@ int sqlite3SafetyCheckOk(sqlite3 *db){ u32 magic; if( db==0 ) return 0; magic = db->magic; - if( magic!=SQLITE_MAGIC_OPEN && - magic!=SQLITE_MAGIC_BUSY ) return 0; - return 1; + if( magic!=SQLITE_MAGIC_OPEN +#ifdef SQLITE_DEBUG + && magic!=SQLITE_MAGIC_BUSY +#endif + ){ + return 0; + }else{ + return 1; + } } int sqlite3SafetyCheckSickOrOk(sqlite3 *db){ u32 magic; - if( db==0 ) return 0; magic = db->magic; if( magic!=SQLITE_MAGIC_SICK && magic!=SQLITE_MAGIC_OPEN && |