From 02ac846814db372d717223d298c749a040cb77fa Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Thu, 20 Mar 2025 13:26:50 +0200 Subject: [PATCH 1/5] libsql-sqlite3: Don't use variable length arrays The C compiler on Windows does not like them... --- libsql-sqlite3/src/pager.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libsql-sqlite3/src/pager.c b/libsql-sqlite3/src/pager.c index 027aabc295..ffa76bd8df 100644 --- a/libsql-sqlite3/src/pager.c +++ b/libsql-sqlite3/src/pager.c @@ -7842,9 +7842,15 @@ int sqlite3PagerWalInsert(Pager *pPager, unsigned int iFrame, void *pBuf, unsign } if (iFrame <= mxFrame) { unsigned long frame_len = nBuf-24; - unsigned char current[frame_len]; + unsigned char *current; + + current = (unsigned char *)sqlite3MallocZero(frame_len); + if (current == NULL) { + return SQLITE_NOMEM; + } rc = pPager->wal->methods.xReadFrame(pPager->wal->pData, iFrame, frame_len, current); if (rc != SQLITE_OK) { + sqlite3_free(current); return rc; } int conflict = 0; @@ -7854,6 +7860,7 @@ int sqlite3PagerWalInsert(Pager *pPager, unsigned int iFrame, void *pBuf, unsign if (pConflict) { *pConflict = conflict; } + sqlite3_free(current); if (conflict) { return SQLITE_ERROR; } From 9bd73874956f7dd62986839acaef4ffaced90cdd Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Thu, 20 Mar 2025 13:31:27 +0200 Subject: [PATCH 2/5] libsql-sqlite3: Don't use pointer arithmetic Let's be kind to Windows compiler. --- libsql-sqlite3/src/pager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsql-sqlite3/src/pager.c b/libsql-sqlite3/src/pager.c index ffa76bd8df..5a2278b616 100644 --- a/libsql-sqlite3/src/pager.c +++ b/libsql-sqlite3/src/pager.c @@ -7854,7 +7854,7 @@ int sqlite3PagerWalInsert(Pager *pPager, unsigned int iFrame, void *pBuf, unsign return rc; } int conflict = 0; - if (memcmp(pBuf+24, current, frame_len) != 0) { + if (memcmp((unsigned char*)pBuf+24, current, frame_len) != 0) { conflict = 1; } if (pConflict) { From c7fac2bc6bbc8e7eed2573a1ebbaacb8368968fe Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Thu, 20 Mar 2025 13:36:15 +0200 Subject: [PATCH 3/5] libsql-ffi: Update bundled SQLite --- libsql-ffi/bundled/src/sqlite3.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libsql-ffi/bundled/src/sqlite3.c b/libsql-ffi/bundled/src/sqlite3.c index bc401c4123..7c73a90a0a 100644 --- a/libsql-ffi/bundled/src/sqlite3.c +++ b/libsql-ffi/bundled/src/sqlite3.c @@ -65356,18 +65356,25 @@ SQLITE_PRIVATE int sqlite3PagerWalInsert(Pager *pPager, unsigned int iFrame, voi } if (iFrame <= mxFrame) { unsigned long frame_len = nBuf-24; - unsigned char current[frame_len]; + unsigned char *current; + + current = (unsigned char *)sqlite3MallocZero(frame_len); + if (current == NULL) { + return SQLITE_NOMEM; + } rc = pPager->wal->methods.xReadFrame(pPager->wal->pData, iFrame, frame_len, current); if (rc != SQLITE_OK) { + sqlite3_free(current); return rc; } int conflict = 0; - if (memcmp(pBuf+24, current, frame_len) != 0) { + if (memcmp((unsigned char*)pBuf+24, current, frame_len) != 0) { conflict = 1; } if (pConflict) { *pConflict = conflict; } + sqlite3_free(current); if (conflict) { return SQLITE_ERROR; } From 04362acf6d92aa08df4f7f2911f76774cd2cbe7c Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Thu, 20 Mar 2025 12:26:52 +0200 Subject: [PATCH 4/5] Add libsql-ffi to workspace depedencies --- Cargo.toml | 1 + libsql-ffi/Cargo.toml | 11 ++++++----- libsql-sys/Cargo.toml | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4061e1c9cc..8107228ee2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ license = "MIT" repository = "https://github.com/tursodatabase/libsql" [workspace.dependencies] +libsql-ffi = { path = "libsql-ffi", version = "0.9.0" } libsql-sys = { path = "libsql-sys", version = "0.9.0", default-features = false } libsql-hrana = { path = "libsql-hrana", version = "0.9.0" } libsql_replication = { path = "libsql-replication", version = "0.9.0" } diff --git a/libsql-ffi/Cargo.toml b/libsql-ffi/Cargo.toml index ad1607913a..52d4a633ae 100644 --- a/libsql-ffi/Cargo.toml +++ b/libsql-ffi/Cargo.toml @@ -1,11 +1,12 @@ [package] name = "libsql-ffi" -version = "0.5.0" -edition = "2021" -build = "build.rs" -license = "MIT" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true description = "Native bindings to libSQL" -repository = "https://github.com/tursodatabase/libsql" +build = "build.rs" exclude = ["bundled/SQLite3MultipleCiphers/build", "bundled/SQLite3MultipleCiphers/test"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/libsql-sys/Cargo.toml b/libsql-sys/Cargo.toml index 51e6c914a2..69839292d2 100644 --- a/libsql-sys/Cargo.toml +++ b/libsql-sys/Cargo.toml @@ -11,7 +11,7 @@ categories = ["external-ffi-bindings"] [dependencies] bytes = "1.5.0" -libsql-ffi = { version = "0.5", path = "../libsql-ffi/" } +libsql-ffi = { workspace = true } once_cell = "1.18.0" rusqlite = { workspace = true, features = ["trace"], optional = true } tracing = "0.1.37" From 7437691d60f918bb0e1930f96b233ef6d13d0719 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Thu, 20 Mar 2025 12:29:05 +0200 Subject: [PATCH 5/5] Fix vendored rusqlite dependency to libsql-ffi --- Cargo.lock | 2 +- vendored/rusqlite/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 821f891b70..0f43fc4924 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2956,7 +2956,7 @@ dependencies = [ [[package]] name = "libsql-ffi" -version = "0.5.0" +version = "0.9.0" dependencies = [ "bindgen", "cc", diff --git a/vendored/rusqlite/Cargo.toml b/vendored/rusqlite/Cargo.toml index 97a6da652e..53f7f3dae8 100644 --- a/vendored/rusqlite/Cargo.toml +++ b/vendored/rusqlite/Cargo.toml @@ -109,7 +109,7 @@ fallible-iterator = "0.2" fallible-streaming-iterator = "0.1" uuid = { version = "1.0", optional = true } smallvec = "1.6.1" -libsql-ffi = { version = "0.5", path = "../../libsql-ffi" } +libsql-ffi = { workspace = true } [dev-dependencies] doc-comment = "0.3"