From dfcdb6eb729fa51cac47f219a90a9f894819f343 Mon Sep 17 00:00:00 2001 From: Jeff Olson Date: Wed, 30 Jan 2013 10:28:27 -0800 Subject: [PATCH] rt/std: update of libuv API glue for libuv submodule update --- src/libstd/uv_iotask.rs | 14 ++- src/libstd/uv_ll.rs | 215 ++++++++++++++++++---------------------- src/rt/rust_uv.cpp | 12 +-- src/rt/rustrt.def.in | 2 +- 4 files changed, 111 insertions(+), 132 deletions(-) diff --git a/src/libstd/uv_iotask.rs b/src/libstd/uv_iotask.rs index a44fef54b726..da5fbc3438a1 100644 --- a/src/libstd/uv_iotask.rs +++ b/src/libstd/uv_iotask.rs @@ -185,15 +185,19 @@ fn begin_teardown(data: *IoTaskLoopData) { ll::close(async_handle as *c_void, tear_down_close_cb); } } +extern fn tear_down_walk_cb(handle: *libc::c_void, arg: *libc::c_void) { + log(debug, ~"IN TEARDOWN WALK CB BOYEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); + // pretty much, if we still have an active handle and it is *not* + // the async handle that facilities global loop communication, we + // want to barf out and fail + assert handle == arg; +} extern fn tear_down_close_cb(handle: *ll::uv_async_t) { unsafe { let loop_ptr = ll::get_loop_for_uv_handle(handle); - let loop_refs = ll::loop_refcount(loop_ptr); - log(debug, - fmt!("tear_down_close_cb called, closing handle at %? refs %?", - handle, loop_refs)); - assert loop_refs == 1i32; + log(debug, ~"in tear_down_close_cb"); + ll::walk(loop_ptr, tear_down_walk_cb, handle as *libc::c_void); } } diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index a3e02ca70706..fb8bbcebf7fc 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -90,7 +90,7 @@ pub struct uv_stream_t { fields: uv_handle_fields, } -// 64bit unix size: 272 +// 64bit unix size: 216 #[cfg(unix)] pub struct uv_tcp_t { fields: uv_handle_fields, @@ -99,10 +99,8 @@ pub struct uv_tcp_t { a08: *u8, a09: *u8, a10: *u8, a11: *u8, a12: *u8, a13: *u8, a14: *u8, a15: *u8, a16: *u8, a17: *u8, a18: *u8, a19: *u8, - a20: *u8, a21: *u8, a22: *u8, a23: *u8, - a24: *u8, a25: *u8, a26: *u8, a27: *u8, - a28: *u8, - a30: uv_tcp_t_32bit_unix_riders, + a20: *u8, a21: *u8, + a22: uv_tcp_t_32bit_unix_riders, } // 32bit unix size: 328 (164) #[cfg(target_arch="x86_64")] @@ -113,8 +111,6 @@ pub struct uv_tcp_t_32bit_unix_riders { #[cfg(target_arch="arm")] pub struct uv_tcp_t_32bit_unix_riders { a29: *u8, a30: *u8, a31: *u8, - a32: *u8, a33: *u8, a34: *u8, - a35: *u8, a36: *u8, } // 32bit win32 size: 240 (120) @@ -130,11 +126,11 @@ pub struct uv_tcp_t { a24: *u8, a25: *u8, } -// unix size: 48 +// unix size: 64 #[cfg(unix)] pub struct uv_connect_t { a00: *u8, a01: *u8, a02: *u8, a03: *u8, - a04: *u8, a05: *u8, + a04: *u8, a05: *u8, a06: *u8, a07: *u8 } // win32 size: 88 (44) #[cfg(windows)] @@ -152,7 +148,7 @@ pub struct uv_buf_t { // no gen stub method.. should create // it via uv::direct::buf_init() -// unix size: 144 +// unix size: 160 #[cfg(unix)] pub struct uv_write_t { fields: uv_handle_fields, @@ -164,12 +160,13 @@ pub struct uv_write_t { } #[cfg(target_arch="x86_64")] pub struct uv_write_t_32bit_unix_riders { - a13: *u8, + a13: *u8, a14: *u8, a15: *u8 } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] pub struct uv_write_t_32bit_unix_riders { - a13: *u8, a14: *u8, + a13: *u8, a14: *u8, a15: *u8, + a16: *u8, } // win32 size: 136 (68) #[cfg(windows)] @@ -180,15 +177,14 @@ pub struct uv_write_t { a08: *u8, a09: *u8, a10: *u8, a11: *u8, a12: *u8, } -// 64bit unix size: 120 +// 64bit unix size: 96 // 32bit unix size: 152 (76) #[cfg(unix)] pub struct uv_async_t { fields: uv_handle_fields, a00: *u8, a01: *u8, a02: *u8, a03: *u8, - a04: *u8, a05: *u8, a06: *u8, a07: *u8, - a08: *u8, a09: *u8, - a11: uv_async_t_32bit_unix_riders, + a04: *u8, a05: *u8, a06: *u8, + a07: uv_async_t_32bit_unix_riders, } #[cfg(target_arch="x86_64")] pub struct uv_async_t_32bit_unix_riders { @@ -197,7 +193,7 @@ pub struct uv_async_t_32bit_unix_riders { #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] pub struct uv_async_t_32bit_unix_riders { - a10: *u8, a11: *u8, a12: *u8, a13: *u8, + a10: *u8, } // win32 size 132 (68) #[cfg(windows)] @@ -209,7 +205,7 @@ pub struct uv_async_t { a12: *u8, } -// 64bit unix size: 128 +// 64bit unix size: 120 // 32bit unix size: 84 #[cfg(unix)] pub struct uv_timer_t { @@ -221,13 +217,12 @@ pub struct uv_timer_t { } #[cfg(target_arch="x86_64")] pub struct uv_timer_t_32bit_unix_riders { - a10: *u8, a11: *u8, + a10: *u8, } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] pub struct uv_timer_t_32bit_unix_riders { - a10: *u8, a11: *u8, a12: *u8, a13: *u8, - a14: *u8, a15: *u8, a16: *u8, + a10: *u8, a11: *u8, a12: *u8 } // win32 size: 64 #[cfg(windows)] @@ -325,7 +320,8 @@ pub mod addrinfo_impl { // unix size: 72 pub struct uv_getaddrinfo_t { a00: *u8, a01: *u8, a02: *u8, a03: *u8, a04: *u8, a05: *u8, - a06: *u8, a07: *u8, a08: *u8, + a06: *u8, a07: *u8, a08: *u8, a09: *u8, + a10: *u8, a11: *u8, a12: *u8, a13: *u8, a14: *u8, a15: *u8 } pub mod uv_ll_struct_stubgen { @@ -378,12 +374,8 @@ pub mod uv_ll_struct_stubgen { a15: 0 as *u8, a16: 0 as *u8, a17: 0 as *u8, a18: 0 as *u8, a19: 0 as *u8, - a20: 0 as *u8, a21: 0 as *u8, a22: 0 as *u8, - a23: 0 as *u8, - a24: 0 as *u8, a25: 0 as *u8, a26: 0 as *u8, - a27: 0 as *u8, - a28: 0 as *u8, - a30: uv_tcp_t_32bit_unix_riders { a29: 0 as *u8 }, + a20: 0 as *u8, a21: 0 as *u8, + a22: uv_tcp_t_32bit_unix_riders { a29: 0 as *u8 }, } } #[cfg(target_arch="x86")] @@ -405,15 +397,9 @@ pub mod uv_ll_struct_stubgen { a15: 0 as *u8, a16: 0 as *u8, a17: 0 as *u8, a18: 0 as *u8, a19: 0 as *u8, - a20: 0 as *u8, a21: 0 as *u8, a22: 0 as *u8, - a23: 0 as *u8, - a24: 0 as *u8, a25: 0 as *u8, a26: 0 as *u8, - a27: 0 as *u8, - a28: 0 as *u8, - a30: uv_tcp_t_32bit_unix_riders { + a20: 0 as *u8, a21: 0 as *u8, + a22: uv_tcp_t_32bit_unix_riders { a29: 0 as *u8, a30: 0 as *u8, a31: 0 as *u8, - a32: 0 as *u8, a33: 0 as *u8, a34: 0 as *u8, - a35: 0 as *u8, a36: 0 as *u8, }, } } @@ -447,7 +433,8 @@ pub mod uv_ll_struct_stubgen { uv_connect_t { a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, - a04: 0 as *u8, a05: 0 as *u8, + a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, + a07: 0 as *u8 } } #[cfg(windows)] @@ -474,9 +461,7 @@ pub mod uv_ll_struct_stubgen { a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, - a07: 0 as *u8, - a08: 0 as *u8, a09: 0 as *u8, - a11: uv_async_t_32bit_unix_riders { a10: 0 as *u8 }, + a07: uv_async_t_32bit_unix_riders { a10: 0 as *u8 }, } } #[cfg(target_arch = "x86")] @@ -491,11 +476,8 @@ pub mod uv_ll_struct_stubgen { a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, - a07: 0 as *u8, - a08: 0 as *u8, a09: 0 as *u8, - a11: uv_async_t_32bit_unix_riders { - a10: 0 as *u8, a11: 0 as *u8, - a12: 0 as *u8, a13: 0 as *u8 + a07: uv_async_t_32bit_unix_riders { + a10: 0 as *u8, } } } @@ -534,7 +516,7 @@ pub mod uv_ll_struct_stubgen { a07: 0 as *u8, a08: 0 as *u8, a09: 0 as *u8, a11: uv_timer_t_32bit_unix_riders { - a10: 0 as *u8, a11: 0 as *u8 + a10: 0 as *u8 }, } } @@ -554,9 +536,7 @@ pub mod uv_ll_struct_stubgen { a08: 0 as *u8, a09: 0 as *u8, a11: uv_timer_t_32bit_unix_riders { a10: 0 as *u8, a11: 0 as *u8, - a12: 0 as *u8, a13: 0 as *u8, - a14: 0 as *u8, a15: 0 as *u8, - a16: 0 as *u8, + a12: 0 as *u8, }, } } @@ -595,7 +575,9 @@ pub mod uv_ll_struct_stubgen { a08: 0 as *u8, a09: 0 as *u8, a10: 0 as *u8, a11: 0 as *u8, a12: 0 as *u8, - a14: uv_write_t_32bit_unix_riders { a13: 0 as *u8 }, + a14: uv_write_t_32bit_unix_riders { a13: 0 as *u8, + a14: 0 as *u8, + a15: 0 as *u8}, } } #[cfg(target_arch="x86")] @@ -617,6 +599,8 @@ pub mod uv_ll_struct_stubgen { a14: uv_write_t_32bit_unix_riders { a13: 0 as *u8, a14: 0 as *u8, + a15: 0 as *u8, + a16: 0 as *u8, } } } @@ -642,7 +626,9 @@ pub mod uv_ll_struct_stubgen { uv_getaddrinfo_t { a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, a07: 0 as *u8, - a08: 0 as *u8 + a08: 0 as *u8, a09: 0 as *u8, + a10: 1 as *u8, a11: 1 as *u8, a12: 1 as *u8, a13: 1 as *u8, + a14: 1 as *u8, a15: 1 as *u8 } } } @@ -652,9 +638,10 @@ extern mod rustrt { // libuv public API unsafe fn rust_uv_loop_new() -> *libc::c_void; unsafe fn rust_uv_loop_delete(lp: *libc::c_void); - unsafe fn rust_uv_loop_refcount(loop_ptr: *libc::c_void) -> libc::c_int; unsafe fn rust_uv_run(loop_handle: *libc::c_void); unsafe fn rust_uv_close(handle: *libc::c_void, cb: *u8); + unsafe fn rust_uv_walk(loop_handle: *libc::c_void, cb: *u8, + arg: *libc::c_void); unsafe fn rust_uv_async_send(handle: *uv_async_t); unsafe fn rust_uv_async_init(loop_handle: *libc::c_void, async_handle: *uv_async_t, @@ -796,10 +783,6 @@ pub unsafe fn loop_delete(loop_handle: *libc::c_void) { rustrt::rust_uv_loop_delete(loop_handle); } -pub unsafe fn loop_refcount(loop_ptr: *libc::c_void) -> libc::c_int { - return rustrt::rust_uv_loop_refcount(loop_ptr); -} - pub unsafe fn run(loop_handle: *libc::c_void) { rustrt::rust_uv_run(loop_handle); } @@ -808,6 +791,10 @@ pub unsafe fn close(handle: *T, cb: *u8) { rustrt::rust_uv_close(handle as *libc::c_void, cb); } +pub unsafe fn walk(loop_handle: *libc::c_void, cb: *u8, arg: *libc::c_void) { + rustrt::rust_uv_walk(loop_handle, cb, arg); +} + pub unsafe fn tcp_init(loop_handle: *libc::c_void, handle: *uv_tcp_t) -> libc::c_int { return rustrt::rust_uv_tcp_init(loop_handle, handle); @@ -1126,7 +1113,7 @@ pub unsafe fn addrinfo_as_sockaddr_in6(input: *addrinfo) -> *sockaddr_in6 { rustrt::rust_uv_addrinfo_as_sockaddr_in6(input) } -#[cfg(test)] +//#[cfg(test)] pub mod test { use core::prelude::*; @@ -1693,66 +1680,66 @@ pub mod test { } } + fn struct_size_check_common(t_name: ~str, + foreign_size: libc::c_uint) { + unsafe { + let rust_size = sys::size_of::(); + let sizes_match = foreign_size as uint == rust_size; + if !sizes_match { + let output = fmt!( + "STRUCT_SIZE FAILURE: %s -- actual: %u expected: %u", + t_name, rust_size, foreign_size as uint); + log(debug, output); + } + assert sizes_match; + } + } + // struct size tests #[test] fn test_uv_ll_struct_size_uv_tcp_t() { 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; + struct_size_check_common::( + ~"uv_tcp_t", + ::uv_ll::rustrt::rust_uv_helper_uv_tcp_t_size() + ); } } #[test] fn test_uv_ll_struct_size_uv_connect_t() { 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; + struct_size_check_common::( + ~"uv_connect_t", + ::uv_ll::rustrt::rust_uv_helper_uv_connect_t_size() + ); } } #[test] fn test_uv_ll_struct_size_uv_buf_t() { 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; + struct_size_check_common::( + ~"uv_buf_t", + ::uv_ll::rustrt::rust_uv_helper_uv_buf_t_size() + ); } } #[test] fn test_uv_ll_struct_size_uv_write_t() { 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; + struct_size_check_common::( + ~"uv_write_t", + ::uv_ll::rustrt::rust_uv_helper_uv_write_t_size() + ); } } #[test] fn test_uv_ll_struct_size_sockaddr_in() { 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; + struct_size_check_common::( + ~"sockaddr_in", + ::uv_ll::rustrt::rust_uv_helper_sockaddr_in_size() + ); } } #[test] @@ -1790,26 +1777,20 @@ pub mod test { #[test] fn test_uv_ll_struct_size_uv_async_t() { 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; + struct_size_check_common::( + ~"uv_async_t", + ::uv_ll::rustrt::rust_uv_helper_uv_async_t_size() + ); } } #[test] fn test_uv_ll_struct_size_uv_timer_t() { 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; + struct_size_check_common::( + ~"uv_timer_t", + ::uv_ll::rustrt::rust_uv_helper_uv_timer_t_size() + ); } } @@ -1817,13 +1798,10 @@ pub mod test { #[ignore(cfg(target_os = "win32"))] fn test_uv_ll_struct_size_uv_getaddrinfo_t() { 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; + struct_size_check_common::( + ~"uv_getaddrinfo_t", + ::uv_ll::rustrt::rust_uv_helper_uv_getaddrinfo_t_size() + ); } } #[test] @@ -1831,13 +1809,10 @@ pub mod test { #[ignore(cfg(target_os = "win32"))] fn test_uv_ll_struct_size_addrinfo() { 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; + struct_size_check_common::( + ~"addrinfo", + ::uv_ll::rustrt::rust_uv_helper_uv_timer_t_size() + ); } } } diff --git a/src/rt/rust_uv.cpp b/src/rt/rust_uv.cpp index 2dc70088628f..f08261c336dc 100644 --- a/src/rt/rust_uv.cpp +++ b/src/rt/rust_uv.cpp @@ -121,11 +121,6 @@ rust_uv_loop_delete(uv_loop_t* loop) { uv_loop_delete(loop); } -extern "C" int -rust_uv_loop_refcount(uv_loop_t* loop) { - return uv_loop_refcount(loop); -} - extern "C" void rust_uv_loop_set_data(uv_loop_t* loop, void* data) { loop->data = data; @@ -151,7 +146,7 @@ rust_uv_stop_op_cb(uv_handle_t* op_handle) { extern "C" void rust_uv_run(uv_loop_t* loop) { - uv_run(loop); + uv_run(loop, UV_RUN_DEFAULT); } extern "C" void @@ -159,6 +154,11 @@ rust_uv_close(uv_handle_t* handle, uv_close_cb cb) { uv_close(handle, cb); } +extern "C" void +rust_uv_walk(uv_loop_t* loop, uv_walk_cb cb, void* arg) { + uv_walk(loop, cb, arg); +} + extern "C" void rust_uv_hilvl_close(uv_handle_t* handle, extern_close_cb cb) { handle_data* data = (handle_data*)handle->data; diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index 818eb5f83a7b..2e687472a8d6 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -73,7 +73,7 @@ rust_upcall_free rust_upcall_malloc rust_uv_loop_new rust_uv_loop_delete -rust_uv_loop_refcount +rust_uv_walk rust_uv_loop_set_data rust_uv_bind_op_cb rust_uv_stop_op_cb