From 554dc63328deb35ccbde1aadc6d776200fbc317f Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 6 Sep 2011 00:24:39 +0200 Subject: [PATCH] uv: upgrade to 58ef43e --- deps/uv/config-unix.mk | 2 +- deps/uv/include/uv.h | 1 + deps/uv/src/unix/core.c | 24 ------------- deps/uv/src/unix/error.c | 7 +++- deps/uv/src/unix/fs.c | 13 +++---- deps/uv/src/unix/internal.h | 27 +++++++++++++++ deps/uv/src/unix/process.c | 1 + deps/uv/src/uv-common.c | 1 + deps/uv/src/uv-common.h | 6 ++-- deps/uv/src/win/fs.c | 69 ++++++++++++++++++++++++++++++------- deps/uv/test/test-fs.c | 35 +++++++++++++++++++ deps/uv/test/test-list.h | 2 ++ 12 files changed, 141 insertions(+), 47 deletions(-) diff --git a/deps/uv/config-unix.mk b/deps/uv/config-unix.mk index e77ad2fee55..7aa3a165429 100644 --- a/deps/uv/config-unix.mk +++ b/deps/uv/config-unix.mk @@ -58,7 +58,7 @@ endif ifeq (Linux,$(uname_S)) EV_CONFIG=config_linux.h EIO_CONFIG=config_linux.h -CSTDFLAG += -D_XOPEN_SOURCE=600 +CSTDFLAG += -D_GNU_SOURCE CPPFLAGS += -Isrc/ares/config_linux LINKFLAGS+=-lrt OBJS += src/unix/linux.o diff --git a/deps/uv/include/uv.h b/deps/uv/include/uv.h index bceb432d78b..5b1144ef22b 100644 --- a/deps/uv/include/uv.h +++ b/deps/uv/include/uv.h @@ -172,6 +172,7 @@ typedef enum { UV_ENOTCONN, UV_ENOTSOCK, UV_ENOTSUP, + UV_ENOENT, UV_EPIPE, UV_EPROTO, UV_EPROTONOSUPPORT, diff --git a/deps/uv/src/unix/core.c b/deps/uv/src/unix/core.c index a016d1b36a6..4d713c295bc 100644 --- a/deps/uv/src/unix/core.c +++ b/deps/uv/src/unix/core.c @@ -18,10 +18,6 @@ * IN THE SOFTWARE. */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE /* O_CLOEXEC, accept4(), etc. */ -#endif - #include "uv.h" #include "unix/internal.h" @@ -42,26 +38,6 @@ #include /* PATH_MAX */ #include /* writev */ -#if defined(__linux__) - -#include -#include - -#undef HAVE_PIPE2 -#undef HAVE_ACCEPT4 - -/* pipe2() requires linux >= 2.6.27 and glibc >= 2.9 */ -#if LINUX_VERSION_CODE >= 0x2061B && __GLIBC_PREREQ(2, 9) -#define HAVE_PIPE2 -#endif - -/* accept4() requires linux >= 2.6.28 and glib >= 2.10 */ -#if LINUX_VERSION_CODE >= 0x2061C && __GLIBC_PREREQ(2, 10) -#define HAVE_ACCEPT4 -#endif - -#endif /* __linux__ */ - #ifdef __sun # include # include diff --git a/deps/uv/src/unix/error.c b/deps/uv/src/unix/error.c index b19aa577c82..96615f36c62 100644 --- a/deps/uv/src/unix/error.c +++ b/deps/uv/src/unix/error.c @@ -31,6 +31,7 @@ #include #include #include +#include /* TODO Expose callback to user to handle fatal error like V8 does. */ @@ -65,9 +66,10 @@ char* uv_strerror(uv_err_t err) { } -static uv_err_code uv_translate_sys_error(int sys_errno) { +uv_err_code uv_translate_sys_error(int sys_errno) { switch (sys_errno) { case 0: return UV_OK; + case ENOENT: return UV_ENOENT; case EACCES: return UV_EACCESS; case EBADF: return UV_EBADF; case EPIPE: return UV_EPIPE; @@ -83,6 +85,9 @@ static uv_err_code uv_translate_sys_error(int sys_errno) { case ENOTCONN: return UV_ENOTCONN; default: return UV_UNKNOWN; } + + assert(0 && "unreachable"); + return -1; } diff --git a/deps/uv/src/unix/fs.c b/deps/uv/src/unix/fs.c index e0dc47d78cb..506367cdee5 100644 --- a/deps/uv/src/unix/fs.c +++ b/deps/uv/src/unix/fs.c @@ -32,6 +32,7 @@ #include #include #include +#include #define ARGS1(a) (a) @@ -43,12 +44,12 @@ uv_fs_req_init(loop, req, type, path, cb); \ if (cb) { \ /* async */ \ - uv_ref(loop); \ req->eio = eiofunc(args, EIO_PRI_DEFAULT, uv__fs_after, req); \ if (!req->eio) { \ uv_err_new(loop, ENOMEM); \ return -1; \ } \ + uv_ref(loop); \ } else { \ /* sync */ \ req->result = func(args); \ @@ -61,7 +62,7 @@ static void uv_fs_req_init(uv_loop_t* loop, uv_fs_t* req, uv_fs_type fs_type, - char* path, uv_fs_cb cb) { + const char* path, uv_fs_cb cb) { /* Make sure the thread pool is initialized. */ uv_eio_init(loop); @@ -110,7 +111,7 @@ static int uv__fs_after(eio_req* eio) { assert(req->cb); req->result = req->eio->result; - req->errorno = req->eio->errorno; + req->errorno = uv_translate_sys_error(req->eio->errorno); switch (req->fs_type) { case UV_FS_READDIR: @@ -344,7 +345,7 @@ int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { - char* pathdup = path; + char* pathdup; int pathlen; uv_fs_req_init(loop, req, UV_FS_STAT, path, cb); @@ -479,7 +480,7 @@ int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file file, double atime, int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { - char* pathdup = path; + char* pathdup; int pathlen; uv_fs_req_init(loop, req, UV_FS_LSTAT, path, cb); @@ -538,7 +539,7 @@ int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req, const char* path, int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { - size_t size; + ssize_t size; int status; char* buf; diff --git a/deps/uv/src/unix/internal.h b/deps/uv/src/unix/internal.h index 6e5be7da03b..024a9b377a1 100644 --- a/deps/uv/src/unix/internal.h +++ b/deps/uv/src/unix/internal.h @@ -25,6 +25,32 @@ #include "uv-common.h" #include "uv-eio.h" +#if defined(__linux__) + +#include +#include + +#undef HAVE_FUTIMES +#undef HAVE_PIPE2 +#undef HAVE_ACCEPT4 + +/* futimes() requires linux >= 2.6.22 and glib >= 2.6 */ +#if LINUX_VERSION_CODE >= 0x20616 && __GLIBC_PREREQ(2, 6) +#define HAVE_FUTIMES +#endif + +/* pipe2() requires linux >= 2.6.27 and glibc >= 2.9 */ +#if LINUX_VERSION_CODE >= 0x2061B && __GLIBC_PREREQ(2, 9) +#define HAVE_PIPE2 +#endif + +/* accept4() requires linux >= 2.6.28 and glib >= 2.10 */ +#if LINUX_VERSION_CODE >= 0x2061C && __GLIBC_PREREQ(2, 10) +#define HAVE_ACCEPT4 +#endif + +#endif /* __linux__ */ + /* flags */ enum { UV_CLOSING = 0x00000001, /* uv_close() called but not finished. */ @@ -48,6 +74,7 @@ int uv__cloexec(int fd, int set) __attribute__((unused)); int uv__socket(int domain, int type, int protocol); /* error */ +uv_err_code uv_translate_sys_error(int sys_errno); uv_err_t uv_err_new(uv_loop_t* loop, int sys_error); uv_err_t uv_err_new_artificial(uv_loop_t* loop, int code); void uv_fatal_error(const int errorno, const char* syscall); diff --git a/deps/uv/src/unix/process.c b/deps/uv/src/unix/process.c index 349e0da6fb6..bbd24f450b7 100644 --- a/deps/uv/src/unix/process.c +++ b/deps/uv/src/unix/process.c @@ -26,6 +26,7 @@ #include #include #include +#include /* O_CLOEXEC, O_NONBLOCK */ #include #include #include diff --git a/deps/uv/src/uv-common.c b/deps/uv/src/uv-common.c index 8e85db27ac0..ec31688fc8f 100644 --- a/deps/uv/src/uv-common.c +++ b/deps/uv/src/uv-common.c @@ -81,6 +81,7 @@ const char* uv_err_name(uv_err_t err) { case UV_ENOTCONN: return "ENOTCONN"; case UV_ENOTSOCK: return "ENOTSOCK"; case UV_ENOTSUP: return "ENOTSUP"; + case UV_ENOENT: return "ENOENT"; case UV_EPIPE: return "EPIPE"; case UV_EPROTO: return "EPROTO"; case UV_EPROTONOSUPPORT: return "EPROTONOSUPPORT"; diff --git a/deps/uv/src/uv-common.h b/deps/uv/src/uv-common.h index 985412d7936..212fc94ab21 100644 --- a/deps/uv/src/uv-common.h +++ b/deps/uv/src/uv-common.h @@ -32,9 +32,9 @@ #define COUNTOF(a) (sizeof(a) / sizeof(a[0])) /* Used for the uv_fs_ functions */ -#define SET_REQ_RESULT(req, result) \ - req->result = result; \ - if (result == -1) { \ +#define SET_REQ_RESULT(req, result_value) \ + req->result = (result_value); \ + if (req->result == -1) { \ req->errorno = errno; \ } diff --git a/deps/uv/src/win/fs.c b/deps/uv/src/win/fs.c index 71ae451fa5f..885520c5331 100644 --- a/deps/uv/src/win/fs.c +++ b/deps/uv/src/win/fs.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -239,33 +240,77 @@ void fs__close(uv_fs_t* req, uv_file file) { void fs__read(uv_fs_t* req, uv_file file, void *buf, size_t length, off_t offset) { - int result = 0; + HANDLE handle; + OVERLAPPED overlapped, *overlapped_ptr; + LARGE_INTEGER offset_; + DWORD bytes; + + handle = (HANDLE) _get_osfhandle(file); + if (handle == INVALID_HANDLE_VALUE) { + SET_REQ_RESULT(req, -1); + return; + } + + if (length > INT_MAX) { + SET_REQ_ERROR(req, ERROR_INSUFFICIENT_BUFFER); + return; + } if (offset != -1) { - result = _lseek(file, offset, SEEK_SET); + memset(&overlapped, 0, sizeof overlapped); + + offset_.QuadPart = offset; + overlapped.Offset = offset_.LowPart; + overlapped.OffsetHigh = offset_.HighPart; + + overlapped_ptr = &overlapped; + } else { + overlapped_ptr = NULL; } - if (result != -1) { - result = _read(file, buf, length); + if (ReadFile(handle, buf, length, &bytes, overlapped_ptr)) { + SET_REQ_RESULT(req, bytes); + } else { + SET_REQ_ERROR(req, GetLastError()); } - - SET_REQ_RESULT(req, result); } void fs__write(uv_fs_t* req, uv_file file, void *buf, size_t length, off_t offset) { - int result = 0; + HANDLE handle; + OVERLAPPED overlapped, *overlapped_ptr; + LARGE_INTEGER offset_; + DWORD bytes; + + handle = (HANDLE) _get_osfhandle(file); + if (handle == INVALID_HANDLE_VALUE) { + SET_REQ_RESULT(req, -1); + return; + } + + if (length > INT_MAX) { + SET_REQ_ERROR(req, ERROR_INSUFFICIENT_BUFFER); + return; + } if (offset != -1) { - result = _lseek(file, offset, SEEK_SET); + memset(&overlapped, 0, sizeof overlapped); + + offset_.QuadPart = offset; + overlapped.Offset = offset_.LowPart; + overlapped.OffsetHigh = offset_.HighPart; + + overlapped_ptr = &overlapped; + } else { + overlapped_ptr = NULL; } - if (result != -1) { - result = _write(file, buf, length); + if (WriteFile(handle, buf, length, &bytes, overlapped_ptr)) { + SET_REQ_RESULT(req, bytes); + } else { + SET_REQ_ERROR(req, GetLastError()); } - - SET_REQ_RESULT(req, result); } diff --git a/deps/uv/test/test-fs.c b/deps/uv/test/test-fs.c index ef3b3b9e6ab..c3712def711 100644 --- a/deps/uv/test/test-fs.c +++ b/deps/uv/test/test-fs.c @@ -360,6 +360,41 @@ static void sendfile_cb(uv_fs_t* req) { } +static void open_noent_cb(uv_fs_t* req) { + ASSERT(req->fs_type == UV_FS_OPEN); + ASSERT(req->errorno == UV_ENOENT); + ASSERT(req->result == -1); + open_cb_count++; + uv_fs_req_cleanup(req); +} + + +TEST_IMPL(fs_file_noent) { + uv_fs_t req; + int r; + + uv_init(); + loop = uv_default_loop(); + + r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, NULL); + ASSERT(r == -1); + ASSERT(req.result == -1); + ASSERT(uv_last_error(loop).code == UV_ENOENT); + uv_fs_req_cleanup(&req); + + r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, open_noent_cb); + ASSERT(r == 0); + + ASSERT(open_cb_count == 0); + uv_run(loop); + ASSERT(open_cb_count == 1); + + /* TODO add EACCES test */ + + return 0; +} + + TEST_IMPL(fs_file_async) { int r; diff --git a/deps/uv/test/test-list.h b/deps/uv/test/test-list.h index fe8f1ed0b02..9d4a57f6949 100644 --- a/deps/uv/test/test-list.h +++ b/deps/uv/test/test-list.h @@ -72,6 +72,7 @@ TEST_DECLARE (spawn_exit_code) TEST_DECLARE (spawn_stdout) TEST_DECLARE (spawn_stdin) TEST_DECLARE (spawn_and_kill) +TEST_DECLARE (fs_file_noent) TEST_DECLARE (fs_file_async) TEST_DECLARE (fs_file_sync) TEST_DECLARE (fs_async_dir) @@ -180,6 +181,7 @@ TASK_LIST_START TEST_ENTRY (environment_creation) #endif + TEST_ENTRY (fs_file_noent) TEST_ENTRY (fs_file_async) TEST_ENTRY (fs_file_sync) TEST_ENTRY (fs_async_dir)