aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--manifest40
-rw-r--r--manifest.uuid2
-rw-r--r--src/analyze.c6
-rw-r--r--src/attach.c6
-rw-r--r--src/main.c51
-rw-r--r--src/os.c6
-rw-r--r--src/prepare.c19
-rw-r--r--src/sqliteInt.h18
-rw-r--r--src/test_devsym.c1
-rw-r--r--src/util.c35
-rw-r--r--src/vdbe.c12
-rw-r--r--src/vdbeapi.c10
-rw-r--r--src/vdbeaux.c12
-rw-r--r--src/vdbeblob.c8
-rw-r--r--src/vtab.c10
-rw-r--r--src/where.c8
-rw-r--r--test/safety.test8
17 files changed, 135 insertions, 117 deletions
diff --git a/manifest b/manifest
index 54b3b13c8..3c34ec2a1 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Improved\stest\scoverage\sfor\sthe\stokenizer\sand\ssqlite3_complete()\sinterface.\nFix\sbugs\sin\sparsing\sblob\sliterals\sand\sSQL\svariables\sbeginning\swith\s$.\s(CVS\s4743)
-D 2008-01-22T23:37:10
+C Make\ssqlite3SafetyOn()\sand\ssqlite3SafetyOff()\smacros\swhich\sdisappear\swhen\ncompiling\swithout\s-DSQLITE_DEBUG=1.\s(CVS\s4744)
+D 2008-01-23T03:03:05
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in bc2b5df3e3d0d4b801b824b7ef6dec43812b049b
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -79,8 +79,8 @@ F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
F sqlite3.def a96c1d0d39362b763d2ddba220a32da41a15c4b4
F sqlite3.pc.in abed4664817e1cd500f2276142c71958087c16bc
F src/alter.c 2a101cb062b82fa29db9b105a1078690aa0a3c11
-F src/analyze.c ac17da1f9c804aabf709a1afff12ed35fc215104
-F src/attach.c f7a34eb0f0e01db5fbfd8acb12109f87aed8159d
+F src/analyze.c 13d64eeba3f49c3096abba96e38b898018afd504
+F src/attach.c 2a0b199467c6c0212fae26a6b51bef132680f881
F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
F src/btmutex.c 5d39da37c9d1282f3c6f9967afae6a34ee36b7ff
F src/btree.c a3125bd53a4112f2f259af858ef2eff63e397c9b
@@ -102,7 +102,7 @@ F src/journal.c 807bed7a158979ac8d63953e1774e8d85bff65e2
F src/legacy.c 4ac53191fad2e3c4d59bde1228879b2dc5a96d66
F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35
F src/loadext.c d17a0f760d6866aacf5262f97d8efaaad379cdd7
-F src/main.c de0a4555caa68268c9c804283e9476a4e9aa0c62
+F src/main.c a85079f79c2b47e704ea644773c610f9fd5cdf7d
F src/malloc.c 60e392a4c12c839517f9b0db7b995f825444fb35
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/mem1.c 6d1a11864963d249c67e72ad5f6533b040333880
@@ -114,7 +114,7 @@ F src/mutex.h 079fa6fe9da18ceb89e79012c010594c6672addb
F src/mutex_os2.c 4058d04e81a6c1e240020d299a3192d92352c7ef
F src/mutex_unix.c a6e111947a3cdaa2cda394ed060d7f496fcb4af8
F src/mutex_w32.c 6e197765f283815496193e78e9548b5d0e53b68e
-F src/os.c 32251c046e86772cedd56a18a2ff317bf493fa53
+F src/os.c 50c0c1706c35f872db312815aaecc4b5ebcd6a4c
F src/os.h d04706d54a072c7a30ab9e346ad916ef28c842d5
F src/os_common.h 98862f120ca6bf7a48ce8b16f158b77d00bc9d2f
F src/os_os2.c 4aca68faa5fe20e41e1b123a46087ebd9e0bb170
@@ -129,7 +129,7 @@ F src/pager.c d8c2f06c3ce225dd14816cd02f07d7c65aff1f53
F src/pager.h f504f7ae84060fee0416a853e368d3d113c3d6fa
F src/parse.y 00f2698c8ae84f315be5e3f10b63c94f531fdd6d
F src/pragma.c 2bb8d6882b9a330e041acd05fb6aff5a01bf0a08
-F src/prepare.c 05433874e7f161124d29877f83d246efb3a10dd7
+F src/prepare.c 1b0601ca3f97a9d253cc08697484e3045a1678e9
F src/printf.c eb27822ba2eec669161409ca31279a24c26ac910
F src/random.c 02ef38b469237482f1ea14a78b2087cfbaec48bd
F src/select.c 9fb094cc0c8acdcbf3581fdfc4490e997b5d1d1e
@@ -137,7 +137,7 @@ F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c ca06cb687c40a8bff6307b5fad41a0e86a0f8558
F src/sqlite.h.in 2a7e3776534bbe6ff2cdc058f3abebe91e7e429f
F src/sqlite3ext.h a93f59cdee3638dc0c9c086f80df743a4e68c3cb
-F src/sqliteInt.h 3b67a79e9b7b9bb1aa5689384ae6524a78070d2c
+F src/sqliteInt.h 9d87dc3aa23d78567e8f83c99dd991ea88e303fe
F src/sqliteLimit.h ee4430f88f69bf63527967bb35ca52af7b0ccb1e
F src/table.c 1aeb9eab57b4235db86fe15a35dec76fb445a9c4
F src/tclsqlite.c 9923abeffc9b3d7dad58e92b319661521f60debf
@@ -154,7 +154,7 @@ F src/test_async.c 5f21392d66869a4c87dc9153e40d0dc0e085261f
F src/test_autoext.c 855157d97aa28cf84233847548bfacda21807436
F src/test_btree.c c1308ba0b88ab577fa56c9e493a09829dfcded9c
F src/test_config.c a3ac9faf2e3c032bb0bdb9e3f2fd36a1e17a6cce
-F src/test_devsym.c 6341971bf1c7769c740501b36bc6192cd975c335
+F src/test_devsym.c fd8884c2269fb7e0db2c52d21ec59d31a33790ba
F src/test_hexio.c 1a1cd8324d57585ea86b922f609fa1fbaaf9662d
F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
F src/test_malloc.c 7ba7e0c283d22c8b079acc4f73d0a034e9779b26
@@ -168,18 +168,18 @@ F src/tokenize.c c4b79fd48ddb709b2b8522b7d93a5a3d98168ca4
F src/trigger.c 9bd3b6fa0beff4a02d262c96466f752ec15a7fc3
F src/update.c 31edd9c9764e80753930bd5f9b43e0edb404636f
F src/utf.c ef4b7d83bae533b76c3e1bf635b113fdad86a736
-F src/util.c ca0e3820ce9b0e0ff9bf21f4b726a81163d7b417
+F src/util.c c56e41ed4769c1f2b8af9ffde4757a7b4fb08ed1
F src/vacuum.c 3f34f278809bf3eb0b62ec46ff779e9c385b28f0
-F src/vdbe.c a3ac8efb7c862ddc3c357ee02612de857cbfd182
+F src/vdbe.c 299e18e4262ba4104710a7fac21d80b2a14eb666
F src/vdbe.h 58a7d931ffb704e034b2a725981cfa5bd406fad9
F src/vdbeInt.h 6b4a438198f98a2a2233cc228ed0f120a18628e7
-F src/vdbeapi.c a0cb07fc69553727b5b25c7fb12348528defd99b
-F src/vdbeaux.c 4a0c75af5366c9114b340c39bea5df76fb26e215
-F src/vdbeblob.c e386d49d8354aa5a58f0a7f2794303442c149120
+F src/vdbeapi.c 93c72ed24d59ed86a634b6d593cdec8376b24513
+F src/vdbeaux.c 771b9ffd7b42cbb4bd029d7a9414a7cb03f924a7
+F src/vdbeblob.c 3626867e85b815f60c3056e9a649869cc09dcea4
F src/vdbefifo.c 334c838c8f42d61a94813d136019ee566b5dc2f6
F src/vdbemem.c 79ec9d0d15167baafde2259dddde2a67bd21bcd7
-F src/vtab.c 9924e37cf7f5c527aeabb5da025874af505fb91d
-F src/where.c 0c18a6d88d78886fd5f3c11ef2cf001321acd918
+F src/vtab.c dc8947c9c79780b19ee6d6bae4ea624a2a303353
+F src/where.c b6c296c5f4a584d837ee1117b31a7e63253aa295
F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
F test/all.test d12210212bada2bde6d5aeb90969b86c1aa977d2
@@ -419,7 +419,7 @@ F test/rdonly.test b34db316525440d3b42c32e83942c02c37d28ef0
F test/reindex.test 38b138abe36bf9a08c791ed44d9f76cd6b97b78b
F test/rollback.test 0bd29070ba2f76da939347773fbda53337ebd61c
F test/rowid.test 1c8fc43c60d273e6ea44dfb992db587f3164312c
-F test/safety.test 4a06934e45d03b8b50ebcd8d174eb0367d2fd851
+F test/safety.test 1b585c4311c85a6a7aa747b7b45a6bbc6d04fbe0
F test/schema.test a8b000723375fd42c68d310091bdbd744fde647c
F test/schema2.test 35e1c9696443d6694c8980c411497c2b5190d32e
F test/select1.test 871df931cbbc0e78170605628e8b5fc60765e265
@@ -614,7 +614,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P 1a335e180183b414fcc3510ce28b98b21cd134a6
-R 1823b998eac2ea2abc6d95d39900dbcf
+P c82033faf8bdb83ce43f0dd1611408e7796d53de
+R a7bab11a5203e06d1125cf46686f1cb9
U drh
-Z 8b71aeae0977a8f741811bf53f9ebac4
+Z 6af45d96f0c2b29ef6c64bd43b03c5c9
diff --git a/manifest.uuid b/manifest.uuid
index 5f6f74313..804cd6b68 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-c82033faf8bdb83ce43f0dd1611408e7796d53de \ No newline at end of file
+5375ad6b4b652f388469b0ce4e8e78b3f49169bd \ No newline at end of file
diff --git a/src/analyze.c b/src/analyze.c
index b7e917fb6..7fd616265 100644
--- a/src/analyze.c
+++ b/src/analyze.c
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code associated with the ANALYZE command.
**
-** @(#) $Id: analyze.c,v 1.39 2008/01/17 02:36:28 drh Exp $
+** @(#) $Id: analyze.c,v 1.40 2008/01/23 03:03:05 drh Exp $
*/
#ifndef SQLITE_OMIT_ANALYZE
#include "sqliteInt.h"
@@ -414,9 +414,9 @@ int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
/* Load new statistics out of the sqlite_stat1 table */
zSql = sqlite3MPrintf(db, "SELECT idx, stat FROM %Q.sqlite_stat1",
sInfo.zDatabase);
- sqlite3SafetyOff(db);
+ (void)sqlite3SafetyOff(db);
rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
- sqlite3SafetyOn(db);
+ (void)sqlite3SafetyOn(db);
sqlite3_free(zSql);
return rc;
}
diff --git a/src/attach.c b/src/attach.c
index af2312c8a..63ad3c7b7 100644
--- a/src/attach.c
+++ b/src/attach.c
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
**
-** $Id: attach.c,v 1.69 2008/01/17 16:22:15 drh Exp $
+** $Id: attach.c,v 1.70 2008/01/23 03:03:05 drh Exp $
*/
#include "sqliteInt.h"
@@ -186,11 +186,11 @@ static void attachFunc(
** we found it.
*/
if( rc==SQLITE_OK ){
- sqlite3SafetyOn(db);
+ (void)sqlite3SafetyOn(db);
sqlite3BtreeEnterAll(db);
rc = sqlite3Init(db, &zErrDyn);
sqlite3BtreeLeaveAll(db);
- sqlite3SafetyOff(db);
+ (void)sqlite3SafetyOff(db);
}
if( rc ){
int iDb = db->nDb - 1;
diff --git a/src/main.c b/src/main.c
index 7fa01c2e8..2d9d2ca86 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.412 2008/01/22 21:30:53 drh Exp $
+** $Id: main.c,v 1.413 2008/01/23 03:03:05 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -134,7 +134,7 @@ int sqlite3_close(sqlite3 *db){
if( !db ){
return SQLITE_OK;
}
- if( sqlite3SafetyCheck(db) ){
+ if( !sqlite3SafetyCheckSickOrOk(db) ){
return SQLITE_MISUSE;
}
sqlite3_mutex_enter(db->mutex);
@@ -164,21 +164,7 @@ int sqlite3_close(sqlite3 *db){
sqlite3_mutex_leave(db->mutex);
return SQLITE_BUSY;
}
- assert( !sqlite3SafetyCheck(db) );
-
- /* FIX ME: db->magic may be set to SQLITE_MAGIC_CLOSED if the database
- ** cannot be opened for some reason. So this routine needs to run in
- ** that case. But maybe there should be an extra magic value for the
- ** "failed to open" state.
- **
- ** TODO: Coverage tests do not test the case where this condition is
- ** true. It's hard to see how to cause it without messing with threads.
- */
- if( db->magic!=SQLITE_MAGIC_CLOSED && sqlite3SafetyOn(db) ){
- /* printf("DID NOT CLOSE\n"); fflush(stdout); */
- sqlite3_mutex_leave(db->mutex);
- return SQLITE_ERROR;
- }
+ assert( sqlite3SafetyCheckSickOrOk(db) );
for(j=0; j<db->nDb; j++){
struct Db *pDb = &db->aDb[j];
@@ -240,6 +226,7 @@ int sqlite3_close(sqlite3 *db){
*/
sqlite3_free(db->aDb[1].pSchema);
sqlite3_mutex_leave(db->mutex);
+ db->magic = SQLITE_MAGIC_CLOSED;
sqlite3_mutex_free(db->mutex);
sqlite3_free(db);
return SQLITE_OK;
@@ -387,7 +374,7 @@ int sqlite3_busy_handler(
int (*xBusy)(void*,int),
void *pArg
){
- if( sqlite3SafetyCheck(db) ){
+ if( !sqlite3SafetyCheckOk(db) ){
return SQLITE_MISUSE;
}
sqlite3_mutex_enter(db->mutex);
@@ -410,7 +397,7 @@ void sqlite3_progress_handler(
int (*xProgress)(void*),
void *pArg
){
- if( !sqlite3SafetyCheck(db) ){
+ if( sqlite3SafetyCheckOk(db) ){
sqlite3_mutex_enter(db->mutex);
if( nOps>0 ){
db->xProgress = xProgress;
@@ -432,7 +419,7 @@ void sqlite3_progress_handler(
** specified number of milliseconds before returning 0.
*/
int sqlite3_busy_timeout(sqlite3 *db, int ms){
- if( sqlite3SafetyCheck(db) ){
+ if( !sqlite3SafetyCheckOk(db) ){
return SQLITE_MISUSE;
}
if( ms>0 ){
@@ -448,7 +435,7 @@ int sqlite3_busy_timeout(sqlite3 *db, int ms){
** Cause any pending operation to stop at its earliest opportunity.
*/
void sqlite3_interrupt(sqlite3 *db){
- if( db && (db->magic==SQLITE_MAGIC_OPEN || db->magic==SQLITE_MAGIC_BUSY) ){
+ if( sqlite3SafetyCheckOk(db) ){
db->u1.isInterrupted = 1;
}
}
@@ -474,7 +461,7 @@ int sqlite3CreateFunc(
int nName;
assert( sqlite3_mutex_held(db->mutex) );
- if( sqlite3SafetyCheck(db) ){
+ if( !sqlite3SafetyCheckOk(db) ){
return SQLITE_MISUSE;
}
if( zFunctionName==0 ||
@@ -798,7 +785,7 @@ const char *sqlite3_errmsg(sqlite3 *db){
if( !db ){
return sqlite3ErrStr(SQLITE_NOMEM);
}
- if( sqlite3SafetyCheck(db) || db->errCode==SQLITE_MISUSE ){
+ if( !sqlite3SafetyCheckSickOrOk(db) || db->errCode==SQLITE_MISUSE ){
return sqlite3ErrStr(SQLITE_MISUSE);
}
sqlite3_mutex_enter(db->mutex);
@@ -840,7 +827,7 @@ const void *sqlite3_errmsg16(sqlite3 *db){
if( !db ){
return (void *)(&outOfMemBe[SQLITE_UTF16NATIVE==SQLITE_UTF16LE?1:0]);
}
- if( sqlite3SafetyCheck(db) || db->errCode==SQLITE_MISUSE ){
+ if( !sqlite3SafetyCheckSickOrOk(db) || db->errCode==SQLITE_MISUSE ){
return (void *)(&misuseBe[SQLITE_UTF16NATIVE==SQLITE_UTF16LE?1:0]);
}
sqlite3_mutex_enter(db->mutex);
@@ -865,7 +852,7 @@ int sqlite3_errcode(sqlite3 *db){
if( !db || db->mallocFailed ){
return SQLITE_NOMEM;
}
- if( sqlite3SafetyCheck(db) ){
+ if( !sqlite3SafetyCheckSickOrOk(db) ){
return SQLITE_MISUSE;
}
return db->errCode & db->errMask;
@@ -886,7 +873,7 @@ static int createCollation(
CollSeq *pColl;
int enc2;
- if( sqlite3SafetyCheck(db) ){
+ if( !sqlite3SafetyCheckOk(db) ){
return SQLITE_MISUSE;
}
assert( sqlite3_mutex_held(db->mutex) );
@@ -1000,7 +987,7 @@ static int openDatabase(
db->pVfs = sqlite3_vfs_find(zVfs);
if( !db->pVfs ){
rc = SQLITE_ERROR;
- db->magic = SQLITE_MAGIC_CLOSED;
+ db->magic = SQLITE_MAGIC_SICK;
sqlite3Error(db, rc, "no such vfs: %s", (zVfs?zVfs:"(null)"));
goto opendb_out;
}
@@ -1016,7 +1003,7 @@ static int openDatabase(
(db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 6, 0))==0
){
assert( db->mallocFailed );
- db->magic = SQLITE_MAGIC_CLOSED;
+ db->magic = SQLITE_MAGIC_SICK;
goto opendb_out;
}
@@ -1037,7 +1024,7 @@ static int openDatabase(
&db->aDb[0].pBt);
if( rc!=SQLITE_OK ){
sqlite3Error(db, rc, 0);
- db->magic = SQLITE_MAGIC_CLOSED;
+ db->magic = SQLITE_MAGIC_SICK;
goto opendb_out;
}
db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
@@ -1253,7 +1240,7 @@ int sqlite3_collation_needed(
void *pCollNeededArg,
void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*)
){
- if( sqlite3SafetyCheck(db) ){
+ if( !sqlite3SafetyCheckOk(db) ){
return SQLITE_MISUSE;
}
sqlite3_mutex_enter(db->mutex);
@@ -1274,7 +1261,7 @@ int sqlite3_collation_needed16(
void *pCollNeededArg,
void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*)
){
- if( sqlite3SafetyCheck(db) ){
+ if( !sqlite3SafetyCheckOk(db) ){
return SQLITE_MISUSE;
}
sqlite3_mutex_enter(db->mutex);
@@ -1358,7 +1345,7 @@ int sqlite3_table_column_metadata(
int autoinc = 0;
/* Ensure the database schema has been loaded */
- if( sqlite3SafetyOn(db) ){
+ if( !sqlite3SafetyCheckOk(db) || sqlite3SafetyOn(db) ){
return SQLITE_MISUSE;
}
sqlite3_mutex_enter(db->mutex);
diff --git a/src/os.c b/src/os.c
index 71284cd90..57e2d0fdd 100644
--- a/src/os.c
+++ b/src/os.c
@@ -191,7 +191,9 @@ static sqlite3_vfs *vfsList = 0;
** first VFS on the list.
*/
sqlite3_vfs *sqlite3_vfs_find(const char *zVfs){
+#ifndef SQLITE_MUTEX_NOOP
sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
+#endif
sqlite3_vfs *pVfs = 0;
static int isInit = 0;
sqlite3_mutex_enter(mutex);
@@ -233,7 +235,9 @@ static void vfsUnlink(sqlite3_vfs *pVfs){
** true.
*/
int sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){
+#ifndef SQLITE_MUTEX_NOOP
sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
+#endif
sqlite3_vfs_find(0); /* Make sure we are initialized */
sqlite3_mutex_enter(mutex);
vfsUnlink(pVfs);
@@ -253,7 +257,9 @@ int sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){
** Unregister a VFS so that it is no longer accessible.
*/
int sqlite3_vfs_unregister(sqlite3_vfs *pVfs){
+#ifndef SQLITE_MUTEX_NOOP
sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
+#endif
sqlite3_mutex_enter(mutex);
vfsUnlink(pVfs);
sqlite3_mutex_leave(mutex);
diff --git a/src/prepare.c b/src/prepare.c
index 324b15afa..a9bc8442e 100644
--- a/src/prepare.c
+++ b/src/prepare.c
@@ -13,7 +13,7 @@
** interface, and routines that contribute to loading the database schema
** from disk.
**
-** $Id: prepare.c,v 1.74 2008/01/22 19:34:28 drh Exp $
+** $Id: prepare.c,v 1.75 2008/01/23 03:03:05 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -174,7 +174,6 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
zMasterName = SCHEMA_TABLE(iDb);
/* Construct the schema tables. */
- sqlite3SafetyOff(db);
azArg[0] = zMasterName;
azArg[1] = "1";
azArg[2] = zMasterSchema;
@@ -182,9 +181,10 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
initData.db = db;
initData.iDb = iDb;
initData.pzErrMsg = pzErrMsg;
+ (void)sqlite3SafetyOff(db);
rc = sqlite3InitCallback(&initData, 3, (char **)azArg, 0);
+ (void)sqlite3SafetyOn(db);
if( rc ){
- sqlite3SafetyOn(db);
rc = initData.rc;
goto error_out;
}
@@ -192,7 +192,6 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
if( pTab ){
pTab->readOnly = 1;
}
- sqlite3SafetyOn(db);
/* Create a cursor to hold the database open
*/
@@ -312,7 +311,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
zSql = sqlite3MPrintf(db,
"SELECT name, rootpage, sql FROM '%q'.%s",
db->aDb[iDb].zName, zMasterName);
- sqlite3SafetyOff(db);
+ (void)sqlite3SafetyOff(db);
#ifndef SQLITE_OMIT_AUTHORIZATION
{
int (*xAuth)(void*,int,const char*,const char*,const char*,const char*);
@@ -325,7 +324,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
}
#endif
if( rc==SQLITE_ABORT ) rc = initData.rc;
- sqlite3SafetyOn(db);
+ (void)sqlite3SafetyOn(db);
sqlite3_free(zSql);
#ifndef SQLITE_OMIT_ANALYZE
if( rc==SQLITE_OK ){
@@ -524,7 +523,7 @@ int sqlite3Prepare(
if( rc ){
const char *zDb = db->aDb[i].zName;
sqlite3Error(db, SQLITE_LOCKED, "database schema is locked: %s", zDb);
- sqlite3SafetyOff(db);
+ (void)sqlite3SafetyOff(db);
return SQLITE_LOCKED;
}
}
@@ -536,7 +535,7 @@ int sqlite3Prepare(
char *zSqlCopy;
if( SQLITE_MAX_SQL_LENGTH>0 && nBytes>SQLITE_MAX_SQL_LENGTH ){
sqlite3Error(db, SQLITE_TOOBIG, "statement too long");
- sqlite3SafetyOff(db);
+ (void)sqlite3SafetyOff(db);
return SQLITE_TOOBIG;
}
zSqlCopy = sqlite3DbStrNDup(db, zSql, nBytes);
@@ -622,7 +621,7 @@ static int sqlite3LockAndPrepare(
const char **pzTail /* OUT: End of parsed string */
){
int rc;
- if( sqlite3SafetyCheck(db) ){
+ if( !sqlite3SafetyCheckOk(db) ){
return SQLITE_MISUSE;
}
sqlite3_mutex_enter(db->mutex);
@@ -715,7 +714,7 @@ static int sqlite3Prepare16(
const char *zTail8 = 0;
int rc = SQLITE_OK;
- if( sqlite3SafetyCheck(db) ){
+ if( !sqlite3SafetyCheckOk(db) ){
return SQLITE_MISUSE;
}
sqlite3_mutex_enter(db->mutex);
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 1ba3b8de8..1c9951d97 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
-** @(#) $Id: sqliteInt.h,v 1.653 2008/01/22 21:30:53 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.654 2008/01/23 03:03:05 drh Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
@@ -590,6 +590,7 @@ struct sqlite3 {
*/
#define SQLITE_MAGIC_OPEN 0xa029a697 /* Database is open */
#define SQLITE_MAGIC_CLOSED 0x9f3c2d33 /* Database is closed */
+#define SQLITE_MAGIC_SICK 0x4b771290 /* Error and awaiting close */
#define SQLITE_MAGIC_BUSY 0xf03b7906 /* Database currently in use */
#define SQLITE_MAGIC_ERROR 0xb5357930 /* An SQLITE_MISUSE error occurred */
@@ -1816,9 +1817,15 @@ Select *sqlite3SelectDup(sqlite3*,Select*);
FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,int);
void sqlite3RegisterBuiltinFunctions(sqlite3*);
void sqlite3RegisterDateTimeFunctions(sqlite3*);
-int sqlite3SafetyOn(sqlite3*);
-int sqlite3SafetyOff(sqlite3*);
-int sqlite3SafetyCheck(sqlite3*);
+#ifdef SQLITE_DEBUG
+ int sqlite3SafetyOn(sqlite3*);
+ int sqlite3SafetyOff(sqlite3*);
+#else
+# define sqlite3SafetyOn(A) 0
+# define sqlite3SafetyOff(A) 0
+#endif
+int sqlite3SafetyCheckOk(sqlite3*);
+int sqlite3SafetyCheckSickOrOk(sqlite3*);
void sqlite3ChangeCookie(Parse*, int);
#ifndef SQLITE_OMIT_TRIGGER
@@ -2008,8 +2015,7 @@ CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
** Available fault injectors. Should be numbered beginning with 0.
*/
#define SQLITE_FAULTINJECTOR_MALLOC 0
-#define SQLITE_FAULTINJECTOR_SAFETY 1
-#define SQLITE_FAULTINJECTOR_COUNT 2
+#define SQLITE_FAULTINJECTOR_COUNT 1
/*
** The interface to the fault injector subsystem. If the fault injector
diff --git a/src/test_devsym.c b/src/test_devsym.c
index 588f5d286..724b29d34 100644
--- a/src/test_devsym.c
+++ b/src/test_devsym.c
@@ -344,4 +344,3 @@ void devsym_register(int iDeviceChar, int iSectorSize){
}
#endif
-
diff --git a/src/util.c b/src/util.c
index e33bcaeed..f8f02a4d0 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.215 2008/01/22 14:50:17 drh Exp $
+** $Id: util.c,v 1.216 2008/01/23 03:03:05 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@@ -660,6 +660,7 @@ void *sqlite3HexToBlob(sqlite3 *db, const char *z, int n){
** call to sqlite3_close(db) and db has been deallocated. And we do
** not want to write into deallocated memory.
*/
+#ifdef SQLITE_DEBUG
int sqlite3SafetyOn(sqlite3 *db){
if( db->magic==SQLITE_MAGIC_OPEN ){
db->magic = SQLITE_MAGIC_BUSY;
@@ -670,38 +671,54 @@ int sqlite3SafetyOn(sqlite3 *db){
}
return 1;
}
+#endif
/*
** Change the magic from SQLITE_MAGIC_BUSY to SQLITE_MAGIC_OPEN.
** Return an error (non-zero) if the magic was not SQLITE_MAGIC_BUSY
** when this routine is called.
*/
+#ifdef SQLITE_DEBUG
int sqlite3SafetyOff(sqlite3 *db){
if( db->magic==SQLITE_MAGIC_BUSY ){
db->magic = SQLITE_MAGIC_OPEN;
return 0;
- }else {
+ }else{
db->magic = SQLITE_MAGIC_ERROR;
db->u1.isInterrupted = 1;
return 1;
}
}
+#endif
/*
** Check to make sure we have a valid db pointer. This test is not
** foolproof but it does provide some measure of protection against
** misuse of the interface such as passing in db pointers that are
** NULL or which have been previously closed. If this routine returns
-** TRUE it means that the db pointer is invalid and should not be
+** 1 it means that the db pointer is valid and 0 if it should not be
** dereferenced for any reason. The calling function should invoke
** SQLITE_MISUSE immediately.
+**
+** sqlite3SafetyCheckOk() requires that the db pointer be valid for
+** use. sqlite3SafetyCheckSickOrOk() allows a db pointer that failed to
+** open properly and is not fit for general use but which can be
+** used as an argument to sqlite3_errmsg() or sqlite3_close().
*/
-int sqlite3SafetyCheck(sqlite3 *db){
+int sqlite3SafetyCheckOk(sqlite3 *db){
int magic;
- if( db==0 ) return 1;
+ if( db==0 ) return 0;
magic = db->magic;
- if( magic!=SQLITE_MAGIC_CLOSED &&
- magic!=SQLITE_MAGIC_OPEN &&
- magic!=SQLITE_MAGIC_BUSY ) return 1;
- return 0;
+ if( magic!=SQLITE_MAGIC_OPEN &&
+ magic!=SQLITE_MAGIC_BUSY ) return 0;
+ return 1;
+}
+int sqlite3SafetyCheckSickOrOk(sqlite3 *db){
+ int magic;
+ if( db==0 ) return 0;
+ magic = db->magic;
+ if( magic!=SQLITE_MAGIC_SICK &&
+ magic!=SQLITE_MAGIC_OPEN &&
+ magic!=SQLITE_MAGIC_BUSY ) return 0;
+ return 1;
}
diff --git a/src/vdbe.c b/src/vdbe.c
index a827115b9..0f74f740b 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
-** $Id: vdbe.c,v 1.704 2008/01/22 21:30:53 drh Exp $
+** $Id: vdbe.c,v 1.705 2008/01/23 03:03:05 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -3905,7 +3905,7 @@ case OP_ParseSchema: {
"SELECT name, rootpage, sql FROM '%q'.%s WHERE %s",
db->aDb[iDb].zName, zMaster, pOp->p4.z);
if( zSql==0 ) goto no_mem;
- sqlite3SafetyOff(db);
+ (void)sqlite3SafetyOff(db);
assert( db->init.busy==0 );
db->init.busy = 1;
assert( !db->mallocFailed );
@@ -3913,7 +3913,7 @@ case OP_ParseSchema: {
if( rc==SQLITE_ABORT ) rc = initData.rc;
sqlite3_free(zSql);
db->init.busy = 0;
- sqlite3SafetyOn(db);
+ (void)sqlite3SafetyOn(db);
if( rc==SQLITE_NOMEM ){
goto no_mem;
}
@@ -4798,11 +4798,7 @@ abort_due_to_error:
*/
abort_due_to_interrupt:
assert( db->u1.isInterrupted );
- if( db->magic!=SQLITE_MAGIC_BUSY ){
- rc = SQLITE_MISUSE;
- }else{
- rc = SQLITE_INTERRUPT;
- }
+ rc = SQLITE_INTERRUPT;
p->rc = rc;
sqlite3SetString(&p->zErrMsg, sqlite3ErrStr(rc), (char*)0);
goto vdbe_error_halt;
diff --git a/src/vdbeapi.c b/src/vdbeapi.c
index 7d44fb158..df9c75f68 100644
--- a/src/vdbeapi.c
+++ b/src/vdbeapi.c
@@ -44,7 +44,9 @@ int sqlite3_finalize(sqlite3_stmt *pStmt){
rc = SQLITE_OK;
}else{
Vdbe *v = (Vdbe*)pStmt;
+#ifndef SQLITE_MUTEX_NOOP
sqlite3_mutex *mutex = v->db->mutex;
+#endif
sqlite3_mutex_enter(mutex);
rc = sqlite3VdbeFinalize(v);
sqlite3_mutex_leave(mutex);
@@ -81,12 +83,14 @@ int sqlite3_reset(sqlite3_stmt *pStmt){
int sqlite3_clear_bindings(sqlite3_stmt *pStmt){
int i;
int rc = SQLITE_OK;
- Vdbe *v = (Vdbe*)pStmt;
- sqlite3_mutex_enter(v->db->mutex);
+#ifndef SQLITE_MUTEX_NOOP
+ sqlite3_mutex *mutex = ((Vdbe*)pStmt)->db->mutex;
+#endif
+ sqlite3_mutex_enter(mutex);
for(i=1; rc==SQLITE_OK && i<=sqlite3_bind_parameter_count(pStmt); i++){
rc = sqlite3_bind_null(pStmt, i);
}
- sqlite3_mutex_leave(v->db->mutex);
+ sqlite3_mutex_leave(mutex);
return rc;
}
diff --git a/src/vdbeaux.c b/src/vdbeaux.c
index dc4cc1a5c..c15207b9b 100644
--- a/src/vdbeaux.c
+++ b/src/vdbeaux.c
@@ -1021,9 +1021,9 @@ void sqlite3VdbeFreeCursor(Vdbe *p, Cursor *pCx){
sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
const sqlite3_module *pModule = pCx->pModule;
p->inVtabMethod = 1;
- sqlite3SafetyOff(p->db);
+ (void)sqlite3SafetyOff(p->db);
pModule->xClose(pVtabCursor);
- sqlite3SafetyOn(p->db);
+ (void)sqlite3SafetyOn(p->db);
p->inVtabMethod = 0;
}
#endif
@@ -1167,9 +1167,9 @@ static int vdbeCommit(sqlite3 *db){
/* If there are any write-transactions at all, invoke the commit hook */
if( needXcommit && db->xCommitCallback ){
- sqlite3SafetyOff(db);
+ (void)sqlite3SafetyOff(db);
rc = db->xCommitCallback(db->pCommitArg);
- sqlite3SafetyOn(db);
+ (void)sqlite3SafetyOn(db);
if( rc ){
return SQLITE_CONSTRAINT;
}
@@ -1617,9 +1617,9 @@ int sqlite3VdbeReset(Vdbe *p){
** error, then it might not have been halted properly. So halt
** it now.
*/
- sqlite3SafetyOn(db);
+ (void)sqlite3SafetyOn(db);
sqlite3VdbeHalt(p);
- sqlite3SafetyOff(db);
+ (void)sqlite3SafetyOff(db);
/* If the VDBE has be run even partially, then transfer the error code
** and error message from the VDBE into the main database structure. But
diff --git a/src/vdbeblob.c b/src/vdbeblob.c
index 1fa71f121..6565294c6 100644
--- a/src/vdbeblob.c
+++ b/src/vdbeblob.c
@@ -12,7 +12,7 @@
**
** This file contains code used to implement incremental BLOB I/O.
**
-** $Id: vdbeblob.c,v 1.18 2008/01/10 23:50:11 drh Exp $
+** $Id: vdbeblob.c,v 1.19 2008/01/23 03:03:05 drh Exp $
*/
#include "sqliteInt.h"
@@ -109,7 +109,7 @@ int sqlite3_blob_open(
}
sqlite3_free(sParse.zErrMsg);
rc = SQLITE_ERROR;
- sqlite3SafetyOff(db);
+ (void)sqlite3SafetyOff(db);
sqlite3BtreeLeaveAll(db);
goto blob_open_out;
}
@@ -123,7 +123,7 @@ int sqlite3_blob_open(
if( iCol==pTab->nCol ){
sqlite3_snprintf(sizeof(zErr), zErr, "no such column: \"%s\"", zColumn);
rc = SQLITE_ERROR;
- sqlite3SafetyOff(db);
+ (void)sqlite3SafetyOff(db);
sqlite3BtreeLeaveAll(db);
goto blob_open_out;
}
@@ -141,7 +141,7 @@ int sqlite3_blob_open(
sqlite3_snprintf(sizeof(zErr), zErr,
"cannot open indexed column for writing");
rc = SQLITE_ERROR;
- sqlite3SafetyOff(db);
+ (void)sqlite3SafetyOff(db);
sqlite3BtreeLeaveAll(db);
goto blob_open_out;
}
diff --git a/src/vtab.c b/src/vtab.c
index 5402695e8..776f36ead 100644
--- a/src/vtab.c
+++ b/src/vtab.c
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to help implement virtual tables.
**
-** $Id: vtab.c,v 1.62 2008/01/17 16:22:15 drh Exp $
+** $Id: vtab.c,v 1.63 2008/01/23 03:03:05 drh Exp $
*/
#ifndef SQLITE_OMIT_VIRTUALTABLE
#include "sqliteInt.h"
@@ -93,12 +93,12 @@ void sqlite3VtabLock(sqlite3_vtab *pVtab){
void sqlite3VtabUnlock(sqlite3 *db, sqlite3_vtab *pVtab){
pVtab->nRef--;
assert(db);
- assert(!sqlite3SafetyCheck(db));
+ assert( sqlite3SafetyCheckOk(db) );
if( pVtab->nRef==0 ){
if( db->magic==SQLITE_MAGIC_BUSY ){
- sqlite3SafetyOff(db);
+ (void)sqlite3SafetyOff(db);
pVtab->pModule->xDisconnect(pVtab);
- sqlite3SafetyOn(db);
+ (void)sqlite3SafetyOn(db);
} else {
pVtab->pModule->xDisconnect(pVtab);
}
@@ -594,7 +594,7 @@ int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab)
if( xDestroy ){
rc = xDestroy(pTab->pVtab);
}
- sqlite3SafetyOn(db);
+ (void)sqlite3SafetyOn(db);
if( rc==SQLITE_OK ){
pTab->pVtab = 0;
}
diff --git a/src/where.c b/src/where.c
index 1ad296e13..ae8fb4b8c 100644
--- a/src/where.c
+++ b/src/where.c
@@ -16,7 +16,7 @@
** so is applicable. Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
**
-** $Id: where.c,v 1.284 2008/01/19 20:11:26 drh Exp $
+** $Id: where.c,v 1.285 2008/01/23 03:03:05 drh Exp $
*/
#include "sqliteInt.h"
@@ -1381,7 +1381,7 @@ static double bestVirtualIndex(
*(int*)&pIdxInfo->nOrderBy = 0;
}
- sqlite3SafetyOff(pParse->db);
+ (void)sqlite3SafetyOff(pParse->db);
WHERETRACE(("xBestIndex for %s\n", pTab->zName));
TRACE_IDX_INPUTS(pIdxInfo);
rc = pTab->pVtab->pModule->xBestIndex(pTab->pVtab, pIdxInfo);
@@ -1392,10 +1392,8 @@ static double bestVirtualIndex(
}else {
sqlite3ErrorMsg(pParse, "%s", sqlite3ErrStr(rc));
}
- sqlite3SafetyOn(pParse->db);
- }else{
- rc = sqlite3SafetyOn(pParse->db);
}
+ (void)sqlite3SafetyOn(pParse->db);
*(int*)&pIdxInfo->nOrderBy = nOrderBy;
return pIdxInfo->estimatedCost;
diff --git a/test/safety.test b/test/safety.test
index fb8c56cbd..ebbe8ec43 100644
--- a/test/safety.test
+++ b/test/safety.test
@@ -13,11 +13,17 @@
# functions. Those routines are not strictly necessary - they are
# designed to detect misuse of the library.
#
-# $Id: safety.test,v 1.2 2006/01/03 00:33:50 drh Exp $
+# $Id: safety.test,v 1.3 2008/01/23 03:03:05 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+ifcapable !debug {
+ puts "Skipping safety tests since SQLITE_DEBUG is off"
+ finish_test
+ return
+}
+
do_test safety-1.1 {
set DB [sqlite3_connection_pointer db]
db eval {CREATE TABLE t1(a)}