Skip to content

Commit

Permalink
Merge pull request #92 from ZettaScaleLabs/v36.2.1
Browse files Browse the repository at this point in the history
Make Box::into_raw const
  • Loading branch information
p-avital committed Sep 16, 2024
2 parents 15fe769 + 0593c3b commit 20d9837
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 36.2.1 (api=2.1.0, abi=2.0.0)
- Make `Box::into_raw` a const fn.

# 36.1.1 (api=2.0.0, abi=2.0.0)
`36.1.1` is the sum of all the previous release candidates. Here's a recap!
- `#[stabby::stabby]` can now understand when a type refers to itself to avoid forming proof cycles.
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ license = " EPL-2.0 OR Apache-2.0"
categories = ["development-tools::ffi", "no-std::no-alloc"]
repository = "https://github.com/ZettaScaleLabs/stabby"
readme = "stabby/README.md"
version = "36.1.1" # Track
version = "36.2.1" # Track

[workspace.dependencies]
stabby-macros = { path = "./stabby-macros/", version = "36.1.1", default-features = false } # Track
stabby-abi = { path = "./stabby-abi/", version = "36.1.1", default-features = false } # Track
stabby = { path = "./stabby/", version = "36.1.1", default-features = false } # Track
stabby-macros = { path = "./stabby-macros/", version = "36.2.1", default-features = false } # Track
stabby-abi = { path = "./stabby-abi/", version = "36.2.1", default-features = false } # Track
stabby = { path = "./stabby/", version = "36.2.1", default-features = false } # Track

abi_stable = "0.11.0"
libc = "0.2"
Expand Down
12 changes: 6 additions & 6 deletions stabby-abi/src/alloc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,18 @@ impl<T, Alloc: IAlloc> Box<T, Alloc> {
unsafe { this.unwrap_unchecked() }
}
/// Extracts the value from the allocation, freeing said allocation.
pub fn into_inner(mut this: Self) -> T {
// SAFETY: `this` will be forgotten, preventing double-frees.
let ret = ManuallyDrop::new(unsafe { core::ptr::read(&*this) });
// SAFETY: `this` is immediately forgotten as required.
pub fn into_inner(this: Self) -> T {
let mut this = core::mem::ManuallyDrop::new(this);
// SAFETY: `this` will not be dropped, preventing double-frees.
let ret = ManuallyDrop::new(unsafe { core::ptr::read(&**this) });
// SAFETY: `Box::free` only frees the memory allocation, without calling the destructor for `ret`'s source.
unsafe { this.free() };
core::mem::forget(this);
ManuallyDrop::into_inner(ret)
}
/// Returns the pointer to the inner raw allocation, leaking `this`.
///
/// Note that the pointer may be dangling if `T` is zero-sized.
pub fn into_raw(this: Self) -> AllocPtr<T, Alloc> {
pub const fn into_raw(this: Self) -> AllocPtr<T, Alloc> {
let inner = this.ptr;
core::mem::forget(this);
inner
Expand Down

0 comments on commit 20d9837

Please sign in to comment.