diff options
author | drh <drh@noemail.net> | 2009-06-02 21:31:38 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2009-06-02 21:31:38 +0000 |
commit | e98c9049a0a56ea8c3a704a986298f1dc5a9af2f (patch) | |
tree | c2050cc77cfe5f1db7bd7619d17453b97a025cba | |
parent | c54a617e1ff59a717960a876977b7c56f2276715 (diff) | |
download | sqlite-e98c9049a0a56ea8c3a704a986298f1dc5a9af2f.tar.gz sqlite-e98c9049a0a56ea8c3a704a986298f1dc5a9af2f.zip |
Further reductions in the amount of stack space required. (CVS 6707)
FossilOrigin-Name: 04bad9eb6dd8bf7cafc9f3918b676e95d5b1c984
-rw-r--r-- | manifest | 20 | ||||
-rw-r--r-- | manifest.uuid | 2 | ||||
-rw-r--r-- | src/backup.c | 25 | ||||
-rw-r--r-- | src/bitvec.c | 41 | ||||
-rw-r--r-- | src/pager.c | 5 | ||||
-rw-r--r-- | src/sqliteInt.h | 4 | ||||
-rw-r--r-- | src/vtab.c | 60 |
7 files changed, 91 insertions, 66 deletions
@@ -1,5 +1,5 @@ -C Tweaks\sto\svdbe.c\sto\sfurther\sreduce\sstack\sspace\srequirements.\s(CVS\s6706) -D 2009-06-02T16:06:04 +C Further\sreductions\sin\sthe\samount\sof\sstack\sspace\srequired.\s(CVS\s6707) +D 2009-06-02T21:31:39 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 8b8fb7823264331210cddf103831816c286ba446 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -103,8 +103,8 @@ F src/alter.c 88b8cc66c09853b5723f66cfd0103dbebb62c562 F src/analyze.c e239496cfb5394ac8867f1c112905ddab8d01cd9 F src/attach.c 13995348fc5a26cdd136a50806faf292aabc173f F src/auth.c 98db07c2088455797678eb1031f42d4d94d18a71 -F src/backup.c 437efc2c3371b52bbb943b8c9dfabba774adcf86 -F src/bitvec.c ef370407e03440b0852d05024fb016b14a471d3d +F src/backup.c d189bc157268570e79377544caeaed2c0e00aac9 +F src/bitvec.c 0ef0651714728055d43de7a4cdd95e703fac0119 F src/btmutex.c 9b899c0d8df3bd68f527b0afe03088321b696d3c F src/btree.c 41bee6e4699e61f9d33beabfcf13caba4467c20a F src/btree.h 3748683b382bc3022f23840c0a35d3231b24fc6e @@ -146,7 +146,7 @@ F src/os_common.h 8c61457df58f1a4bd5f5adc3e90e01b37bf7afbc F src/os_os2.c bed77dc26e3a95ce4a204936b9a1ca6fe612fcc5 F src/os_unix.c e55d977c516ed880a2f83f0610b019efd9f8bc06 F src/os_win.c 725c38a524d168ce280446ad8761d731bc516405 -F src/pager.c 47acbe149a48abbe578f1d753706e6b0ab9d8001 +F src/pager.c 30aafb668c2b88a653d5232b2a61f59d3da32df2 F src/pager.h 73f481a308a873ccd626d97331c081db3b53e2e5 F src/parse.y 07690df997d50b3fdb5e5121e5a27f1a080db13d F src/pcache.c 395f752a13574120bd7513a400ba02a265aaa76d @@ -162,7 +162,7 @@ F src/select.c 2d97084a176a63eabce2d043eb4fbb13c46d6e9f F src/shell.c db2643650b9268df89a4bedca3f1c6d9e786f1bb F src/sqlite.h.in 79210c4d8905cfb4b038486dde5f36fabb796a86 F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17 -F src/sqliteInt.h 210280ec1b4ecc2627b37a6555943e253e615d65 +F src/sqliteInt.h 474e85cc85f78c18b8dbaec5cb786cdba6b45183 F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76 F src/table.c cc86ad3d6ad54df7c63a3e807b5783c90411a08d @@ -210,7 +210,7 @@ F src/vdbeapi.c 86aa27a5f3493aaffb8ac051782aa3b22670d7ed F src/vdbeaux.c 37730f227a5301c04e5bf03fd303b9086ada990c F src/vdbeblob.c c25d7e7bc6d5917feeb17270bd275fa771f26e5c F src/vdbemem.c 05183d46094aa99b8f8350e5761b9369dbef35a8 -F src/vtab.c b0216337ae7d27708dedd56d220e6f4fecda92f1 +F src/vtab.c e2f4c92df7d06330b151448718c4724742ff444b F src/walker.c ec4b9742a4077ef80346e2f9aaf0f44c2d95087a F src/where.c 1a21128db4905a29c287086acd7962cbba1c6f7b F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -732,7 +732,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746 -P 2472f6db95cd537a908bdbbbbc41bad2bd987b2f -R 57397b8b65ede5893d2dad509980c211 +P 6f2aab3f7be12710b703eda22b1d5c0e8f85f814 +R 5346d3235c7afe17cabab7c153640d73 U drh -Z 17489243ec8afd4b7332979c8573eb17 +Z 6beea0badfe5d9c08fcc3df2f861a173 diff --git a/manifest.uuid b/manifest.uuid index ed32c6c96..ca7b8de85 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6f2aab3f7be12710b703eda22b1d5c0e8f85f814
\ No newline at end of file +04bad9eb6dd8bf7cafc9f3918b676e95d5b1c984
\ No newline at end of file diff --git a/src/backup.c b/src/backup.c index e0ab5d882..a1cb85503 100644 --- a/src/backup.c +++ b/src/backup.c @@ -12,7 +12,7 @@ ** This file contains the implementation of the sqlite3_backup_XXX() ** API functions and the related features. ** -** $Id: backup.c,v 1.15 2009/05/14 19:26:51 drh Exp $ +** $Id: backup.c,v 1.16 2009/06/02 21:31:39 drh Exp $ */ #include "sqliteInt.h" #include "btreeInt.h" @@ -91,15 +91,24 @@ static Btree *findBtree(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb){ int i = sqlite3FindDbName(pDb, zDb); if( i==1 ){ - Parse sParse; - memset(&sParse, 0, sizeof(sParse)); - sParse.db = pDb; - if( sqlite3OpenTempDatabase(&sParse) ){ - sqlite3ErrorClear(&sParse); - sqlite3Error(pErrorDb, sParse.rc, "%s", sParse.zErrMsg); + Parse *pParse; + int rc = 0; + pParse = sqlite3StackAllocZero(pErrorDb, sizeof(*pParse)); + if( pParse==0 ){ + sqlite3Error(pErrorDb, SQLITE_NOMEM, "out of memory"); + rc = SQLITE_NOMEM; + }else{ + pParse->db = pDb; + if( sqlite3OpenTempDatabase(pParse) ){ + sqlite3ErrorClear(pParse); + sqlite3Error(pErrorDb, pParse->rc, "%s", pParse->zErrMsg); + rc = SQLITE_ERROR; + } + sqlite3StackFree(pErrorDb, pParse); + } + if( rc ){ return 0; } - assert( sParse.zErrMsg==0 ); } if( i<0 ){ diff --git a/src/bitvec.c b/src/bitvec.c index b6420a7f2..616c2adc5 100644 --- a/src/bitvec.c +++ b/src/bitvec.c @@ -34,7 +34,7 @@ ** start of a transaction, and is thus usually less than a few thousand, ** but can be as large as 2 billion for a really big database. ** -** @(#) $Id: bitvec.c,v 1.14 2009/04/01 23:49:04 drh Exp $ +** @(#) $Id: bitvec.c,v 1.15 2009/06/02 21:31:39 drh Exp $ */ #include "sqliteInt.h" @@ -209,15 +209,20 @@ bitvec_set_rehash: if( p->nSet>=BITVEC_MXHASH ){ unsigned int j; int rc; - u32 aiValues[BITVEC_NINT]; - memcpy(aiValues, p->u.aHash, sizeof(aiValues)); - memset(p->u.apSub, 0, sizeof(aiValues)); - p->iDivisor = (p->iSize + BITVEC_NPTR - 1)/BITVEC_NPTR; - rc = sqlite3BitvecSet(p, i); - for(j=0; j<BITVEC_NINT; j++){ - if( aiValues[j] ) rc |= sqlite3BitvecSet(p, aiValues[j]); + u32 *aiValues = sqlite3StackAllocRaw(0, sizeof(p->u.aHash)); + if( aiValues==0 ){ + return SQLITE_NOMEM; + }else{ + memcpy(aiValues, p->u.aHash, sizeof(p->u.aHash)); + memset(p->u.apSub, 0, sizeof(p->u.apSub)); + p->iDivisor = (p->iSize + BITVEC_NPTR - 1)/BITVEC_NPTR; + rc = sqlite3BitvecSet(p, i); + for(j=0; j<BITVEC_NINT; j++){ + if( aiValues[j] ) rc |= sqlite3BitvecSet(p, aiValues[j]); + } + sqlite3StackFree(0, aiValues); + return rc; } - return rc; } bitvec_set_end: p->nSet++; @@ -227,8 +232,11 @@ bitvec_set_end: /* ** Clear the i-th bit. +** +** pBuf must be a pointer to at least BITVEC_SZ bytes of temporary storage +** that BitvecClear can use to rebuilt its hash table. */ -void sqlite3BitvecClear(Bitvec *p, u32 i){ +void sqlite3BitvecClear(Bitvec *p, u32 i, void *pBuf){ assert( p!=0 ); assert( i>0 ); i--; @@ -244,9 +252,9 @@ void sqlite3BitvecClear(Bitvec *p, u32 i){ p->u.aBitmap[i/BITVEC_SZELEM] &= ~(1 << (i&(BITVEC_SZELEM-1))); }else{ unsigned int j; - u32 aiValues[BITVEC_NINT]; - memcpy(aiValues, p->u.aHash, sizeof(aiValues)); - memset(p->u.aHash, 0, sizeof(aiValues)); + u32 *aiValues = pBuf; + memcpy(aiValues, p->u.aHash, sizeof(p->u.aHash)); + memset(p->u.aHash, 0, sizeof(p->u.aHash)); p->nSet = 0; for(j=0; j<BITVEC_NINT; j++){ if( aiValues[j] && aiValues[j]!=(i+1) ){ @@ -330,12 +338,14 @@ int sqlite3BitvecBuiltinTest(int sz, int *aOp){ unsigned char *pV = 0; int rc = -1; int i, nx, pc, op; + void *pTmpSpace; /* Allocate the Bitvec to be tested and a linear array of ** bits to act as the reference */ pBitvec = sqlite3BitvecCreate( sz ); pV = sqlite3_malloc( (sz+7)/8 + 1 ); - if( pBitvec==0 || pV==0 ) goto bitvec_end; + pTmpSpace = sqlite3_malloc(BITVEC_SZ); + if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end; memset(pV, 0, (sz+7)/8 + 1); /* Run the program */ @@ -368,7 +378,7 @@ int sqlite3BitvecBuiltinTest(int sz, int *aOp){ } }else{ CLEARBIT(pV, (i+1)); - sqlite3BitvecClear(pBitvec, i+1); + sqlite3BitvecClear(pBitvec, i+1, pTmpSpace); } } @@ -389,6 +399,7 @@ int sqlite3BitvecBuiltinTest(int sz, int *aOp){ /* Free allocated structure */ bitvec_end: + sqlite3_free(pTmpSpace); sqlite3_free(pV); sqlite3BitvecDestroy(pBitvec); return rc; diff --git a/src/pager.c b/src/pager.c index 274949043..16cc70c81 100644 --- a/src/pager.c +++ b/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.590 2009/05/29 11:57:38 drh Exp $ +** @(#) $Id: pager.c,v 1.591 2009/06/02 21:31:39 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -5166,7 +5166,8 @@ int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, int isCommit){ rc = sqlite3PagerGet(pPager, needSyncPgno, &pPgHdr); if( rc!=SQLITE_OK ){ if( pPager->pInJournal && needSyncPgno<=pPager->dbOrigSize ){ - sqlite3BitvecClear(pPager->pInJournal, needSyncPgno); + assert( pPager->pTmpSpace!=0 ); + sqlite3BitvecClear(pPager->pInJournal, needSyncPgno, pPager->pTmpSpace); } return rc; } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index d6b150630..eaf35872f 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.880 2009/06/01 18:18:21 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.881 2009/06/02 21:31:39 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -2455,7 +2455,7 @@ void sqlite3EndTable(Parse*,Token*,Token*,Select*); Bitvec *sqlite3BitvecCreate(u32); int sqlite3BitvecTest(Bitvec*, u32); int sqlite3BitvecSet(Bitvec*, u32); -void sqlite3BitvecClear(Bitvec*, u32); +void sqlite3BitvecClear(Bitvec*, u32, void*); void sqlite3BitvecDestroy(Bitvec*); u32 sqlite3BitvecSize(Bitvec*); int sqlite3BitvecBuiltinTest(int,int*); diff --git a/src/vtab.c b/src/vtab.c index 3c7316c02..10a168162 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.89 2009/05/20 20:10:47 drh Exp $ +** $Id: vtab.c,v 1.90 2009/06/02 21:31:39 drh Exp $ */ #ifndef SQLITE_OMIT_VIRTUALTABLE #include "sqliteInt.h" @@ -550,7 +550,7 @@ int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){ ** virtual table module. */ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ - Parse sParse; + Parse *pParse; int rc = SQLITE_OK; Table *pTab; @@ -565,33 +565,37 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ } assert((pTab->tabFlags & TF_Virtual)!=0 && pTab->nCol==0 && pTab->aCol==0); - memset(&sParse, 0, sizeof(Parse)); - sParse.declareVtab = 1; - sParse.db = db; - - if( - SQLITE_OK == sqlite3RunParser(&sParse, zCreateTable, &zErr) && - sParse.pNewTable && - !sParse.pNewTable->pSelect && - (sParse.pNewTable->tabFlags & TF_Virtual)==0 - ){ - pTab->aCol = sParse.pNewTable->aCol; - pTab->nCol = sParse.pNewTable->nCol; - sParse.pNewTable->nCol = 0; - sParse.pNewTable->aCol = 0; - db->pVTab = 0; - } else { - sqlite3Error(db, SQLITE_ERROR, zErr); - sqlite3DbFree(db, zErr); - rc = SQLITE_ERROR; - } - sParse.declareVtab = 0; - - if( sParse.pVdbe ){ - sqlite3VdbeFinalize(sParse.pVdbe); + pParse = sqlite3StackAllocZero(db, sizeof(*pParse)); + if( pParse==0 ){ + rc = SQLITE_NOMEM; + }else{ + pParse->declareVtab = 1; + pParse->db = db; + + if( + SQLITE_OK == sqlite3RunParser(pParse, zCreateTable, &zErr) && + pParse->pNewTable && + !pParse->pNewTable->pSelect && + (pParse->pNewTable->tabFlags & TF_Virtual)==0 + ){ + pTab->aCol = pParse->pNewTable->aCol; + pTab->nCol = pParse->pNewTable->nCol; + pParse->pNewTable->nCol = 0; + pParse->pNewTable->aCol = 0; + db->pVTab = 0; + } else { + sqlite3Error(db, SQLITE_ERROR, zErr); + sqlite3DbFree(db, zErr); + rc = SQLITE_ERROR; + } + pParse->declareVtab = 0; + + if( pParse->pVdbe ){ + sqlite3VdbeFinalize(pParse->pVdbe); + } + sqlite3DeleteTable(pParse->pNewTable); + sqlite3StackFree(db, pParse); } - sqlite3DeleteTable(sParse.pNewTable); - sParse.pNewTable = 0; assert( (rc&0xff)==rc ); rc = sqlite3ApiExit(db, rc); |