Fix generational box in release mode
This commit is contained in:
10 files changed
+182
-34
No files matched your search
@@ -244,6 +244,7 @@ impl<T: 'static, S: Storage<T>> GenerationalBox<T, S> {
|
||||
);
|
||||
|
||||
if result.is_ok() {
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
self.raw
|
||||
.0
|
||||
.borrow
|
||||
@@ -280,7 +281,10 @@ impl<T: 'static, S: Storage<T>> GenerationalBox<T, S> {
|
||||
);
|
||||
|
||||
if result.is_ok() {
|
||||
*self.raw.0.borrow.borrowed_mut_at.write() = Some(std::panic::Location::caller());
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
{
|
||||
*self.raw.0.borrow.borrowed_mut_at.write() = Some(std::panic::Location::caller());
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
@@ -419,6 +423,7 @@ struct MemoryLocationBorrowInfo {
|
||||
pub(crate) borrowed_mut_at: parking_lot::RwLock<Option<&'static std::panic::Location<'static>>>,
|
||||
}
|
||||
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
impl MemoryLocationBorrowInfo {
|
||||
fn borrow_mut_error(&self) -> BorrowMutError {
|
||||
if let Some(borrowed_mut_at) = self.borrowed_mut_at.read().as_ref() {
|
||||
|
||||
@@ -89,10 +89,15 @@ impl<T: Sync + Send + 'static> Storage<T> for SyncStorage {
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
at: crate::GenerationalRefBorrowInfo,
|
||||
) -> Result<Self::Ref, error::BorrowError> {
|
||||
let read = self
|
||||
.0
|
||||
.try_read()
|
||||
.ok_or_else(|| at.borrowed_from.borrow_error())?;
|
||||
let read = self.0.try_read();
|
||||
// .ok_or_else(|| at.borrowed_from.borrow_error())?;
|
||||
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
let read = read.ok_or_else(|| at.borrowed_from.borrow_error())?;
|
||||
|
||||
#[cfg(not(any(debug_assertions, feature = "debug_ownership")))]
|
||||
let read = read.unwrap();
|
||||
|
||||
RwLockReadGuard::try_map(read, |any| any.as_ref()?.downcast_ref())
|
||||
.map_err(|_| {
|
||||
error::BorrowError::Dropped(ValueDroppedError {
|
||||
@@ -116,10 +121,14 @@ impl<T: Sync + Send + 'static> Storage<T> for SyncStorage {
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
at: crate::GenerationalRefMutBorrowInfo,
|
||||
) -> Result<Self::Mut, error::BorrowMutError> {
|
||||
let write = self
|
||||
.0
|
||||
.try_write()
|
||||
.ok_or_else(|| at.borrowed_from.borrow_mut_error())?;
|
||||
let write = self.0.try_write();
|
||||
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
let write = write.ok_or_else(|| at.borrowed_from.borrow_mut_error())?;
|
||||
|
||||
#[cfg(not(any(debug_assertions, feature = "debug_ownership")))]
|
||||
let write = write.unwrap();
|
||||
|
||||
RwLockWriteGuard::try_map(write, |any| any.as_mut()?.downcast_mut())
|
||||
.map_err(|_| {
|
||||
error::BorrowMutError::Dropped(ValueDroppedError {
|
||||
|
||||
@@ -54,10 +54,14 @@ impl<T: 'static> Storage<T> for UnsyncStorage {
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
at: crate::GenerationalRefBorrowInfo,
|
||||
) -> Result<Self::Ref, crate::error::BorrowError> {
|
||||
let borrow = self
|
||||
.0
|
||||
.try_borrow()
|
||||
.map_err(|_| at.borrowed_from.borrow_error())?;
|
||||
let borrow = self.0.try_borrow();
|
||||
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
let borrow = borrow.map_err(|_| at.borrowed_from.borrow_error())?;
|
||||
|
||||
#[cfg(not(any(debug_assertions, feature = "debug_ownership")))]
|
||||
let borrow = borrow.unwrap();
|
||||
|
||||
Ref::filter_map(borrow, |any| any.as_ref()?.downcast_ref())
|
||||
.map_err(|_| {
|
||||
crate::error::BorrowError::Dropped(crate::error::ValueDroppedError {
|
||||
@@ -81,10 +85,14 @@ impl<T: 'static> Storage<T> for UnsyncStorage {
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
at: crate::GenerationalRefMutBorrowInfo,
|
||||
) -> Result<Self::Mut, crate::error::BorrowMutError> {
|
||||
let borrow = self
|
||||
.0
|
||||
.try_borrow_mut()
|
||||
.map_err(|_| at.borrowed_from.borrow_mut_error())?;
|
||||
let borrow = self.0.try_borrow_mut();
|
||||
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
let borrow = borrow.map_err(|_| at.borrowed_from.borrow_mut_error())?;
|
||||
|
||||
#[cfg(not(any(debug_assertions, feature = "debug_ownership")))]
|
||||
let borrow = borrow.unwrap();
|
||||
|
||||
RefMut::filter_map(borrow, |any| any.as_mut()?.downcast_mut())
|
||||
.map_err(|_| {
|
||||
crate::error::BorrowMutError::Dropped(crate::error::ValueDroppedError {
|
||||
|
||||
Reference in new issue
Block a user