mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 18:18:03 +00:00
Improve C binding error reporting
This commit is contained in:
parent
3ecb0fb2a9
commit
b2f46e156b
4 changed files with 16 additions and 13 deletions
|
@ -1,9 +1,10 @@
|
|||
#ifndef MVCC_H
|
||||
#define MVCC_H
|
||||
|
||||
#define MVCC_OK 0
|
||||
|
||||
#define MVCC_IO_ERROR_WRITE 778
|
||||
typedef enum {
|
||||
MVCC_OK = 0,
|
||||
MVCC_IO_ERROR_WRITE = 778,
|
||||
} MVCCError;
|
||||
|
||||
typedef struct DbContext DbContext;
|
||||
|
||||
|
@ -17,7 +18,7 @@ MVCCDatabaseRef MVCCDatabaseOpen(const char *path);
|
|||
|
||||
void MVCCDatabaseClose(MVCCDatabaseRef db);
|
||||
|
||||
int32_t MVCCDatabaseInsert(MVCCDatabaseRef db, uint64_t id, const uint8_t *value_ptr, uintptr_t value_len);
|
||||
MVCCError MVCCDatabaseInsert(MVCCDatabaseRef db, uint64_t id, const uint8_t *value_ptr, uintptr_t value_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
pub const MVCC_OK: i32 = 0;
|
||||
|
||||
pub const MVCC_IO_ERROR_WRITE: i32 = 778;
|
||||
#[repr(C)]
|
||||
pub enum MVCCError {
|
||||
MVCC_OK = 0,
|
||||
MVCC_IO_ERROR_WRITE = 778,
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
mod errors;
|
||||
mod types;
|
||||
|
||||
use types::{MVCCDatabaseRef, DbContext};
|
||||
use errors::*;
|
||||
use errors::MVCCError;
|
||||
use mvcc_rs::*;
|
||||
use types::{DbContext, MVCCDatabaseRef};
|
||||
|
||||
/// cbindgen:ignore
|
||||
type Clock = clock::LocalClock;
|
||||
|
@ -63,7 +63,7 @@ pub unsafe extern "C" fn MVCCDatabaseInsert(
|
|||
id: u64,
|
||||
value_ptr: *const u8,
|
||||
value_len: usize,
|
||||
) -> i32 {
|
||||
) -> MVCCError {
|
||||
let db = db.get_ref();
|
||||
let value = std::slice::from_raw_parts(value_ptr, value_len);
|
||||
let data = match std::str::from_utf8(value) {
|
||||
|
@ -84,11 +84,11 @@ pub unsafe extern "C" fn MVCCDatabaseInsert(
|
|||
}) {
|
||||
Ok(_) => {
|
||||
tracing::debug!("MVCCDatabaseInsert: success");
|
||||
MVCC_OK
|
||||
MVCCError::MVCC_OK
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("MVCCDatabaseInsert: {e}");
|
||||
MVCC_IO_ERROR_WRITE
|
||||
MVCCError::MVCC_IO_ERROR_WRITE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,4 +35,4 @@ pub mod clock;
|
|||
pub mod database;
|
||||
pub mod errors;
|
||||
pub mod persistent_storage;
|
||||
pub mod sync;
|
||||
pub mod sync;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue