Skip to content

Commit

Permalink
auto merge of #7047 : bblum/rust/bug_triage, r=graydon
Browse files Browse the repository at this point in the history
r? anybody
  • Loading branch information
bors committed Jun 11, 2013
2 parents bf41586 + 8081aea commit d1d8559
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/libextra/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ pub fn recv_timeout<T:Copy + Owned>(iotask: &IoTask,
unsafe {
let wait_po = cast::transmute_mut(wait_po);

// FIXME: This could be written clearer (#2618)
either::either(
|_| {
None
Expand Down
1 change: 1 addition & 0 deletions src/libstd/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ struct BufferResource<T> {
impl<T> Drop for BufferResource<T> {
fn finalize(&self) {
unsafe {
// FIXME(#4330) Need self by value to get mutability.
let this: &mut BufferResource<T> = transmute(self);

let mut b = move_it!(this.buffer);
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/rt/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<T> Drop for RC<T> {
assert!(self.refcount() > 0);

unsafe {
// XXX: Mutable finalizer
// FIXME(#4330) Need self by value to get mutability.
let this: &mut RC<T> = cast::transmute_mut(self);

match *this.get_mut_state() {
Expand Down
16 changes: 1 addition & 15 deletions src/libstd/rt/uv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,28 +238,14 @@ pub fn last_uv_error<H, W: Watcher + NativeHandle<*H>>(watcher: &W) -> UvError {
}

pub fn uv_error_to_io_error(uverr: UvError) -> IoError {

// XXX: Could go in str::raw
unsafe fn c_str_to_static_slice(s: *libc::c_char) -> &'static str {
let s = s as *u8;
let mut (curr, len) = (s, 0u);
while *curr != 0u8 {
len += 1u;
curr = ptr::offset(s, len);
}

str::raw::buf_as_slice(s, len, |d| cast::transmute(d))
}


unsafe {
// Importing error constants
use rt::uv::uvll::*;
use rt::io::*;

// uv error descriptions are static
let c_desc = uvll::strerror(&*uverr);
let desc = c_str_to_static_slice(c_desc);
let desc = str::raw::c_str_to_static_slice(c_desc);

let kind = match uverr.code {
UNKNOWN => OtherIoError,
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ impl Process {

impl Drop for Process {
fn finalize(&self) {
// FIXME #4943: transmute is bad.
// FIXME(#4330) Need self by value to get mutability.
let mut_self: &mut Process = unsafe { cast::transmute(self) };

mut_self.finish();
Expand Down
17 changes: 12 additions & 5 deletions src/libstd/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1396,12 +1396,19 @@ pub mod raw {
/// Converts a byte to a string.
pub unsafe fn from_byte(u: u8) -> ~str { raw::from_bytes([u]) }

/// Form a slice from a *u8 buffer of the given length without copying.
pub unsafe fn buf_as_slice<T>(buf: *u8, len: uint,
f: &fn(v: &str) -> T) -> T {
let v = (buf, len + 1);
/// Form a slice from a C string. Unsafe because the caller must ensure the
/// C string has the static lifetime, or else the return value may be
/// invalidated later.
pub unsafe fn c_str_to_static_slice(s: *libc::c_char) -> &'static str {
let s = s as *u8;
let mut (curr, len) = (s, 0u);
while *curr != 0u8 {
len += 1u;
curr = ptr::offset(s, len);
}
let v = (s, len + 1);
assert!(is_utf8(::cast::transmute(v)));
f(::cast::transmute(v))
::cast::transmute(v)
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/libstd/task/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ impl Drop for TCB {
// Runs on task exit.
fn finalize(&self) {
unsafe {
// FIXME(#4330) Need self by value to get mutability.
let this: &mut TCB = transmute(self);

// If we are failing, the whole taskgroup needs to die.
Expand Down
1 change: 1 addition & 0 deletions src/libstd/unstable/atomics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ impl<T> Drop for AtomicOption<T> {
// This will ensure that the contained data is
// destroyed, unless it's null.
unsafe {
// FIXME(#4330) Need self by value to get mutability.
let this : &mut AtomicOption<T> = cast::transmute(self);
let _ = this.take(SeqCst);
}
Expand Down

0 comments on commit d1d8559

Please sign in to comment.