core: Rename unsafe::leak to unsafe::forget. Closes #2031
This commit is contained in:
parent
56828d49fd
commit
b181ea415e
@ -119,7 +119,7 @@ fn send<T: send>(ch: chan<T>, -data: T) {
|
||||
let res = rustrt::rust_port_id_send(sys::get_type_desc::<T>(), p, data);
|
||||
if res != 0u unsafe {
|
||||
// Data sent successfully
|
||||
unsafe::leak(data);
|
||||
unsafe::forget(data);
|
||||
}
|
||||
task::yield();
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ fn unwrap<T>(-opt: option<T>) -> T unsafe {
|
||||
none { fail "option none" }
|
||||
};
|
||||
let liberated_value = unsafe::reinterpret_cast(*addr);
|
||||
unsafe::leak(opt);
|
||||
unsafe::forget(opt);
|
||||
ret liberated_value;
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ fn with_envp<T>(env: option<[(str,str)]>,
|
||||
let t = #fmt("%s=%s", k, v);
|
||||
let mut v : [u8] = ::unsafe::reinterpret_cast(t);
|
||||
blk += v;
|
||||
::unsafe::leak(v);
|
||||
::unsafe::forget(v);
|
||||
}
|
||||
blk += [0_u8];
|
||||
vec::as_buf(blk) {|p| cb(::unsafe::reinterpret_cast(p)) }
|
||||
|
@ -129,7 +129,7 @@ fn from_byte(b: u8) -> str unsafe {
|
||||
assert b < 128u8;
|
||||
let mut v = [b, 0u8];
|
||||
let s: str = ::unsafe::reinterpret_cast(v);
|
||||
::unsafe::leak(v);
|
||||
::unsafe::forget(v);
|
||||
s
|
||||
}
|
||||
|
||||
@ -273,7 +273,7 @@ The result vector is not null-terminated.
|
||||
fn bytes(s: str) -> [u8] unsafe {
|
||||
let mut s_copy = s;
|
||||
let mut v: [u8] = ::unsafe::reinterpret_cast(s_copy);
|
||||
::unsafe::leak(s_copy);
|
||||
::unsafe::forget(s_copy);
|
||||
vec::unsafe::set_len(v, len(s));
|
||||
ret v;
|
||||
}
|
||||
@ -1445,7 +1445,7 @@ let i = str::as_bytes(\"Hello World\") { |bytes| vec::len(bytes) };
|
||||
fn as_bytes<T>(s: str, f: fn([u8]) -> T) -> T unsafe {
|
||||
let mut v: [u8] = ::unsafe::reinterpret_cast(s);
|
||||
let r = f(v);
|
||||
::unsafe::leak(v);
|
||||
::unsafe::forget(v);
|
||||
r
|
||||
}
|
||||
|
||||
@ -1517,7 +1517,7 @@ mod unsafe {
|
||||
|
||||
assert is_utf8(v);
|
||||
let s: str = ::unsafe::reinterpret_cast(v);
|
||||
::unsafe::leak(v);
|
||||
::unsafe::forget(v);
|
||||
ret s;
|
||||
}
|
||||
|
||||
@ -1541,7 +1541,7 @@ mod unsafe {
|
||||
unsafe fn from_bytes(v: [const u8]) -> str unsafe {
|
||||
let mut vcopy: [u8] = v + [0u8];
|
||||
let scopy: str = ::unsafe::reinterpret_cast(vcopy);
|
||||
::unsafe::leak(vcopy);
|
||||
::unsafe::forget(vcopy);
|
||||
ret scopy;
|
||||
}
|
||||
|
||||
@ -1578,7 +1578,7 @@ mod unsafe {
|
||||
};
|
||||
v += [0u8];
|
||||
let s: str = ::unsafe::reinterpret_cast(v);
|
||||
::unsafe::leak(v);
|
||||
::unsafe::forget(v);
|
||||
ret s;
|
||||
}
|
||||
|
||||
|
@ -504,7 +504,7 @@ fn spawn_raw(opts: task_opts, +f: fn~()) unsafe {
|
||||
}
|
||||
|
||||
rustrt::start_task(new_task, closure);
|
||||
unsafe::leak(f);
|
||||
unsafe::forget(f);
|
||||
|
||||
fn new_task_in_new_sched(opts: sched_opts) -> *rust_task {
|
||||
if opts.native_stack_size != none {
|
||||
|
@ -1,6 +1,6 @@
|
||||
#[doc = "Unsafe operations"];
|
||||
|
||||
export reinterpret_cast, leak;
|
||||
export reinterpret_cast, forget;
|
||||
|
||||
#[abi = "rust-intrinsic"]
|
||||
native mod rusti {
|
||||
@ -24,13 +24,13 @@ unsafe fn reinterpret_cast<T, U>(src: T) -> U {
|
||||
#[doc ="
|
||||
Move a thing into the void
|
||||
|
||||
The leak function will take ownership of the provided value but neglect
|
||||
The forget function will take ownership of the provided value but neglect
|
||||
to run any required cleanup or memory-management operations on it. This
|
||||
can be used for various acts of magick, particularly when using
|
||||
reinterpret_cast on managed pointer types.
|
||||
"]
|
||||
#[inline(always)]
|
||||
unsafe fn leak<T>(-thing: T) { rusti::leak(thing); }
|
||||
unsafe fn forget<T>(-thing: T) { rusti::leak(thing); }
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
@ -155,14 +155,14 @@ fn from_elem<T: copy>(n_elts: uint, t: T) -> [T] {
|
||||
#[doc = "Produces a mutable vector from an immutable vector."]
|
||||
fn to_mut<T>(+v: [T]) -> [mutable T] unsafe {
|
||||
let r = ::unsafe::reinterpret_cast(v);
|
||||
::unsafe::leak(v);
|
||||
::unsafe::forget(v);
|
||||
r
|
||||
}
|
||||
|
||||
#[doc = "Produces an immutable vector from a mutable vector."]
|
||||
fn from_mut<T>(+v: [mutable T]) -> [T] unsafe {
|
||||
let r = ::unsafe::reinterpret_cast(v);
|
||||
::unsafe::leak(v);
|
||||
::unsafe::forget(v);
|
||||
r
|
||||
}
|
||||
|
||||
|
@ -813,12 +813,12 @@ mod node {
|
||||
offset += 1u;
|
||||
i += 1u;
|
||||
}
|
||||
unsafe::leak(local_buf);
|
||||
unsafe::forget(local_buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
let str : str = unsafe::reinterpret_cast(buf);
|
||||
unsafe::leak(buf);//TODO: Check if this is correct
|
||||
unsafe::forget(buf);//TODO: Check if this is correct
|
||||
ret str;
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ enum debug_metadata {
|
||||
fn cast_safely<T: copy, U>(val: T) -> U unsafe {
|
||||
let val2 = val;
|
||||
let val3 = unsafe::reinterpret_cast(val2);
|
||||
unsafe::leak(val2);
|
||||
unsafe::forget(val2);
|
||||
ret val3;
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ type t = *t_opaque;
|
||||
pure fn get(t: t) -> t_box unsafe {
|
||||
let t2 = unsafe::reinterpret_cast::<t, t_box>(t);
|
||||
let t3 = t2;
|
||||
unsafe::leak(t2);
|
||||
unsafe::forget(t2);
|
||||
t3
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,6 @@ fn main() unsafe {
|
||||
};
|
||||
let fptr = unsafe::reinterpret_cast(ptr::addr_of(f));
|
||||
rustrt::start_task(new_task_id, fptr);
|
||||
unsafe::leak(f);
|
||||
unsafe::forget(f);
|
||||
comm::recv(po);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user