Change the Vdbe.aMem array so that it is zero-based instead of one-based.

FossilOrigin-Name: e07b0c47eb5a39623f5fe0e66b939bba0906691c
This commit is contained in:
drh
2016-03-19 23:32:58 +00:00
parent b6eb666264
commit 9f6168b6a3
5 changed files with 67 additions and 61 deletions
+11 -10
View File
@@ -1801,7 +1801,7 @@ void sqlite3VdbeRewind(Vdbe *p){
p->magic = VDBE_MAGIC_RUN;
#ifdef SQLITE_DEBUG
for(i=1; i<p->nMem; i++){
for(i=0; i<p->nMem; i++){
assert( p->aMem[i].db==p->db );
}
#endif
@@ -1866,16 +1866,18 @@ void sqlite3VdbeMakeReady(
nOnce = pParse->nOnce;
if( nOnce==0 ) nOnce = 1; /* Ensure at least one byte in p->aOnceFlag[] */
/* For each cursor required, also allocate a memory cell. Memory
** cells (nMem+1-nCursor)..nMem, inclusive, will never be used by
/* For each cursor required, also allocate a memory cell. Memory
** cells 0 and (nMem-nCursor)..nMem-1 inclusive will never be used by
** the vdbe program. Instead they are used to allocate memory for
** VdbeCursor/BtCursor structures. The blob of memory associated with
** cursor 0 is stored in memory cell nMem. Memory cell (nMem-1)
** stores the blob of memory associated with cursor 1, etc.
** cursor 0 is stored in memory cell 0. Memory cell (nMem-1)
** stores the blob of memory associated with cursor 1. Memory cell
** (nMem-iCur) is used for cursor iCur.
**
** See also: allocateCursor().
*/
nMem += nCursor;
if( nCursor==0 && nMem>0 ) nMem++; /* Space for aMem[0] even if not used */
/* Figure out how much reusable memory is available at the end of the
** opcode array. This extra memory will be reallocated for other elements
@@ -1937,9 +1939,8 @@ void sqlite3VdbeMakeReady(
pParse->nzVar = 0;
pParse->azVar = 0;
if( p->aMem ){
p->aMem--; /* aMem[] goes from 1..nMem */
p->nMem = nMem; /* not from 0..nMem-1 */
for(n=1; n<=nMem; n++){
p->nMem = nMem;
for(n=0; n<nMem; n++){
p->aMem[n].flags = MEM_Undefined;
p->aMem[n].db = db;
}
@@ -2049,7 +2050,7 @@ static void closeAllCursors(Vdbe *p){
assert( p->nFrame==0 );
closeCursorsInFrame(p);
if( p->aMem ){
releaseMemArray(&p->aMem[1], p->nMem);
releaseMemArray(p->aMem, p->nMem);
}
while( p->pDelFrame ){
VdbeFrame *pDel = p->pDelFrame;
@@ -2074,7 +2075,7 @@ static void Cleanup(Vdbe *p){
int i;
if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
if( p->aMem ){
for(i=1; i<=p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
for(i=0; i<p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
}
#endif