Split out the RUN state into separate READY and RUN states.

FossilOrigin-Name: d698826b08b88e227eb83f84b3cdb19f17306b532eccfa162090abccdf3c63d8
This commit is contained in:
drh 2022-03-31 21:15:09 +00:00
parent 66181ce2b8
commit 99a218282c
4 changed files with 97 additions and 90 deletions

View File

@ -1,5 +1,5 @@
C Rename\sVdbe.iVdbeMagic\sto\seVdbeState.\s\sRemove\sunnecessary\sstates.\s\sThis\sis\na\spreliminary\sstep\stoward\ssplitting\sRUN_STATE\sout\sinto\sseveral\sother\sstates.
D 2022-03-31T20:04:49.855
C Split\sout\sthe\sRUN\sstate\sinto\sseparate\sREADY\sand\sRUN\sstates.
D 2022-03-31T21:15:09.341
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -627,8 +627,8 @@ F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3
F src/vdbe.c c7982c468cf39e3ad690da427aa72d43744debc32cea943849b688c17dfe2bff
F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e
F src/vdbeInt.h fe6987d90048eee26bf0e9a2498ff3f2c5d4149b0d6e78b9fcc6bce13274faae
F src/vdbeapi.c 0bfeb0ebfb2b064b97bcb389a92f9f819bacc2ae70c819c6976157616f48c31c
F src/vdbeaux.c 4260b1016c9e47a20c75f7d311c4bf1fe5b0efa9dafa2f72f7959fcb0517792b
F src/vdbeapi.c bdc977e721fbadb9b075f8f4eb5f4ac5289eb2bffc0786ffae303e915580484a
F src/vdbeaux.c 6c76956b969cdb65b52fe120e1e5424868ec4473f454dd81039e5b07a2b44ee4
F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd
F src/vdbemem.c 512499e51eb7cbe1d886031f19ab6f3e05655a0b25655991af01b61a631a78f7
F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35
@ -1945,11 +1945,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P b916087aacba53530d2bd19eef2a4fd7a253bf7fa87b49e0df17f7987d7164ae
R 3c60b6ccbc6ab91e39cbf56c4038bfa8
T *branch * vdbe-state-refactor
T *sym-vdbe-state-refactor *
T -sym-trunk *
P ff91191d232305d44ae6c0fbca2542a749422dc716fa1fd5d54f58c7d6052c14
R ec623ff49fd7a3945e7e6cf4e06ba68c
U drh
Z 839815ce9594c9953a4b8872bf63aa11
Z 2cbaf76e3cc43bc83d2f6fc2647ea3ec
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
ff91191d232305d44ae6c0fbca2542a749422dc716fa1fd5d54f58c7d6052c14
d698826b08b88e227eb83f84b3cdb19f17306b532eccfa162090abccdf3c63d8

View File

@ -642,35 +642,6 @@ static int sqlite3Step(Vdbe *p){
sqlite3 *db;
int rc;
assert(p);
if( p->eVdbeState!=VDBE_RUN_STATE ){
/* We used to require that sqlite3_reset() be called before retrying
** sqlite3_step() after any error or after SQLITE_DONE. But beginning
** with version 3.7.0, we changed this so that sqlite3_reset() would
** be called automatically instead of throwing the SQLITE_MISUSE error.
** This "automatic-reset" change is not technically an incompatibility,
** since any application that receives an SQLITE_MISUSE is broken by
** definition.
**
** Nevertheless, some published applications that were originally written
** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE
** returns, and those were broken by the automatic-reset change. As a
** a work-around, the SQLITE_OMIT_AUTORESET compile-time restores the
** legacy behavior of returning SQLITE_MISUSE for cases where the
** previous sqlite3_step() returned something other than a SQLITE_LOCKED
** or SQLITE_BUSY error.
*/
#ifdef SQLITE_OMIT_AUTORESET
if( (rc = p->rc&0xff)==SQLITE_BUSY || rc==SQLITE_LOCKED ){
sqlite3_reset((sqlite3_stmt*)p);
}else{
return SQLITE_MISUSE_BKPT;
}
#else
sqlite3_reset((sqlite3_stmt*)p);
#endif
}
/* Check that malloc() has not failed. If it has, return early. */
db = p->db;
if( db->mallocFailed ){
@ -678,45 +649,83 @@ static int sqlite3Step(Vdbe *p){
return SQLITE_NOMEM_BKPT;
}
if( p->pc<0 && p->expired ){
p->rc = SQLITE_SCHEMA;
rc = SQLITE_ERROR;
if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ){
/* If this statement was prepared using saved SQL and an
** error has occurred, then return the error code in p->rc to the
** caller. Set the error code in the database handle to the same value.
*/
rc = sqlite3VdbeTransferError(p);
}
goto end_of_step;
}
if( p->pc<0 ){
/* If there are no other statements currently running, then
** reset the interrupt flag. This prevents a call to sqlite3_interrupt
** from interrupting a statement that has not yet started.
*/
if( db->nVdbeActive==0 ){
AtomicStore(&db->u1.isInterrupted, 0);
}
assert(p);
if( p->eVdbeState!=VDBE_RUN_STATE ){
restart_step:
if( p->eVdbeState==VDBE_READY_STATE ){
if( p->expired ){
p->rc = SQLITE_SCHEMA;
rc = SQLITE_ERROR;
if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ){
/* If this statement was prepared using saved SQL and an
** error has occurred, then return the error code in p->rc to the
** caller. Set the error code in the database handle to the same
** value.
*/
rc = sqlite3VdbeTransferError(p);
}
goto end_of_step;
}
assert( db->nVdbeWrite>0 || db->autoCommit==0
|| (db->nDeferredCons==0 && db->nDeferredImmCons==0)
);
/* If there are no other statements currently running, then
** reset the interrupt flag. This prevents a call to sqlite3_interrupt
** from interrupting a statement that has not yet started.
*/
if( db->nVdbeActive==0 ){
AtomicStore(&db->u1.isInterrupted, 0);
}
assert( db->nVdbeWrite>0 || db->autoCommit==0
|| (db->nDeferredCons==0 && db->nDeferredImmCons==0)
);
#ifndef SQLITE_OMIT_TRACE
if( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0
&& !db->init.busy && p->zSql ){
sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
}else{
assert( p->startTime==0 );
}
if( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0
&& !db->init.busy && p->zSql ){
sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
}else{
assert( p->startTime==0 );
}
#endif
db->nVdbeActive++;
if( p->readOnly==0 ) db->nVdbeWrite++;
if( p->bIsReader ) db->nVdbeRead++;
p->pc = 0;
db->nVdbeActive++;
if( p->readOnly==0 ) db->nVdbeWrite++;
if( p->bIsReader ) db->nVdbeRead++;
p->pc = 0;
p->eVdbeState = VDBE_RUN_STATE;
}else
if( p->eVdbeState==VDBE_HALT_STATE ){
/* We used to require that sqlite3_reset() be called before retrying
** sqlite3_step() after any error or after SQLITE_DONE. But beginning
** with version 3.7.0, we changed this so that sqlite3_reset() would
** be called automatically instead of throwing the SQLITE_MISUSE error.
** This "automatic-reset" change is not technically an incompatibility,
** since any application that receives an SQLITE_MISUSE is broken by
** definition.
**
** Nevertheless, some published applications that were originally written
** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE
** returns, and those were broken by the automatic-reset change. As a
** a work-around, the SQLITE_OMIT_AUTORESET compile-time restores the
** legacy behavior of returning SQLITE_MISUSE for cases where the
** previous sqlite3_step() returned something other than a SQLITE_LOCKED
** or SQLITE_BUSY error.
*/
#ifdef SQLITE_OMIT_AUTORESET
if( (rc = p->rc&0xff)==SQLITE_BUSY || rc==SQLITE_LOCKED ){
sqlite3_reset((sqlite3_stmt*)p);
}else{
return SQLITE_MISUSE_BKPT;
}
#else
sqlite3_reset((sqlite3_stmt*)p);
#endif
assert( p->eVdbeState==VDBE_READY_STATE );
goto restart_step;
}
}
#ifdef SQLITE_DEBUG
p->rcApp = SQLITE_OK;
#endif
@ -1428,7 +1437,7 @@ static int vdbeUnbind(Vdbe *p, int i){
return SQLITE_MISUSE_BKPT;
}
sqlite3_mutex_enter(p->db->mutex);
if( p->eVdbeState!=VDBE_RUN_STATE || p->pc>=0 ){
if( p->eVdbeState!=VDBE_READY_STATE ){
sqlite3Error(p->db, SQLITE_MISUSE);
sqlite3_mutex_leave(p->db->mutex);
sqlite3_log(SQLITE_MISUSE,
@ -1781,7 +1790,7 @@ int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt){
*/
int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
Vdbe *v = (Vdbe*)pStmt;
return v!=0 && v->eVdbeState==VDBE_RUN_STATE && v->pc>=0;
return v!=0 && v->eVdbeState==VDBE_RUN_STATE;
}
/*

View File

@ -2299,13 +2299,15 @@ void sqlite3VdbeRewind(Vdbe *p){
int i;
#endif
assert( p!=0 );
assert( p->eVdbeState==VDBE_INIT_STATE || p->eVdbeState==VDBE_HALT_STATE );
assert( p->eVdbeState==VDBE_INIT_STATE
|| p->eVdbeState==VDBE_READY_STATE
|| p->eVdbeState==VDBE_HALT_STATE );
/* There should be at least one opcode.
*/
assert( p->nOp>0 );
p->eVdbeState = VDBE_RUN_STATE;
p->eVdbeState = VDBE_READY_STATE;
#ifdef SQLITE_DEBUG
for(i=0; i<p->nMem; i++){
@ -2558,9 +2560,7 @@ static void closeAllCursors(Vdbe *p){
}
assert( p->nFrame==0 );
closeCursorsInFrame(p);
if( p->aMem ){
releaseMemArray(p->aMem, p->nMem);
}
releaseMemArray(p->aMem, p->nMem);
while( p->pDelFrame ){
VdbeFrame *pDel = p->pDelFrame;
p->pDelFrame = pDel->pParent;
@ -3051,7 +3051,7 @@ int sqlite3VdbeHalt(Vdbe *p){
/* No commit or rollback needed if the program never started or if the
** SQL statement does not read or write a database file. */
if( p->pc>=0 && p->bIsReader ){
if( p->bIsReader ){
int mrc; /* Primary error code from p->rc */
int eStatementOp = 0;
int isSpecialError; /* Set to true if a 'special' error */
@ -3199,14 +3199,12 @@ int sqlite3VdbeHalt(Vdbe *p){
}
/* We have successfully halted and closed the VM. Record this fact. */
if( p->pc>=0 ){
db->nVdbeActive--;
if( !p->readOnly ) db->nVdbeWrite--;
if( p->bIsReader ) db->nVdbeRead--;
assert( db->nVdbeActive>=db->nVdbeRead );
assert( db->nVdbeRead>=db->nVdbeWrite );
assert( db->nVdbeWrite>=0 );
}
db->nVdbeActive--;
if( !p->readOnly ) db->nVdbeWrite--;
if( p->bIsReader ) db->nVdbeRead--;
assert( db->nVdbeActive>=db->nVdbeRead );
assert( db->nVdbeRead>=db->nVdbeWrite );
assert( db->nVdbeWrite>=0 );
p->eVdbeState = VDBE_HALT_STATE;
checkActiveVdbeCnt(db);
if( db->mallocFailed ){
@ -3390,7 +3388,10 @@ int sqlite3VdbeReset(Vdbe *p){
*/
int sqlite3VdbeFinalize(Vdbe *p){
int rc = SQLITE_OK;
if( p->eVdbeState==VDBE_RUN_STATE || p->eVdbeState==VDBE_HALT_STATE ){
assert( VDBE_RUN_STATE>VDBE_READY_STATE );
assert( VDBE_HALT_STATE>VDBE_READY_STATE );
assert( VDBE_INIT_STATE<VDBE_READY_STATE );
if( p->eVdbeState>=VDBE_READY_STATE ){
rc = sqlite3VdbeReset(p);
assert( (rc & p->db->errMask)==rc );
}