From c024121fd23d9299cb20ef2d60c35fc402786110 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Fri, 17 Jan 2025 10:51:25 +0000 Subject: [PATCH] C tweaks. --- sqlite3/hooks.c | 4 ++-- sqlite3/sqlite_cfg.h | 10 ++++------ sqlite3/vfs.c | 11 +++++++---- vfs/tests/mptest/wasm/main.c | 3 +++ vfs/tests/speedtest1/wasm/main.c | 5 ++++- vfs/tests/speedtest1/wasm/speedtest1.wasm | Bin 1393100 -> 1393109 bytes 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/sqlite3/hooks.c b/sqlite3/hooks.c index 7bf7547..73933ef 100644 --- a/sqlite3/hooks.c +++ b/sqlite3/hooks.c @@ -65,8 +65,8 @@ int sqlite3_autovacuum_pages_go(sqlite3 *db, go_handle app) { #ifndef sqliteBusyCallback -static int sqliteBusyCallback(sqlite3 *db, int count) { - return go_busy_timeout(count, db->busyTimeout); +static int sqliteBusyCallback(void *ptr, int count) { + return go_busy_timeout(count, ((sqlite3 *)ptr)->busyTimeout); } #endif \ No newline at end of file diff --git a/sqlite3/sqlite_cfg.h b/sqlite3/sqlite_cfg.h index 219927b..84edf7e 100644 --- a/sqlite3/sqlite_cfg.h +++ b/sqlite3/sqlite_cfg.h @@ -33,10 +33,8 @@ #define HAVE_MALLOC_H 1 #define HAVE_MALLOC_USABLE_SIZE 1 -// Implemented in vfs.c. -int localtime_s(struct tm *const pTm, time_t const *const pTime); - // Implemented in hooks.c. -#ifndef sqliteBusyCallback -static int sqliteBusyCallback(sqlite3 *, int); -#endif \ No newline at end of file +static int sqliteBusyCallback(void *, int); + +// Implemented in vfs.c. +int localtime_s(struct tm *const pTm, time_t const *const pTime); \ No newline at end of file diff --git a/sqlite3/vfs.c b/sqlite3/vfs.c index d28633e..e69396e 100644 --- a/sqlite3/vfs.c +++ b/sqlite3/vfs.c @@ -90,6 +90,7 @@ struct go_file { }; sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName) { + // The default VFS. if (!zVfsName || !strcmp(zVfsName, "os")) { static sqlite3_vfs os_vfs = { .iVersion = 2, @@ -109,18 +110,21 @@ sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName) { return &os_vfs; } + // Check if a Go VFS exists. if (!go_vfs_find(zVfsName)) { return NULL; } static sqlite3_vfs *go_vfs_list; + // Do we already have a C wrapper for the Go VFS? for (sqlite3_vfs *it = go_vfs_list; it; it = it->pNext) { if (!strcmp(zVfsName, it->zName)) { return it; } } + // Delete C wrappers that are no longer needed. for (sqlite3_vfs **ptr = &go_vfs_list; *ptr;) { sqlite3_vfs *it = *ptr; if (go_vfs_find(it->zName)) { @@ -131,6 +135,7 @@ sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName) { } } + // Create a new C wrapper. sqlite3_vfs *head = go_vfs_list; go_vfs_list = malloc(sizeof(sqlite3_vfs) + strlen(zVfsName) + 1); char *name = (char *)(go_vfs_list + 1); @@ -158,13 +163,11 @@ int localtime_s(struct tm *const pTm, time_t const *const pTime) { return go_localtime(pTm, (sqlite3_int64)*pTime); } -int sqlite3_os_init() { - return SQLITE_OK; -} +int sqlite3_os_init() { return SQLITE_OK; } int sqlite3_invoke_busy_handler_go(sqlite3_int64 token) { void **ap = (void **)&token; - return ((int(*)(void *))(ap[0]))(ap[1]); + return ((int (*)(void *))(ap[0]))(ap[1]); } static_assert(offsetof(sqlite3_vfs, zName) == 16, "Unexpected offset"); diff --git a/vfs/tests/mptest/wasm/main.c b/vfs/tests/mptest/wasm/main.c index ba02c75..4ba64d2 100644 --- a/vfs/tests/mptest/wasm/main.c +++ b/vfs/tests/mptest/wasm/main.c @@ -1,5 +1,6 @@ #include +// Use the default call back, not the Go one we patched in. #define sqliteBusyCallback sqliteDefaultBusyCallback // Amalgamation @@ -9,8 +10,10 @@ __attribute__((constructor)) void init() { sqlite3_initialize(); } +// Ignore these. #define sqlite3_enable_load_extension(...) #define sqlite3_trace(...) #define unlink(...) (0) #undef UNUSED_PARAMETER + #include "mptest.c" \ No newline at end of file diff --git a/vfs/tests/speedtest1/wasm/main.c b/vfs/tests/speedtest1/wasm/main.c index 8b6ccf1..e837bd0 100644 --- a/vfs/tests/speedtest1/wasm/main.c +++ b/vfs/tests/speedtest1/wasm/main.c @@ -1,3 +1,4 @@ +// Use the default call back, not the Go one we patched in. #define sqliteBusyCallback sqliteDefaultBusyCallback // Amalgamation @@ -5,5 +6,7 @@ // VFS #include "vfs.c" -#define randomFunc randomFunc2 +// Can't have two functions with the same name. +#define randomFunc randomFuncRepeatable + #include "speedtest1.c" \ No newline at end of file diff --git a/vfs/tests/speedtest1/wasm/speedtest1.wasm b/vfs/tests/speedtest1/wasm/speedtest1.wasm index f4ca40ab22d21fc7d39b11e63192eb7b2b994436..3245a60439ceb3a5b7803791da369d09c007137b 100644 GIT binary patch delta 92 zcmX@p9D21mw4sHug{g(Pg{6hHg{_6Xg`Hq)$ delta 83 zcmccG9D1fXw4sHug{g(Pg{6hHg{_6Xg`LsP!ET