-C Recursive\smutexes\sin\sos_win.c.\s(CVS\s2969)
-D 2006-01-18T14:20:17
+C Change\ssqlite3MallocClearFailed()\scalls\sto\ssqlite3ApiExit(),\sa\sbetter\sAPI.\s(CVS\s2970)
+D 2006-01-18T15:25:17
F Makefile.in ab3ffd8d469cef4477257169b82810030a6bb967
F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
F src/analyze.c 7d2b7ab9a9c2fd6e55700f69064dfdd3e36d7a8a
F src/attach.c a447b4672a5125abc4ee27df10621abd84d18301
F src/auth.c 9ae84d2d94eb96195e04515715e08e85963e96c2
-F src/btree.c fcf6aec3b6a6df8130213a45f7b543e0a025be9d
+F src/btree.c cff3ab167ad25b394d8c8dcac783bf3db5ae7e31
F src/btree.h 5663c4f43e8521546ccebc8fc95acb013b8f3184
F src/build.c 539b5c6e21aa633e480ff97706f331baef1a859a
F src/callback.c ba3e6cc7a6beb562e7a66f92e26fabcb21aab1e2
-F src/complete.c df1681cef40dec33a286006981845f87b194e7a4
+F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675
F src/date.c 2f148728b53675266cd9e1a873fd702929d3f4ee
F src/delete.c c7bd5708a629585e073ce34cf3b1fcb52c2fef38
F src/experimental.c 50c1e3b34f752f4ac10c36f287db095c2b61766d
F src/hash.c 8747cf51d12de46512880dfcf1b68b4e24072863
F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
F src/insert.c a5595cf8d1d8ba087b676a63f1f7277ea44b5ac1
-F src/legacy.c 9bf7ee1b63c99aac6669533986a5240b16101458
-F src/main.c fd9cb79c9fb6c61a67ad8be19a782372b0c4f48d
+F src/legacy.c 0fd27db5e07a46853b9876baaa370b40e75a9b40
+F src/main.c bf810309d9760654f58c77688524d2a556b2827c
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/os.c 1d1a61cdf150e9f9520a3bc787c8465148ea2e78
F src/os.h 9debc3d3ca4cdafde222a0ea74a4c8415aef4f22
F src/os_common.h 95b29ca6f3e6636cb33c9219b3f91a96fa7224b1
F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c
F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3
-F src/os_unix.c 7c085f807922309006f00b5fd8963865b92ff939
+F src/os_unix.c fb7ae89d8672102b60e855dae5834f9d1ef7c99c
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
F src/os_win.c e1c0600129f2468c8a852ae61f7b7bacf72aa7dc
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
-F src/pager.c e84713f7196a81103cc8e2b55cebbaa1723c4926
+F src/pager.c 62c0f6b4c4856a760d4a7430c88492a7b626ac18
F src/pager.h e0acb095b3ad0bca48f2ab00c87346665643f64f
F src/parse.y 83df51fea35f68f7e07384d75dce83d1ed30434c
F src/pragma.c 4496cc77dc35824e1c978c3d1413b8a5a4c777d3
-F src/prepare.c 84c3cbca337a49133554108d748864c5e13aef34
+F src/prepare.c 1294009215173899f3d64dc16f1dc50edaedbb6a
F src/printf.c f47a2f4b5387cd2ebb12e9117a1a5d6bd9a2b812
F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261
F src/select.c 28d449c7762dd580aaba49a9c6c16e93ca951e49
F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c 66b073375efbdee19045e7e0cd38b85f9aff71da
F src/sqlite.h.in 492580f7e3ff71eb43193eb7bb98e2d549889ce3
-F src/sqliteInt.h d7b20e0a9453db123809d0bcc46d6ae0e4cf6bca
+F src/sqliteInt.h b23caafa3ce3d71f4a0f0e3aa3fb6779eda3a1b7
F src/table.c 486dcfce532685b53b5a2b5da8bba0ded6fb2316
F src/tclsqlite.c d650bea0248fc0a310ddc2cb94273a3a5021fddf
F src/test1.c b076d9c42b547ec0891b67722f00681b21756d91
F src/trigger.c 694b247476d2fc0dce003af564f79e8752fc1158
F src/update.c 261d75c702c2852d1a64274d7c414485e6f2d177
F src/utf.c 5ab8ca05d4e9ec81174b010f01ab12a232f0087d
-F src/util.c 25e867296bce168095c87460ab5eec150015cb7d
+F src/util.c 28f399a6e3b4b55caf635f1941ee2391072d1a78
F src/vacuum.c 21a3c7f6f7be86bb1182fbc3df416ad702435b9e
F src/vdbe.c 3db9bfc86e71dc0758524fb82cfcfd4c30e92716
F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13
F src/vdbeInt.h 5451cf71f229e366ac543607c0a17f36e5737ea9
-F src/vdbeapi.c 2c3068bc5d17f7bd179b346a4a920199ea451694
+F src/vdbeapi.c cbc552ea2d1acca790cfee88bb7e670cf34a054b
F src/vdbeaux.c 723e0ec773aeec53e9448b2ac5b136677e64ece0
F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
F src/vdbemem.c dd08a0eea4868ac4a2d91fdec32424308b1db772
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 8830bbbac8e0c9243956aac42dc9f86a0bd1fa07
-R 7ad1313dca6d71746c68d32b98aa5742
-U drh
-Z 25414a8af7b032353ad4c225fe562fb4
+P dd3e07cae4d0cbd4f8977e1dd11e0103e0e45b75
+R baef608325fb18b2b8e10ab8f84cb339
+U danielk1977
+Z 2a85eb76c461ae700bdd874fef6ec61c
-dd3e07cae4d0cbd4f8977e1dd11e0103e0e45b75
\ No newline at end of file
+e0b022e5b2bfd272b4e25cd7a7b472206a118bbe
\ No newline at end of file
** May you share freely, never taking more than you give.
**
*************************************************************************
-** $Id: btree.c,v 1.299 2006/01/16 15:14:27 danielk1977 Exp $
+** $Id: btree.c,v 1.300 2006/01/18 15:25:17 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
sqlite3pager_set_pagesize(pBt->pPager, pBt->pageSize);
#ifndef SQLITE_OMIT_SHARED_CACHE
- /* Add the new btree to the linked list starting at ThreadData.pBtree */
+ /* Add the new btree to the linked list starting at ThreadData.pBtree.
+ ** There is no chance that a malloc() may fail inside of the
+ ** sqlite3ThreadData() call, as the ThreadData structure must have already
+ ** been allocated for pTsdro->useSharedData to be non-zero.
+ */
if( pTsdro->useSharedData && zFilename && !isMemdb ){
pBt->pNext = pTsdro->pBtree;
sqlite3ThreadData()->pBtree = pBt;
return SQLITE_OK;
}
- /* Remove the shared-btree from the thread wide list */
- pTsd = sqlite3ThreadData();
+ /* Remove the shared-btree from the thread wide list. Call
+ ** ThreadDataReadOnly() and then cast away the const property of the
+ ** pointer to avoid allocating thread data if it is not really required.
+ */
+ pTsd = (ThreadData *)sqlite3ThreadDataReadOnly();
if( pTsd->pBtree==pBt ){
+ assert( pTsd==sqlite3ThreadData() );
pTsd->pBtree = pBt->pNext;
}else{
BtShared *pPrev;
for(pPrev=pTsd->pBtree; pPrev && pPrev->pNext!=pBt; pPrev=pPrev->pNext);
if( pPrev ){
+ assert( pTsd==sqlite3ThreadData() );
pPrev->pNext = pBt->pNext;
}
}
** separating it out, the code will be automatically omitted from
** static links that do not use it.
**
-** $Id: complete.c,v 1.2 2005/12/12 06:53:04 danielk1977 Exp $
+** $Id: complete.c,v 1.3 2006/01/18 15:25:17 danielk1977 Exp $
*/
#include "sqliteInt.h"
#ifndef SQLITE_OMIT_COMPLETE
zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8);
if( zSql8 ){
rc = sqlite3_complete(zSql8);
- }else if( zSql ){
- rc = SQLITE_NOMEM;
- sqlite3MallocClearFailed();
}
sqlite3ValueFree(pVal);
- return rc;
+ return sqlite3ApiExit(0, rc);
}
#endif /* SQLITE_OMIT_UTF16 */
#endif /* SQLITE_OMIT_COMPLETE */
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
-** $Id: legacy.c,v 1.11 2006/01/11 21:41:22 drh Exp $
+** $Id: legacy.c,v 1.12 2006/01/18 15:25:17 danielk1977 Exp $
*/
#include "sqliteInt.h"
if( pStmt ) sqlite3_finalize(pStmt);
if( azCols ) sqliteFree(azCols);
- if( sqlite3ThreadDataReadOnly()->mallocFailed ){
- rc = SQLITE_NOMEM;
- sqlite3MallocClearFailed();
- }
-
+ rc = sqlite3ApiExit(0, rc);
if( rc!=SQLITE_OK && rc==sqlite3_errcode(db) && pzErrMsg ){
*pzErrMsg = malloc(1+strlen(sqlite3_errmsg(db)));
if( *pzErrMsg ){
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
-** $Id: main.c,v 1.326 2006/01/18 05:51:58 danielk1977 Exp $
+** $Id: main.c,v 1.327 2006/01/18 15:25:17 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
assert( !sqlite3ThreadDataReadOnly()->mallocFailed );
rc = sqlite3CreateFunc(db, zFunctionName, nArg, enc, p, xFunc, xStep, xFinal);
- if( sqlite3ThreadDataReadOnly()->mallocFailed ){
- sqlite3MallocClearFailed();
- rc = SQLITE_NOMEM;
- sqlite3Error(db, SQLITE_NOMEM, 0);
- }
- return rc;
+ return sqlite3ApiExit(db, rc);
}
#ifndef SQLITE_OMIT_UTF16
rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal);
sqliteFree(zFunc8);
- if( sqlite3ThreadDataReadOnly()->mallocFailed ){
- sqlite3MallocClearFailed();
- rc = SQLITE_NOMEM;
- sqlite3Error(db, SQLITE_NOMEM, 0);
- }
- return rc;
+ return sqlite3ApiExit(db, rc);
}
#endif
SQLITE_UTF8, SQLITE_STATIC);
z = sqlite3_value_text16(db->pErr);
}
- sqlite3MallocClearFailed();
+ sqlite3ApiExit(0, 0);
return z;
}
#endif /* SQLITE_OMIT_UTF16 */
createCollation(db, "BINARY", SQLITE_UTF16, 0,binCollFunc) ||
(db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 6, 0))==0
){
- /* sqlite3_create_collation() is an external API. So the mallocFailed flag
- ** will have been cleared before returning. So set it explicitly here.
- */
- sqlite3ThreadData()->mallocFailed = 1;
+ assert( sqlite3ThreadDataReadOnly()->mallocFailed );
db->magic = SQLITE_MAGIC_CLOSED;
goto opendb_out;
}
db = 0;
}
*ppDb = db;
- sqlite3MallocClearFailed();
- return rc;
+ return sqlite3ApiExit(0, rc);
}
/*
sqlite3 **ppDb
){
char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */
- int rc = SQLITE_NOMEM;
+ int rc = SQLITE_OK;
sqlite3_value *pVal;
assert( zFilename );
*ppDb = 0;
}
}
- }else{
- assert( sqlite3ThreadDataReadOnly()->mallocFailed );
- sqlite3MallocClearFailed();
}
sqlite3ValueFree(pVal);
- return rc;
+ return sqlite3ApiExit(0, rc);
}
#endif /* SQLITE_OMIT_UTF16 */
int rc;
assert( !sqlite3ThreadDataReadOnly()->mallocFailed );
rc = createCollation(db, zName, enc, pCtx, xCompare);
- if( sqlite3ThreadDataReadOnly()->mallocFailed ){
- sqlite3MallocClearFailed();
- rc = SQLITE_NOMEM;
- sqlite3Error(db, rc, 0);
- }
- return rc;
+ return sqlite3ApiExit(db, rc);
}
#ifndef SQLITE_OMIT_UTF16
rc = createCollation(db, zName8, enc, pCtx, xCompare);
sqliteFree(zName8);
}
- if( sqlite3ThreadDataReadOnly()->mallocFailed ){
- sqlite3MallocClearFailed();
- rc = SQLITE_NOMEM;
- sqlite3Error(db, rc, 0);
- }
- return rc;
+ return sqlite3ApiExit(db, rc);
}
#endif /* SQLITE_OMIT_UTF16 */
*/
int sqlite3_enable_shared_cache(int enable){
ThreadData *pTd = sqlite3ThreadData();
+ if( !pTd ){
+ return SQLITE_NOMEM;
+ }
/* It is only legal to call sqlite3_enable_shared_cache() when there
** are no currently open b-trees that were opened by the calling thread.
*/
void sqlite3_thread_cleanup(void){
ThreadData *pTd = sqlite3ThreadData();
- memset(pTd, 0, sizeof(*pTd));
+ if( pTd ){
+ memset(pTd, 0, sizeof(*pTd));
+ }
sqlite3ReleaseThreadData();
}
# define TSD_COUNTER(N) /* no-op */
#endif
+#if 0 && defined(SQLITE_MEMDEBUG)
+static void *mallocThreadData(size_t nBytes){
+ if( sqlite3_iMallocFail>=0 ){
+ sqlite3_iMallocFail--;
+ if( sqlite3_iMallocFail==0 ){
+ return 0;
+ }
+ }
+ return sqlite3OsMalloc(nBytes);
+}
+#else
+ #define mallocThreadData(x) sqlite3OsMalloc(x)
+#endif
/*
** If called with allocateFlag>0, then return a pointer to thread
pTsd = pthread_getspecific(key);
if( allocateFlag>0 ){
if( pTsd==0 ){
- pTsd = sqlite3OsMalloc(sizeof(zeroData));
+ pTsd = mallocThreadData(sizeof(zeroData));
if( pTsd ){
*pTsd = zeroData;
pthread_setspecific(key, pTsd);
static ThreadData *pTsd = 0;
if( allocateFlag>0 ){
if( pTsd==0 ){
- pTsd = sqlite3OsMalloc( sizeof(zeroData) );
+ pTsd = mallocThreadData( sizeof(zeroData) );
if( pTsd ){
*pTsd = zeroData;
TSD_COUNTER(+1);
** file simultaneously, or one process from reading the database while
** another is writing.
**
-** @(#) $Id: pager.c,v 1.241 2006/01/16 15:32:23 danielk1977 Exp $
+** @(#) $Id: pager.c,v 1.242 2006/01/18 15:25:17 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
int noReadlock = (flags & PAGER_NO_READLOCK)!=0;
char zTemp[SQLITE_TEMPNAME_SIZE];
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
+ /* A malloc() cannot fail in sqlite3ThreadData() as one or more calls to
+ ** malloc() must have already been made by this thread before it gets
+ ** to this point. This means the ThreadData must have been allocated already
+ ** so that ThreadData.nAlloc can be set. It would be nice to assert
+ ** that ThreadData.nAlloc is non-zero, but alas this breaks test cases
+ ** written to invoke the pager directly.
+ */
ThreadData *pTsd = sqlite3ThreadData();
+ assert( pTsd );
#endif
/* If malloc() has already failed return SQLITE_NOMEM. Before even
int sqlite3pager_close(Pager *pPager){
PgHdr *pPg, *pNext;
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
+ /* A malloc() cannot fail in sqlite3ThreadData() as one or more calls to
+ ** malloc() must have already been made by this thread before it gets
+ ** to this point. This means the ThreadData must have been allocated already
+ ** so that ThreadData.nAlloc can be set.
+ */
ThreadData *pTsd = sqlite3ThreadData();
+ assert( pTsd && pTsd->nAlloc );
#endif
switch( pPager->state ){
** interface, and routines that contribute to loading the database schema
** from disk.
**
-** $Id: prepare.c,v 1.24 2006/01/17 13:21:40 danielk1977 Exp $
+** $Id: prepare.c,v 1.25 2006/01/18 15:25:18 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
sqlite3Error(db, rc, 0);
}
- /* We must check for malloc failure last of all, in case malloc() failed
- ** inside of the sqlite3Error() call above or something.
- */
- if( sParse.pTsd->mallocFailed ){
- rc = SQLITE_NOMEM;
- sqlite3Error(db, rc, 0);
- }
-
sParse.pTsd->nRef--;
- sqlite3MallocClearFailed();
+ rc = sqlite3ApiExit(db, rc);
sqlite3ReleaseThreadData();
return rc;
}
** encoded string to UTF-8, then invoking sqlite3_prepare(). The
** tricky bit is figuring out the pointer to return in *pzTail.
*/
- char *zSql8 = 0;
+ char *zSql8;
const char *zTail8 = 0;
- int rc;
+ int rc = SQLITE_OK;
if( sqlite3SafetyCheck(db) ){
return SQLITE_MISUSE;
}
zSql8 = sqlite3utf16to8(zSql, nBytes);
- if( !zSql8 ){
- sqlite3MallocClearFailed();
- sqlite3Error(db, SQLITE_NOMEM, 0);
- return SQLITE_NOMEM;
+ if( zSql8 ){
+ rc = sqlite3_prepare(db, zSql8, -1, ppStmt, &zTail8);
}
- rc = sqlite3_prepare(db, zSql8, -1, ppStmt, &zTail8);
if( zTail8 && pzTail ){
/* If sqlite3_prepare returns a tail pointer, we calculate the
*pzTail = (u8 *)zSql + sqlite3utf16ByteLen(zSql, chars_parsed);
}
sqliteFree(zSql8);
- return rc;
+ return sqlite3ApiExit(db, rc);
}
#endif /* SQLITE_OMIT_UTF16 */
*************************************************************************
** Internal interface definitions for SQLite.
**
-** @(#) $Id: sqliteInt.h,v 1.472 2006/01/17 16:10:14 danielk1977 Exp $
+** @(#) $Id: sqliteInt.h,v 1.473 2006/01/18 15:25:18 danielk1977 Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
void (*)(sqlite3_context*,int,sqlite3_value **),
void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*));
+int sqlite3ApiExit(sqlite3 *db, int);
#ifndef SQLITE_OMIT_SHARED_CACHE
void sqlite3TableLock(Parse *, int, int, u8, const char *);
#define sqlite3TableLock(v,w,x,y,z)
#endif
-void sqlite3MallocClearFailed();
#ifdef SQLITE_MEMDEBUG
void sqlite3MallocDisallow();
void sqlite3MallocAllow();
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
-** $Id: util.c,v 1.173 2006/01/17 15:36:32 danielk1977 Exp $
+** $Id: util.c,v 1.174 2006/01/18 15:25:18 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
}
/*
-** Clear the "mallocFailed" flag. This should be invoked before exiting any
-** entry points that may have called sqliteMalloc().
+** This function must be called before exiting any API function (i.e.
+** returning control to the user) that has called sqlite3Malloc or
+** sqlite3Realloc.
+**
+** The returned value is normally a copy of the second argument to this
+** function. However, if a malloc() failure has occured since the previous
+** invocation SQLITE_NOMEM is returned instead.
+**
+** If the first argument, db, is not NULL and a malloc() error has occured,
+** then the connection error-code (the value returned by sqlite3_errcode())
+** is set to SQLITE_NOMEM.
*/
-void sqlite3MallocClearFailed(){
+int sqlite3ApiExit(sqlite3* db, int rc){
ThreadData *pTd = sqlite3OsThreadSpecificData(0);
if( pTd && pTd->mallocFailed ){
pTd->mallocFailed = 0;
- sqlite3OsThreadSpecificData(0);
+ if( db ){
+ sqlite3Error(db, SQLITE_NOMEM, 0);
+ }
+ return SQLITE_NOMEM;
}
+ return rc;
}
#ifdef SQLITE_MEMDEBUG
#endif
sqlite3Error(p->db, rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
- sqlite3MallocClearFailed();
- return rc;
+ return sqlite3ApiExit(p->db, rc);
}
/*
** SQLITE_NOMEM. The next call to _step() (if any) will return SQLITE_ERROR
** and _finalize() will return NOMEM.
*/
- if( sqlite3ThreadDataReadOnly()->mallocFailed ){
- ((Vdbe *)pStmt)->rc = SQLITE_NOMEM;
- sqlite3MallocClearFailed();
- }
+ Vdbe *p = (Vdbe *)pStmt;
+ p->rc = sqlite3ApiExit(0, p->rc);
}
/**************************** sqlite3_column_ *******************************
/* A malloc may have failed inside of the xFunc() call. If this is the case,
** clear the mallocFailed flag and return NULL.
*/
- sqlite3MallocClearFailed();
+ sqlite3ApiExit(0, 0);
return ret;
}
if( rc==SQLITE_OK && encoding!=0 ){
rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
}
- sqlite3MallocClearFailed();
+
sqlite3Error(((Vdbe *)pStmt)->db, rc, 0);
- return rc;
+ return sqlite3ApiExit(((Vdbe *)pStmt)->db, rc);
}