From ed204257a0c6abc8386879bb631471ec17d8a96a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 18 Aug 2013 17:11:45 -0700 Subject: [PATCH] Upgrade libuv to the current master + our patches There were two main differences with the old libuv and the master version: 1. The uv_last_error function is now gone. The error code returned by each function is the "last error" so now a UvError is just a wrapper around a c_int. 2. The repo no longer includes a makefile, and the build system has change. According to the build directions on joyent/libuv, this now downloads a `gyp` program into the `libuv/build` directory and builds using that. This shouldn't add any dependences on autotools or anything like that. Closes #8407 Closes #6567 Closes #6315 --- .gitmodules | 2 +- mk/rt.mk | 33 ++++++++++++----- src/libstd/rt/io/net/tcp.rs | 2 +- src/libstd/rt/uv/mod.rs | 53 ++++++++-------------------- src/libstd/rt/uv/net.rs | 5 ++- src/libstd/rt/uv/uvll.rs | 70 +++++++++++++++---------------------- src/libuv | 2 +- src/rt/rust_uv.cpp | 11 ++---- src/rt/rustrt.def.in | 3 +- 9 files changed, 76 insertions(+), 105 deletions(-) diff --git a/.gitmodules b/.gitmodules index 88ead6e608d..fa979b6d868 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,5 +4,5 @@ branch = master [submodule "src/libuv"] path = src/libuv - url = https://github.com/brson/libuv.git + url = https://github.com/alexcrichton/libuv.git branch = master diff --git a/mk/rt.mk b/mk/rt.mk index 6a9620c7364..41d42433aae 100644 --- a/mk/rt.mk +++ b/mk/rt.mk @@ -163,34 +163,44 @@ LIBUV_DEPS := $$(wildcard \ $$(S)src/libuv/*/*/*/*) endif +LIBUV_GYP := $$(S)src/libuv/build/gyp +LIBUV_MAKEFILE := $$(S)src/libuv/out/Makefile +LIBUV_NO_LOAD = run-benchmarks.target.mk run-tests.target.mk \ + uv_dtrace_header.target.mk uv_dtrace_provider.target.mk + # XXX: Shouldn't need platform-specific conditions here ifdef CFG_WINDOWSY_$(1) -$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) +$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) $$(LIBUV_MAKEFILE) $$(Q)$$(MAKE) -C $$(S)src/libuv/ \ - builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \ + builddir="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \ OS=mingw \ + BUILDTYPE=Release \ + NO_LOAD="$$(LIBUV_NO_LOAD)" \ V=$$(VERBOSE) else ifeq ($(OSTYPE_$(1)), linux-androideabi) -$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) +$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) $$(LIBUV_MAKEFILE) $$(Q)$$(MAKE) -C $$(S)src/libuv/ \ CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \ LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \ CC="$$(CC_$(1))" \ CXX="$$(CXX_$(1))" \ AR="$$(AR_$(1))" \ - BUILDTYPE=Release \ - builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \ + builddir="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \ host=android OS=linux \ + BUILDTYPE=Release \ + NO_LOAD="$$(LIBUV_NO_LOAD)" \ V=$$(VERBOSE) else -$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) - $$(Q)$$(MAKE) -C $$(S)src/libuv/ \ +$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) $$(LIBUV_MAKEFILE) + $$(Q)$$(MAKE) -C $$(S)src/libuv/out \ CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \ LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \ CC="$$(CC_$(1))" \ CXX="$$(CXX_$(1))" \ AR="$$(AR_$(1))" \ - builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \ + builddir="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \ + BUILDTYPE=Release \ + NO_LOAD="$$(LIBUV_NO_LOAD)" \ V=$$(VERBOSE) endif @@ -250,6 +260,13 @@ endif endef +$(LIBUV_GYP): + mkdir -p $(S)src/libuv/build + git clone https://git.chromium.org/external/gyp.git $(S)src/libuv/build/gyp + +$(LIBUV_MAKEFILE): $(LIBUV_GYP) + (cd $(S)src/libuv/ && ./gyp_uv -f make) + # Instantiate template for all stages $(foreach stage,$(STAGES), \ $(foreach target,$(CFG_TARGET_TRIPLES), \ diff --git a/src/libstd/rt/io/net/tcp.rs b/src/libstd/rt/io/net/tcp.rs index 9be5540de48..85fb5d08848 100644 --- a/src/libstd/rt/io/net/tcp.rs +++ b/src/libstd/rt/io/net/tcp.rs @@ -166,7 +166,7 @@ mod test { do run_in_newsched_task { let mut called = false; do io_error::cond.trap(|e| { - assert!(e.kind == ConnectionRefused); + assert_eq!(e.kind, ConnectionRefused); called = true; }).inside { let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 }; diff --git a/src/libstd/rt/uv/mod.rs b/src/libstd/rt/uv/mod.rs index 75b9a5ac553..5a592b92a38 100644 --- a/src/libstd/rt/uv/mod.rs +++ b/src/libstd/rt/uv/mod.rs @@ -202,12 +202,12 @@ impl> WatcherInterop for W { // XXX: Need to define the error constants like EOF so they can be // compared to the UvError type -pub struct UvError(uvll::uv_err_t); +pub struct UvError(c_int); impl UvError { pub fn name(&self) -> ~str { unsafe { - let inner = match self { &UvError(ref a) => a }; + let inner = match self { &UvError(a) => a }; let name_str = uvll::err_name(inner); assert!(name_str.is_not_null()); from_c_str(name_str) @@ -216,7 +216,7 @@ impl UvError { pub fn desc(&self) -> ~str { unsafe { - let inner = match self { &UvError(ref a) => a }; + let inner = match self { &UvError(a) => a }; let desc_str = uvll::strerror(inner); assert!(desc_str.is_not_null()); from_c_str(desc_str) @@ -224,7 +224,7 @@ impl UvError { } pub fn is_eof(&self) -> bool { - self.code == uvll::EOF + **self == uvll::EOF } } @@ -236,18 +236,10 @@ impl ToStr for UvError { #[test] fn error_smoke_test() { - let err = uvll::uv_err_t { code: 1, sys_errno_: 1 }; - let err: UvError = UvError(err); + let err: UvError = UvError(uvll::EOF); assert_eq!(err.to_str(), ~"EOF: end of file"); } -pub fn last_uv_error>(watcher: &W) -> UvError { - unsafe { - let loop_ = watcher.event_loop(); - UvError(uvll::last_error(loop_.native_handle())) - } -} - pub fn uv_error_to_io_error(uverr: UvError) -> IoError { unsafe { // Importing error constants @@ -255,10 +247,10 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError { use rt::io::*; // uv error descriptions are static - let c_desc = uvll::strerror(&*uverr); + let c_desc = uvll::strerror(*uverr); let desc = str::raw::c_str_to_static_slice(c_desc); - let kind = match uverr.code { + let kind = match *uverr { UNKNOWN => OtherIoError, OK => OtherIoError, EOF => EndOfFile, @@ -266,8 +258,8 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError { ECONNREFUSED => ConnectionRefused, ECONNRESET => ConnectionReset, EPIPE => BrokenPipe, - _ => { - rtdebug!("uverr.code %u", uverr.code as uint); + err => { + rtdebug!("uverr.code %d", err as int); // XXX: Need to map remaining uv error types OtherIoError } @@ -282,30 +274,13 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError { } /// Given a uv handle, convert a callback status to a UvError -pub fn status_to_maybe_uv_error_with_loop( - loop_: *uvll::uv_loop_t, - status: c_int) -> Option { - if status != -1 { +pub fn status_to_maybe_uv_error>( + handle: U, status: c_int) -> Option +{ + if status >= 0 { None } else { - unsafe { - rtdebug!("loop: %x", loop_ as uint); - let err = uvll::last_error(loop_); - Some(UvError(err)) - } - } -} -/// Given a uv handle, convert a callback status to a UvError -pub fn status_to_maybe_uv_error>(handle: U, - status: c_int) -> Option { - if status != -1 { - None - } else { - unsafe { - rtdebug!("handle: %x", handle.native_handle() as uint); - let loop_ = uvll::get_loop_for_uv_handle(handle.native_handle()); - status_to_maybe_uv_error_with_loop(loop_, status) - } + Some(UvError(status)) } } diff --git a/src/libstd/rt/uv/net.rs b/src/libstd/rt/uv/net.rs index e8d0296e543..bb3a00ca243 100644 --- a/src/libstd/rt/uv/net.rs +++ b/src/libstd/rt/uv/net.rs @@ -16,7 +16,6 @@ use rt::uv::{AllocCallback, ConnectionCallback, ReadCallback, UdpReceiveCallback use rt::uv::{Loop, Watcher, Request, UvError, Buf, NativeHandle, NullCallback, status_to_maybe_uv_error}; use rt::io::net::ip::{SocketAddr, Ipv4Addr, Ipv6Addr}; -use rt::uv::last_uv_error; use vec; use str; use from_str::{FromStr}; @@ -232,7 +231,7 @@ impl TcpWatcher { }; match result { 0 => Ok(()), - _ => Err(last_uv_error(self)), + _ => Err(UvError(result)), } } } @@ -327,7 +326,7 @@ impl UdpWatcher { }; match result { 0 => Ok(()), - _ => Err(last_uv_error(self)), + _ => Err(UvError(result)), } } } diff --git a/src/libstd/rt/uv/uvll.rs b/src/libstd/rt/uv/uvll.rs index 1e189e90885..00c2974cb54 100644 --- a/src/libstd/rt/uv/uvll.rs +++ b/src/libstd/rt/uv/uvll.rs @@ -37,21 +37,34 @@ use libc::{malloc, free}; use libc; use prelude::*; use ptr; -use str; use vec; -pub static UNKNOWN: c_int = -1; -pub static OK: c_int = 0; -pub static EOF: c_int = 1; -pub static EADDRINFO: c_int = 2; -pub static EACCES: c_int = 3; -pub static ECONNREFUSED: c_int = 12; -pub static ECONNRESET: c_int = 13; -pub static EPIPE: c_int = 36; +pub use self::errors::*; -pub struct uv_err_t { - code: c_int, - sys_errno_: c_int +pub static OK: c_int = 0; +pub static EOF: c_int = -4095; +pub static UNKNOWN: c_int = -4094; + +// uv-errno.h redefines error codes for windows, but not for unix... + +#[cfg(windows)] +pub mod errors { + use libc::c_int; + + pub static EACCES: c_int = -4093; + pub static ECONNREFUSED: c_int = -4079; + pub static ECONNRESET: c_int = -4078; + pub static EPIPE: c_int = -4048; +} +#[cfg(not(windows))] +pub mod errors { + use libc; + use libc::c_int; + + pub static EACCES: c_int = -libc::EACCES; + pub static ECONNREFUSED: c_int = -libc::ECONNREFUSED; + pub static ECONNRESET: c_int = -libc::ECONNRESET; + pub static EPIPE: c_int = -libc::EPIPE; } pub struct uv_buf_t { @@ -487,20 +500,12 @@ pub unsafe fn read_stop(stream: *uv_stream_t) -> c_int { return rust_uv_read_stop(stream as *c_void); } -pub unsafe fn last_error(loop_handle: *c_void) -> uv_err_t { +pub unsafe fn strerror(err: c_int) -> *c_char { #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_last_error(loop_handle); -} - -pub unsafe fn strerror(err: *uv_err_t) -> *c_char { - #[fixed_stack_segment]; #[inline(never)]; - return rust_uv_strerror(err); } -pub unsafe fn err_name(err: *uv_err_t) -> *c_char { +pub unsafe fn err_name(err: c_int) -> *c_char { #[fixed_stack_segment]; #[inline(never)]; - return rust_uv_err_name(err); } @@ -720,22 +725,6 @@ pub unsafe fn get_len_from_buf(buf: uv_buf_t) -> size_t { return rust_uv_get_len_from_buf(buf); } -pub unsafe fn get_last_err_info(uv_loop: *c_void) -> ~str { - let err = last_error(uv_loop); - let err_ptr = ptr::to_unsafe_ptr(&err); - let err_name = str::raw::from_c_str(err_name(err_ptr)); - let err_msg = str::raw::from_c_str(strerror(err_ptr)); - return fmt!("LIBUV ERROR: name: %s msg: %s", - err_name, err_msg); -} - -pub unsafe fn get_last_err_data(uv_loop: *c_void) -> uv_err_data { - let err = last_error(uv_loop); - let err_ptr = ptr::to_unsafe_ptr(&err); - let err_name = str::raw::from_c_str(err_name(err_ptr)); - let err_msg = str::raw::from_c_str(strerror(err_ptr)); - uv_err_data { err_name: err_name, err_msg: err_msg } -} pub struct uv_err_data { err_name: ~str, @@ -768,9 +757,8 @@ extern { cb: uv_async_cb) -> c_int; fn rust_uv_tcp_init(loop_handle: *c_void, handle_ptr: *uv_tcp_t) -> c_int; fn rust_uv_buf_init(out_buf: *uv_buf_t, base: *u8, len: size_t); - fn rust_uv_last_error(loop_handle: *c_void) -> uv_err_t; - fn rust_uv_strerror(err: *uv_err_t) -> *c_char; - fn rust_uv_err_name(err: *uv_err_t) -> *c_char; + fn rust_uv_strerror(err: c_int) -> *c_char; + fn rust_uv_err_name(err: c_int) -> *c_char; fn rust_uv_ip4_addrp(ip: *u8, port: c_int) -> *sockaddr_in; fn rust_uv_ip6_addrp(ip: *u8, port: c_int) -> *sockaddr_in6; fn rust_uv_free_ip4_addr(addr: *sockaddr_in); diff --git a/src/libuv b/src/libuv index dfae9c3e958..fb2fc332dc2 160000 --- a/src/libuv +++ b/src/libuv @@ -1 +1 @@ -Subproject commit dfae9c3e958dc086d9c0ab068cd76d196c95a433 +Subproject commit fb2fc332dc2bce0c72818a45f3b8c6824d5e046e diff --git a/src/rt/rust_uv.cpp b/src/rt/rust_uv.cpp index 8ef4572f810..23b97a43655 100644 --- a/src/rt/rust_uv.cpp +++ b/src/rt/rust_uv.cpp @@ -329,20 +329,13 @@ rust_uv_get_len_from_buf(uv_buf_t buf) { return buf.len; } -extern "C" uv_err_t -rust_uv_last_error(uv_loop_t* loop) { - return uv_last_error(loop); -} - extern "C" const char* -rust_uv_strerror(uv_err_t* err_ptr) { - uv_err_t err = *err_ptr; +rust_uv_strerror(int err) { return uv_strerror(err); } extern "C" const char* -rust_uv_err_name(uv_err_t* err_ptr) { - uv_err_t err = *err_ptr; +rust_uv_err_name(int err) { return uv_err_name(err); } diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index b668d394406..edc9f494615 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -47,7 +47,6 @@ rust_uv_timer_start rust_uv_timer_stop rust_uv_tcp_init rust_uv_buf_init -rust_uv_last_error rust_uv_strerror rust_uv_err_name rust_uv_ip4_addr @@ -191,4 +190,4 @@ rust_drop_global_args_lock rust_take_change_dir_lock rust_drop_change_dir_lock rust_get_test_int -rust_get_task \ No newline at end of file +rust_get_task