Skip to content

Commit

Permalink
Fix static_mut_ref warning
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Jan 10, 2024
1 parent e9eefee commit 6720a34
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/unwinder/find_fde/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ unsafe fn lock_global_state() -> impl ops::DerefMut<Target = GlobalState> {
#[cfg(feature = "libc")]
{
static mut MUTEX: libc::pthread_mutex_t = libc::PTHREAD_MUTEX_INITIALIZER;
unsafe { libc::pthread_mutex_lock(&mut MUTEX) };
unsafe { libc::pthread_mutex_lock(core::ptr::addr_of_mut!(MUTEX)) };

static mut STATE: GlobalState = GlobalState {
object: ptr::null_mut(),
Expand All @@ -41,20 +41,22 @@ unsafe fn lock_global_state() -> impl ops::DerefMut<Target = GlobalState> {
struct LockGuard;
impl Drop for LockGuard {
fn drop(&mut self) {
unsafe { libc::pthread_mutex_unlock(&mut MUTEX) };
unsafe { libc::pthread_mutex_unlock(core::ptr::addr_of_mut!(MUTEX)) };
}
}

impl ops::Deref for LockGuard {
type Target = GlobalState;

#[allow(static_mut_ref)]
fn deref(&self) -> &GlobalState {
unsafe { &STATE }
unsafe { &*core::ptr::addr_of!(STATE) }
}
}

impl ops::DerefMut for LockGuard {
fn deref_mut(&mut self) -> &mut GlobalState {
unsafe { &mut STATE }
unsafe { &mut *core::ptr::addr_of_mut!(STATE) }
}
}

Expand Down

0 comments on commit 6720a34

Please sign in to comment.