Skip to content

Fix 13933 #14487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ impl<T: Send + Share + Clone> Arc<T> {
// reference count is guaranteed to be 1 at this point, and we required
// the Arc itself to be `mut`, so we're returning the only possible
// reference to the inner data.
unsafe { mem::transmute::<&_, &mut _>(self.deref()) }
let inner = unsafe { &mut *self._ptr };
&mut inner.data
}
}

Expand Down
40 changes: 23 additions & 17 deletions src/libnative/io/file_win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ impl FileDesc {
pub fn handle(&self) -> libc::HANDLE {
unsafe { libc::get_osfhandle(self.fd()) as libc::HANDLE }
}

// A version of seek that takes &self so that tell can call it
// - the private seek should of course take &mut self.
fn seek_common(&self, pos: i64, style: io::SeekStyle) -> Result<u64, IoError> {
let whence = match style {
io::SeekSet => libc::FILE_BEGIN,
io::SeekEnd => libc::FILE_END,
io::SeekCur => libc::FILE_CURRENT,
};
unsafe {
let mut newpos = 0;
match libc::SetFilePointerEx(self.handle(), pos, &mut newpos,
whence) {
0 => Err(super::last_error()),
_ => Ok(newpos as u64),
}
}
}

}

impl io::Reader for FileDesc {
Expand Down Expand Up @@ -151,26 +170,13 @@ impl rtio::RtioFileStream for FileDesc {
}
Ok(())
}

fn seek(&mut self, pos: i64, style: io::SeekStyle) -> Result<u64, IoError> {
let whence = match style {
io::SeekSet => libc::FILE_BEGIN,
io::SeekEnd => libc::FILE_END,
io::SeekCur => libc::FILE_CURRENT,
};
unsafe {
let mut newpos = 0;
match libc::SetFilePointerEx(self.handle(), pos, &mut newpos,
whence) {
0 => Err(super::last_error()),
_ => Ok(newpos as u64),
}
}
self.seek_common(pos, style)
}

fn tell(&self) -> Result<u64, IoError> {
// This transmute is fine because our seek implementation doesn't
// actually use the mutable self at all.
// FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes
unsafe { mem::transmute::<&_, &mut FileDesc>(self).seek(0, io::SeekCur) }
self.seek_common(0, io::SeekCur)
}

fn fsync(&mut self) -> Result<(), IoError> {
Expand Down
8 changes: 3 additions & 5 deletions src/librustuv/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ impl FileWatcher {
let r = FsRequest::write(&self.loop_, self.fd, buf, offset);
r.map_err(uv_error_to_io_error)
}
fn seek_common(&mut self, pos: i64, whence: c_int) ->
fn seek_common(&self, pos: i64, whence: c_int) ->
Result<u64, IoError>{
unsafe {
match libc::lseek(self.fd, pos as libc::off_t, whence) {
Expand Down Expand Up @@ -446,10 +446,8 @@ impl rtio::RtioFileStream for FileWatcher {
}
fn tell(&self) -> Result<u64, IoError> {
use libc::SEEK_CUR;
// this is temporary
// FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes
let self_ = unsafe { mem::transmute::<&_, &mut FileWatcher>(self) };
self_.seek_common(0, SEEK_CUR)

self.seek_common(0, SEEK_CUR)
}
fn fsync(&mut self) -> Result<(), IoError> {
let _m = self.fire_homing_missile();
Expand Down