mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 05:59:14 +00:00
C tweaks.
This commit is contained in:
@@ -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
|
||||
@@ -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);
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user