diff --git a/core/mvcc/bindings/c/include/mvcc.h b/core/mvcc/bindings/c/include/mvcc.h index 92595e41b..808c4047e 100644 --- a/core/mvcc/bindings/c/include/mvcc.h +++ b/core/mvcc/bindings/c/include/mvcc.h @@ -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" diff --git a/core/mvcc/bindings/c/src/errors.rs b/core/mvcc/bindings/c/src/errors.rs index e260394f6..8b40ad2ba 100644 --- a/core/mvcc/bindings/c/src/errors.rs +++ b/core/mvcc/bindings/c/src/errors.rs @@ -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, +} diff --git a/core/mvcc/bindings/c/src/lib.rs b/core/mvcc/bindings/c/src/lib.rs index 6efecf8d5..2a429cbdb 100644 --- a/core/mvcc/bindings/c/src/lib.rs +++ b/core/mvcc/bindings/c/src/lib.rs @@ -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 } } } diff --git a/core/mvcc/database/src/lib.rs b/core/mvcc/database/src/lib.rs index b14e27be3..d88011290 100644 --- a/core/mvcc/database/src/lib.rs +++ b/core/mvcc/database/src/lib.rs @@ -35,4 +35,4 @@ pub mod clock; pub mod database; pub mod errors; pub mod persistent_storage; -pub mod sync; \ No newline at end of file +pub mod sync;