diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2015-02-10 10:04:39 +0100 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2015-03-26 14:08:54 +0100 |
| commit | 3902190ac4d64962b2c1ac9a6ae88777b7112f82 (patch) | |
| tree | 61759f62fbca6a1e9c25e3e95dd1d957340510df /src/libcore/ptr.rs | |
| parent | 1501f33e76f6f9621aa08fb0cbbc5f85a5ac7f0f (diff) | |
| download | rust-3902190ac4d64962b2c1ac9a6ae88777b7112f82.tar.gz rust-3902190ac4d64962b2c1ac9a6ae88777b7112f82.zip | |
Switch drop-flag to `u8` to allow special tags to instrument state.
Refactored code so that the drop-flag values for initialized (`DTOR_NEEDED`) versus dropped (`DTOR_DONE`) are given explicit names. Add `mem::dropped()` (which with `DTOR_DONE == 0` is semantically the same as `mem::zeroed`, but the point is that it abstracts away from the particular choice of value for `DTOR_DONE`). Filling-drop needs to use something other than `ptr::read_and_zero`, so I added such a function: `ptr::read_and_drop`. But, libraries should not use it if they can otherwise avoid it. Fixes to tests to accommodate filling-drop.
Diffstat (limited to 'src/libcore/ptr.rs')
| -rw-r--r-- | src/libcore/ptr.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 9b3ee3ef5e0..7a9c9274f3b 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -230,6 +230,21 @@ pub unsafe fn read_and_zero<T>(dest: *mut T) -> T { tmp } +/// Variant of read_and_zero that writes the specific drop-flag byte +/// (which may be more apropriate than zero). +#[inline(always)] +#[unstable(feature = "core", + reason = "may play a larger role in std::ptr future extensions")] +pub unsafe fn read_and_drop<T>(dest: *mut T) -> T { + // Copy the data out from `dest`: + let tmp = read(&*dest); + + // Now mark `dest` as dropped: + write_bytes(dest, mem::POST_DROP_U8, 1); + + tmp +} + /// Overwrites a memory location with the given value without reading or /// dropping the old value. /// |
