You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the current design we have for accessing the game context stored in the Context object:
impl<G>Context<G>{/// Returns the game context.pubfngame<'a,'b>(&'a self) -> &'b G{// Extend the lifetime of the game context so that we can borrow it at// the same time as the rest of the context.//// This *should* be safe because:// (1) The game context is opaque within Peacock, so nothing in the// engine will be modifying it,// (2) the game context is not modifiable externally unless// (3) the caller obtains a mutable reference with `game_mut`, which// is then checked by the borrow checker.unsafe{ std::mem::transmute::<&'a G,&'b G>(&self.game)}}/// Returns a mutable reference to game context.pubfngame_mut(&mutself) -> &mutG{&mutself.game}}
I shared this on Twitter and a number of people have come out and said that this is unsound.
A lot of the examples shown aren't working within the full constraints that Peacock enforces, so each one will have to be assessed within Peacock's constraints to determine whether it is actually a problem that can arise.
The game_context example shows a very basic example of how this is used. This can serve as a baseline for building up examples that show how the current implementation is either okay or problematic.
This is the current design we have for accessing the game context stored in the
Context
object:I shared this on Twitter and a number of people have come out and said that this is unsound.
A lot of the examples shown aren't working within the full constraints that Peacock enforces, so each one will have to be assessed within Peacock's constraints to determine whether it is actually a problem that can arise.
The
game_context
example shows a very basic example of how this is used. This can serve as a baseline for building up examples that show how the current implementation is either okay or problematic.Problematic Examples
Use after free
A use after free error is possible if
game
is dropped before theContext
:Aliasing between mutable and immutable borrows
The text was updated successfully, but these errors were encountered: