-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a sound (but memory-leaky) abstraction around an unsafe dereference, which lets us access our movetable without reference counting or atomic operations or locks or anything! Yay!
- Loading branch information
1 parent
69e9176
commit 9dd6cb5
Showing
3 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use std::ops::Deref; | ||
|
||
#[derive(Clone)] | ||
pub struct NoArc<T> { | ||
ptr: *mut T, | ||
} | ||
|
||
impl<T> NoArc<T> { | ||
pub fn new(val: T) -> Self { | ||
Self { | ||
ptr: Box::leak(Box::new(val)), | ||
} | ||
} | ||
} | ||
|
||
unsafe impl<T> Sync for NoArc<T> {} | ||
unsafe impl<T> Send for NoArc<T> {} | ||
|
||
impl<T> Deref for NoArc<T> { | ||
type Target = T; | ||
fn deref(&self) -> &Self::Target { | ||
unsafe { self.ptr.as_ref().unwrap() } | ||
} | ||
} |