Commit graph

95 commits

Author SHA1 Message Date
bors
d1e81ef234 Auto merge of #69079 - CAD97:layout-of-ptr, r=RalfJung
Allow calculating the layout behind a pointer

There was some discussion around allowing this previously.

This does make the requirement for raw pointers to have valid metadata exposed as part of the std API (as a safety invariant, not validity invariant), though I think this is not strictly necessarily required as of current. cc @rust-lang/wg-unsafe-code-guidelines

Naming is hard; I picked the best "obvious" name I could come up with.

If it's agreed that this is actually a desired API surface, I'll file a tracking issue and update the attributes.
2020-03-22 18:37:19 +00:00
CAD97
dd973d1b12 Allow calculating the layout behind a pointer
Let align/size_of_of_val intrinsics work on ptrs
2020-03-21 19:45:45 -04:00
Tim Diekmann
f77afc8f9c Allow ZSTs in AllocRef 2020-03-08 11:01:12 +01:00
Tim Diekmann
09d3ba13af
Update alloc.rs 2020-03-07 02:45:55 +01:00
Tim Diekmann
545ef9d83a Add Layout::dangling() to return a well-aligned NonNull<u8> 2020-03-07 02:40:54 +01:00
Tim Diekmann
d8e3557dba Remove usable_size APIs 2020-03-03 00:08:24 +01:00
Yuki Okushi
a50ccd980a
Rollup merge of #69027 - TimDiekmann:zeroed-alloc, r=Amanieu
Add missing `_zeroed` varants to `AllocRef`

The majority of the allocator wg has decided to add the missing `_zeroed` variants to `AllocRef`:

> these should be added since they can be efficiently implemented with the `mremap` system call on Linux. `mremap` allows you to move/grow/shrink a memory mapping, and any new pages added for growth are guaranteed to be zeroed.
>
> If `AllocRef` does not have these methods then the user will have to manually write zeroes to the added memory since the API makes no guarantees on their contents.

For the full discussion please see https://github.com/rust-lang/wg-allocators/issues/14.

This PR provides default implementations for `realloc_zeroed`, `alloc_excess_zeroed`, `realloc_excess_zeroed`, and `grow_in_place_zeroed`.

r? @Amanieu
2020-02-12 18:55:46 +09:00
Tim Diekmann
97d1f8d9bb Add missing _zeroed varants to AllocRef 2020-02-10 19:44:29 +01:00
Tim Diekmann
25de80ad23 Remove common usage pattern from AllocRef 2020-02-10 18:38:09 +01:00
Tim Diekmann
8bbaeb7ff9
Remove Alloc in favor of AllocRef
`AllocRef` was reexported as `Alloc` in order to not break toolstate in the week before the next stable release.
2020-02-01 18:40:12 +01:00
Tim Diekmann
7ca25db816
Rename Alloc to AllocRef 2020-01-27 21:39:51 +01:00
Matthew Parkinson
6be3446f92 Added minor clarification to specification of realloc.
The `layout` for the returned allocation of a `realloc` is
only implicitly specified.  This change makes it explicit.
2020-01-20 10:09:51 +00:00
Lukas Lueg
c5a9a14c9f Constify alloc::Layout
Tracking issue #67521, Layout::new in #66254
2020-01-11 16:59:15 +01:00
CAD97
d860def8e2 Mark Layout::new as const stable 2020-01-09 13:41:43 -05:00
Christopher Durham
e47fec56dd Make Layout::new const 2020-01-09 13:41:40 -05:00
Mark Rousskov
a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Mark Rousskov
82184440ec Propagate cfg bootstrap 2019-12-18 12:16:19 -05:00
Oliver Scherer
5e17e39881 Require stable/unstable annotations for the constness of all stable functions with a const modifier 2019-12-13 11:27:02 +01:00
Mazdak Farrokhzad
b768328242
Rollup merge of #67174 - kraai:remove-checked_add, r=rkruppe
Remove `checked_add` in `Layout::repeat`
2019-12-11 10:10:47 +01:00
Yuki Okushi
9af3eec9a6
Rollup merge of #67154 - kraai:alloc-typos, r=Dylan-DPC
Fix typos in src/libcore/alloc.rs docs
2019-12-11 04:33:00 +09:00
Tyler Mandry
196ca9dc94
Rollup merge of #67155 - kraai:move-instead-of-binding-to-reference, r=cramertj
Move `Layout`s instead of binding by reference
2019-12-09 14:33:13 -08:00
Matthew Kraai
a983e0590a Remove checked_add in Layout::repeat 2019-12-09 06:49:37 -08:00
Matthew Kraai
4ea7bb8f12 Move Layouts instead of binding by reference 2019-12-08 08:36:22 -05:00
Matthew Kraai
9e8505d79e Change "attributes" to "attribute" in Alloc's docs 2019-12-08 08:21:27 -05:00
Matthew Kraai
cca954eb22 Change "alloc/realloc" to "realloc/dealloc" 2019-12-08 08:21:27 -05:00
Matthew Kraai
b2392fddab Add "this" to GlobalAlloc::alloc's docs 2019-12-08 08:21:27 -05:00
Matthew Kraai
852be72c43 Change "though" to "through" in Alloc's docs 2019-12-08 08:21:27 -05:00
Matthew Kraai
76d3003d4c Change "result" to "resulting" in Layout::extend's docs 2019-12-08 08:21:27 -05:00
Matthew Kraai
2b2b16c2a4 Simplify Layout::extend_packed 2019-12-07 21:23:21 -05:00
Mazdak Farrokhzad
fd78173484
Rollup merge of #67092 - kraai:us-to-is, r=jonas-schievink
Fix comment typos in src/libcore/alloc.rs
2019-12-06 23:27:05 +01:00
Matthew Kraai
292b998c64 Change "wth" to "with" in Layout::padding_needed_for comment 2019-12-06 07:59:13 -08:00
Matthew Kraai
a3c85770fb Change "us" to "is" in Layout::for_value comment 2019-12-06 07:35:30 -08:00
Matthew Kraai
0c4bc58cee Change "either" to "any" in Layout::from_size_align's docs 2019-12-06 07:06:03 -08:00
Christopher Durham
d1e53da809
Clarify Layout::pad_to_align safety comment 2019-11-25 16:39:24 -05:00
Christopher Durham
6773064b05
Remove unsafe in Layout::pad_to_align 2019-11-25 16:05:33 -05:00
Christopher Durham
b9da350b09
Fix typo
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-11-09 18:28:41 -05:00
Christopher Durham
183e61b661
Fix Layout::pad_to_align type mismatch 2019-11-09 15:28:32 -05:00
Christopher Durham
fd3594b9ee
Layout::pad_to_align is infallible 2019-11-09 15:19:09 -05:00
Oliver Scherer
02f9167f94 Have tidy ensure that we document all unsafe blocks in libcore 2019-11-06 11:04:42 +01:00
Mateusz Mikuła
f93032c818 Fix clippy::clone_on_copy warnings 2019-07-18 15:14:56 +02:00
Guillaume Gomez
4c1332afd9 Add missing links for CannotReallocInPlace type 2019-07-09 16:21:59 +02:00
Mazdak Farrokhzad
9389c69415
Rollup merge of #60947 - blkerby:global_alloc_typo, r=jonas-schievink
Fix typos in docs of GlobalAlloc
2019-05-19 02:31:46 +02:00
Brent Kerby
86cda2d48e Fix typos in docs of GlobalAlloc 2019-05-18 16:22:59 -06:00
Richard Wiedenhöft
a7a05203f1 Mark core::alloc::Layout::from_size_align_unchecked const 2019-05-14 09:40:10 +02:00
Mazdak Farrokhzad
dbfbadeac4 libcore: deny more... 2019-04-19 01:37:12 +02:00
Taiki Endo
360432f1e8 libcore => 2018 2019-04-18 14:47:35 +09:00
Mazdak Farrokhzad
4ca865e929 heading # Unsafety => # Safety in stdlib docs. 2019-02-25 08:01:35 +01:00
Alexander Regueiro
b87363e763 tests: doc comments 2019-02-10 23:42:32 +00:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Alexander Regueiro
ee89c088b0 Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00