Skip to content

Commit 929f9ba

Browse files
committed
wal remove ifdefs from libsql_wal_methods
ABI should be consistent regardless of the compilation options, so the optional functions are in there anyway - they can be simply set to nulls if the user did not compile support for them in libSQL.
1 parent 8419336 commit 929f9ba

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

src/wal.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,25 @@ typedef struct libsql_wal_methods {
108108
*/
109109
int (*xHeapMemory)(Wal *pWal);
110110

111-
#ifdef SQLITE_ENABLE_SNAPSHOT
111+
// Only needed with SQLITE_ENABLE_SNAPSHOT, but part of the ABI
112112
int (*xSnapshotGet)(Wal *pWal, sqlite3_snapshot **ppSnapshot);
113113
void (*xSnapshotOpen)(Wal *pWal, sqlite3_snapshot *pSnapshot);
114114
int (*xSnapshotRecover)(Wal *pWal);
115115
int (*xSnapshotCheck)(Wal *pWal, sqlite3_snapshot *pSnapshot);
116116
void (*xSnapshotUnlock)(Wal *pWal);
117-
#endif
118117

119-
#ifdef SQLITE_ENABLE_ZIPVFS
118+
// Only needed with SQLITE_ENABLE_ZIPVFS, but part of the ABI
120119
/* If the WAL file is not empty, return the number of bytes of content
121120
** stored in each frame (i.e. the db page-size when the WAL was created).
122121
*/
123122
int (*xFramesize)(Wal *pWal);
124-
#endif
123+
125124

126125
/* Return the sqlite3_file object for the WAL file */
127126
sqlite3_file *(*xFile)(Wal *pWal);
128127

129-
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
128+
// Only needed with SQLITE_ENABLE_SETLK_TIMEOUT
130129
int (*xWriteLock)(Wal *pWal, int bLock);
131-
#endif
132130

133131
void (*xDb)(Wal *pWal, sqlite3 *db);
134132

@@ -220,15 +218,9 @@ struct Wal {
220218
u32 iReCksum; /* On commit, recalculate checksums from here */
221219
const char *zWalName; /* Name of WAL file */
222220
u32 nCkpt; /* Checkpoint sequence counter in the wal-header */
223-
#ifdef SQLITE_DEBUG
224221
u8 lockError; /* True if a locking error has occurred */
225-
#endif
226-
#ifdef SQLITE_ENABLE_SNAPSHOT
227222
WalIndexHdr *pSnapshot; /* Start transaction here if not NULL */
228-
#endif
229-
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
230223
sqlite3 *db;
231-
#endif
232224
libsql_wal_methods *pMethods; /* Virtual methods for interacting with WAL */;
233225
};
234226

test/rust_suite/src/virtual_wal.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ mod tests {
3131
recalculate_checksums: u32,
3232
wal_name: *const u8,
3333
n_checkpoints: u32,
34-
// debug: log_error
35-
// snapshot: p_snapshot
36-
// setlk: *db
34+
lock_error: u8,
35+
p_snapshot: *const c_void,
36+
p_db: *const c_void,
3737
wal_methods: *mut libsql_wal_methods,
3838
}
3939

@@ -107,9 +107,17 @@ mod tests {
107107
callback: extern "C" fn(wal: *mut Wal) -> i32,
108108
exclusive_mode: extern "C" fn(wal: *mut Wal) -> i32,
109109
heap_memory: extern "C" fn(wal: *mut Wal) -> i32,
110-
// snapshot: get, open, recover, check, unlock
111-
// enable_zipvfs: framesize
110+
// stubs, only useful with snapshot support compiled-in
111+
snapshot_get_stub: *const c_void,
112+
snapshot_open_stub: *const c_void,
113+
snapshot_recover_stub: *const c_void,
114+
snapshot_check_stub: *const c_void,
115+
snapshot_unlock_stub: *const c_void,
116+
// stub, only useful with zipfs support compiled-in
117+
framesize_stub: *const c_void,
112118
file: extern "C" fn(wal: *mut Wal) -> *const c_void,
119+
// stub, only useful with setlk timeout compiled-in
120+
write_lock_stub: *const c_void,
113121
db: extern "C" fn(wal: *mut Wal, db: *const c_void),
114122
pathname_len: extern "C" fn(orig_len: i32) -> i32,
115123
get_pathname: extern "C" fn(buf: *mut u8, orig: *const u8, orig_len: i32),
@@ -193,6 +201,9 @@ mod tests {
193201
recalculate_checksums: 0,
194202
wal_name: wal_name,
195203
n_checkpoints: 0,
204+
lock_error: 0,
205+
p_snapshot: std::ptr::null(),
206+
p_db: std::ptr::null(),
196207
wal_methods: methods,
197208
});
198209
unsafe { *wal = &*new_wal }
@@ -363,7 +374,16 @@ mod tests {
363374
callback,
364375
exclusive_mode,
365376
heap_memory,
377+
snapshot_get_stub: std::ptr::null(),
378+
snapshot_open_stub: std::ptr::null(),
379+
snapshot_recover_stub: std::ptr::null(),
380+
snapshot_check_stub: std::ptr::null(),
381+
snapshot_unlock_stub: std::ptr::null(),
382+
// stub, only useful with zipfs support compiled-in
383+
framesize_stub: std::ptr::null(),
366384
file,
385+
// stub, only useful with setlk timeout compiled-in
386+
write_lock_stub: std::ptr::null(),
367387
db,
368388
pathname_len,
369389
get_pathname,

0 commit comments

Comments
 (0)