From: drh Date: Sat, 10 Jan 2009 16:15:20 +0000 (+0000) Subject: When compiled with SQLITE_DEBUG (in other words, when assert() is enabled) X-Git-Tag: version-3.6.10~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47c3b3e0991f00da8ce206fbe639a142b7db0c50;p=thirdparty%2Fsqlite.git When compiled with SQLITE_DEBUG (in other words, when assert() is enabled) the ALWAYS and NEVER macros will throw an assertion if their arguments are not true or false, respectively. (CVS 6159) FossilOrigin-Name: 64a8dcd8d6152108809e4d10c459f1de5d36a435 --- diff --git a/manifest b/manifest index 4df5076602..7fd6300f6b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improve\scoverage\sof\spager.c.\s(CVS\s6158) -D 2009-01-10T16:15:09 +C When\scompiled\swith\sSQLITE_DEBUG\s(in\sother\swords,\swhen\sassert()\sis\senabled)\nthe\sALWAYS\sand\sNEVER\smacros\swill\sthrow\san\sassertion\sif\stheir\sarguments\sare\nnot\strue\sor\sfalse,\srespectively.\s(CVS\s6159) +D 2009-01-10T16:15:21 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 05461a9b5803d5ad10c79f989801e9fd2cc3e592 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -103,7 +103,7 @@ F src/attach.c 1c35f95da3c62d19de75b44cfefd12c81c1791b3 F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627 F src/bitvec.c a97d315fc7c0ec54fabd8859a45bd4e8e0d16b0b F src/btmutex.c 63c5cc4ad5715690767ffcb741e185d7bc35ec1a -F src/btree.c 6ece0e362ad902b86d153f4cb52194d30aa4d817 +F src/btree.c 603ce1969c601d9bf3ea92d49a53a445912fa3bc F src/btree.h 4f141cf748d2ee7c6d7fc175f64f87a45cd44113 F src/btreeInt.h 8fea5cd7021cb8848fc2183a3e909469659daa0a F src/build.c 6eb9d20e99db8da8c7c6e7316096a6ff3d9acab9 @@ -122,7 +122,7 @@ F src/insert.c f6db1e6f43aae337e64a755208abb6ff124edc19 F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e F src/legacy.c 4f7410b29598d991628ca40b150aa089649f17d8 F src/loadext.c 2f53996c693a347edc2d773e9217dde49d96ae64 -F src/main.c 1d2b56821327321af1d6275603c22f86d55b3438 +F src/main.c e7cc4e3223f7dd40ceccb71d32cbb493f3e5632b F src/malloc.c e2b4e6d7033372bd43adb0192bf5f64c0aa03c91 F src/mem0.c f2f84062d1f35814d6535c9f9e33de3bfb3b132c F src/mem1.c 3bfb39e4f60b0179713a7c087b2d4f0dc205735f @@ -158,7 +158,7 @@ F src/select.c ae72b604e47092521c4d9ae54e1b1cbeb872a747 F src/shell.c 65d19f8996a160f288087e31810f24025439c62a F src/sqlite.h.in 6cd2489e40fe97ba58c60044a4ced377e08b6d09 F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17 -F src/sqliteInt.h 4b2a8eb466c30daa90d25f9d3bb2e85b60ad47af +F src/sqliteInt.h 10e934f5532a45dcfe9846e1bf4b424b82c5e64d F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76 F src/table.c 23db1e5f27c03160987c122a078b4bb51ef0b2f8 @@ -196,7 +196,7 @@ F src/tokenize.c aaa5fa6a4536a9dd7c855a3f66f32508f1612138 F src/trigger.c ca6d78f7c1314053800386ca64361e487774fda3 F src/update.c 8c4925f9ca664effc8a1faaad67449d2074567b1 F src/utf.c 1da9c832dba0fa8f865b5b902d93f420a1ee4245 -F src/util.c ea62608f66f33a7e8322de83024ae37c415c0c7f +F src/util.c 7b1e3987e1ae6b3aa773b0eb1b7391b1f72569d2 F src/vacuum.c 383d6297bddc011ab04a9eed110db6eaf523e8e9 F src/vdbe.c 4e9b83e758a43882a29fe5cde479acb1db04f7dd F src/vdbe.h 03516f28bf5aca00a53c4dccd6c313f96adb94f6 @@ -696,7 +696,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 3da5578726cb22118dfca38a2098a1e378644387 -R 320ab8e7bd88e5e4d3a0d64f8789cffb -U danielk1977 -Z 43f0761b39243fe434b2dca241a4ad9a +P 855c4093cf331496d9ef508011ad814e91e3882f +R b9c742fffe6a789dace921fa1885cb8a +U drh +Z 36a241c258b9ef95ddefc24be4403954 diff --git a/manifest.uuid b/manifest.uuid index abf1c9538f..7222b7ed7f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -855c4093cf331496d9ef508011ad814e91e3882f \ No newline at end of file +64a8dcd8d6152108809e4d10c459f1de5d36a435 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 505da0c135..fbf886c968 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.557 2009/01/09 14:11:05 drh Exp $ +** $Id: btree.c,v 1.558 2009/01/10 16:15:21 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. @@ -7346,7 +7346,6 @@ int sqlite3BtreeIsInTrans(Btree *p){ */ int sqlite3BtreeIsInStmt(Btree *p){ assert( sqlite3BtreeHoldsMutex(p) ); - assert( p->pBt ); return ALWAYS(p->pBt) && p->pBt->inStmt; } diff --git a/src/main.c b/src/main.c index 5cecd7b252..35f36661be 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.520 2008/12/17 17:30:26 danielk1977 Exp $ +** $Id: main.c,v 1.521 2009/01/10 16:15:22 drh Exp $ */ #include "sqliteInt.h" #include @@ -454,16 +454,6 @@ int sqlite3_db_config(sqlite3 *db, int op, ...){ return rc; } -/* -** Routine needed to support the testcase() macro. -*/ -#ifdef SQLITE_COVERAGE_TEST -void sqlite3Coverage(int x){ - static int dummy = 0; - dummy += x; -} -#endif - /* ** Return true if the buffer z[0..n-1] contains all spaces. diff --git a/src/sqliteInt.h b/src/sqliteInt.h index a1f9250696..bbb824d0c6 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.822 2009/01/10 13:24:51 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.823 2009/01/10 16:15:22 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -50,57 +50,6 @@ #include #endif -/* -** A macro used to aid in coverage testing. When doing coverage -** testing, the condition inside the argument must be evaluated -** both true and false in order to get full branch coverage. -** This macro can be inserted to ensure adequate test coverage -** in places where simple condition/decision coverage is inadequate. -*/ -#ifdef SQLITE_COVERAGE_TEST - void sqlite3Coverage(int); -# define testcase(X) if( X ){ sqlite3Coverage(__LINE__); } -# define TESTONLY(X) X -#else -# define testcase(X) -# define TESTONLY(X) -#endif - -/* -** The ALWAYS and NEVER macros surround boolean expressions which -** are intended to always be true or false, respectively. Such -** expressions could be omitted from the code completely. But they -** are included in a few cases in order to enhance the resilience -** of SQLite to unexpected behavior - to make the code "self-healing" -** or "ductile" rather than being "brittle" and crashing at the first -** hint of unplanned behavior. -** -** When doing coverage testing ALWAYS and NEVER are hard-coded to -** be true and false so that the unreachable code then specify will -** not be counted as untested code. -*/ -#ifdef SQLITE_COVERAGE_TEST -# define ALWAYS(X) (1) -# define NEVER(X) (0) -#else -# define ALWAYS(X) (X) -# define NEVER(X) (X) -#endif - -/* -** The macro unlikely() is a hint that surrounds a boolean -** expression that is usually false. Macro likely() surrounds -** a boolean expression that is usually true. GCC is able to -** use these hints to generate better code, sometimes. -*/ -#if defined(__GNUC__) && 0 -# define likely(X) __builtin_expect((X),1) -# define unlikely(X) __builtin_expect((X),0) -#else -# define likely(X) !!(X) -# define unlikely(X) !!(X) -#endif - /* * This macro is used to "hide" some ugliness in casting an int * value to a ptr value under the MSVC 64-bit compiler. Casting @@ -238,6 +187,73 @@ # define NDEBUG 1 #endif +/* +** The testcase() macro is used to aid in coverage testing. When +** doing coverage testing, the condition inside the argument to +** testcase() must be evaluated both true and false in order to +** get full branch coverage. The testcase() macro is inserted +** to help ensure adequate test coverage in places where simple +** condition/decision coverage is inadequate. For example, testcase() +** can be used to make sure boundary values are tested. For +** bitmask tests, testcase() can be used to make sure each bit +** is significant and used at least once. On switch statements +** where multiple cases go to the same block of code, testcase() +** can insure that all cases are evaluated. +** +** The TESTONLY macro is used to enclose variable declarations or +** other bits of code that are needed to support the arguments +** within testcase() macros. +*/ +#ifdef SQLITE_COVERAGE_TEST + void sqlite3Coverage(int); +# define testcase(X) if( X ){ sqlite3Coverage(__LINE__); } +# define TESTONLY(X) X +#else +# define testcase(X) +# define TESTONLY(X) +#endif + +/* +** The ALWAYS and NEVER macros surround boolean expressions which +** are intended to always be true or false, respectively. Such +** expressions could be omitted from the code completely. But they +** are included in a few cases in order to enhance the resilience +** of SQLite to unexpected behavior - to make the code "self-healing" +** or "ductile" rather than being "brittle" and crashing at the first +** hint of unplanned behavior. +** +** In other words, ALWAYS and NEVER are added for defensive code. +** +** When doing coverage testing ALWAYS and NEVER are hard-coded to +** be true and false so that the unreachable code then specify will +** not be counted as untested code. +*/ +#if defined(SQLITE_COVERAGE_TEST) +# define ALWAYS(X) (1) +# define NEVER(X) (0) +#elif !defined(NDEBUG) + int sqlite3Assert(void); +# define ALWAYS(X) ((X)?1:sqlite3Assert()) +# define NEVER(X) ((X)?sqlite3Assert():0) +#else +# define ALWAYS(X) (X) +# define NEVER(X) (X) +#endif + +/* +** The macro unlikely() is a hint that surrounds a boolean +** expression that is usually false. Macro likely() surrounds +** a boolean expression that is usually true. GCC is able to +** use these hints to generate better code, sometimes. +*/ +#if defined(__GNUC__) && 0 +# define likely(X) __builtin_expect((X),1) +# define unlikely(X) __builtin_expect((X),0) +#else +# define likely(X) !!(X) +# define unlikely(X) !!(X) +#endif + /* ** Sometimes we need a small amount of code such as a variable initialization ** to setup for a later assert() statement. We do not want this code to diff --git a/src/util.c b/src/util.c index 20be6d7284..2846c39429 100644 --- a/src/util.c +++ b/src/util.c @@ -14,13 +14,44 @@ ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** -** $Id: util.c,v 1.245 2008/12/10 22:15:00 drh Exp $ +** $Id: util.c,v 1.246 2009/01/10 16:15:22 drh Exp $ */ #include "sqliteInt.h" #include #include +/* +** Routine needed to support the testcase() macro. +*/ +#ifdef SQLITE_COVERAGE_TEST +void sqlite3Coverage(int x){ + static int dummy = 0; + dummy += x; +} +#endif + +/* +** Routine needed to support the ALWAYS() and NEVER() macros. +** +** The argument to ALWAYS() should always be true and the argument +** to NEVER() should always be false. If either is not the case +** then this routine is called in order to throw an error. +** +** This routine only exists if assert() is operational. It always +** throws an assert on its first invocation. The variable has a long +** name to help the assert() message be more readable. The variable +** is used to prevent a too-clever optimizer from optimizing out the +** entire call. +*/ +#ifndef NDEBUG +int sqlite3Assert(void){ + static volatile int ALWAYS_was_false_or_NEVER_was_true = 0; + assert( ALWAYS_was_false_or_NEVER_was_true ); /* Always fails */ + return ALWAYS_was_false_or_NEVER_was_true++; /* Not Reached */ +} +#endif + /* ** Return true if the floating point value is Not a Number (NaN). */