mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-04 18:40:57 +03:00
native: be more const correct with the FFI calls.
These calls are mutating their argument and so it's bad behaviour to be pretending that the values are immutable to rustc.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
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;
|
||||
|
||||
@@ -42,13 +42,13 @@ pub fn run(host: Option<&str>, servname: Option<&str>,
|
||||
});
|
||||
|
||||
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?
|
||||
@@ -74,7 +74,7 @@ pub fn run(host: Option<&str>, servname: Option<&str>,
|
||||
flags: (*rp).ai_flags as uint
|
||||
});
|
||||
|
||||
rp = (*rp).ai_next;
|
||||
rp = (*rp).ai_next as *mut libc::addrinfo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,8 +86,8 @@ pub fn run(host: Option<&str>, servname: Option<&str>,
|
||||
|
||||
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)]
|
||||
|
||||
@@ -91,7 +91,7 @@ pub fn inner_read(&mut self, buf: &mut [u8]) -> Result<uint, IoError> {
|
||||
#[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 {
|
||||
|
||||
@@ -309,7 +309,7 @@ fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user