@@ -57,18 +57,18 @@ pub extern "C" fn xOpen(
57
57
let rc = unsafe {
58
58
(orig_methods.xOpen.unwrap())(vfs, db_file, wal_name, no_shm_mode, max_size, methods, wal)
59
59
};
60
- if rc != ffi::SQLITE_OK {
60
+ if rc != ffi::SQLITE_OK as i32 {
61
61
return rc;
62
62
}
63
63
64
64
if !is_regular(vfs) {
65
65
tracing::error!("Bottomless WAL is currently only supported for regular VFS");
66
- return ffi::SQLITE_CANTOPEN;
66
+ return ffi::SQLITE_CANTOPEN as i32 ;
67
67
}
68
68
69
69
if is_local() {
70
70
tracing::info!("Running in local-mode only, without any replication");
71
- return ffi::SQLITE_OK;
71
+ return ffi::SQLITE_OK as i32 ;
72
72
}
73
73
74
74
let runtime = match tokio::runtime::Builder::new_current_thread()
@@ -78,7 +78,7 @@ pub extern "C" fn xOpen(
78
78
Ok(runtime) => runtime,
79
79
Err(e) => {
80
80
tracing::error!("Failed to initialize async runtime: {}", e);
81
- return ffi::SQLITE_CANTOPEN;
81
+ return ffi::SQLITE_CANTOPEN as i32 ;
82
82
}
83
83
};
84
84
@@ -88,7 +88,7 @@ pub extern "C" fn xOpen(
88
88
Ok(path) => path,
89
89
Err(e) => {
90
90
tracing::error!("Failed to parse the main database path: {}", e);
91
- return ffi::SQLITE_CANTOPEN;
91
+ return ffi::SQLITE_CANTOPEN as i32 ;
92
92
}
93
93
}
94
94
};
@@ -98,12 +98,12 @@ pub extern "C" fn xOpen(
98
98
Ok(repl) => repl,
99
99
Err(e) => {
100
100
tracing::error!("Failed to initialize replicator: {}", e);
101
- return ffi::SQLITE_CANTOPEN;
101
+ return ffi::SQLITE_CANTOPEN as i32 ;
102
102
}
103
103
};
104
104
105
105
let rc = block_on!(runtime, try_restore(&mut replicator));
106
- if rc != ffi::SQLITE_OK {
106
+ if rc != ffi::SQLITE_OK as i32 {
107
107
return rc;
108
108
}
109
109
@@ -114,7 +114,7 @@ pub extern "C" fn xOpen(
114
114
let context_ptr = Box::into_raw(Box::new(context)) as *mut c_void;
115
115
unsafe { (*(*wal)).pMethodsData = context_ptr };
116
116
117
- ffi::SQLITE_OK
117
+ ffi::SQLITE_OK as i32
118
118
}
119
119
120
120
fn get_orig_methods(wal: *mut Wal) -> &'static libsql_wal_methods {
@@ -138,7 +138,7 @@ pub extern "C" fn xClose(
138
138
let orig_methods = get_orig_methods(wal);
139
139
let methods_data = unsafe { (*wal).pMethodsData as *mut replicator::Context };
140
140
let rc = unsafe { (orig_methods.xClose.unwrap())(wal, db, sync_flags, n_buf, z_buf) };
141
- if rc != ffi::SQLITE_OK {
141
+ if rc != ffi::SQLITE_OK as i32 {
142
142
return rc;
143
143
}
144
144
if !is_local() && !methods_data.is_null() {
@@ -194,7 +194,7 @@ pub extern "C" fn xUndo(
194
194
) -> i32 {
195
195
let orig_methods = get_orig_methods(wal);
196
196
let rc = unsafe { (orig_methods.xUndo.unwrap())(wal, func, ctx) };
197
- if is_local() || rc != ffi::SQLITE_OK {
197
+ if is_local() || rc != ffi::SQLITE_OK as i32 {
198
198
return rc;
199
199
}
200
200
@@ -207,7 +207,7 @@ pub extern "C" fn xUndo(
207
207
);
208
208
ctx.replicator.rollback_to_frame(last_valid_frame);
209
209
210
- ffi::SQLITE_OK
210
+ ffi::SQLITE_OK as i32
211
211
}
212
212
213
213
pub extern "C" fn xSavepoint(wal: *mut Wal, wal_data: *mut u32) {
@@ -218,7 +218,7 @@ pub extern "C" fn xSavepoint(wal: *mut Wal, wal_data: *mut u32) {
218
218
pub extern "C" fn xSavepointUndo(wal: *mut Wal, wal_data: *mut u32) -> i32 {
219
219
let orig_methods = get_orig_methods(wal);
220
220
let rc = unsafe { (orig_methods.xSavepointUndo.unwrap())(wal, wal_data) };
221
- if is_local() || rc != ffi::SQLITE_OK {
221
+ if is_local() || rc != ffi::SQLITE_OK as i32 {
222
222
return rc;
223
223
}
224
224
@@ -231,7 +231,7 @@ pub extern "C" fn xSavepointUndo(wal: *mut Wal, wal_data: *mut u32) -> i32 {
231
231
);
232
232
ctx.replicator.rollback_to_frame(last_valid_frame);
233
233
234
- ffi::SQLITE_OK
234
+ ffi::SQLITE_OK as i32
235
235
}
236
236
237
237
pub extern "C" fn xFrames(
@@ -253,7 +253,7 @@ pub extern "C" fn xFrames(
253
253
// supported by bottomless storage.
254
254
if let Err(e) = ctx.replicator.set_page_size(page_size as usize) {
255
255
tracing::error!("{}", e);
256
- return ffi::SQLITE_IOERR_WRITE;
256
+ return ffi::SQLITE_IOERR_WRITE as i32 ;
257
257
}
258
258
let frame_count = ffi::PageHdrIter::new(page_headers, page_size as usize).count();
259
259
if size_after != 0 {
@@ -273,11 +273,11 @@ pub extern "C" fn xFrames(
273
273
sync_flags,
274
274
)
275
275
};
276
- if is_local() || rc != ffi::SQLITE_OK {
276
+ if is_local() || rc != ffi::SQLITE_OK as i32 {
277
277
return rc;
278
278
}
279
279
280
- ffi::SQLITE_OK
280
+ ffi::SQLITE_OK as i32
281
281
}
282
282
283
283
extern "C" fn always_wait(_busy_param: *mut c_void) -> i32 {
@@ -307,9 +307,9 @@ pub extern "C" fn xCheckpoint(
307
307
** In order to avoid autocheckpoint on close (that's too often),
308
308
** checkpoint attempts weaker than TRUNCATE are ignored.
309
309
*/
310
- if emode < ffi::SQLITE_CHECKPOINT_TRUNCATE {
310
+ if emode < ffi::SQLITE_CHECKPOINT_TRUNCATE as i32 {
311
311
tracing::trace!("Ignoring a checkpoint request weaker than TRUNCATE");
312
- return ffi::SQLITE_OK;
312
+ return ffi::SQLITE_OK as i32 ;
313
313
}
314
314
/* If there's no busy handler, let's provide a default one,
315
315
** since we auto-upgrade the passive checkpoint
@@ -335,14 +335,14 @@ pub extern "C" fn xCheckpoint(
335
335
)
336
336
};
337
337
338
- if is_local() || rc != ffi::SQLITE_OK {
338
+ if is_local() || rc != ffi::SQLITE_OK as i32 {
339
339
return rc;
340
340
}
341
341
342
342
let ctx = get_replicator_context(wal);
343
343
if ctx.replicator.commits_in_current_generation() == 0 {
344
344
tracing::debug!("No commits happened in this generation, not snapshotting");
345
- return ffi::SQLITE_OK;
345
+ return ffi::SQLITE_OK as i32 ;
346
346
}
347
347
348
348
let last_known_frame = ctx.replicator.last_known_frame();
@@ -352,7 +352,7 @@ pub extern "C" fn xCheckpoint(
352
352
ctx.replicator.wait_until_committed(last_known_frame)
353
353
) {
354
354
tracing::error!("Failed to finalize replication: {}", e);
355
- return ffi::SQLITE_IOERR_WRITE;
355
+ return ffi::SQLITE_IOERR_WRITE as i32 ;
356
356
}
357
357
358
358
ctx.replicator.new_generation();
@@ -363,10 +363,10 @@ pub extern "C" fn xCheckpoint(
363
363
"Failed to snapshot the main db file during checkpoint: {}",
364
364
e
365
365
);
366
- return ffi::SQLITE_IOERR_WRITE;
366
+ return ffi::SQLITE_IOERR_WRITE as i32 ;
367
367
}
368
368
369
- ffi::SQLITE_OK
369
+ ffi::SQLITE_OK as i32
370
370
}
371
371
372
372
pub extern "C" fn xCallback(wal: *mut Wal) -> i32 {
@@ -416,42 +416,42 @@ async fn try_restore(replicator: &mut replicator::Replicator) -> i32 {
416
416
replicator.new_generation();
417
417
if let Err(e) = replicator.snapshot_main_db_file().await {
418
418
tracing::error!("Failed to snapshot the main db file: {}", e);
419
- return ffi::SQLITE_CANTOPEN;
419
+ return ffi::SQLITE_CANTOPEN as i32 ;
420
420
}
421
421
// Restoration process only leaves the local WAL file if it was
422
422
// detected to be newer than its remote counterpart.
423
423
if let Err(e) = replicator.maybe_replicate_wal().await {
424
424
tracing::error!("Failed to replicate local WAL: {}", e);
425
- return ffi::SQLITE_CANTOPEN;
425
+ return ffi::SQLITE_CANTOPEN as i32 ;
426
426
}
427
427
}
428
428
Ok(replicator::RestoreAction::ReuseGeneration(gen)) => {
429
429
replicator.set_generation(gen);
430
430
}
431
431
Err(e) => {
432
432
tracing::error!("Failed to restore the database: {}", e);
433
- return ffi::SQLITE_CANTOPEN;
433
+ return ffi::SQLITE_CANTOPEN as i32 ;
434
434
}
435
435
}
436
436
437
- ffi::SQLITE_OK
437
+ ffi::SQLITE_OK as i32
438
438
}
439
439
440
440
pub extern "C" fn xPreMainDbOpen(_methods: *mut libsql_wal_methods, path: *const c_char) -> i32 {
441
441
if is_local() {
442
442
tracing::info!("Running in local-mode only, without any replication");
443
- return ffi::SQLITE_OK;
443
+ return ffi::SQLITE_OK as i32 ;
444
444
}
445
445
446
446
if path.is_null() {
447
- return ffi::SQLITE_OK;
447
+ return ffi::SQLITE_OK as i32 ;
448
448
}
449
449
let path = unsafe {
450
450
match std::ffi::CStr::from_ptr(path).to_str() {
451
451
Ok(path) => path,
452
452
Err(e) => {
453
453
tracing::error!("Failed to parse the main database path: {}", e);
454
- return ffi::SQLITE_CANTOPEN;
454
+ return ffi::SQLITE_CANTOPEN as i32 ;
455
455
}
456
456
}
457
457
};
@@ -464,23 +464,23 @@ pub extern "C" fn xPreMainDbOpen(_methods: *mut libsql_wal_methods, path: *const
464
464
Ok(runtime) => runtime,
465
465
Err(e) => {
466
466
tracing::error!("Failed to initialize async runtime: {}", e);
467
- return ffi::SQLITE_CANTOPEN;
467
+ return ffi::SQLITE_CANTOPEN as i32 ;
468
468
}
469
469
};
470
470
471
471
let options = match replicator::Options::from_env() {
472
472
Ok(options) => options,
473
473
Err(e) => {
474
474
tracing::error!("Failed to parse replicator options: {}", e);
475
- return ffi::SQLITE_CANTOPEN;
475
+ return ffi::SQLITE_CANTOPEN as i32 ;
476
476
}
477
477
};
478
478
let replicator = block_on!(runtime, replicator::Replicator::with_options(path, options));
479
479
let mut replicator = match replicator {
480
480
Ok(repl) => repl,
481
481
Err(e) => {
482
482
tracing::error!("Failed to initialize replicator: {}", e);
483
- return ffi::SQLITE_CANTOPEN;
483
+ return ffi::SQLITE_CANTOPEN as i32 ;
484
484
}
485
485
};
486
486
block_on!(runtime, try_restore(&mut replicator))
@@ -561,7 +561,7 @@ pub mod static_init {
561
561
if orig_methods.is_null() {}
562
562
let methods = crate::bottomless_methods(orig_methods);
563
563
let rc = unsafe { libsql_wal_methods_register(methods) };
564
- if rc != crate::ffi::SQLITE_OK {
564
+ if rc != crate::ffi::SQLITE_OK as i32 {
565
565
let _box = unsafe { Box::from_raw(methods as *mut libsql_wal_methods) };
566
566
tracing::warn!("Failed to instantiate bottomless WAL methods");
567
567
}
0 commit comments