Skip to content

Commit

Permalink
properly check SQLITE_THREADSAFE for static compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
asg017 committed Aug 9, 2024
1 parent ad5510d commit a6498d0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
12 changes: 6 additions & 6 deletions sqlite-vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -3608,7 +3608,7 @@ int vec0_rowids_insert_rowid(vec0_vtab *p, i64 rowid) {
}
}

#ifdef SQLITE_THREADSAFE
#if SQLITE_THREADSAFE
if (sqlite3_mutex_enter) {
sqlite3_mutex_enter(sqlite3_db_mutex(p->db));
entered = 1;
Expand Down Expand Up @@ -3640,7 +3640,7 @@ int vec0_rowids_insert_rowid(vec0_vtab *p, i64 rowid) {
sqlite3_clear_bindings(p->stmtRowidsInsertRowid);
}

#ifdef SQLITE_THREADSAFE
#if SQLITE_THREADSAFE
if (sqlite3_mutex_leave && entered) {
sqlite3_mutex_leave(sqlite3_db_mutex(p->db));
}
Expand Down Expand Up @@ -3670,7 +3670,7 @@ int vec0_rowids_insert_id(vec0_vtab *p, sqlite3_value *idValue, i64 *rowid) {
}
}

#ifdef SQLITE_THREADSAFE
#if SQLITE_THREADSAFE
if (sqlite3_mutex_enter) {
sqlite3_mutex_enter(sqlite3_db_mutex(p->db));
entered = 1;
Expand Down Expand Up @@ -3707,7 +3707,7 @@ int vec0_rowids_insert_id(vec0_vtab *p, sqlite3_value *idValue, i64 *rowid) {
sqlite3_clear_bindings(p->stmtRowidsInsertId);
}

#ifdef SQLITE_THREADSAFE
#if SQLITE_THREADSAFE
if (sqlite3_mutex_leave && entered) {
sqlite3_mutex_leave(sqlite3_db_mutex(p->db));
}
Expand Down Expand Up @@ -3795,7 +3795,7 @@ int vec0_new_chunk(vec0_vtab *p, i64 *chunk_rowid) {
return rc;
}

#ifdef SQLITE_THREADSAFE
#if SQLITE_THREADSAFE
if (sqlite3_mutex_enter) {
sqlite3_mutex_enter(sqlite3_db_mutex(p->db));
}
Expand All @@ -3808,7 +3808,7 @@ int vec0_new_chunk(vec0_vtab *p, i64 *chunk_rowid) {
rc = sqlite3_step(stmt);
int failed = rc != SQLITE_DONE;
rowid = sqlite3_last_insert_rowid(p->db);
#ifdef SQLITE_THREADSAFE
#if SQLITE_THREADSAFE
if (sqlite3_mutex_leave) {
sqlite3_mutex_leave(sqlite3_db_mutex(p->db));
}
Expand Down
30 changes: 20 additions & 10 deletions tests/minimum/Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
#curl -q -o sqlite-amalgamation-3310100.zip https://www.sqlite.org/2020/sqlite-amalgamation-3310100.zip
#unzip https://www.sqlite.org/2020/sqlite-amalgamation-3310100.zip

dist/:
dist/.stammp:
mkdir -p dist
touch $@

dist/sqlite-amalgamation-3310100: dist/
rm -rf sqlite-amalgamation-3310100/ || true
dist/sqlite-amalgamation-3310100/.stamp: dist/.stammp
rm -rf dist/sqlite-amalgamation-3310100/ || true
curl -q -o sqlite-amalgamation-3310100.zip https://www.sqlite.org/2020/sqlite-amalgamation-3310100.zip
unzip -d dist/ sqlite-amalgamation-3310100.zip
rm sqlite-amalgamation-3310100.zip
touch $@

dist/t3310100: demo.c dist/sqlite-amalgamation-3310100
dist/t3310100: demo.c dist/sqlite-amalgamation-3310100/.stamp ../../sqlite-vec.c
gcc \
-lm \
-DSQLITE_CORE -DSQLITE_ENABLE_JSON1 \
-I dist/sqlite-amalgamation-3310100 \
-I ../../ \
$< dist/sqlite-amalgamation-3310100/sqlite3.c \
../../sqlite-vec.c \
-o $@

dist/t3310100-threadsafe: demo.c dist/sqlite-amalgamation-3310100/.stamp ../../sqlite-vec.c
gcc \
-lm \
-DSQLITE_CORE \
-DSQLITE_CORE -DSQLITE_ENABLE_JSON1 -DSQLITE_THREADSAFE=0 \
-I dist/sqlite-amalgamation-3310100 \
-I ../../ \
$< dist/sqlite-amalgamation-3310100/sqlite3.c \
../../sqlite-vec.c \
-o $@

test:
make dist/t3310100
test: dist/t3310100 dist/t3310100-threadsafe
./dist/t3310100
./dist/t3310100-threadsafe

clean:
rm -rf dist/
9 changes: 5 additions & 4 deletions tests/minimum/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ int main(int argc, char *argv[]) {
sqlite3 *db;
sqlite3_stmt *stmt;

rc = sqlite3_auto_extension((void (*)())sqlite3_vec_init);
rc = sqlite3_open(":memory:", &db);
assert(rc == SQLITE_OK);

rc = sqlite3_open(":memory:", &db);
rc = sqlite3_vec_init(db, NULL, NULL);
assert(rc == SQLITE_OK);

rc = sqlite3_prepare_v2(db, "SELECT sqlite_version(), vec_version()", -1, &stmt, NULL);

rc = sqlite3_prepare_v2(db, "SELECT sqlite_version(), vec_version(), (select json_group_array(compile_options) from pragma_compile_options)", -1, &stmt, NULL);
assert(rc == SQLITE_OK);

rc = sqlite3_step(stmt);
printf("sqlite_version=%s, vec_version=%s\n", sqlite3_column_text(stmt, 0), sqlite3_column_text(stmt, 1));
printf("sqlite_version=%s, vec_version=%s %s\n", sqlite3_column_text(stmt, 0), sqlite3_column_text(stmt, 1), sqlite3_column_text(stmt, 2));
sqlite3_finalize(stmt);
sqlite3_close(db);
return 0;
Expand Down

0 comments on commit a6498d0

Please sign in to comment.