From af7b8b6768e7436d11b49d3b02a061640b6c2dba Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 17 Jul 2024 12:53:55 +0300 Subject: [PATCH] sqlite3: Implement some auxiliary functions This adds `sqlite3_libversion()`, `sqlite3_libversion_number()`, and `libsql3_threadsafe()`. --- sqlite3/src/lib.rs | 8 +++++--- sqlite3/tests/Makefile | 1 + sqlite3/tests/main.c | 4 ++++ sqlite3/tests/test-aux.c | 11 +++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 sqlite3/tests/test-aux.c diff --git a/sqlite3/src/lib.rs b/sqlite3/src/lib.rs index f724e6ab8..aad33b792 100644 --- a/sqlite3/src/lib.rs +++ b/sqlite3/src/lib.rs @@ -773,15 +773,17 @@ pub unsafe extern "C" fn sqlite3_complete(_sql: *const std::ffi::c_char) -> ffi: #[no_mangle] pub unsafe extern "C" fn sqlite3_threadsafe() -> ffi::c_int { - todo!(); + 1 } #[no_mangle] pub unsafe extern "C" fn sqlite3_libversion() -> *const std::ffi::c_char { - todo!(); + ffi::CStr::from_bytes_with_nul(b"3.42.0\0") + .unwrap() + .as_ptr() } #[no_mangle] pub unsafe extern "C" fn sqlite3_libversion_number() -> ffi::c_int { - todo!(); + 3042000 } diff --git a/sqlite3/tests/Makefile b/sqlite3/tests/Makefile index 84beb2307..1450fb499 100644 --- a/sqlite3/tests/Makefile +++ b/sqlite3/tests/Makefile @@ -15,6 +15,7 @@ CFLAGS = -g -Wall -std=c17 -MMD -MP LIBS ?= -lsqlite3 OBJS += main.o +OBJS += test-aux.o OBJS += test-close.o OBJS += test-open.o OBJS += test-prepare.o diff --git a/sqlite3/tests/main.c b/sqlite3/tests/main.c index 58590ea84..0166aa860 100644 --- a/sqlite3/tests/main.c +++ b/sqlite3/tests/main.c @@ -1,3 +1,5 @@ +extern void test_libversion(); +extern void test_libversion_number(); extern void test_open_misuse(); extern void test_open_not_found(); extern void test_open_existing(); @@ -6,6 +8,8 @@ extern void test_prepare_misuse(); int main(int argc, char *argv[]) { + test_libversion(); + test_libversion_number(); test_open_misuse(); test_open_not_found(); test_open_existing(); diff --git a/sqlite3/tests/test-aux.c b/sqlite3/tests/test-aux.c new file mode 100644 index 000000000..77c1c3b7a --- /dev/null +++ b/sqlite3/tests/test-aux.c @@ -0,0 +1,11 @@ +#include "check.h" + +#include + +void test_libversion(void) { + sqlite3_libversion(); +} + +void test_libversion_number(void) { + sqlite3_libversion_number(); +}