Skip to content

Commit 4cc723d

Browse files
committed
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.
1 parent 8b246fd commit 4cc723d

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/libnative/io/addrinfo.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::cast;
1414
use std::io::IoError;
1515
use std::libc;
1616
use std::libc::{c_char, c_int};
17-
use std::ptr::null;
17+
use std::ptr::{null, mut_null};
1818

1919
use super::net::sockaddr_to_addr;
2020

@@ -42,13 +42,13 @@ impl GetAddrInfoRequest {
4242
});
4343

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

4747
// Make the call
4848
let s = unsafe {
4949
let ch = if c_host.is_null() { null() } else { c_host.with_ref(|x| x) };
5050
let cs = if c_serv.is_null() { null() } else { c_serv.with_ref(|x| x) };
51-
getaddrinfo(ch, cs, hint_ptr, &res)
51+
getaddrinfo(ch, cs, hint_ptr, &mut res)
5252
};
5353

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

77-
rp = (*rp).ai_next;
77+
rp = (*rp).ai_next as *mut libc::addrinfo;
7878
}
7979
}
8080

@@ -86,8 +86,8 @@ impl GetAddrInfoRequest {
8686

8787
extern "system" {
8888
fn getaddrinfo(node: *c_char, service: *c_char,
89-
hints: *libc::addrinfo, res: **libc::addrinfo) -> c_int;
90-
fn freeaddrinfo(res: *libc::addrinfo);
89+
hints: *libc::addrinfo, res: *mut *mut libc::addrinfo) -> c_int;
90+
fn freeaddrinfo(res: *mut libc::addrinfo);
9191
#[cfg(not(windows))]
9292
fn gai_strerror(errcode: c_int) -> *c_char;
9393
#[cfg(windows)]

src/libnative/io/file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl FileDesc {
9191
#[cfg(not(windows))] type rlen = libc::size_t;
9292
let ret = retry(|| unsafe {
9393
libc::read(self.fd(),
94-
buf.as_ptr() as *mut libc::c_void,
94+
buf.as_mut_ptr() as *mut libc::c_void,
9595
buf.len() as rlen) as libc::c_int
9696
});
9797
if ret == 0 {

src/libnative/io/net.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl rtio::RtioTcpStream for TcpStream {
309309
let ret = retry(|| {
310310
unsafe {
311311
libc::recv(self.fd(),
312-
buf.as_ptr() as *mut libc::c_void,
312+
buf.as_mut_ptr() as *mut libc::c_void,
313313
buf.len() as wrlen,
314314
0) as libc::c_int
315315
}

0 commit comments

Comments
 (0)