Skip to content

Commit 4e3b196

Browse files
AatchJames Miller
authored and
James Miller
committed
libextra: cleanup warnings
1 parent b6ecf60 commit 4e3b196

File tree

3 files changed

+134
-147
lines changed

3 files changed

+134
-147
lines changed

src/libextra/arc.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,13 @@ impl<T:Owned> MutexARC<T> {
200200
*/
201201
#[inline]
202202
pub unsafe fn access<U>(&self, blk: &fn(x: &mut T) -> U) -> U {
203-
unsafe {
204-
let state = self.x.get();
205-
// Borrowck would complain about this if the function were
206-
// not already unsafe. See borrow_rwlock, far below.
207-
do (&(*state).lock).lock {
208-
check_poison(true, (*state).failed);
209-
let _z = PoisonOnFail(&mut (*state).failed);
210-
blk(&mut (*state).data)
211-
}
203+
let state = self.x.get();
204+
// Borrowck would complain about this if the function were
205+
// not already unsafe. See borrow_rwlock, far below.
206+
do (&(*state).lock).lock {
207+
check_poison(true, (*state).failed);
208+
let _z = PoisonOnFail(&mut (*state).failed);
209+
blk(&mut (*state).data)
212210
}
213211
}
214212

src/libextra/flatpipes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@ pub mod bytepipes {
516516
use core::comm::{Port, Chan};
517517
use core::comm;
518518
use core::io::{Writer, Reader, ReaderUtil};
519-
use core::vec;
520519

521520
pub struct ReaderBytePort<R> {
522521
reader: R

src/libextra/net_tcp.rs

Lines changed: 127 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -181,90 +181,88 @@ pub fn connect(input_ip: ip::IpAddr, port: uint,
181181
debug!("stream_handle_ptr outside interact %?",
182182
stream_handle_ptr);
183183
do iotask::interact(iotask) |loop_ptr| {
184-
unsafe {
185-
debug!("in interact cb for tcp client connect..");
186-
debug!("stream_handle_ptr in interact %?",
187-
stream_handle_ptr);
188-
match uv::ll::tcp_init( loop_ptr, stream_handle_ptr) {
189-
0i32 => {
190-
debug!("tcp_init successful");
191-
debug!("dealing w/ ipv4 connection..");
192-
let connect_req_ptr: *uv::ll::uv_connect_t =
193-
&(*socket_data_ptr).connect_req;
194-
let addr_str = ip::format_addr(&input_ip);
195-
let connect_result = match input_ip {
196-
ip::Ipv4(ref addr) => {
197-
// have to "recreate" the
198-
// sockaddr_in/6 since the ip_addr
199-
// discards the port info.. should
200-
// probably add an additional rust
201-
// type that actually is closer to
202-
// what the libuv API expects (ip str
203-
// + port num)
204-
debug!("addr: %?", addr);
205-
let in_addr = uv::ll::ip4_addr(addr_str,
206-
port as int);
207-
uv::ll::tcp_connect(
208-
connect_req_ptr,
209-
stream_handle_ptr,
210-
&in_addr,
211-
tcp_connect_on_connect_cb)
212-
}
213-
ip::Ipv6(ref addr) => {
214-
debug!("addr: %?", addr);
215-
let in_addr = uv::ll::ip6_addr(addr_str,
216-
port as int);
217-
uv::ll::tcp_connect6(
218-
connect_req_ptr,
219-
stream_handle_ptr,
220-
&in_addr,
221-
tcp_connect_on_connect_cb)
222-
}
223-
};
224-
match connect_result {
225-
0i32 => {
226-
debug!("tcp_connect successful: \
227-
stream %x,
228-
socket data %x",
229-
stream_handle_ptr as uint,
230-
socket_data_ptr as uint);
231-
// reusable data that we'll have for the
232-
// duration..
233-
uv::ll::set_data_for_uv_handle(
234-
stream_handle_ptr,
235-
socket_data_ptr as
236-
*libc::c_void);
237-
// just so the connect_cb can send the
238-
// outcome..
239-
uv::ll::set_data_for_req(connect_req_ptr,
240-
conn_data_ptr);
241-
debug!("leaving tcp_connect interact cb...");
242-
// let tcp_connect_on_connect_cb send on
243-
// the result_ch, now..
244-
}
245-
_ => {
246-
// immediate connect
247-
// failure.. probably a garbage ip or
248-
// somesuch
249-
let err_data =
250-
uv::ll::get_last_err_data(loop_ptr);
251-
let result_ch = (*conn_data_ptr)
252-
.result_ch.clone();
253-
result_ch.send(ConnFailure(err_data));
254-
uv::ll::set_data_for_uv_handle(
255-
stream_handle_ptr,
256-
conn_data_ptr);
257-
uv::ll::close(stream_handle_ptr,
258-
stream_error_close_cb);
259-
}
184+
debug!("in interact cb for tcp client connect..");
185+
debug!("stream_handle_ptr in interact %?",
186+
stream_handle_ptr);
187+
match uv::ll::tcp_init( loop_ptr, stream_handle_ptr) {
188+
0i32 => {
189+
debug!("tcp_init successful");
190+
debug!("dealing w/ ipv4 connection..");
191+
let connect_req_ptr: *uv::ll::uv_connect_t =
192+
&(*socket_data_ptr).connect_req;
193+
let addr_str = ip::format_addr(&input_ip);
194+
let connect_result = match input_ip {
195+
ip::Ipv4(ref addr) => {
196+
// have to "recreate" the
197+
// sockaddr_in/6 since the ip_addr
198+
// discards the port info.. should
199+
// probably add an additional rust
200+
// type that actually is closer to
201+
// what the libuv API expects (ip str
202+
// + port num)
203+
debug!("addr: %?", addr);
204+
let in_addr = uv::ll::ip4_addr(addr_str,
205+
port as int);
206+
uv::ll::tcp_connect(
207+
connect_req_ptr,
208+
stream_handle_ptr,
209+
&in_addr,
210+
tcp_connect_on_connect_cb)
211+
}
212+
ip::Ipv6(ref addr) => {
213+
debug!("addr: %?", addr);
214+
let in_addr = uv::ll::ip6_addr(addr_str,
215+
port as int);
216+
uv::ll::tcp_connect6(
217+
connect_req_ptr,
218+
stream_handle_ptr,
219+
&in_addr,
220+
tcp_connect_on_connect_cb)
221+
}
222+
};
223+
match connect_result {
224+
0i32 => {
225+
debug!("tcp_connect successful: \
226+
stream %x,
227+
socket data %x",
228+
stream_handle_ptr as uint,
229+
socket_data_ptr as uint);
230+
// reusable data that we'll have for the
231+
// duration..
232+
uv::ll::set_data_for_uv_handle(
233+
stream_handle_ptr,
234+
socket_data_ptr as
235+
*libc::c_void);
236+
// just so the connect_cb can send the
237+
// outcome..
238+
uv::ll::set_data_for_req(connect_req_ptr,
239+
conn_data_ptr);
240+
debug!("leaving tcp_connect interact cb...");
241+
// let tcp_connect_on_connect_cb send on
242+
// the result_ch, now..
243+
}
244+
_ => {
245+
// immediate connect
246+
// failure.. probably a garbage ip or
247+
// somesuch
248+
let err_data =
249+
uv::ll::get_last_err_data(loop_ptr);
250+
let result_ch = (*conn_data_ptr)
251+
.result_ch.clone();
252+
result_ch.send(ConnFailure(err_data));
253+
uv::ll::set_data_for_uv_handle(
254+
stream_handle_ptr,
255+
conn_data_ptr);
256+
uv::ll::close(stream_handle_ptr,
257+
stream_error_close_cb);
260258
}
261259
}
262-
_ => {
263-
// failure to create a tcp handle
264-
let err_data = uv::ll::get_last_err_data(loop_ptr);
265-
let result_ch = (*conn_data_ptr).result_ch.clone();
266-
result_ch.send(ConnFailure(err_data));
267-
}
260+
}
261+
_ => {
262+
// failure to create a tcp handle
263+
let err_data = uv::ll::get_last_err_data(loop_ptr);
264+
let result_ch = (*conn_data_ptr).result_ch.clone();
265+
result_ch.send(ConnFailure(err_data));
268266
}
269267
}
270268
}
@@ -1015,14 +1013,12 @@ fn tear_down_socket_data(socket_data: @TcpSocketData) {
10151013
let close_data_ptr: *TcpSocketCloseData = &close_data;
10161014
let stream_handle_ptr = (*socket_data).stream_handle_ptr;
10171015
do iotask::interact(&(*socket_data).iotask) |loop_ptr| {
1018-
unsafe {
1019-
debug!(
1020-
"interact dtor for tcp_socket stream %? loop %?",
1021-
stream_handle_ptr, loop_ptr);
1022-
uv::ll::set_data_for_uv_handle(stream_handle_ptr,
1023-
close_data_ptr);
1024-
uv::ll::close(stream_handle_ptr, tcp_socket_dtor_close_cb);
1025-
}
1016+
debug!(
1017+
"interact dtor for tcp_socket stream %? loop %?",
1018+
stream_handle_ptr, loop_ptr);
1019+
uv::ll::set_data_for_uv_handle(stream_handle_ptr,
1020+
close_data_ptr);
1021+
uv::ll::close(stream_handle_ptr, tcp_socket_dtor_close_cb);
10261022
};
10271023
closed_po.recv();
10281024
//the line below will most likely crash
@@ -1082,19 +1078,17 @@ fn read_stop_common_impl(socket_data: *TcpSocketData) ->
10821078
let stream_handle_ptr = (*socket_data).stream_handle_ptr;
10831079
let (stop_po, stop_ch) = stream::<Option<TcpErrData>>();
10841080
do iotask::interact(&(*socket_data).iotask) |loop_ptr| {
1085-
unsafe {
1086-
debug!("in interact cb for tcp::read_stop");
1087-
match uv::ll::read_stop(stream_handle_ptr
1088-
as *uv::ll::uv_stream_t) {
1089-
0i32 => {
1090-
debug!("successfully called uv_read_stop");
1091-
stop_ch.send(None);
1092-
}
1093-
_ => {
1094-
debug!("failure in calling uv_read_stop");
1095-
let err_data = uv::ll::get_last_err_data(loop_ptr);
1096-
stop_ch.send(Some(err_data.to_tcp_err()));
1097-
}
1081+
debug!("in interact cb for tcp::read_stop");
1082+
match uv::ll::read_stop(stream_handle_ptr
1083+
as *uv::ll::uv_stream_t) {
1084+
0i32 => {
1085+
debug!("successfully called uv_read_stop");
1086+
stop_ch.send(None);
1087+
}
1088+
_ => {
1089+
debug!("failure in calling uv_read_stop");
1090+
let err_data = uv::ll::get_last_err_data(loop_ptr);
1091+
stop_ch.send(Some(err_data.to_tcp_err()));
10981092
}
10991093
}
11001094
}
@@ -1114,22 +1108,20 @@ fn read_start_common_impl(socket_data: *TcpSocketData)
11141108
let (start_po, start_ch) = stream::<Option<uv::ll::uv_err_data>>();
11151109
debug!("in tcp::read_start before interact loop");
11161110
do iotask::interact(&(*socket_data).iotask) |loop_ptr| {
1117-
unsafe {
1118-
debug!("in tcp::read_start interact cb %?",
1119-
loop_ptr);
1120-
match uv::ll::read_start(stream_handle_ptr
1121-
as *uv::ll::uv_stream_t,
1122-
on_alloc_cb,
1123-
on_tcp_read_cb) {
1124-
0i32 => {
1125-
debug!("success doing uv_read_start");
1126-
start_ch.send(None);
1127-
}
1128-
_ => {
1129-
debug!("error attempting uv_read_start");
1130-
let err_data = uv::ll::get_last_err_data(loop_ptr);
1131-
start_ch.send(Some(err_data));
1132-
}
1111+
debug!("in tcp::read_start interact cb %?",
1112+
loop_ptr);
1113+
match uv::ll::read_start(stream_handle_ptr
1114+
as *uv::ll::uv_stream_t,
1115+
on_alloc_cb,
1116+
on_tcp_read_cb) {
1117+
0i32 => {
1118+
debug!("success doing uv_read_start");
1119+
start_ch.send(None);
1120+
}
1121+
_ => {
1122+
debug!("error attempting uv_read_start");
1123+
let err_data = uv::ll::get_last_err_data(loop_ptr);
1124+
start_ch.send(Some(err_data));
11331125
}
11341126
}
11351127
}
@@ -1166,24 +1158,22 @@ fn write_common_impl(socket_data_ptr: *TcpSocketData,
11661158
};
11671159
let write_data_ptr: *WriteReqData = &write_data;
11681160
do iotask::interact(&(*socket_data_ptr).iotask) |loop_ptr| {
1169-
unsafe {
1170-
debug!("in interact cb for tcp::write %?",
1171-
loop_ptr);
1172-
match uv::ll::write(write_req_ptr,
1173-
stream_handle_ptr,
1174-
write_buf_vec_ptr,
1175-
tcp_write_complete_cb) {
1176-
0i32 => {
1177-
debug!("uv_write() invoked successfully");
1178-
uv::ll::set_data_for_req(write_req_ptr,
1179-
write_data_ptr);
1180-
}
1181-
_ => {
1182-
debug!("error invoking uv_write()");
1183-
let err_data = uv::ll::get_last_err_data(loop_ptr);
1184-
let result_ch = (*write_data_ptr).result_ch.clone();
1185-
result_ch.send(TcpWriteError(err_data.to_tcp_err()));
1186-
}
1161+
debug!("in interact cb for tcp::write %?",
1162+
loop_ptr);
1163+
match uv::ll::write(write_req_ptr,
1164+
stream_handle_ptr,
1165+
write_buf_vec_ptr,
1166+
tcp_write_complete_cb) {
1167+
0i32 => {
1168+
debug!("uv_write() invoked successfully");
1169+
uv::ll::set_data_for_req(write_req_ptr,
1170+
write_data_ptr);
1171+
}
1172+
_ => {
1173+
debug!("error invoking uv_write()");
1174+
let err_data = uv::ll::get_last_err_data(loop_ptr);
1175+
let result_ch = (*write_data_ptr).result_ch.clone();
1176+
result_ch.send(TcpWriteError(err_data.to_tcp_err()));
11871177
}
11881178
}
11891179
}

0 commit comments

Comments
 (0)