Skip to content

Commit c024121

Browse files
committed
C tweaks.
1 parent aa8287f commit c024121

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

sqlite3/hooks.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ int sqlite3_autovacuum_pages_go(sqlite3 *db, go_handle app) {
6565

6666
#ifndef sqliteBusyCallback
6767

68-
static int sqliteBusyCallback(sqlite3 *db, int count) {
69-
return go_busy_timeout(count, db->busyTimeout);
68+
static int sqliteBusyCallback(void *ptr, int count) {
69+
return go_busy_timeout(count, ((sqlite3 *)ptr)->busyTimeout);
7070
}
7171

7272
#endif

sqlite3/sqlite_cfg.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@
3333
#define HAVE_MALLOC_H 1
3434
#define HAVE_MALLOC_USABLE_SIZE 1
3535

36-
// Implemented in vfs.c.
37-
int localtime_s(struct tm *const pTm, time_t const *const pTime);
38-
3936
// Implemented in hooks.c.
40-
#ifndef sqliteBusyCallback
41-
static int sqliteBusyCallback(sqlite3 *, int);
42-
#endif
37+
static int sqliteBusyCallback(void *, int);
38+
39+
// Implemented in vfs.c.
40+
int localtime_s(struct tm *const pTm, time_t const *const pTime);

sqlite3/vfs.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ struct go_file {
9090
};
9191

9292
sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName) {
93+
// The default VFS.
9394
if (!zVfsName || !strcmp(zVfsName, "os")) {
9495
static sqlite3_vfs os_vfs = {
9596
.iVersion = 2,
@@ -109,18 +110,21 @@ sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName) {
109110
return &os_vfs;
110111
}
111112

113+
// Check if a Go VFS exists.
112114
if (!go_vfs_find(zVfsName)) {
113115
return NULL;
114116
}
115117

116118
static sqlite3_vfs *go_vfs_list;
117119

120+
// Do we already have a C wrapper for the Go VFS?
118121
for (sqlite3_vfs *it = go_vfs_list; it; it = it->pNext) {
119122
if (!strcmp(zVfsName, it->zName)) {
120123
return it;
121124
}
122125
}
123126

127+
// Delete C wrappers that are no longer needed.
124128
for (sqlite3_vfs **ptr = &go_vfs_list; *ptr;) {
125129
sqlite3_vfs *it = *ptr;
126130
if (go_vfs_find(it->zName)) {
@@ -131,6 +135,7 @@ sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName) {
131135
}
132136
}
133137

138+
// Create a new C wrapper.
134139
sqlite3_vfs *head = go_vfs_list;
135140
go_vfs_list = malloc(sizeof(sqlite3_vfs) + strlen(zVfsName) + 1);
136141
char *name = (char *)(go_vfs_list + 1);
@@ -158,13 +163,11 @@ int localtime_s(struct tm *const pTm, time_t const *const pTime) {
158163
return go_localtime(pTm, (sqlite3_int64)*pTime);
159164
}
160165

161-
int sqlite3_os_init() {
162-
return SQLITE_OK;
163-
}
166+
int sqlite3_os_init() { return SQLITE_OK; }
164167

165168
int sqlite3_invoke_busy_handler_go(sqlite3_int64 token) {
166169
void **ap = (void **)&token;
167-
return ((int(*)(void *))(ap[0]))(ap[1]);
170+
return ((int (*)(void *))(ap[0]))(ap[1]);
168171
}
169172

170173
static_assert(offsetof(sqlite3_vfs, zName) == 16, "Unexpected offset");

vfs/tests/mptest/wasm/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <unistd.h>
22

3+
// Use the default call back, not the Go one we patched in.
34
#define sqliteBusyCallback sqliteDefaultBusyCallback
45

56
// Amalgamation
@@ -9,8 +10,10 @@
910

1011
__attribute__((constructor)) void init() { sqlite3_initialize(); }
1112

13+
// Ignore these.
1214
#define sqlite3_enable_load_extension(...)
1315
#define sqlite3_trace(...)
1416
#define unlink(...) (0)
1517
#undef UNUSED_PARAMETER
18+
1619
#include "mptest.c"

vfs/tests/speedtest1/wasm/main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
// Use the default call back, not the Go one we patched in.
12
#define sqliteBusyCallback sqliteDefaultBusyCallback
23

34
// Amalgamation
45
#include "sqlite3.c"
56
// VFS
67
#include "vfs.c"
78

8-
#define randomFunc randomFunc2
9+
// Can't have two functions with the same name.
10+
#define randomFunc randomFuncRepeatable
11+
912
#include "speedtest1.c"
9 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)