1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Some elements of the new malloc() failure handling. Not all cases work properly yet. Also, library is not threadsafe if malloc() fails right now. (CVS 2800)

FossilOrigin-Name: e1606658f1b4530e3001db4779b5669c8d13c853
This commit is contained in:
danielk1977
2005-12-06 12:52:59 +00:00
parent 67e0b84f7d
commit 261919cc16
30 changed files with 446 additions and 267 deletions

View File

@@ -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.304 2005/11/30 03:20:31 drh Exp $
** $Id: main.c,v 1.305 2005/12/06 12:52:59 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -635,7 +635,7 @@ int sqlite3BtreeFactory(
*/
const char *sqlite3_errmsg(sqlite3 *db){
const char *z;
if( sqlite3_malloc_failed ){
if( sqlite3Tsd()->mallocFailed ){
return sqlite3ErrStr(SQLITE_NOMEM);
}
if( sqlite3SafetyCheck(db) || db->errCode==SQLITE_MISUSE ){
@@ -674,7 +674,7 @@ const void *sqlite3_errmsg16(sqlite3 *db){
};
const void *z;
if( sqlite3_malloc_failed ){
if( sqlite3Tsd()->mallocFailed ){
return (void *)(&outOfMemBe[SQLITE_UTF16NATIVE==SQLITE_UTF16LE?1:0]);
}
if( sqlite3SafetyCheck(db) || db->errCode==SQLITE_MISUSE ){
@@ -694,7 +694,7 @@ const void *sqlite3_errmsg16(sqlite3 *db){
** Return the most recent error code generated by an SQLite routine.
*/
int sqlite3_errcode(sqlite3 *db){
if( sqlite3_malloc_failed ){
if( sqlite3Tsd()->mallocFailed ){
return SQLITE_NOMEM;
}
if( sqlite3SafetyCheck(db) ){
@@ -742,8 +742,7 @@ static int openDatabase(
if( sqlite3_create_collation(db, "BINARY", SQLITE_UTF8, 0,binCollFunc) ||
sqlite3_create_collation(db, "BINARY", SQLITE_UTF16, 0,binCollFunc) ||
(db->pDfltColl = sqlite3FindCollSeq(db, db->enc, "BINARY", 6, 0))==0 ){
rc = db->errCode;
assert( rc!=SQLITE_OK );
assert(rc!=SQLITE_OK || sqlite3Tsd()->mallocFailed);
db->magic = SQLITE_MAGIC_CLOSED;
goto opendb_out;
}
@@ -786,7 +785,7 @@ static int openDatabase(
db->magic = SQLITE_MAGIC_OPEN;
opendb_out:
if( sqlite3_errcode(db)==SQLITE_OK && sqlite3_malloc_failed ){
if( sqlite3_errcode(db)==SQLITE_OK && sqlite3Tsd()->mallocFailed ){
sqlite3Error(db, SQLITE_NOMEM, 0);
}
*ppDb = db;
@@ -1010,12 +1009,13 @@ int sqlite3_collation_needed16(
** dangerous and will almost certainly result in malfunctions.
*/
int sqlite3_global_recover(){
#if 0
int rc = SQLITE_OK;
if( sqlite3_malloc_failed ){
if( sqlite3Tsd()->mallocFailed ){
sqlite3 *db;
int i;
sqlite3_malloc_failed = 0;
sqlite3Tsd()->mallocFailed = 0;
for(db=pDbList; db; db=db->pNext ){
sqlite3ExpirePreparedStatements(db);
for(i=0; i<db->nDb; i++){
@@ -1030,9 +1030,11 @@ int sqlite3_global_recover(){
recover_out:
if( rc!=SQLITE_OK ){
sqlite3_malloc_failed = 1;
sqlite3Tsd()->mallocFailed = 1;
}
return rc;
#endif
return SQLITE_OK;
}
#endif