48447 } |
48447 } |
48448 } |
48448 } |
48449 #endif /* !SQLITE_OMIT_TRACE && SQLITE_ENABLE_IOTRACE */ |
48449 #endif /* !SQLITE_OMIT_TRACE && SQLITE_ENABLE_IOTRACE */ |
48450 |
48450 |
48451 /* |
48451 /* |
48452 ** Allocate space from a fixed size buffer. Make *pp point to the |
48452 ** Allocate space from a fixed size buffer and return a pointer to |
48453 ** allocated space. (Note: pp is a char* rather than a void** to |
48453 ** that space. If insufficient space is available, return NULL. |
48454 ** work around the pointer aliasing rules of C.) *pp should initially |
48454 ** |
48455 ** be zero. If *pp is not zero, that means that the space has already |
48455 ** The pBuf parameter is the initial value of a pointer which will |
48456 ** been allocated and this routine is a noop. |
48456 ** receive the new memory. pBuf is normally NULL. If pBuf is not |
|
48457 ** NULL, it means that memory space has already been allocated and that |
|
48458 ** this routine should not allocate any new memory. When pBuf is not |
|
48459 ** NULL simply return pBuf. Only allocate new memory space when pBuf |
|
48460 ** is NULL. |
48457 ** |
48461 ** |
48458 ** nByte is the number of bytes of space needed. |
48462 ** nByte is the number of bytes of space needed. |
48459 ** |
48463 ** |
48460 ** *ppFrom point to available space and pEnd points to the end of the |
48464 ** *ppFrom point to available space and pEnd points to the end of the |
48461 ** available space. |
48465 ** available space. |
48462 ** |
48466 ** |
48463 ** *pnByte is a counter of the number of bytes of space that have failed |
48467 ** *pnByte is a counter of the number of bytes of space that have failed |
48464 ** to allocate. If there is insufficient space in *ppFrom to satisfy the |
48468 ** to allocate. If there is insufficient space in *ppFrom to satisfy the |
48465 ** request, then increment *pnByte by the amount of the request. |
48469 ** request, then increment *pnByte by the amount of the request. |
48466 */ |
48470 */ |
48467 static void allocSpace( |
48471 static void *allocSpace( |
48468 char *pp, /* IN/OUT: Set *pp to point to allocated buffer */ |
48472 void *pBuf, /* Where return pointer will be stored */ |
48469 int nByte, /* Number of bytes to allocate */ |
48473 int nByte, /* Number of bytes to allocate */ |
48470 u8 **ppFrom, /* IN/OUT: Allocate from *ppFrom */ |
48474 u8 **ppFrom, /* IN/OUT: Allocate from *ppFrom */ |
48471 u8 *pEnd, /* Pointer to 1 byte past the end of *ppFrom buffer */ |
48475 u8 *pEnd, /* Pointer to 1 byte past the end of *ppFrom buffer */ |
48472 int *pnByte /* If allocation cannot be made, increment *pnByte */ |
48476 int *pnByte /* If allocation cannot be made, increment *pnByte */ |
48473 ){ |
48477 ){ |
48474 assert( EIGHT_BYTE_ALIGNMENT(*ppFrom) ); |
48478 assert( EIGHT_BYTE_ALIGNMENT(*ppFrom) ); |
48475 if( (*(void**)pp)==0 ){ |
48479 if( pBuf ) return pBuf; |
48476 nByte = ROUND8(nByte); |
48480 nByte = ROUND8(nByte); |
48477 if( &(*ppFrom)[nByte] <= pEnd ){ |
48481 if( &(*ppFrom)[nByte] <= pEnd ){ |
48478 *(void**)pp = (void *)*ppFrom; |
48482 pBuf = (void*)*ppFrom; |
48479 *ppFrom += nByte; |
48483 *ppFrom += nByte; |
48480 }else{ |
48484 }else{ |
48481 *pnByte += nByte; |
48485 *pnByte += nByte; |
48482 } |
48486 } |
48483 } |
48487 return pBuf; |
48484 } |
48488 } |
48485 |
48489 |
48486 /* |
48490 /* |
48487 ** Prepare a virtual machine for execution. This involves things such |
48491 ** Prepare a virtual machine for execution. This involves things such |
48488 ** as allocating stack space and initializing the program counter. |
48492 ** as allocating stack space and initializing the program counter. |
48551 zCsr += (zCsr - (u8*)0)&7; |
48555 zCsr += (zCsr - (u8*)0)&7; |
48552 assert( EIGHT_BYTE_ALIGNMENT(zCsr) ); |
48556 assert( EIGHT_BYTE_ALIGNMENT(zCsr) ); |
48553 |
48557 |
48554 do { |
48558 do { |
48555 nByte = 0; |
48559 nByte = 0; |
48556 allocSpace((char*)&p->aMem, nMem*sizeof(Mem), &zCsr, zEnd, &nByte); |
48560 p->aMem = allocSpace(p->aMem, nMem*sizeof(Mem), &zCsr, zEnd, &nByte); |
48557 allocSpace((char*)&p->aVar, nVar*sizeof(Mem), &zCsr, zEnd, &nByte); |
48561 p->aVar = allocSpace(p->aVar, nVar*sizeof(Mem), &zCsr, zEnd, &nByte); |
48558 allocSpace((char*)&p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte); |
48562 p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte); |
48559 allocSpace((char*)&p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte); |
48563 p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte); |
48560 allocSpace((char*)&p->apCsr, |
48564 p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*), |
48561 nCursor*sizeof(VdbeCursor*), &zCsr, zEnd, &nByte |
48565 &zCsr, zEnd, &nByte); |
48562 ); |
|
48563 if( nByte ){ |
48566 if( nByte ){ |
48564 p->pFree = sqlite3DbMallocZero(db, nByte); |
48567 p->pFree = sqlite3DbMallocZero(db, nByte); |
48565 } |
48568 } |
48566 zCsr = p->pFree; |
48569 zCsr = p->pFree; |
48567 zEnd = &zCsr[nByte]; |
48570 zEnd = &zCsr[nByte]; |