mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-11 01:42:22 +03:00
Attempt to modify btree.c so that it assumes that calls to sqlite3PagerWrite()
will reallocate the page buffer. As there is not good way to test this assumption yet, probably a few spots were missed. FossilOrigin-Name: ceee03c79a55ea39866758aa76b78b10e5f4246d
This commit is contained in:
12
manifest
12
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Pull\sover\sall\sthe\slatest\schanges\sfrom\strunk.
|
C Attempt\sto\smodify\sbtree.c\sso\sthat\sit\sassumes\sthat\scalls\sto\ssqlite3PagerWrite()\nwill\sreallocate\sthe\spage\sbuffer.\s\sAs\sthere\sis\snot\sgood\sway\sto\stest\sthis\nassumption\syet,\sprobably\sa\sfew\sspots\swere\smissed.
|
||||||
D 2011-11-11T14:12:36.001
|
D 2011-11-12T23:10:13.436
|
||||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||||
F Makefile.in 5b4a3e12a850b021547e43daf886b25133b44c07
|
F Makefile.in 5b4a3e12a850b021547e43daf886b25133b44c07
|
||||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||||
@@ -125,7 +125,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
|
|||||||
F src/backup.c 4368158da74d4711888e03264105c5c527d76caf
|
F src/backup.c 4368158da74d4711888e03264105c5c527d76caf
|
||||||
F src/bitvec.c af50f1c8c0ff54d6bdb7a80e2fceca5a93670bef
|
F src/bitvec.c af50f1c8c0ff54d6bdb7a80e2fceca5a93670bef
|
||||||
F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
|
F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
|
||||||
F src/btree.c 2521a74f04cf288497af3b318fa3a31efb272ef6
|
F src/btree.c 149cccf2134f555583d0825e47b17104aa06cb84
|
||||||
F src/btree.h f5d775cd6cfc7ac32a2535b70e8d2af48ef5f2ce
|
F src/btree.h f5d775cd6cfc7ac32a2535b70e8d2af48ef5f2ce
|
||||||
F src/btreeInt.h ea863a819224d3e6845ad1e39954d41558b8cd8b
|
F src/btreeInt.h ea863a819224d3e6845ad1e39954d41558b8cd8b
|
||||||
F src/build.c 8af67a08a852ff4c63701963cb1ab7166f577814
|
F src/build.c 8af67a08a852ff4c63701963cb1ab7166f577814
|
||||||
@@ -974,7 +974,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
|
|||||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||||
F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a
|
F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a
|
||||||
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
||||||
P 6bda711f93e753dd0be8d896a007b3f7b5064787 471cf0d8e7857110e525e029c2d535cb518dba6a
|
P 1bbbf8574a820c5f787a937f02a8e2a91264ace0
|
||||||
R 50394ddf6c21b3d5be10b1579addf880
|
R 8fe5168196d72d713cb64bacae73a939
|
||||||
U drh
|
U drh
|
||||||
Z 183f0080d0ed04f08eff14296686e20c
|
Z db5deb4d4c1ff85ac518999d30605134
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
1bbbf8574a820c5f787a937f02a8e2a91264ace0
|
ceee03c79a55ea39866758aa76b78b10e5f4246d
|
||||||
66
src/btree.c
66
src/btree.c
@@ -1776,7 +1776,12 @@ int sqlite3BtreeOpen(
|
|||||||
sqlite3_free(p);
|
sqlite3_free(p);
|
||||||
return SQLITE_NOMEM;
|
return SQLITE_NOMEM;
|
||||||
}
|
}
|
||||||
sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname);
|
rc = sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname);
|
||||||
|
if( rc ){
|
||||||
|
sqlite3_free(zFullPathname);
|
||||||
|
sqlite3_free(p);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
#if SQLITE_THREADSAFE
|
#if SQLITE_THREADSAFE
|
||||||
mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN);
|
mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN);
|
||||||
sqlite3_mutex_enter(mutexOpen);
|
sqlite3_mutex_enter(mutexOpen);
|
||||||
@@ -2477,9 +2482,9 @@ static int newDatabase(BtShared *pBt){
|
|||||||
}
|
}
|
||||||
pP1 = pBt->pPage1;
|
pP1 = pBt->pPage1;
|
||||||
assert( pP1!=0 );
|
assert( pP1!=0 );
|
||||||
data = pP1->aData;
|
|
||||||
rc = sqlite3PagerWrite(pP1->pDbPage);
|
rc = sqlite3PagerWrite(pP1->pDbPage);
|
||||||
if( rc ) return rc;
|
if( rc ) return rc;
|
||||||
|
data = pP1->aData;
|
||||||
memcpy(data, zMagicHeader, sizeof(zMagicHeader));
|
memcpy(data, zMagicHeader, sizeof(zMagicHeader));
|
||||||
assert( sizeof(zMagicHeader)==16 );
|
assert( sizeof(zMagicHeader)==16 );
|
||||||
data[16] = (u8)((pBt->pageSize>>8)&0xff);
|
data[16] = (u8)((pBt->pageSize>>8)&0xff);
|
||||||
@@ -3777,38 +3782,6 @@ static int getOverflowPage(
|
|||||||
return (rc==SQLITE_DONE ? SQLITE_OK : rc);
|
return (rc==SQLITE_DONE ? SQLITE_OK : rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
** Copy data from a buffer to a page, or from a page to a buffer.
|
|
||||||
**
|
|
||||||
** pPayload is a pointer to data stored on database page pDbPage.
|
|
||||||
** If argument eOp is false, then nByte bytes of data are copied
|
|
||||||
** from pPayload to the buffer pointed at by pBuf. If eOp is true,
|
|
||||||
** then sqlite3PagerWrite() is called on pDbPage and nByte bytes
|
|
||||||
** of data are copied from the buffer pBuf to pPayload.
|
|
||||||
**
|
|
||||||
** SQLITE_OK is returned on success, otherwise an error code.
|
|
||||||
*/
|
|
||||||
static int copyPayload(
|
|
||||||
void *pPayload, /* Pointer to page data */
|
|
||||||
void *pBuf, /* Pointer to buffer */
|
|
||||||
int nByte, /* Number of bytes to copy */
|
|
||||||
int eOp, /* 0 -> copy from page, 1 -> copy to page */
|
|
||||||
DbPage *pDbPage /* Page containing pPayload */
|
|
||||||
){
|
|
||||||
if( eOp ){
|
|
||||||
/* Copy data from buffer to page (a write operation) */
|
|
||||||
int rc = sqlite3PagerWrite(pDbPage);
|
|
||||||
if( rc!=SQLITE_OK ){
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
memcpy(pPayload, pBuf, nByte);
|
|
||||||
}else{
|
|
||||||
/* Copy data from page to buffer (a read operation) */
|
|
||||||
memcpy(pBuf, pPayload, nByte);
|
|
||||||
}
|
|
||||||
return SQLITE_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** This function is used to read or overwrite payload information
|
** This function is used to read or overwrite payload information
|
||||||
** for the entry that the pCur cursor is pointing to. If the eOp
|
** for the entry that the pCur cursor is pointing to. If the eOp
|
||||||
@@ -3856,6 +3829,7 @@ static int accessPayload(
|
|||||||
assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
|
assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
|
||||||
assert( cursorHoldsMutex(pCur) );
|
assert( cursorHoldsMutex(pCur) );
|
||||||
|
|
||||||
|
|
||||||
getCellInfo(pCur);
|
getCellInfo(pCur);
|
||||||
aPayload = pCur->info.pCell + pCur->info.nHeader;
|
aPayload = pCur->info.pCell + pCur->info.nHeader;
|
||||||
nKey = (pPage->intKey ? 0 : (int)pCur->info.nKey);
|
nKey = (pPage->intKey ? 0 : (int)pCur->info.nKey);
|
||||||
@@ -3873,7 +3847,14 @@ static int accessPayload(
|
|||||||
if( a+offset>pCur->info.nLocal ){
|
if( a+offset>pCur->info.nLocal ){
|
||||||
a = pCur->info.nLocal - offset;
|
a = pCur->info.nLocal - offset;
|
||||||
}
|
}
|
||||||
rc = copyPayload(&aPayload[offset], pBuf, a, eOp, pPage->pDbPage);
|
if( eOp ){
|
||||||
|
if( (rc = sqlite3PagerWrite(pPage->pDbPage))!=SQLITE_OK ) return rc;
|
||||||
|
getCellInfo(pCur);
|
||||||
|
aPayload = pCur->info.pCell + pCur->info.nHeader;
|
||||||
|
memcpy(aPayload+offset, pBuf, a);
|
||||||
|
}else{
|
||||||
|
memcpy(pBuf, aPayload+offset, a);
|
||||||
|
}
|
||||||
offset = 0;
|
offset = 0;
|
||||||
pBuf += a;
|
pBuf += a;
|
||||||
amt -= a;
|
amt -= a;
|
||||||
@@ -3984,9 +3965,17 @@ static int accessPayload(
|
|||||||
DbPage *pDbPage;
|
DbPage *pDbPage;
|
||||||
rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage);
|
rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage);
|
||||||
if( rc==SQLITE_OK ){
|
if( rc==SQLITE_OK ){
|
||||||
|
if( eOp && (rc = sqlite3PagerWrite(pDbPage))!=SQLITE_OK ){
|
||||||
|
sqlite3PagerUnref(pDbPage);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
aPayload = sqlite3PagerGetData(pDbPage);
|
aPayload = sqlite3PagerGetData(pDbPage);
|
||||||
nextPage = get4byte(aPayload);
|
nextPage = get4byte(aPayload);
|
||||||
rc = copyPayload(&aPayload[offset+4], pBuf, a, eOp, pDbPage);
|
if( eOp ){
|
||||||
|
memcpy(&aPayload[offset+4], pBuf, a);
|
||||||
|
}else{
|
||||||
|
memcpy(pBuf, &aPayload[offset+4], a);
|
||||||
|
}
|
||||||
sqlite3PagerUnref(pDbPage);
|
sqlite3PagerUnref(pDbPage);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
@@ -7385,16 +7374,14 @@ void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
|
|||||||
*/
|
*/
|
||||||
int sqlite3BtreeUpdateMeta(Btree *p, int idx, u32 iMeta){
|
int sqlite3BtreeUpdateMeta(Btree *p, int idx, u32 iMeta){
|
||||||
BtShared *pBt = p->pBt;
|
BtShared *pBt = p->pBt;
|
||||||
unsigned char *pP1;
|
|
||||||
int rc;
|
int rc;
|
||||||
assert( idx>=1 && idx<=15 );
|
assert( idx>=1 && idx<=15 );
|
||||||
sqlite3BtreeEnter(p);
|
sqlite3BtreeEnter(p);
|
||||||
assert( p->inTrans==TRANS_WRITE );
|
assert( p->inTrans==TRANS_WRITE );
|
||||||
assert( pBt->pPage1!=0 );
|
assert( pBt->pPage1!=0 );
|
||||||
pP1 = pBt->pPage1->aData;
|
|
||||||
rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
|
rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
|
||||||
if( rc==SQLITE_OK ){
|
if( rc==SQLITE_OK ){
|
||||||
put4byte(&pP1[36 + idx*4], iMeta);
|
put4byte(&pBt->pPage1->aData[36 + idx*4], iMeta);
|
||||||
#ifndef SQLITE_OMIT_AUTOVACUUM
|
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||||
if( idx==BTREE_INCR_VACUUM ){
|
if( idx==BTREE_INCR_VACUUM ){
|
||||||
assert( pBt->autoVacuum || iMeta==0 );
|
assert( pBt->autoVacuum || iMeta==0 );
|
||||||
@@ -8223,6 +8210,7 @@ int sqlite3BtreeSetVersion(Btree *pBtree, int iVersion){
|
|||||||
if( rc==SQLITE_OK ){
|
if( rc==SQLITE_OK ){
|
||||||
rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
|
rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
|
||||||
if( rc==SQLITE_OK ){
|
if( rc==SQLITE_OK ){
|
||||||
|
aData = pBt->pPage1->aData;
|
||||||
aData[18] = (u8)iVersion;
|
aData[18] = (u8)iVersion;
|
||||||
aData[19] = (u8)iVersion;
|
aData[19] = (u8)iVersion;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user