Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 25 additions & 6 deletions libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
** src/sqlite3ext.h
** src/sqliteInt.h
** src/status.c
** src/test1.c
** src/test2.c
** src/test3.c
** src/test8.c
Expand Down Expand Up @@ -90201,7 +90202,7 @@ SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
#ifdef SQLITE_DEBUG
p->nWrite = 0;
#endif
p->isInterrupted = 0;
AtomicStore(&p->isInterrupted, 0);

/* Save profiling information from this VDBE run.
*/
Expand Down Expand Up @@ -93043,7 +93044,9 @@ void libsql_stmt_interrupt(sqlite3_stmt *pStmt){
(void)SQLITE_MISUSE_BKPT;
return;
}
v->isInterrupted = 1;
/* Set atomically: this may be called from a different thread than the one
** executing the statement, mirroring sqlite3_interrupt(). */
AtomicStore(&v->isInterrupted, 1);
}

/*
Expand All @@ -93061,7 +93064,7 @@ SQLITE_API int sqlite3_step(sqlite3_stmt *pStmt){
return SQLITE_MISUSE_BKPT;
}
db = v->db;
if( v->isInterrupted ){
if( AtomicLoad(&v->isInterrupted) ){
rc = SQLITE_INTERRUPT;
v->rc = rc;
db->errCode = rc;
Expand Down Expand Up @@ -95105,6 +95108,12 @@ SQLITE_API int sqlite3_search_count = 0;
*/
#ifdef SQLITE_TEST
SQLITE_API int sqlite3_interrupt_count = 0;
/*
** As above, but simulates a statement-level interrupt
** (libsql_stmt_interrupt()) on the statement that is currently executing,
** rather than a connection-wide sqlite3_interrupt().
*/
SQLITE_API int sqlite3_stmt_interrupt_count = 0;
#endif

/*
Expand Down Expand Up @@ -95928,7 +95937,9 @@ SQLITE_PRIVATE int sqlite3VdbeExec(
p->iCurrentTime = 0;
assert( p->explain==0 );
db->busyHandler.nBusy = 0;
if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
if( AtomicLoad(&db->u1.isInterrupted) || AtomicLoad(&p->isInterrupted) ){
goto abort_due_to_interrupt;
}
sqlite3VdbeIOTraceSql(p);
#ifdef SQLITE_DEBUG
sqlite3BeginBenignMalloc();
Expand Down Expand Up @@ -95997,6 +96008,12 @@ SQLITE_PRIVATE int sqlite3VdbeExec(
sqlite3_interrupt(db);
}
}
if( sqlite3_stmt_interrupt_count>0 ){
sqlite3_stmt_interrupt_count--;
if( sqlite3_stmt_interrupt_count==0 ){
libsql_stmt_interrupt((sqlite3_stmt*)p);
}
}
#endif

/* Sanity checking on other operands */
Expand Down Expand Up @@ -96118,7 +96135,9 @@ case OP_Goto: { /* jump */
** checks on every opcode. This helps sqlite3_step() to run about 1.5%
** faster according to "valgrind --tool=cachegrind" */
check_for_interrupt:
if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
if( AtomicLoad(&db->u1.isInterrupted) || AtomicLoad(&p->isInterrupted) ){
goto abort_due_to_interrupt;
}
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
/* Call the progress callback if it is configured and the required number
** of VDBE ops have been executed (either since this invocation of
Expand Down Expand Up @@ -104463,7 +104482,7 @@ default: { /* This is really OP_Noop, OP_Explain */
** flag.
*/
abort_due_to_interrupt:
assert( AtomicLoad(&db->u1.isInterrupted) );
assert( AtomicLoad(&db->u1.isInterrupted) || AtomicLoad(&p->isInterrupted) );
rc = SQLITE_INTERRUPT;
goto abort_due_to_error;
}
Expand Down
31 changes: 25 additions & 6 deletions libsql-ffi/bundled/src/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
** src/sqlite3ext.h
** src/sqliteInt.h
** src/status.c
** src/test1.c
** src/test2.c
** src/test3.c
** src/test8.c
Expand Down Expand Up @@ -90201,7 +90202,7 @@ SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
#ifdef SQLITE_DEBUG
p->nWrite = 0;
#endif
p->isInterrupted = 0;
AtomicStore(&p->isInterrupted, 0);

/* Save profiling information from this VDBE run.
*/
Expand Down Expand Up @@ -93043,7 +93044,9 @@ void libsql_stmt_interrupt(sqlite3_stmt *pStmt){
(void)SQLITE_MISUSE_BKPT;
return;
}
v->isInterrupted = 1;
/* Set atomically: this may be called from a different thread than the one
** executing the statement, mirroring sqlite3_interrupt(). */
AtomicStore(&v->isInterrupted, 1);
}

/*
Expand All @@ -93061,7 +93064,7 @@ SQLITE_API int sqlite3_step(sqlite3_stmt *pStmt){
return SQLITE_MISUSE_BKPT;
}
db = v->db;
if( v->isInterrupted ){
if( AtomicLoad(&v->isInterrupted) ){
rc = SQLITE_INTERRUPT;
v->rc = rc;
db->errCode = rc;
Expand Down Expand Up @@ -95105,6 +95108,12 @@ SQLITE_API int sqlite3_search_count = 0;
*/
#ifdef SQLITE_TEST
SQLITE_API int sqlite3_interrupt_count = 0;
/*
** As above, but simulates a statement-level interrupt
** (libsql_stmt_interrupt()) on the statement that is currently executing,
** rather than a connection-wide sqlite3_interrupt().
*/
SQLITE_API int sqlite3_stmt_interrupt_count = 0;
#endif

/*
Expand Down Expand Up @@ -95928,7 +95937,9 @@ SQLITE_PRIVATE int sqlite3VdbeExec(
p->iCurrentTime = 0;
assert( p->explain==0 );
db->busyHandler.nBusy = 0;
if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
if( AtomicLoad(&db->u1.isInterrupted) || AtomicLoad(&p->isInterrupted) ){
goto abort_due_to_interrupt;
}
sqlite3VdbeIOTraceSql(p);
#ifdef SQLITE_DEBUG
sqlite3BeginBenignMalloc();
Expand Down Expand Up @@ -95997,6 +96008,12 @@ SQLITE_PRIVATE int sqlite3VdbeExec(
sqlite3_interrupt(db);
}
}
if( sqlite3_stmt_interrupt_count>0 ){
sqlite3_stmt_interrupt_count--;
if( sqlite3_stmt_interrupt_count==0 ){
libsql_stmt_interrupt((sqlite3_stmt*)p);
}
}
#endif

/* Sanity checking on other operands */
Expand Down Expand Up @@ -96118,7 +96135,9 @@ case OP_Goto: { /* jump */
** checks on every opcode. This helps sqlite3_step() to run about 1.5%
** faster according to "valgrind --tool=cachegrind" */
check_for_interrupt:
if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
if( AtomicLoad(&db->u1.isInterrupted) || AtomicLoad(&p->isInterrupted) ){
goto abort_due_to_interrupt;
}
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
/* Call the progress callback if it is configured and the required number
** of VDBE ops have been executed (either since this invocation of
Expand Down Expand Up @@ -104463,7 +104482,7 @@ default: { /* This is really OP_Noop, OP_Explain */
** flag.
*/
abort_due_to_interrupt:
assert( AtomicLoad(&db->u1.isInterrupted) );
assert( AtomicLoad(&db->u1.isInterrupted) || AtomicLoad(&p->isInterrupted) );
rc = SQLITE_INTERRUPT;
goto abort_due_to_error;
}
Expand Down
5 changes: 5 additions & 0 deletions libsql-sqlite3/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,11 @@ threadtest: threadtest3$(TEXE)
threadtest5: sqlite3.c $(TOP)/test/threadtest5.c
$(LTLINK) $(TOP)/test/threadtest5.c sqlite3.c -o $@ $(TLIBS)

# Multi-threaded test of the libsql_stmt_interrupt() API. Builds a small
# standalone binary; run it directly to check the result.
interrupttest: sqlite3.c $(TOP)/test/interrupttest.c
$(LTLINK) $(TOP)/test/interrupttest.c sqlite3.c -o $@ $(TLIBS)

# Standard install and cleanup targets
#
liblibsql_wasm_install: liblibsql_wasm
Expand Down
5 changes: 5 additions & 0 deletions libsql-sqlite3/main.mk
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,11 @@ threadtest3$(EXE): sqlite3.o $(THREADTEST3_SRC) $(TOP)/src/test_multiplex.c
threadtest: threadtest3$(EXE)
./threadtest3$(EXE)

# Multi-threaded test of the libsql_stmt_interrupt() API. Builds a small
# standalone binary; run it directly to check the result.
interrupttest$(EXE): sqlite3.o $(TOP)/test/interrupttest.c
$(TCCX) $(TOP)/test/interrupttest.c sqlite3.o -o $@ $(THREADLIB)

TEST_EXTENSION = $(SHPREFIX)testloadext.$(SO)
$(TEST_EXTENSION): $(TOP)/src/test_loadext.c
$(MKSHLIB) $(TOP)/src/test_loadext.c -o $(TEST_EXTENSION)
Expand Down
5 changes: 4 additions & 1 deletion libsql-sqlite3/src/test1.c
Original file line number Diff line number Diff line change
Expand Up @@ -8970,6 +8970,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
extern int sqlite3_search_count;
extern int sqlite3_found_count;
extern int sqlite3_interrupt_count;
extern int sqlite3_stmt_interrupt_count;
extern int sqlite3_open_file_count;
extern int sqlite3_sort_count;
extern int sqlite3_current_time;
Expand Down Expand Up @@ -9306,8 +9307,10 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
(char*)&sqlite3_max_blobsize, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_like_count",
(char*)&sqlite3_like_count, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_interrupt_count",
Tcl_LinkVar(interp, "sqlite_interrupt_count",
(char*)&sqlite3_interrupt_count, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_stmt_interrupt_count",
(char*)&sqlite3_stmt_interrupt_count, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_open_file_count",
(char*)&sqlite3_open_file_count, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_current_time",
Expand Down
22 changes: 19 additions & 3 deletions libsql-sqlite3/src/vdbe.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ int sqlite3_search_count = 0;
*/
#ifdef SQLITE_TEST
int sqlite3_interrupt_count = 0;
/*
** As above, but simulates a statement-level interrupt
** (libsql_stmt_interrupt()) on the statement that is currently executing,
** rather than a connection-wide sqlite3_interrupt().
*/
int sqlite3_stmt_interrupt_count = 0;
#endif

/*
Expand Down Expand Up @@ -895,7 +901,9 @@ int sqlite3VdbeExec(
p->iCurrentTime = 0;
assert( p->explain==0 );
db->busyHandler.nBusy = 0;
if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
if( AtomicLoad(&db->u1.isInterrupted) || AtomicLoad(&p->isInterrupted) ){
goto abort_due_to_interrupt;
}
sqlite3VdbeIOTraceSql(p);
#ifdef SQLITE_DEBUG
sqlite3BeginBenignMalloc();
Expand Down Expand Up @@ -964,6 +972,12 @@ int sqlite3VdbeExec(
sqlite3_interrupt(db);
}
}
if( sqlite3_stmt_interrupt_count>0 ){
sqlite3_stmt_interrupt_count--;
if( sqlite3_stmt_interrupt_count==0 ){
libsql_stmt_interrupt((sqlite3_stmt*)p);
}
}
#endif

/* Sanity checking on other operands */
Expand Down Expand Up @@ -1085,7 +1099,9 @@ case OP_Goto: { /* jump */
** checks on every opcode. This helps sqlite3_step() to run about 1.5%
** faster according to "valgrind --tool=cachegrind" */
check_for_interrupt:
if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
if( AtomicLoad(&db->u1.isInterrupted) || AtomicLoad(&p->isInterrupted) ){
goto abort_due_to_interrupt;
}
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
/* Call the progress callback if it is configured and the required number
** of VDBE ops have been executed (either since this invocation of
Expand Down Expand Up @@ -9430,7 +9446,7 @@ default: { /* This is really OP_Noop, OP_Explain */
** flag.
*/
abort_due_to_interrupt:
assert( AtomicLoad(&db->u1.isInterrupted) );
assert( AtomicLoad(&db->u1.isInterrupted) || AtomicLoad(&p->isInterrupted) );
rc = SQLITE_INTERRUPT;
goto abort_due_to_error;
}
6 changes: 4 additions & 2 deletions libsql-sqlite3/src/vdbeapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,9 @@ void libsql_stmt_interrupt(sqlite3_stmt *pStmt){
(void)SQLITE_MISUSE_BKPT;
return;
}
v->isInterrupted = 1;
/* Set atomically: this may be called from a different thread than the one
** executing the statement, mirroring sqlite3_interrupt(). */
AtomicStore(&v->isInterrupted, 1);
}

/*
Expand All @@ -915,7 +917,7 @@ int sqlite3_step(sqlite3_stmt *pStmt){
return SQLITE_MISUSE_BKPT;
}
db = v->db;
if( v->isInterrupted ){
if( AtomicLoad(&v->isInterrupted) ){
rc = SQLITE_INTERRUPT;
v->rc = rc;
db->errCode = rc;
Expand Down
2 changes: 1 addition & 1 deletion libsql-sqlite3/src/vdbeaux.c
Original file line number Diff line number Diff line change
Expand Up @@ -3632,7 +3632,7 @@ int sqlite3VdbeReset(Vdbe *p){
#ifdef SQLITE_DEBUG
p->nWrite = 0;
#endif
p->isInterrupted = 0;
AtomicStore(&p->isInterrupted, 0);

/* Save profiling information from this VDBE run.
*/
Expand Down
Loading
Loading