Skip to content

Commit

Permalink
wal remove ifdefs from libsql_wal_methods
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
psarna committed Dec 14, 2022
1 parent 8419336 commit 51daf43
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
10 changes: 4 additions & 6 deletions src/wal.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,25 @@ typedef struct libsql_wal_methods {
*/
int (*xHeapMemory)(Wal *pWal);

#ifdef SQLITE_ENABLE_SNAPSHOT
// Only needed with SQLITE_ENABLE_SNAPSHOT, but part of the ABI
int (*xSnapshotGet)(Wal *pWal, sqlite3_snapshot **ppSnapshot);
void (*xSnapshotOpen)(Wal *pWal, sqlite3_snapshot *pSnapshot);
int (*xSnapshotRecover)(Wal *pWal);
int (*xSnapshotCheck)(Wal *pWal, sqlite3_snapshot *pSnapshot);
void (*xSnapshotUnlock)(Wal *pWal);
#endif

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


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

#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
// Only needed with SQLITE_ENABLE_SETLK_TIMEOUT
int (*xWriteLock)(Wal *pWal, int bLock);
#endif

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

Expand Down
21 changes: 19 additions & 2 deletions test/rust_suite/src/virtual_wal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,17 @@ mod tests {
callback: extern "C" fn(wal: *mut Wal) -> i32,
exclusive_mode: extern "C" fn(wal: *mut Wal) -> i32,
heap_memory: extern "C" fn(wal: *mut Wal) -> i32,
// snapshot: get, open, recover, check, unlock
// enable_zipvfs: framesize
// stubs, only useful with snapshot support compiled-in
snapshot_get_stub: *const c_void,
snapshot_open_stub: *const c_void,
snapshot_recover_stub: *const c_void,
snapshot_check_stub: *const c_void,
snapshot_unlock_stub: *const c_void,
// stub, only useful with zipfs support compiled-in
framesize_stub: *const c_void,
file: extern "C" fn(wal: *mut Wal) -> *const c_void,
// stub, only useful with setlk timeout compiled-in
write_lock_stub: *const c_void,
db: extern "C" fn(wal: *mut Wal, db: *const c_void),
pathname_len: extern "C" fn(orig_len: i32) -> i32,
get_pathname: extern "C" fn(buf: *mut u8, orig: *const u8, orig_len: i32),
Expand Down Expand Up @@ -363,7 +371,16 @@ mod tests {
callback,
exclusive_mode,
heap_memory,
snapshot_get_stub: std::ptr::null(),
snapshot_open_stub: std::ptr::null(),
snapshot_recover_stub: std::ptr::null(),
snapshot_check_stub: std::ptr::null(),
snapshot_unlock_stub: std::ptr::null(),
// stub, only useful with zipfs support compiled-in
framesize_stub: std::ptr::null(),
file,
// stub, only useful with setlk timeout compiled-in
write_lock_stub: std::ptr::null(),
db,
pathname_len,
get_pathname,
Expand Down

0 comments on commit 51daf43

Please sign in to comment.