From 59148e88c3151176e1e76daebdee92852a877f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Sat, 14 Dec 2024 12:27:47 +0100 Subject: [PATCH] Fix most of the issues --- heed/src/cookbook.rs | 2 +- heed/src/databases/database.rs | 4 ++-- heed/src/envs/env.rs | 6 +++++- heed/src/txn.rs | 18 +++++++++++------- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/heed/src/cookbook.rs b/heed/src/cookbook.rs index d0fd0be1..c47d5f9c 100644 --- a/heed/src/cookbook.rs +++ b/heed/src/cookbook.rs @@ -423,7 +423,7 @@ //! } //! //! impl<'t> ImmutableMap<'t> { -//! fn from_db(rtxn: &'t RoTxn, db: Database) -> heed::Result { +//! fn from_db(rtxn: &'t RoTxn, db: Database) -> heed::Result { //! let mut map = HashMap::new(); //! for result in db.iter(rtxn)? { //! let (k, v) = result?; diff --git a/heed/src/databases/database.rs b/heed/src/databases/database.rs index c5226634..de9b31df 100644 --- a/heed/src/databases/database.rs +++ b/heed/src/databases/database.rs @@ -1079,7 +1079,7 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn iter_mut<'txn, T>(&self, txn: &'txn mut RwTxn) -> Result> { + pub fn iter_mut<'txn>(&self, txn: &'txn mut RwTxn) -> Result> { assert_eq_env_db_txn!(self, txn); RwCursor::new(txn, self.dbi).map(|cursor| RwIter::new(cursor)) @@ -1182,7 +1182,7 @@ impl Database { /// wtxn.commit()?; /// # Ok(()) } /// ``` - pub fn rev_iter_mut<'txn, T>(&self, txn: &'txn mut RwTxn) -> Result> { + pub fn rev_iter_mut<'txn>(&self, txn: &'txn mut RwTxn) -> Result> { assert_eq_env_db_txn!(self, txn); RwCursor::new(txn, self.dbi).map(|cursor| RwRevIter::new(cursor)) diff --git a/heed/src/envs/env.rs b/heed/src/envs/env.rs index 52b86200..e1921388 100644 --- a/heed/src/envs/env.rs +++ b/heed/src/envs/env.rs @@ -22,7 +22,7 @@ use crate::mdb::lmdb_flags::AllDatabaseFlags; use crate::EnvOpenOptions; use crate::{ CompactionOption, Database, DatabaseOpenOptions, EnvFlags, Error, Result, RoTxn, RwTxn, - Unspecified, + Unspecified, WithoutTls, }; /// An environment handle constructed by using [`EnvOpenOptions::open`]. @@ -43,6 +43,10 @@ impl Env { self.inner.env_ptr } + pub(crate) unsafe fn as_without_tls(&self) -> &Env { + unsafe { std::mem::transmute::<&Env, &Env>(self) } + } + /// The size of the data file on disk. /// /// # Example diff --git a/heed/src/txn.rs b/heed/src/txn.rs index e7dfa010..18ecc4c7 100644 --- a/heed/src/txn.rs +++ b/heed/src/txn.rs @@ -33,15 +33,15 @@ use crate::Result; /// ```rust /// #[allow(dead_code)] /// trait CovariantMarker<'a>: 'static { -/// type T: 'a; +/// type R: 'a; /// -/// fn is_covariant(&'a self) -> &'a Self::T; +/// fn is_covariant(&'a self) -> &'a Self::R; /// } /// -/// impl<'a> CovariantMarker<'a> for heed::RoTxn<'static> { -/// type T = heed::RoTxn<'a>; +/// impl<'a, T> CovariantMarker<'a> for heed::RoTxn<'static, T> { +/// type R = heed::RoTxn<'a, T>; /// -/// fn is_covariant(&'a self) -> &'a heed::RoTxn<'a> { +/// fn is_covariant(&'a self) -> &'a heed::RoTxn<'a, T> { /// self /// } /// } @@ -193,10 +193,12 @@ impl<'p> RwTxn<'p> { ))? }; + let env_without_tls = unsafe { env.as_without_tls() }; + Ok(RwTxn { txn: RoTxn { txn: NonNull::new(txn), - env: Cow::Borrowed(env), + env: Cow::Borrowed(env_without_tls), _tls_marker: PhantomData, }, }) @@ -210,10 +212,12 @@ impl<'p> RwTxn<'p> { mdb_result(ffi::mdb_txn_begin(env.env_mut_ptr().as_mut(), parent_ptr, 0, &mut txn))? }; + let env_without_tls = unsafe { env.as_without_tls() }; + Ok(RwTxn { txn: RoTxn { txn: NonNull::new(txn), - env: Cow::Borrowed(env), + env: Cow::Borrowed(env_without_tls), _tls_marker: PhantomData, }, })