mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-16 23:02:26 +03:00
All of the malloc test cases run. Still seeing failures in malloc4.test. (CVS 4272)
FossilOrigin-Name: 205d0b881d541db65837ce6cf44d58d607635bc2
This commit is contained in:
11
src/mem2.c
11
src/mem2.c
@@ -12,7 +12,7 @@
|
||||
** This file contains the C functions that implement a memory
|
||||
** allocation subsystem for use by SQLite.
|
||||
**
|
||||
** $Id: mem2.c,v 1.6 2007/08/22 20:18:22 drh Exp $
|
||||
** $Id: mem2.c,v 1.7 2007/08/22 22:04:37 drh Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -454,6 +454,15 @@ int sqlite3_memdebug_fail(int iFail, int iRepeat){
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine returns the number of successful mallocs remaining until
|
||||
** the next simulated malloc failure. -1 is returned if no simulated
|
||||
** failure is currently scheduled.
|
||||
*/
|
||||
int sqlite3_memdebug_pending(void){
|
||||
return mem.iFail-1;
|
||||
}
|
||||
|
||||
/*
|
||||
** The following two routines are used to assert that no memory
|
||||
** allocations occur between one call and the next. The use of
|
||||
|
||||
19
src/pager.c
19
src/pager.c
@@ -18,7 +18,7 @@
|
||||
** file simultaneously, or one process from reading the database while
|
||||
** another is writing.
|
||||
**
|
||||
** @(#) $Id: pager.c,v 1.367 2007/08/22 18:54:33 danielk1977 Exp $
|
||||
** @(#) $Id: pager.c,v 1.368 2007/08/22 22:04:37 drh Exp $
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_DISKIO
|
||||
#include "sqliteInt.h"
|
||||
@@ -538,7 +538,9 @@ static int pageInStatement(PgHdr *pPg){
|
||||
static void pager_resize_hash_table(Pager *pPager, int N){
|
||||
PgHdr **aHash, *pPg;
|
||||
assert( N>0 && (N&(N-1))==0 );
|
||||
pagerLeave(pPager);
|
||||
aHash = sqlite3MallocZero( sizeof(aHash[0])*N );
|
||||
pagerEnter(pPager);
|
||||
if( aHash==0 ){
|
||||
/* Failure to rehash is not an error. It is only a performance hit. */
|
||||
return;
|
||||
@@ -2873,7 +2875,7 @@ int sqlite3PagerReleaseMemory(int nReq){
|
||||
Pager *pPager = sqlite3PagerList;
|
||||
for( ; pPager && (nReq<0 || nReleased<nReq); pPager=pPager->pNext){
|
||||
PgHdr *pPg;
|
||||
int rc;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
/* In-memory databases should not appear on the pager list */
|
||||
assert( !MEMDB );
|
||||
@@ -2885,7 +2887,10 @@ int sqlite3PagerReleaseMemory(int nReq){
|
||||
** calling fsync() if this is the first iteration of the outermost
|
||||
** loop).
|
||||
*/
|
||||
while( SQLITE_OK==(rc = pager_recycle(pPager, i, &pPg)) && pPg) {
|
||||
while( (nReq<0 || nReleased<nReq) &&
|
||||
SQLITE_OK==(rc = pager_recycle(pPager, i, &pPg)) &&
|
||||
pPg
|
||||
) {
|
||||
/* We've found a page to free. At this point the page has been
|
||||
** removed from the page hash-table, free-list and synced-list
|
||||
** (pFirstSynced). It is still in the all pages (pAll) list.
|
||||
@@ -3163,9 +3168,11 @@ static int pagerAllocatePage(Pager *pPager, PgHdr **ppPg){
|
||||
goto pager_allocate_out;
|
||||
}
|
||||
}
|
||||
pagerLeave(pPager);
|
||||
pPg = sqlite3_malloc( sizeof(*pPg) + pPager->pageSize
|
||||
+ sizeof(u32) + pPager->nExtra
|
||||
+ MEMDB*sizeof(PgHistory) );
|
||||
pagerEnter(pPager);
|
||||
if( pPg==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto pager_allocate_out;
|
||||
@@ -3486,7 +3493,9 @@ static int pager_open_journal(Pager *pPager){
|
||||
assert( pPager->useJournal );
|
||||
assert( pPager->aInJournal==0 );
|
||||
sqlite3PagerPagecount(pPager);
|
||||
pagerLeave(pPager);
|
||||
pPager->aInJournal = sqlite3MallocZero( pPager->dbSize/8 + 1 );
|
||||
pagerEnter(pPager);
|
||||
if( pPager->aInJournal==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto failed_to_open_journal;
|
||||
@@ -3610,7 +3619,9 @@ int sqlite3PagerBegin(DbPage *pPg, int exFlag){
|
||||
assert( pPager->origDbSize==0 );
|
||||
assert( pPager->aInJournal==0 );
|
||||
sqlite3PagerPagecount(pPager);
|
||||
pagerLeave(pPager);
|
||||
pPager->aInJournal = sqlite3MallocZero( pPager->dbSize/8 + 1 );
|
||||
pagerEnter(pPager);
|
||||
if( !pPager->aInJournal ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
@@ -4439,7 +4450,9 @@ static int pagerStmtBegin(Pager *pPager){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
assert( pPager->journalOpen );
|
||||
pagerLeave(pPager);
|
||||
pPager->aInStmt = sqlite3MallocZero( pPager->dbSize/8 + 1 );
|
||||
pagerEnter(pPager);
|
||||
if( pPager->aInStmt==0 ){
|
||||
/* sqlite3OsLock(pPager->fd, SHARED_LOCK); */
|
||||
return SQLITE_NOMEM;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
** This file contains code used to implement test interfaces to the
|
||||
** memory allocation subsystem.
|
||||
**
|
||||
** $Id: test_malloc.c,v 1.2 2007/08/15 20:41:29 drh Exp $
|
||||
** $Id: test_malloc.c,v 1.3 2007/08/22 22:04:37 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "tcl.h"
|
||||
@@ -228,7 +228,7 @@ static int test_memdebug_dump(
|
||||
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_memdebug_fail COUNTER REPEAT
|
||||
** Usage: sqlite3_memdebug_fail COUNTER ?REPEAT?
|
||||
**
|
||||
** Arrange for a simulated malloc() failure after COUNTER successes.
|
||||
** If REPEAT is 1 then all subsequent malloc()s fail. If REPEAT is
|
||||
@@ -249,12 +249,16 @@ static int test_memdebug_fail(
|
||||
int iFail;
|
||||
int iRepeat;
|
||||
int nFail = 0;
|
||||
if( objc!=3 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "COUNTER REPEAT");
|
||||
if( objc!=3 && objc!=2 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "COUNTER ?REPEAT?");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetIntFromObj(interp, objv[1], &iFail) ) return TCL_ERROR;
|
||||
if( Tcl_GetIntFromObj(interp, objv[2], &iRepeat) ) return TCL_ERROR;
|
||||
if( objc==3 ){
|
||||
if( Tcl_GetIntFromObj(interp, objv[2], &iRepeat) ) return TCL_ERROR;
|
||||
}else{
|
||||
iRepeat = -1;
|
||||
}
|
||||
#ifdef SQLITE_MEMDEBUG
|
||||
{
|
||||
extern int sqlite3_memdebug_fail(int,int);
|
||||
@@ -266,6 +270,25 @@ static int test_memdebug_fail(
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_memdebug_pending
|
||||
**
|
||||
** Return the number of successful mallocs remaining before the
|
||||
** next simulated failure. Return -1 if no simulated failure is
|
||||
** currently scheduled.
|
||||
*/
|
||||
static int test_memdebug_pending(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
extern int sqlite3_memdebug_pending(void);
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_memdebug_pending()));
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Register commands with the TCL interpreter.
|
||||
*/
|
||||
@@ -282,6 +305,7 @@ int Sqlitetest_malloc_Init(Tcl_Interp *interp){
|
||||
{ "sqlite3_memdebug_backtrace", test_memdebug_backtrace },
|
||||
{ "sqlite3_memdebug_dump", test_memdebug_dump },
|
||||
{ "sqlite3_memdebug_fail", test_memdebug_fail },
|
||||
{ "sqlite3_memdebug_pending", test_memdebug_pending },
|
||||
};
|
||||
int i;
|
||||
for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
|
||||
|
||||
Reference in New Issue
Block a user