Skip to content

Commit

Permalink
Use master3 and imports everywhere needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Aug 20, 2024
1 parent 91b0c73 commit 92104a4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
24 changes: 24 additions & 0 deletions heed/src/mdb/lmdb_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use std::os::raw::c_char;
use std::{fmt, str};

use libc::c_int;
#[cfg(master3)]
use lmdb_master3_sys as ffi;
#[cfg(not(master3))]
use lmdb_master_sys as ffi;

/// An LMDB error kind.
Expand Down Expand Up @@ -66,6 +69,15 @@ pub enum Error {
BadDbi,
/// Unexpected problem - transaction should abort.
Problem,
/// Page checksum incorrect.
#[cfg(master3)]
BadChecksum,
/// Encryption/decryption failed.
#[cfg(master3)]
CryptoFail,
/// Environment encryption mismatch.
#[cfg(master3)]
EnvEncryption,
/// Other error.
Other(c_int),
}
Expand Down Expand Up @@ -100,6 +112,12 @@ impl Error {
ffi::MDB_BAD_VALSIZE => Error::BadValSize,
ffi::MDB_BAD_DBI => Error::BadDbi,
ffi::MDB_PROBLEM => Error::Problem,
#[cfg(master3)]
ffi::MDB_BAD_CHECKSUM => Error::BadChecksum,
#[cfg(master3)]
ffi::MDB_CRYPTO_FAIL => Error::CryptoFail,
#[cfg(master3)]
ffi::MDB_ENV_ENCRYPTION => Error::EnvEncryption,
other => Error::Other(other),
}
}
Expand Down Expand Up @@ -129,6 +147,12 @@ impl Error {
Error::BadValSize => ffi::MDB_BAD_VALSIZE,
Error::BadDbi => ffi::MDB_BAD_DBI,
Error::Problem => ffi::MDB_PROBLEM,
#[cfg(master3)]
Error::BadChecksum => ffi::MDB_BAD_CHECKSUM,
#[cfg(master3)]
Error::CryptoFail => ffi::MDB_CRYPTO_FAIL,
#[cfg(master3)]
Error::EnvEncryption => ffi::MDB_ENV_ENCRYPTION,
Error::Other(err_code) => err_code,
}
}
Expand Down
5 changes: 5 additions & 0 deletions heed/src/mdb/lmdb_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ pub use ffi::{
MDB_cursor, MDB_dbi, MDB_env, MDB_stat, MDB_txn, MDB_val, MDB_CP_COMPACT, MDB_CURRENT,
MDB_RDONLY, MDB_RESERVE,
};
#[cfg(master3)]
pub use ffi::{mdb_env_set_checksum, mdb_env_set_encrypt};
#[cfg(master3)]
use lmdb_master3_sys as ffi;
#[cfg(not(master3))]
use lmdb_master_sys as ffi;

pub mod cursor_op {
Expand Down
3 changes: 3 additions & 0 deletions heed/src/mdb/lmdb_flags.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use bitflags::bitflags;
#[cfg(master3)]
use lmdb_master3_sys as ffi;
#[cfg(not(master3))]
use lmdb_master_sys as ffi;

bitflags! {
Expand Down
15 changes: 9 additions & 6 deletions heed3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ readme = "../README.md"
edition = "2021"

[dependencies]
# TODO update dependencies
aead = { version = "0.5.1", default-features = false, optional = true }
bitflags = { version = "2.6.0", features = ["serde"] }
byteorder = { version = "1.5.0", default-features = false }
generic-array = { version = "0.14.6", features = ["serde"], optional = true }
heed-master3-proc-macro = { path = "../heed-master3-proc-macro", optional = true }
heed-traits = { version = "0.20.0", path = "../heed-traits" }
heed-types = { version = "0.20.1", default-features = false, path = "../heed-types" }
libc = "0.2.155"
Expand All @@ -21,13 +25,12 @@ once_cell = "1.19.0"
page_size = "0.6.0"
serde = { version = "1.0.203", features = ["derive"], optional = true }
synchronoise = "1.0.1"
# TODO find a better name, depend on that only with heed3
# move the proc macro directly in the heed3 crate (not possible?)
# Set a cfg to react on the crate name: https://github.com/bodil/im-rs/blob/master/build.rs
heed-master3-proc-macro = { path = "../heed-master3-proc-macro", optional = true }

[dev-dependencies]
# TODO update dependencies
argon2 = { version = "0.4.1", features = ["std"] }
serde = { version = "1.0.203", features = ["derive"] }
chacha20poly1305 = "0.10.1"
tempfile = "3.10.1"

[target.'cfg(windows)'.dependencies]
Expand All @@ -41,7 +44,7 @@ default = ["serde", "serde-bincode", "serde-json", "encryption"]

# Enable the LMDB encryption feature
# TODO add more information here
encryption = ["dep:heed-master3-proc-macro"]
encryption = ["dep:heed-master3-proc-macro", "dep:aead", "dep:generic-array"]

serde = ["bitflags/serde", "dep:serde"]

Expand Down Expand Up @@ -78,7 +81,7 @@ unbounded_depth = ["heed-types/unbounded_depth"]
# There are tradeoffs for both POSIX and SysV semaphores; which you
# should look into before enabling this feature. Also, see here:
# <https://github.com/LMDB/lmdb/blob/3947014aed7ffe39a79991fa7fb5b234da47ad1a/libraries/liblmdb/lmdb.h#L46-L69>
posix-sem = ["lmdb-master-sys/posix-sem"]
posix-sem = ["lmdb-master3-sys/posix-sem"]

# These features configure the MDB_IDL_LOGN macro, which determines
# the size of the free and dirty page lists (and thus the amount of memory
Expand Down

0 comments on commit 92104a4

Please sign in to comment.