From 416c087e8063b763e7abc464a0b11216e8342187 Mon Sep 17 00:00:00 2001 From: Mykhailo Kremniov Date: Wed, 14 Jan 2026 20:15:35 +0200 Subject: [PATCH 1/2] Fix CI, fix warnings, appease clippy (cherry-picked from master with slight modifications) --- .github/workflows/code_checks.yml | 2 ++ benches/transaction.rs | 4 ++-- lmdb-sys/build.rs | 7 +++++++ lmdb-sys/tests/simple.rs | 17 ++++++++++++----- src/cursor.rs | 8 ++++---- src/environment.rs | 6 +++--- src/transaction.rs | 6 +++--- src/transaction_guard.rs | 2 +- 8 files changed, 34 insertions(+), 18 deletions(-) diff --git a/.github/workflows/code_checks.yml b/.github/workflows/code_checks.yml index 577b47f..6b93e37 100644 --- a/.github/workflows/code_checks.yml +++ b/.github/workflows/code_checks.yml @@ -8,6 +8,8 @@ jobs: clippy_check_ubuntu: name: Clippy runs-on: ubuntu-latest + permissions: + checks: write steps: - uses: actions/checkout@v1 - run: rustup component add clippy diff --git a/benches/transaction.rs b/benches/transaction.rs index ddc4b60..c95f9fd 100644 --- a/benches/transaction.rs +++ b/benches/transaction.rs @@ -74,7 +74,7 @@ fn bench_put_rand(b: &mut Bencher) { b.iter(|| { let mut txn = env.begin_rw_txn(None).unwrap(); - for &(ref key, ref data) in items.iter() { + for (key, data) in items.iter() { txn.put(db, key, data, WriteFlags::empty()).unwrap(); } txn.abort(); @@ -106,7 +106,7 @@ fn bench_put_rand_raw(b: &mut Bencher) { mdb_txn_begin(env, ptr::null_mut(), 0, &mut txn); let mut i: ::libc::c_int = 0; - for &(ref key, ref data) in items.iter() { + for (key, data) in items.iter() { key_val.mv_size = key.len() as size_t; key_val.mv_data = key.as_bytes().as_ptr() as *mut _; data_val.mv_size = data.len() as size_t; diff --git a/lmdb-sys/build.rs b/lmdb-sys/build.rs index eafaba3..9d3b693 100644 --- a/lmdb-sys/build.rs +++ b/lmdb-sys/build.rs @@ -84,4 +84,11 @@ fn main() { builder.compile("liblmdb.a") } + + // Fix linker errors: + // "unresolved external symbol __imp_InitializeSecurityDescriptor referenced in function mdb_env_setup_locks", + // "unresolved external symbol __imp_SetSecurityDescriptorDacl referenced in function mdb_env_setup_locks". + if cfg!(windows) { + println!("cargo:rustc-link-lib=advapi32"); + } } diff --git a/lmdb-sys/tests/simple.rs b/lmdb-sys/tests/simple.rs index 6682f29..ac555d5 100644 --- a/lmdb-sys/tests/simple.rs +++ b/lmdb-sys/tests/simple.rs @@ -17,7 +17,7 @@ macro_rules! E { macro_rules! str { ($expr:expr) => { - CString::new($expr).unwrap().as_ptr() + CString::new($expr).unwrap() }; } @@ -57,16 +57,23 @@ fn test_simple(env_path: &str) { mv_data: ptr::null_mut(), }; let mut txn: *mut MDB_txn = ptr::null_mut(); - let sval = str!("foo") as *mut c_void; - let dval = str!("bar") as *mut c_void; + let s = str!("foo"); + let sval = s.as_ptr() as *mut c_void; + let d = str!("bar"); + let dval = d.as_ptr() as *mut c_void; unsafe { E!(mdb_env_create(&mut env)); E!(mdb_env_set_maxdbs(env, 2)); - E!(mdb_env_open(env, str!(env_path), 0, 664)); + E!(mdb_env_open(env, str!(env_path).as_ptr(), 0, 664)); E!(mdb_txn_begin(env, ptr::null_mut(), 0, &mut txn)); - E!(mdb_dbi_open(txn, str!("subdb"), MDB_CREATE, &mut dbi)); + E!(mdb_dbi_open( + txn, + str!("subdb").as_ptr(), + MDB_CREATE, + &mut dbi + )); E!(mdb_txn_commit(txn)); key.mv_size = 3; diff --git a/src/cursor.rs b/src/cursor.rs index 5a3698f..90b644d 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -415,7 +415,7 @@ mod test { { let mut txn = env.begin_rw_txn(None).unwrap(); - for &(ref key, ref data) in &items { + for (key, data) in &items { txn.put(db, key, data, WriteFlags::empty()).unwrap(); } txn.commit().unwrap(); @@ -530,7 +530,7 @@ mod test { { let mut txn = env.begin_rw_txn(None).unwrap(); - for &(ref key, ref data) in &items { + for (key, data) in &items { txn.put(db, key, data, WriteFlags::empty()).unwrap(); } txn.commit().unwrap(); @@ -541,7 +541,7 @@ mod test { let cursor = txn.open_ro_cursor(db).unwrap(); assert_eq!( items.clone().into_iter().skip(3).take(3).collect::>(), - cursor.into_iter_dup_of(b"b").into_iter().collect::>>().unwrap() + cursor.into_iter_dup_of(b"b").collect::>>().unwrap() ); let cursor = txn.open_ro_cursor(db).unwrap(); @@ -564,7 +564,7 @@ mod test { { let mut txn = env.begin_rw_txn(None).unwrap(); - for &(ref key, ref data) in &items { + for (key, data) in &items { txn.put(db, key, data, WriteFlags::empty()).unwrap(); } txn.commit().unwrap(); diff --git a/src/environment.rs b/src/environment.rs index 589b5ca..0eee5c0 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -131,7 +131,7 @@ impl Environment { } /// Create a read-only transaction for use with the environment. - pub fn begin_ro_txn(&self) -> Result { + pub fn begin_ro_txn(&self) -> Result> { RoTransaction::new(self) } @@ -159,7 +159,7 @@ impl Environment { /// Create a read-write transaction for use with the environment. This method will block while /// there are any other read-write transactions open on the environment. - pub fn begin_rw_txn(&self, headroom: Option) -> Result { + pub fn begin_rw_txn(&self, headroom: Option) -> Result> { let _lock = self.db_resize_lock.lock().expect("Database resize mutex lock failed"); self.resize_db_if_necessary(headroom)?; RwTransaction::new(self) @@ -521,7 +521,7 @@ impl Drop for Environment { } /////////////////////////////////////////////////////////////////////////////////////////////////// -//// Environment Builder +////// Environment Builder /////////////////////////////////////////////////////////////////////////////////////////////////// /// Options for opening or creating an environment. diff --git a/src/transaction.rs b/src/transaction.rs index 8a94618..586e385 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -98,7 +98,7 @@ pub trait Transaction: Sized + private::TransactionSealedProps { } /// Open a new read-only cursor on the given database. - fn open_ro_cursor(&self, db: Database) -> Result { + fn open_ro_cursor(&self, db: Database) -> Result> { RoCursor::new(self, db) } @@ -305,7 +305,7 @@ impl<'env> RwTransaction<'env> { } /// Opens a new read-write cursor on the given database and transaction. - pub fn open_rw_cursor(&mut self, db: Database) -> Result { + pub fn open_rw_cursor(&mut self, db: Database) -> Result> { RwCursor::new(self, db) } @@ -414,7 +414,7 @@ impl<'env> RwTransaction<'env> { } /// Begins a new nested transaction inside of this transaction. - pub fn begin_nested_txn(&mut self) -> Result { + pub fn begin_nested_txn(&mut self) -> Result> { let mut nested: *mut ffi::MDB_txn = ptr::null_mut(); unsafe { let env: *mut ffi::MDB_env = ffi::mdb_txn_env(self.txn()); diff --git a/src/transaction_guard.rs b/src/transaction_guard.rs index 0a5e3dd..91fbd17 100644 --- a/src/transaction_guard.rs +++ b/src/transaction_guard.rs @@ -64,7 +64,7 @@ struct SpinLock<'a> { } impl<'a> SpinLock<'a> { - fn new(lock: &'a AtomicBool) -> SpinLock { + fn new(lock: &'a AtomicBool) -> SpinLock<'a> { while lock.compare_exchange_weak(false, true, Ordering::Acquire, Ordering::Relaxed).unwrap_or(true) { std::thread::yield_now(); } From 88d9f2bd49399f75ca1baa1537b2387252f9b5db Mon Sep 17 00:00:00 2001 From: Mykhailo Kremniov Date: Fri, 27 Feb 2026 18:40:34 +0200 Subject: [PATCH 2/2] Fix off_t overflow on Windows (from https://github.com/LMDB/lmdb/commit/b77c2ba72af8053e221b337995feb4e8f7fbb1e9) --- lmdb-sys/lmdb/libraries/liblmdb/mdb.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lmdb-sys/lmdb/libraries/liblmdb/mdb.c b/lmdb-sys/lmdb/libraries/liblmdb/mdb.c index a7a27f2..51b1484 100644 --- a/lmdb-sys/lmdb/libraries/liblmdb/mdb.c +++ b/lmdb-sys/lmdb/libraries/liblmdb/mdb.c @@ -96,6 +96,7 @@ static NtCloseFunc *NtClose; # define SSIZE_MAX INT_MAX # endif #endif +#define MDB_OFF_T int64_t #else #include #include @@ -108,6 +109,7 @@ static NtCloseFunc *NtClose; #include #endif #include +#define MDB_OFF_T off_t #endif #if defined(__mips) && defined(__linux) @@ -1507,7 +1509,7 @@ struct MDB_env { MDB_txn *me_txn; /**< current write transaction */ MDB_txn *me_txn0; /**< prealloc'd write transaction */ mdb_size_t me_mapsize; /**< size of the data memory map */ - off_t me_size; /**< current file size */ + MDB_OFF_T me_size; /**< current file size */ pgno_t me_maxpg; /**< me_mapsize / me_psize */ MDB_dbx *me_dbxs; /**< array of static DB info */ uint16_t *me_dbflags; /**< array of flags from MDB_db.md_flags */ @@ -3668,7 +3670,7 @@ mdb_page_flush(MDB_txn *txn, int keep) unsigned psize = env->me_psize, j; int i, pagecount = dl[0].mid, rc; size_t size = 0; - off_t pos = 0; + MDB_OFF_T pos = 0; pgno_t pgno = 0; MDB_page *dp = NULL; #ifdef _WIN32 @@ -3676,7 +3678,7 @@ mdb_page_flush(MDB_txn *txn, int keep) #else struct iovec iov[MDB_COMMIT_PAGES]; ssize_t wsize = 0, wres; - off_t wpos = 0, next_pos = 1; /* impossible pos, so pos != next_pos */ + MDB_OFF_T wpos = 0, next_pos = 1; /* impossible pos, so pos != next_pos */ int n = 0; #endif @@ -4240,7 +4242,7 @@ mdb_env_write_meta(MDB_txn *txn) MDB_meta meta, metab, *mp; unsigned flags; mdb_size_t mapsize; - off_t off; + MDB_OFF_T off; int rc, len, toggle; char *ptr; HANDLE mfd; @@ -5229,7 +5231,7 @@ mdb_env_setup_locks(MDB_env *env, MDB_name *fname, int mode, int *excl) union semun semu; #endif int rc; - off_t size, rsize; + MDB_OFF_T size, rsize; rc = mdb_fopen(env, fname, MDB_O_LOCKS, mode, &env->me_lfd); if (rc) { @@ -6097,7 +6099,7 @@ mdb_rpage_get(MDB_txn *txn, pgno_t pg0, MDB_page **ret) len, &off, &len, ViewUnmap, (env->me_flags & MDB_RDONLY) ? 0 : MEM_RESERVE, PAGE_READONLY); \ if (rc) rc = mdb_nt2win32(rc) #else - off_t off; + MDB_OFF_T off; size_t len; #define SET_OFF(off,val) off = val #define MAP(rc,env,addr,len,off) \