Skip to content

Commit

Permalink
native: be more const correct with the FFI calls.
Browse files Browse the repository at this point in the history
These calls are mutating their argument and so it's bad behaviour to be
pretending that the values are immutable to rustc.
  • Loading branch information
huonw committed Feb 23, 2014
1 parent 8b246fd commit 4cc723d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/libnative/io/addrinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::cast;
use std::io::IoError;
use std::libc;
use std::libc::{c_char, c_int};
use std::ptr::null;
use std::ptr::{null, mut_null};

use super::net::sockaddr_to_addr;

Expand Down Expand Up @@ -42,13 +42,13 @@ impl GetAddrInfoRequest {
});

let hint_ptr = hint.as_ref().map_or(null(), |x| x as *libc::addrinfo);
let res = null();
let mut res = mut_null();

// Make the call
let s = unsafe {
let ch = if c_host.is_null() { null() } else { c_host.with_ref(|x| x) };
let cs = if c_serv.is_null() { null() } else { c_serv.with_ref(|x| x) };
getaddrinfo(ch, cs, hint_ptr, &res)
getaddrinfo(ch, cs, hint_ptr, &mut res)
};

// Error?
Expand All @@ -74,7 +74,7 @@ impl GetAddrInfoRequest {
flags: (*rp).ai_flags as uint
});

rp = (*rp).ai_next;
rp = (*rp).ai_next as *mut libc::addrinfo;
}
}

Expand All @@ -86,8 +86,8 @@ impl GetAddrInfoRequest {

extern "system" {
fn getaddrinfo(node: *c_char, service: *c_char,
hints: *libc::addrinfo, res: **libc::addrinfo) -> c_int;
fn freeaddrinfo(res: *libc::addrinfo);
hints: *libc::addrinfo, res: *mut *mut libc::addrinfo) -> c_int;
fn freeaddrinfo(res: *mut libc::addrinfo);
#[cfg(not(windows))]
fn gai_strerror(errcode: c_int) -> *c_char;
#[cfg(windows)]
Expand Down
2 changes: 1 addition & 1 deletion src/libnative/io/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl FileDesc {
#[cfg(not(windows))] type rlen = libc::size_t;
let ret = retry(|| unsafe {
libc::read(self.fd(),
buf.as_ptr() as *mut libc::c_void,
buf.as_mut_ptr() as *mut libc::c_void,
buf.len() as rlen) as libc::c_int
});
if ret == 0 {
Expand Down
2 changes: 1 addition & 1 deletion src/libnative/io/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl rtio::RtioTcpStream for TcpStream {
let ret = retry(|| {
unsafe {
libc::recv(self.fd(),
buf.as_ptr() as *mut libc::c_void,
buf.as_mut_ptr() as *mut libc::c_void,
buf.len() as wrlen,
0) as libc::c_int
}
Expand Down

0 comments on commit 4cc723d

Please sign in to comment.