From 9b3452e10a3b8685370fea99664eccfd8fe958bb Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 11 Jan 2013 09:22:23 -0800 Subject: [PATCH] libstd: Fix std test. rs=busted --- src/libstd/c_vec.rs | 10 ++- src/libstd/uv_ll.rs | 187 +++++++++++++++++++++++++------------------- 2 files changed, 111 insertions(+), 86 deletions(-) diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index fe1bfa62fb1a..359d3039229e 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -161,12 +161,14 @@ mod tests { use core::libc; fn malloc(n: size_t) -> CVec { - let mem = libc::malloc(n); + unsafe { + let mem = libc::malloc(n); - assert mem as int != 0; + assert mem as int != 0; - return unsafe { c_vec_with_dtor(mem as *mut u8, n as uint, - ||free(mem)) }; + return unsafe { c_vec_with_dtor(mem as *mut u8, n as uint, + || unsafe { free(mem) }) }; + } } #[test] diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index c9ff5e3796b1..778daf131c4b 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -1594,125 +1594,148 @@ pub mod test { // struct size tests #[test] fn test_uv_ll_struct_size_uv_tcp_t() { - let foreign_handle_size = - ::uv_ll::rustrt::rust_uv_helper_uv_tcp_t_size(); - let rust_handle_size = sys::size_of::(); - let output = fmt!("uv_tcp_t -- foreign: %u rust: %u", - foreign_handle_size as uint, rust_handle_size); - log(debug, output); - assert foreign_handle_size as uint == rust_handle_size; + unsafe { + let foreign_handle_size = + ::uv_ll::rustrt::rust_uv_helper_uv_tcp_t_size(); + let rust_handle_size = sys::size_of::(); + let output = fmt!("uv_tcp_t -- foreign: %u rust: %u", + foreign_handle_size as uint, rust_handle_size); + log(debug, output); + assert foreign_handle_size as uint == rust_handle_size; + } } #[test] fn test_uv_ll_struct_size_uv_connect_t() { - let foreign_handle_size = - ::uv_ll::rustrt::rust_uv_helper_uv_connect_t_size(); - let rust_handle_size = sys::size_of::(); - let output = fmt!("uv_connect_t -- foreign: %u rust: %u", - foreign_handle_size as uint, rust_handle_size); - log(debug, output); - assert foreign_handle_size as uint == rust_handle_size; + unsafe { + let foreign_handle_size = + ::uv_ll::rustrt::rust_uv_helper_uv_connect_t_size(); + let rust_handle_size = sys::size_of::(); + let output = fmt!("uv_connect_t -- foreign: %u rust: %u", + foreign_handle_size as uint, rust_handle_size); + log(debug, output); + assert foreign_handle_size as uint == rust_handle_size; + } } #[test] fn test_uv_ll_struct_size_uv_buf_t() { - let foreign_handle_size = - ::uv_ll::rustrt::rust_uv_helper_uv_buf_t_size(); - let rust_handle_size = sys::size_of::(); - let output = fmt!("uv_buf_t -- foreign: %u rust: %u", - foreign_handle_size as uint, rust_handle_size); - log(debug, output); - assert foreign_handle_size as uint == rust_handle_size; + unsafe { + let foreign_handle_size = + ::uv_ll::rustrt::rust_uv_helper_uv_buf_t_size(); + let rust_handle_size = sys::size_of::(); + let output = fmt!("uv_buf_t -- foreign: %u rust: %u", + foreign_handle_size as uint, rust_handle_size); + log(debug, output); + assert foreign_handle_size as uint == rust_handle_size; + } } #[test] fn test_uv_ll_struct_size_uv_write_t() { - let foreign_handle_size = - ::uv_ll::rustrt::rust_uv_helper_uv_write_t_size(); - let rust_handle_size = sys::size_of::(); - let output = fmt!("uv_write_t -- foreign: %u rust: %u", - foreign_handle_size as uint, rust_handle_size); - log(debug, output); - assert foreign_handle_size as uint == rust_handle_size; + unsafe { + let foreign_handle_size = + ::uv_ll::rustrt::rust_uv_helper_uv_write_t_size(); + let rust_handle_size = sys::size_of::(); + let output = fmt!("uv_write_t -- foreign: %u rust: %u", + foreign_handle_size as uint, rust_handle_size); + log(debug, output); + assert foreign_handle_size as uint == rust_handle_size; + } } #[test] fn test_uv_ll_struct_size_sockaddr_in() { - let foreign_handle_size = - ::uv_ll::rustrt::rust_uv_helper_sockaddr_in_size(); - let rust_handle_size = sys::size_of::(); - let output = fmt!("sockaddr_in -- foreign: %u rust: %u", - foreign_handle_size as uint, rust_handle_size); - log(debug, output); - assert foreign_handle_size as uint == rust_handle_size; + unsafe { + let foreign_handle_size = + ::uv_ll::rustrt::rust_uv_helper_sockaddr_in_size(); + let rust_handle_size = sys::size_of::(); + let output = fmt!("sockaddr_in -- foreign: %u rust: %u", + foreign_handle_size as uint, rust_handle_size); + log(debug, output); + assert foreign_handle_size as uint == rust_handle_size; + } } #[test] fn test_uv_ll_struct_size_sockaddr_in6() { - let foreign_handle_size = - ::uv_ll::rustrt::rust_uv_helper_sockaddr_in6_size(); - let rust_handle_size = sys::size_of::(); - let output = fmt!("sockaddr_in6 -- foreign: %u rust: %u", - foreign_handle_size as uint, rust_handle_size); - log(debug, output); - // FIXME #1645 .. rust appears to pad structs to the nearest byte..? - // .. can't get the uv::ll::sockaddr_in6 to == 28 :/ - // .. so the type always appears to be 32 in size.. which is - // good, i guess.. better too big than too little - assert (4u+foreign_handle_size as uint) == rust_handle_size; + unsafe { + let foreign_handle_size = + ::uv_ll::rustrt::rust_uv_helper_sockaddr_in6_size(); + let rust_handle_size = sys::size_of::(); + let output = fmt!("sockaddr_in6 -- foreign: %u rust: %u", + foreign_handle_size as uint, rust_handle_size); + log(debug, output); + // FIXME #1645 .. rust appears to pad structs to the nearest + // byte..? + // .. can't get the uv::ll::sockaddr_in6 to == 28 :/ + // .. so the type always appears to be 32 in size.. which is + // good, i guess.. better too big than too little + assert (4u+foreign_handle_size as uint) == rust_handle_size; + } } #[test] #[ignore(reason = "questionable size calculations")] fn test_uv_ll_struct_size_addr_in() { - let foreign_handle_size = - ::uv_ll::rustrt::rust_uv_helper_addr_in_size(); - let rust_handle_size = sys::size_of::(); - let output = fmt!("addr_in -- foreign: %u rust: %u", - foreign_handle_size as uint, rust_handle_size); - log(debug, output); - // FIXME #1645 .. see note above about struct padding - assert (4u+foreign_handle_size as uint) == rust_handle_size; + unsafe { + let foreign_handle_size = + ::uv_ll::rustrt::rust_uv_helper_addr_in_size(); + let rust_handle_size = sys::size_of::(); + let output = fmt!("addr_in -- foreign: %u rust: %u", + foreign_handle_size as uint, rust_handle_size); + log(debug, output); + // FIXME #1645 .. see note above about struct padding + assert (4u+foreign_handle_size as uint) == rust_handle_size; + } } #[test] fn test_uv_ll_struct_size_uv_async_t() { - let foreign_handle_size = - ::uv_ll::rustrt::rust_uv_helper_uv_async_t_size(); - let rust_handle_size = sys::size_of::(); - let output = fmt!("uv_async_t -- foreign: %u rust: %u", - foreign_handle_size as uint, rust_handle_size); - log(debug, output); - assert foreign_handle_size as uint == rust_handle_size; + unsafe { + let foreign_handle_size = + ::uv_ll::rustrt::rust_uv_helper_uv_async_t_size(); + let rust_handle_size = sys::size_of::(); + let output = fmt!("uv_async_t -- foreign: %u rust: %u", + foreign_handle_size as uint, rust_handle_size); + log(debug, output); + assert foreign_handle_size as uint == rust_handle_size; + } } #[test] fn test_uv_ll_struct_size_uv_timer_t() { - let foreign_handle_size = - ::uv_ll::rustrt::rust_uv_helper_uv_timer_t_size(); - let rust_handle_size = sys::size_of::(); - let output = fmt!("uv_timer_t -- foreign: %u rust: %u", - foreign_handle_size as uint, rust_handle_size); - log(debug, output); - assert foreign_handle_size as uint == rust_handle_size; + unsafe { + let foreign_handle_size = + ::uv_ll::rustrt::rust_uv_helper_uv_timer_t_size(); + let rust_handle_size = sys::size_of::(); + let output = fmt!("uv_timer_t -- foreign: %u rust: %u", + foreign_handle_size as uint, rust_handle_size); + log(debug, output); + assert foreign_handle_size as uint == rust_handle_size; + } } #[test] #[ignore(cfg(target_os = "win32"))] fn test_uv_ll_struct_size_uv_getaddrinfo_t() { - let foreign_handle_size = - ::uv_ll::rustrt::rust_uv_helper_uv_getaddrinfo_t_size(); - let rust_handle_size = sys::size_of::(); - let output = fmt!("uv_getaddrinfo_t -- foreign: %u rust: %u", - foreign_handle_size as uint, rust_handle_size); - log(debug, output); - assert foreign_handle_size as uint == rust_handle_size; + unsafe { + let foreign_handle_size = + ::uv_ll::rustrt::rust_uv_helper_uv_getaddrinfo_t_size(); + let rust_handle_size = sys::size_of::(); + let output = fmt!("uv_getaddrinfo_t -- foreign: %u rust: %u", + foreign_handle_size as uint, rust_handle_size); + log(debug, output); + assert foreign_handle_size as uint == rust_handle_size; + } } #[test] #[ignore(cfg(target_os = "macos"))] #[ignore(cfg(target_os = "win32"))] fn test_uv_ll_struct_size_addrinfo() { - let foreign_handle_size = - ::uv_ll::rustrt::rust_uv_helper_addrinfo_size(); - let rust_handle_size = sys::size_of::(); - let output = fmt!("addrinfo -- foreign: %u rust: %u", - foreign_handle_size as uint, rust_handle_size); - log(debug, output); - assert foreign_handle_size as uint == rust_handle_size; + unsafe { + let foreign_handle_size = + ::uv_ll::rustrt::rust_uv_helper_addrinfo_size(); + let rust_handle_size = sys::size_of::(); + let output = fmt!("addrinfo -- foreign: %u rust: %u", + foreign_handle_size as uint, rust_handle_size); + log(debug, output); + assert foreign_handle_size as uint == rust_handle_size; + } } }