Skip to content

Commit

Permalink
fix(fdi): fix downgrade on release mode
Browse files Browse the repository at this point in the history
  • Loading branch information
qti3e committed May 16, 2024
1 parent 0a21358 commit 1a2d61c
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/fdi/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::any::Any;
use std::cell::UnsafeCell;
use std::collections::HashMap;
use std::marker::PhantomData;
use std::mem::MaybeUninit;
use std::ops::{Deref, DerefMut};
use std::sync::atomic::{AtomicBool, Ordering};

Expand Down Expand Up @@ -327,13 +326,10 @@ impl ProviderGuard {

impl<T: 'static> RefMut<T> {
#[inline]
pub fn downgrade(mut self) -> Ref<T> {
// SAFETY: Since we follow with mem::forget() it does not matter that we insert invalid
// (null) bytes in place. Since no destructor is going to be called.
#[allow(invalid_value)]
let entry = std::mem::replace(&mut self.entry, unsafe {
MaybeUninit::zeroed().assume_init()
});
pub fn downgrade(self) -> Ref<T> {
// SAFETY: Since we forget the value in the next line `drop` will not be called twice. So
// the internal state of the `Arc`s will stay valid.
let entry = unsafe { std::mem::transmute_copy::<MapEntry, MapEntry>(&self.entry) };
std::mem::forget(self);

// SAFETY: We own an exclusive lock right now. So it must be possible and safe to downgrade
Expand Down

0 comments on commit 1a2d61c

Please sign in to comment.