about summary refs log tree commit diff
path: root/src/liballoc/allocator.rs
AgeCommit message (Collapse)AuthorLines
2017-07-05rustc: Implement the #[global_allocator] attributeAlex Crichton-2/+21
This PR is an implementation of [RFC 1974] which specifies a new method of defining a global allocator for a program. This obsoletes the old `#![allocator]` attribute and also removes support for it. [RFC 1974]: https://github.com/rust-lang/rfcs/pull/197 The new `#[global_allocator]` attribute solves many issues encountered with the `#![allocator]` attribute such as composition and restrictions on the crate graph itself. The compiler now has much more control over the ABI of the allocator and how it's implemented, allowing much more freedom in terms of how this feature is implemented. cc #27389
2017-06-25std: Fix implementation of `Alloc::alloc_one`Alex Crichton-1/+1
This had an accidental `u8 as *mut T` where it was intended to have just a normal pointer-to-pointer cast. Closes #42827
2017-06-19Minor Allocator doc fixAlex Crichton-1/+0
2017-06-15implement Error trait for error structs added in allocator API.Felix S. Klock II-0/+28
2017-06-15Changed `Layout::from_size_align` to return `Option`.Felix S. Klock II-19/+43
Added `unwrap` calls in all the places where I can infer that the conditions are met to avoid panic (or when the calling method itself says it will panic in such a case).
2017-06-15Add API for `Alloc` trait.Felix S. Klock II-0/+986
Includes `alloc_zeroed` method that `RawVec` has come to depend on. Exposed private `Layout::from_size_align` ctor to be `pub`, and added explicit conditions for when it will panic (namely, when `align` is not power-of-two, or if rounding up `size` to a multiple of `align` overflows). Normalized all `Layout` construction to go through `Layout::from_size_align`. Addressed review feedback regarding `struct Layout` and zero-sized layouts. Restrict specification for `dealloc`, adding additional constraint that the given alignment has to match that used to allocate the block. (This is a maximally conservative constraint on the alignment. An open question to resolve (before stabilization) is whether we can return to a looser constraint such as the one previously specified.) Split `fn realloc_in_place` into separate `fn grow_in_place` and `fn shrink_in_place` methods, which have default impls that check against usable_size for reuse. Make `realloc` default impl try `grow_in_place` or `shrink_in_place` as appropriate before fallback on alloc+copy+dealloc. Drive-by: When reviewing calls to `padding_needed_for`, discovered what I think was an over-conservative choice for its argument alignment. Namely, in `fn extend`, we automatically realign the whole resulting layout to satisfy both old (self) and new alignments. When the old alignment exceeds the new, this means we would insert unnecessary padding. So I changed the code to pass in `next.align` instead of `new_align` to `padding_needed_for`. Replaced ref to `realloc_in_place` with `grow_in_place`/`shrink_in_place`. Revised docs replacing my idiosyncratic style of `fn foo` with just `foo` when referring to the function or method `foo`. (Alpha-renamed `Allocator` to `Alloc`.) Post-rebased, added `Debug` derive for `allocator::Excess` to satisfy `missing_debug_implementations`.