Skip to content

Commit ed20425

Browse files
committed
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
1 parent 578e680 commit ed20425

File tree

9 files changed

+75
-104
lines changed

9 files changed

+75
-104
lines changed

Diff for: .gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
branch = master
55
[submodule "src/libuv"]
66
path = src/libuv
7-
url = https://github.com/brson/libuv.git
7+
url = https://github.com/alexcrichton/libuv.git
88
branch = master

Diff for: mk/rt.mk

+25-8
Original file line numberDiff line numberDiff line change
@@ -163,34 +163,44 @@ LIBUV_DEPS := $$(wildcard \
163163
$$(S)src/libuv/*/*/*/*)
164164
endif
165165

166+
LIBUV_GYP := $$(S)src/libuv/build/gyp
167+
LIBUV_MAKEFILE := $$(S)src/libuv/out/Makefile
168+
LIBUV_NO_LOAD = run-benchmarks.target.mk run-tests.target.mk \
169+
uv_dtrace_header.target.mk uv_dtrace_provider.target.mk
170+
166171
# XXX: Shouldn't need platform-specific conditions here
167172
ifdef CFG_WINDOWSY_$(1)
168-
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
173+
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) $$(LIBUV_MAKEFILE)
169174
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
170-
builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
175+
builddir="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
171176
OS=mingw \
177+
BUILDTYPE=Release \
178+
NO_LOAD="$$(LIBUV_NO_LOAD)" \
172179
V=$$(VERBOSE)
173180
else ifeq ($(OSTYPE_$(1)), linux-androideabi)
174-
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
181+
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) $$(LIBUV_MAKEFILE)
175182
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
176183
CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
177184
LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
178185
CC="$$(CC_$(1))" \
179186
CXX="$$(CXX_$(1))" \
180187
AR="$$(AR_$(1))" \
181-
BUILDTYPE=Release \
182-
builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
188+
builddir="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
183189
host=android OS=linux \
190+
BUILDTYPE=Release \
191+
NO_LOAD="$$(LIBUV_NO_LOAD)" \
184192
V=$$(VERBOSE)
185193
else
186-
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
187-
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
194+
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) $$(LIBUV_MAKEFILE)
195+
$$(Q)$$(MAKE) -C $$(S)src/libuv/out \
188196
CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
189197
LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
190198
CC="$$(CC_$(1))" \
191199
CXX="$$(CXX_$(1))" \
192200
AR="$$(AR_$(1))" \
193-
builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
201+
builddir="$$(CFG_BUILD_DIR)/rt/$(1)/stage$(2)/libuv" \
202+
BUILDTYPE=Release \
203+
NO_LOAD="$$(LIBUV_NO_LOAD)" \
194204
V=$$(VERBOSE)
195205
endif
196206

@@ -250,6 +260,13 @@ endif
250260

251261
endef
252262

263+
$(LIBUV_GYP):
264+
mkdir -p $(S)src/libuv/build
265+
git clone https://git.chromium.org/external/gyp.git $(S)src/libuv/build/gyp
266+
267+
$(LIBUV_MAKEFILE): $(LIBUV_GYP)
268+
(cd $(S)src/libuv/ && ./gyp_uv -f make)
269+
253270
# Instantiate template for all stages
254271
$(foreach stage,$(STAGES), \
255272
$(foreach target,$(CFG_TARGET_TRIPLES), \

Diff for: src/libstd/rt/io/net/tcp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ mod test {
166166
do run_in_newsched_task {
167167
let mut called = false;
168168
do io_error::cond.trap(|e| {
169-
assert!(e.kind == ConnectionRefused);
169+
assert_eq!(e.kind, ConnectionRefused);
170170
called = true;
171171
}).inside {
172172
let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 };

Diff for: src/libstd/rt/uv/mod.rs

+14-39
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ impl<H, W: Watcher + NativeHandle<*H>> WatcherInterop for W {
202202
// XXX: Need to define the error constants like EOF so they can be
203203
// compared to the UvError type
204204

205-
pub struct UvError(uvll::uv_err_t);
205+
pub struct UvError(c_int);
206206

207207
impl UvError {
208208
pub fn name(&self) -> ~str {
209209
unsafe {
210-
let inner = match self { &UvError(ref a) => a };
210+
let inner = match self { &UvError(a) => a };
211211
let name_str = uvll::err_name(inner);
212212
assert!(name_str.is_not_null());
213213
from_c_str(name_str)
@@ -216,15 +216,15 @@ impl UvError {
216216

217217
pub fn desc(&self) -> ~str {
218218
unsafe {
219-
let inner = match self { &UvError(ref a) => a };
219+
let inner = match self { &UvError(a) => a };
220220
let desc_str = uvll::strerror(inner);
221221
assert!(desc_str.is_not_null());
222222
from_c_str(desc_str)
223223
}
224224
}
225225

226226
pub fn is_eof(&self) -> bool {
227-
self.code == uvll::EOF
227+
**self == uvll::EOF
228228
}
229229
}
230230

@@ -236,38 +236,30 @@ impl ToStr for UvError {
236236

237237
#[test]
238238
fn error_smoke_test() {
239-
let err = uvll::uv_err_t { code: 1, sys_errno_: 1 };
240-
let err: UvError = UvError(err);
239+
let err: UvError = UvError(uvll::EOF);
241240
assert_eq!(err.to_str(), ~"EOF: end of file");
242241
}
243242
244-
pub fn last_uv_error<H, W: Watcher + NativeHandle<*H>>(watcher: &W) -> UvError {
245-
unsafe {
246-
let loop_ = watcher.event_loop();
247-
UvError(uvll::last_error(loop_.native_handle()))
248-
}
249-
}
250-
251243
pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
252244
unsafe {
253245
// Importing error constants
254246
use rt::uv::uvll::*;
255247
use rt::io::*;
256248
257249
// uv error descriptions are static
258-
let c_desc = uvll::strerror(&*uverr);
250+
let c_desc = uvll::strerror(*uverr);
259251
let desc = str::raw::c_str_to_static_slice(c_desc);
260252
261-
let kind = match uverr.code {
253+
let kind = match *uverr {
262254
UNKNOWN => OtherIoError,
263255
OK => OtherIoError,
264256
EOF => EndOfFile,
265257
EACCES => PermissionDenied,
266258
ECONNREFUSED => ConnectionRefused,
267259
ECONNRESET => ConnectionReset,
268260
EPIPE => BrokenPipe,
269-
_ => {
270-
rtdebug!("uverr.code %u", uverr.code as uint);
261+
err => {
262+
rtdebug!("uverr.code %d", err as int);
271263
// XXX: Need to map remaining uv error types
272264
OtherIoError
273265
}
@@ -282,30 +274,13 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
282274
}
283275
284276
/// Given a uv handle, convert a callback status to a UvError
285-
pub fn status_to_maybe_uv_error_with_loop(
286-
loop_: *uvll::uv_loop_t,
287-
status: c_int) -> Option<UvError> {
288-
if status != -1 {
277+
pub fn status_to_maybe_uv_error<T, U: Watcher + NativeHandle<*T>>(
278+
handle: U, status: c_int) -> Option<UvError>
279+
{
280+
if status >= 0 {
289281
None
290282
} else {
291-
unsafe {
292-
rtdebug!("loop: %x", loop_ as uint);
293-
let err = uvll::last_error(loop_);
294-
Some(UvError(err))
295-
}
296-
}
297-
}
298-
/// Given a uv handle, convert a callback status to a UvError
299-
pub fn status_to_maybe_uv_error<T, U: Watcher + NativeHandle<*T>>(handle: U,
300-
status: c_int) -> Option<UvError> {
301-
if status != -1 {
302-
None
303-
} else {
304-
unsafe {
305-
rtdebug!("handle: %x", handle.native_handle() as uint);
306-
let loop_ = uvll::get_loop_for_uv_handle(handle.native_handle());
307-
status_to_maybe_uv_error_with_loop(loop_, status)
308-
}
283+
Some(UvError(status))
309284
}
310285
}
311286

Diff for: src/libstd/rt/uv/net.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rt::uv::{AllocCallback, ConnectionCallback, ReadCallback, UdpReceiveCallback
1616
use rt::uv::{Loop, Watcher, Request, UvError, Buf, NativeHandle, NullCallback,
1717
status_to_maybe_uv_error};
1818
use rt::io::net::ip::{SocketAddr, Ipv4Addr, Ipv6Addr};
19-
use rt::uv::last_uv_error;
2019
use vec;
2120
use str;
2221
use from_str::{FromStr};
@@ -232,7 +231,7 @@ impl TcpWatcher {
232231
};
233232
match result {
234233
0 => Ok(()),
235-
_ => Err(last_uv_error(self)),
234+
_ => Err(UvError(result)),
236235
}
237236
}
238237
}
@@ -327,7 +326,7 @@ impl UdpWatcher {
327326
};
328327
match result {
329328
0 => Ok(()),
330-
_ => Err(last_uv_error(self)),
329+
_ => Err(UvError(result)),
331330
}
332331
}
333332
}

Diff for: src/libstd/rt/uv/uvll.rs

+28-40
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,34 @@ use libc::{malloc, free};
3737
use libc;
3838
use prelude::*;
3939
use ptr;
40-
use str;
4140
use vec;
4241

43-
pub static UNKNOWN: c_int = -1;
42+
pub use self::errors::*;
43+
4444
pub static OK: c_int = 0;
45-
pub static EOF: c_int = 1;
46-
pub static EADDRINFO: c_int = 2;
47-
pub static EACCES: c_int = 3;
48-
pub static ECONNREFUSED: c_int = 12;
49-
pub static ECONNRESET: c_int = 13;
50-
pub static EPIPE: c_int = 36;
45+
pub static EOF: c_int = -4095;
46+
pub static UNKNOWN: c_int = -4094;
47+
48+
// uv-errno.h redefines error codes for windows, but not for unix...
5149

52-
pub struct uv_err_t {
53-
code: c_int,
54-
sys_errno_: c_int
50+
#[cfg(windows)]
51+
pub mod errors {
52+
use libc::c_int;
53+
54+
pub static EACCES: c_int = -4093;
55+
pub static ECONNREFUSED: c_int = -4079;
56+
pub static ECONNRESET: c_int = -4078;
57+
pub static EPIPE: c_int = -4048;
58+
}
59+
#[cfg(not(windows))]
60+
pub mod errors {
61+
use libc;
62+
use libc::c_int;
63+
64+
pub static EACCES: c_int = -libc::EACCES;
65+
pub static ECONNREFUSED: c_int = -libc::ECONNREFUSED;
66+
pub static ECONNRESET: c_int = -libc::ECONNRESET;
67+
pub static EPIPE: c_int = -libc::EPIPE;
5568
}
5669

5770
pub struct uv_buf_t {
@@ -487,20 +500,12 @@ pub unsafe fn read_stop(stream: *uv_stream_t) -> c_int {
487500
return rust_uv_read_stop(stream as *c_void);
488501
}
489502

490-
pub unsafe fn last_error(loop_handle: *c_void) -> uv_err_t {
491-
#[fixed_stack_segment]; #[inline(never)];
492-
493-
return rust_uv_last_error(loop_handle);
494-
}
495-
496-
pub unsafe fn strerror(err: *uv_err_t) -> *c_char {
503+
pub unsafe fn strerror(err: c_int) -> *c_char {
497504
#[fixed_stack_segment]; #[inline(never)];
498-
499505
return rust_uv_strerror(err);
500506
}
501-
pub unsafe fn err_name(err: *uv_err_t) -> *c_char {
507+
pub unsafe fn err_name(err: c_int) -> *c_char {
502508
#[fixed_stack_segment]; #[inline(never)];
503-
504509
return rust_uv_err_name(err);
505510
}
506511

@@ -720,22 +725,6 @@ pub unsafe fn get_len_from_buf(buf: uv_buf_t) -> size_t {
720725

721726
return rust_uv_get_len_from_buf(buf);
722727
}
723-
pub unsafe fn get_last_err_info(uv_loop: *c_void) -> ~str {
724-
let err = last_error(uv_loop);
725-
let err_ptr = ptr::to_unsafe_ptr(&err);
726-
let err_name = str::raw::from_c_str(err_name(err_ptr));
727-
let err_msg = str::raw::from_c_str(strerror(err_ptr));
728-
return fmt!("LIBUV ERROR: name: %s msg: %s",
729-
err_name, err_msg);
730-
}
731-
732-
pub unsafe fn get_last_err_data(uv_loop: *c_void) -> uv_err_data {
733-
let err = last_error(uv_loop);
734-
let err_ptr = ptr::to_unsafe_ptr(&err);
735-
let err_name = str::raw::from_c_str(err_name(err_ptr));
736-
let err_msg = str::raw::from_c_str(strerror(err_ptr));
737-
uv_err_data { err_name: err_name, err_msg: err_msg }
738-
}
739728

740729
pub struct uv_err_data {
741730
err_name: ~str,
@@ -768,9 +757,8 @@ extern {
768757
cb: uv_async_cb) -> c_int;
769758
fn rust_uv_tcp_init(loop_handle: *c_void, handle_ptr: *uv_tcp_t) -> c_int;
770759
fn rust_uv_buf_init(out_buf: *uv_buf_t, base: *u8, len: size_t);
771-
fn rust_uv_last_error(loop_handle: *c_void) -> uv_err_t;
772-
fn rust_uv_strerror(err: *uv_err_t) -> *c_char;
773-
fn rust_uv_err_name(err: *uv_err_t) -> *c_char;
760+
fn rust_uv_strerror(err: c_int) -> *c_char;
761+
fn rust_uv_err_name(err: c_int) -> *c_char;
774762
fn rust_uv_ip4_addrp(ip: *u8, port: c_int) -> *sockaddr_in;
775763
fn rust_uv_ip6_addrp(ip: *u8, port: c_int) -> *sockaddr_in6;
776764
fn rust_uv_free_ip4_addr(addr: *sockaddr_in);

Diff for: src/libuv

Submodule libuv updated 168 files

Diff for: src/rt/rust_uv.cpp

+2-9
Original file line numberDiff line numberDiff line change
@@ -329,20 +329,13 @@ rust_uv_get_len_from_buf(uv_buf_t buf) {
329329
return buf.len;
330330
}
331331

332-
extern "C" uv_err_t
333-
rust_uv_last_error(uv_loop_t* loop) {
334-
return uv_last_error(loop);
335-
}
336-
337332
extern "C" const char*
338-
rust_uv_strerror(uv_err_t* err_ptr) {
339-
uv_err_t err = *err_ptr;
333+
rust_uv_strerror(int err) {
340334
return uv_strerror(err);
341335
}
342336

343337
extern "C" const char*
344-
rust_uv_err_name(uv_err_t* err_ptr) {
345-
uv_err_t err = *err_ptr;
338+
rust_uv_err_name(int err) {
346339
return uv_err_name(err);
347340
}
348341

Diff for: src/rt/rustrt.def.in

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ rust_uv_timer_start
4747
rust_uv_timer_stop
4848
rust_uv_tcp_init
4949
rust_uv_buf_init
50-
rust_uv_last_error
5150
rust_uv_strerror
5251
rust_uv_err_name
5352
rust_uv_ip4_addr
@@ -191,4 +190,4 @@ rust_drop_global_args_lock
191190
rust_take_change_dir_lock
192191
rust_drop_change_dir_lock
193192
rust_get_test_int
194-
rust_get_task
193+
rust_get_task

0 commit comments

Comments
 (0)