C tweaks.

This commit is contained in:
Nuno Cruces
2025-01-17 10:51:25 +00:00
parent aa8287f8e7
commit c024121fd2
6 changed files with 20 additions and 13 deletions

View File

@@ -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

View File

@@ -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
static int sqliteBusyCallback(void *, int);
// Implemented in vfs.c.
int localtime_s(struct tm *const pTm, time_t const *const pTime);

View File

@@ -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");

View File

@@ -1,5 +1,6 @@
#include <unistd.h>
// 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"

View File

@@ -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"