Browse Source

Upgrade libuv to 7738306

v0.7.4-release
Ryan Dahl 13 years ago
parent
commit
9b2335a356
  1. 4
      deps/uv/include/uv-private/uv-win.h
  2. 4
      deps/uv/include/uv.h
  3. 8
      deps/uv/src/unix/cygwin.c
  4. 8
      deps/uv/src/unix/darwin.c
  5. 8
      deps/uv/src/unix/freebsd.c
  6. 3
      deps/uv/src/unix/fs.c
  7. 8
      deps/uv/src/unix/linux.c
  8. 8
      deps/uv/src/unix/netbsd.c
  9. 8
      deps/uv/src/unix/openbsd.c
  10. 8
      deps/uv/src/unix/sunos.c
  11. 42
      deps/uv/src/win/internal.h
  12. 9
      deps/uv/src/win/pipe.c
  13. 1
      deps/uv/src/win/tcp.c
  14. 160
      deps/uv/src/win/tty.c
  15. 8
      deps/uv/src/win/util.c
  16. 6
      deps/uv/test/test-get-memory.c

4
deps/uv/include/uv-private/uv-win.h

@ -313,7 +313,9 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
/* ansi parser state */ \ /* ansi parser state */ \
unsigned char ansi_parser_state; \ unsigned char ansi_parser_state; \
unsigned char ansi_csi_argc; \ unsigned char ansi_csi_argc; \
unsigned short ansi_csi_argv[4]; unsigned short ansi_csi_argv[4]; \
COORD saved_position; \
WORD saved_attributes;
#define UV_TIMER_PRIVATE_FIELDS \ #define UV_TIMER_PRIVATE_FIELDS \
RB_ENTRY(uv_timer_s) tree_entry; \ RB_ENTRY(uv_timer_s) tree_entry; \

4
deps/uv/include/uv.h

@ -1127,8 +1127,8 @@ int uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size);
int uv_exepath(char* buffer, size_t* size); int uv_exepath(char* buffer, size_t* size);
/* Gets memory info in bytes */ /* Gets memory info in bytes */
double uv_get_free_memory(void); uint64_t uv_get_free_memory(void);
double uv_get_total_memory(void); uint64_t uv_get_total_memory(void);
/* /*
* Returns the current high-resolution real time. This is expressed in * Returns the current high-resolution real time. This is expressed in

8
deps/uv/src/unix/cygwin.c

@ -58,12 +58,12 @@ int uv_exepath(char* buffer, size_t* size) {
return 0; return 0;
} }
double uv_get_free_memory(void) { uint64_t uv_get_free_memory(void) {
return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES); return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES);
} }
double uv_get_total_memory(void) { uint64_t uv_get_total_memory(void) {
return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES); return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES);
} }
int uv_fs_event_init(uv_loop_t* loop, int uv_fs_event_init(uv_loop_t* loop,

8
deps/uv/src/unix/darwin.c

@ -71,7 +71,7 @@ int uv_exepath(char* buffer, size_t* size) {
return 0; return 0;
} }
double uv_get_free_memory(void) { uint64_t uv_get_free_memory(void) {
vm_statistics_data_t info; vm_statistics_data_t info;
mach_msg_type_number_t count = sizeof(info) / sizeof(integer_t); mach_msg_type_number_t count = sizeof(info) / sizeof(integer_t);
@ -80,10 +80,10 @@ double uv_get_free_memory(void) {
return -1; return -1;
} }
return (double) info.free_count * sysconf(_SC_PAGESIZE); return (uint64_t) info.free_count * sysconf(_SC_PAGESIZE);
} }
double uv_get_total_memory(void) { uint64_t uv_get_total_memory(void) {
uint64_t info; uint64_t info;
int which[] = {CTL_HW, HW_MEMSIZE}; int which[] = {CTL_HW, HW_MEMSIZE};
size_t size = sizeof(info); size_t size = sizeof(info);
@ -92,7 +92,7 @@ double uv_get_total_memory(void) {
return -1; return -1;
} }
return (double) info; return (uint64_t) info;
} }
void uv_loadavg(double avg[3]) { void uv_loadavg(double avg[3]) {

8
deps/uv/src/unix/freebsd.c

@ -70,7 +70,7 @@ int uv_exepath(char* buffer, size_t* size) {
return 0; return 0;
} }
double uv_get_free_memory(void) { uint64_t uv_get_free_memory(void) {
int freecount; int freecount;
size_t size = sizeof(freecount); size_t size = sizeof(freecount);
@ -78,11 +78,11 @@ double uv_get_free_memory(void) {
&freecount, &size, NULL, 0) == -1){ &freecount, &size, NULL, 0) == -1){
return -1; return -1;
} }
return (double) freecount * sysconf(_SC_PAGESIZE); return (uint64_t) freecount * sysconf(_SC_PAGESIZE);
} }
double uv_get_total_memory(void) { uint64_t uv_get_total_memory(void) {
unsigned long info; unsigned long info;
int which[] = {CTL_HW, HW_PHYSMEM}; int which[] = {CTL_HW, HW_PHYSMEM};
@ -92,7 +92,7 @@ double uv_get_total_memory(void) {
return -1; return -1;
} }
return (double) info; return (uint64_t) info;
} }
void uv_loadavg(double avg[3]) { void uv_loadavg(double avg[3]) {

3
deps/uv/src/unix/fs.c

@ -593,11 +593,8 @@ 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, int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
uv_fs_cb cb) { uv_fs_cb cb) {
ssize_t size; ssize_t size;
int status;
char* buf; char* buf;
status = -1;
uv_fs_req_init(loop, req, UV_FS_READLINK, path, cb); uv_fs_req_init(loop, req, UV_FS_READLINK, path, cb);
if (cb) { if (cb) {

8
deps/uv/src/unix/linux.c

@ -75,12 +75,12 @@ int uv_exepath(char* buffer, size_t* size) {
return 0; return 0;
} }
double uv_get_free_memory(void) { uint64_t uv_get_free_memory(void) {
return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES); return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES);
} }
double uv_get_total_memory(void) { uint64_t uv_get_total_memory(void) {
return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES); return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES);
} }
static int new_inotify_fd(void) { static int new_inotify_fd(void) {

8
deps/uv/src/unix/netbsd.c

@ -82,7 +82,7 @@ int uv_exepath(char* buffer, size_t* size) {
return 0; return 0;
} }
double uv_get_free_memory(void) { uint64_t uv_get_free_memory(void) {
struct uvmexp info; struct uvmexp info;
size_t size = sizeof(info); size_t size = sizeof(info);
int which[] = {CTL_VM, VM_UVMEXP}; int which[] = {CTL_VM, VM_UVMEXP};
@ -91,10 +91,10 @@ double uv_get_free_memory(void) {
return -1; return -1;
} }
return (double) info.free * psysconf(_SC_PAGESIZE); return (uint64_t) info.free * psysconf(_SC_PAGESIZE);
} }
double uv_get_total_memory(void) { uint64_t uv_get_total_memory(void) {
#if defined(HW_PHYSMEM64) #if defined(HW_PHYSMEM64)
uint64_t info; uint64_t info;
int which[] = {CTL_HW, HW_PHYSMEM64}; int which[] = {CTL_HW, HW_PHYSMEM64};
@ -108,5 +108,5 @@ double uv_get_total_memory(void) {
return -1; return -1;
} }
return (double) info; return (uint64_t) info;
} }

8
deps/uv/src/unix/openbsd.c

@ -98,7 +98,7 @@ out:
return status; return status;
} }
double uv_get_free_memory(void) { uint64_t uv_get_free_memory(void) {
struct uvmexp info; struct uvmexp info;
size_t size = sizeof(info); size_t size = sizeof(info);
int which[] = {CTL_VM, VM_UVMEXP}; int which[] = {CTL_VM, VM_UVMEXP};
@ -107,10 +107,10 @@ double uv_get_free_memory(void) {
return -1; return -1;
} }
return (double) info.free * sysconf(_SC_PAGESIZE); return (uint64_t) info.free * sysconf(_SC_PAGESIZE);
} }
double uv_get_total_memory(void) { uint64_t uv_get_total_memory(void) {
uint64_t info; uint64_t info;
int which[] = {CTL_HW, HW_PHYSMEM64}; int which[] = {CTL_HW, HW_PHYSMEM64};
size_t size = sizeof(info); size_t size = sizeof(info);
@ -119,5 +119,5 @@ double uv_get_total_memory(void) {
return -1; return -1;
} }
return (double) info; return (uint64_t) info;
} }

8
deps/uv/src/unix/sunos.c

@ -66,13 +66,13 @@ int uv_exepath(char* buffer, size_t* size) {
} }
double uv_get_free_memory(void) { uint64_t uv_get_free_memory(void) {
return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES); return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES);
} }
double uv_get_total_memory(void) { uint64_t uv_get_total_memory(void) {
return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES); return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES);
} }

42
deps/uv/src/win/internal.h

@ -44,28 +44,30 @@ void uv_process_timers(uv_loop_t* loop);
*/ */
/* Private uv_handle flags */ /* Private uv_handle flags */
#define UV_HANDLE_CLOSING 0x0001 #define UV_HANDLE_CLOSING 0x000001
#define UV_HANDLE_CLOSED 0x0002 #define UV_HANDLE_CLOSED 0x000002
#define UV_HANDLE_BOUND 0x0004 #define UV_HANDLE_BOUND 0x000004
#define UV_HANDLE_LISTENING 0x0008 #define UV_HANDLE_LISTENING 0x000008
#define UV_HANDLE_CONNECTION 0x0010 #define UV_HANDLE_CONNECTION 0x000010
#define UV_HANDLE_CONNECTED 0x0020 #define UV_HANDLE_CONNECTED 0x000020
#define UV_HANDLE_READING 0x0040 #define UV_HANDLE_READING 0x000040
#define UV_HANDLE_ACTIVE 0x0040 #define UV_HANDLE_ACTIVE 0x000040
#define UV_HANDLE_EOF 0x0080 #define UV_HANDLE_EOF 0x000080
#define UV_HANDLE_SHUTTING 0x0100 #define UV_HANDLE_SHUTTING 0x000100
#define UV_HANDLE_SHUT 0x0200 #define UV_HANDLE_SHUT 0x000200
#define UV_HANDLE_ENDGAME_QUEUED 0x0400 #define UV_HANDLE_ENDGAME_QUEUED 0x000400
#define UV_HANDLE_BIND_ERROR 0x1000 #define UV_HANDLE_BIND_ERROR 0x001000
#define UV_HANDLE_IPV6 0x2000 #define UV_HANDLE_IPV6 0x002000
#define UV_HANDLE_PIPESERVER 0x4000 #define UV_HANDLE_PIPESERVER 0x004000
#define UV_HANDLE_READ_PENDING 0x8000 #define UV_HANDLE_READ_PENDING 0x008000
#define UV_HANDLE_UV_ALLOCED 0x10000 #define UV_HANDLE_UV_ALLOCED 0x010000
#define UV_HANDLE_SYNC_BYPASS_IOCP 0x20000 #define UV_HANDLE_SYNC_BYPASS_IOCP 0x020000
#define UV_HANDLE_ZERO_READ 0x40000 #define UV_HANDLE_ZERO_READ 0x040000
#define UV_HANDLE_TTY_RAW 0x80000 #define UV_HANDLE_TTY_RAW 0x080000
#define UV_HANDLE_EMULATE_IOCP 0x100000 #define UV_HANDLE_EMULATE_IOCP 0x100000
#define UV_HANDLE_NON_OVERLAPPED_PIPE 0x200000 #define UV_HANDLE_NON_OVERLAPPED_PIPE 0x200000
#define UV_HANDLE_TTY_SAVED_POSITION 0x400000
#define UV_HANDLE_TTY_SAVED_ATTRIBUTES 0x800000
void uv_want_endgame(uv_loop_t* loop, uv_handle_t* handle); void uv_want_endgame(uv_loop_t* loop, uv_handle_t* handle);
void uv_process_endgames(uv_loop_t* loop); void uv_process_endgames(uv_loop_t* loop);

9
deps/uv/src/win/pipe.c

@ -949,7 +949,6 @@ static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req,
int result; int result;
uv_tcp_t* tcp_send_handle; uv_tcp_t* tcp_send_handle;
uv_write_t* ipc_header_req; uv_write_t* ipc_header_req;
DWORD written;
uv_ipc_frame_uv_stream ipc_frame; uv_ipc_frame_uv_stream ipc_frame;
if (bufcnt != 1 && (bufcnt != 0 || !send_handle)) { if (bufcnt != 1 && (bufcnt != 0 || !send_handle)) {
@ -1038,7 +1037,7 @@ static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req,
&ipc_frame, &ipc_frame,
ipc_frame.header.flags & UV_IPC_UV_STREAM ? ipc_frame.header.flags & UV_IPC_UV_STREAM ?
sizeof(ipc_frame) : sizeof(ipc_frame.header), sizeof(ipc_frame) : sizeof(ipc_frame.header),
&written, NULL,
&ipc_header_req->overlapped); &ipc_header_req->overlapped);
if (!result && GetLastError() != ERROR_IO_PENDING) { if (!result && GetLastError() != ERROR_IO_PENDING) {
uv__set_sys_error(loop, GetLastError()); uv__set_sys_error(loop, GetLastError());
@ -1047,10 +1046,11 @@ static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req,
if (result) { if (result) {
/* Request completed immediately. */ /* Request completed immediately. */
req->queued_bytes = 0; ipc_header_req->queued_bytes = 0;
} else { } else {
/* Request queued by the kernel. */ /* Request queued by the kernel. */
req->queued_bytes = written; ipc_header_req->queued_bytes = ipc_frame.header.flags & UV_IPC_UV_STREAM ?
sizeof(ipc_frame) : sizeof(ipc_frame.header);
handle->write_queue_size += req->queued_bytes; handle->write_queue_size += req->queued_bytes;
} }
@ -1332,6 +1332,7 @@ void uv_process_pipe_write_req(uv_loop_t* loop, uv_pipe_t* handle,
uv_write_t* req) { uv_write_t* req) {
assert(handle->type == UV_NAMED_PIPE); assert(handle->type == UV_NAMED_PIPE);
assert(handle->write_queue_size >= req->queued_bytes);
handle->write_queue_size -= req->queued_bytes; handle->write_queue_size -= req->queued_bytes;
if (handle->flags & UV_HANDLE_EMULATE_IOCP) { if (handle->flags & UV_HANDLE_EMULATE_IOCP) {

1
deps/uv/src/win/tcp.c

@ -847,6 +847,7 @@ void uv_process_tcp_write_req(uv_loop_t* loop, uv_tcp_t* handle,
uv_write_t* req) { uv_write_t* req) {
assert(handle->type == UV_TCP); assert(handle->type == UV_TCP);
assert(handle->write_queue_size >= req->queued_bytes);
handle->write_queue_size -= req->queued_bytes; handle->write_queue_size -= req->queued_bytes;
if (req->cb) { if (req->cb) {

160
deps/uv/src/win/tty.c

@ -898,6 +898,64 @@ static int uv_tty_move_caret(uv_tty_t* handle, int x, unsigned char x_relative,
} }
static int uv_tty_reset(uv_tty_t* handle, DWORD* error) {
const COORD origin = {0, 0};
const WORD char_attrs = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_RED;
CONSOLE_SCREEN_BUFFER_INFO info;
DWORD count, written;
if (*error != ERROR_SUCCESS) {
return -1;
}
/* Reset original text attributes. */
if (!SetConsoleTextAttribute(handle->handle, char_attrs)) {
*error = GetLastError();
return -1;
}
/* Move the cursor position to (0, 0). */
if (!SetConsoleCursorPosition(handle->handle, origin)) {
*error = GetLastError();
return -1;
}
/* Clear the screen buffer. */
retry:
if (!GetConsoleScreenBufferInfo(handle->handle, &info)) {
*error = GetLastError();
return -1;
}
count = info.dwSize.X * info.dwSize.Y;
if (!(FillConsoleOutputCharacterW(handle->handle,
L'\x20',
count,
origin,
&written) &&
FillConsoleOutputAttribute(handle->handle,
char_attrs,
written,
origin,
&written))) {
if (GetLastError() == ERROR_INVALID_PARAMETER) {
/* The console may be resized - retry */
goto retry;
} else {
*error = GetLastError();
return -1;
}
}
/* Move the virtual window up to the top. */
uv_tty_virtual_offset = 0;
uv_tty_update_virtual_window(&info);
return 0;
}
static int uv_tty_clear(uv_tty_t* handle, int dir, char entire_screen, static int uv_tty_clear(uv_tty_t* handle, int dir, char entire_screen,
DWORD* error) { DWORD* error) {
unsigned short argc = handle->ansi_csi_argc; unsigned short argc = handle->ansi_csi_argc;
@ -1084,6 +1142,76 @@ static int uv_tty_set_style(uv_tty_t* handle, DWORD* error) {
} }
static int uv_tty_save_state(uv_tty_t* handle, unsigned char save_attributes,
DWORD* error) {
CONSOLE_SCREEN_BUFFER_INFO info;
if (*error != ERROR_SUCCESS) {
return -1;
}
if (!GetConsoleScreenBufferInfo(handle->handle, &info)) {
*error = GetLastError();
return -1;
}
uv_tty_update_virtual_window(&info);
handle->saved_position.X = info.dwCursorPosition.X;
handle->saved_position.Y = info.dwCursorPosition.Y - uv_tty_virtual_offset;
handle->flags |= UV_HANDLE_TTY_SAVED_POSITION;
if (save_attributes) {
handle->saved_attributes = info.wAttributes &
(FOREGROUND_INTENSITY | BACKGROUND_INTENSITY);
handle->flags |= UV_HANDLE_TTY_SAVED_ATTRIBUTES;
}
return 0;
}
static int uv_tty_restore_state(uv_tty_t* handle,
unsigned char restore_attributes, DWORD* error) {
CONSOLE_SCREEN_BUFFER_INFO info;
WORD new_attributes;
if (*error != ERROR_SUCCESS) {
return -1;
}
if (handle->flags & UV_HANDLE_TTY_SAVED_POSITION) {
if (uv_tty_move_caret(handle,
handle->saved_position.X,
0,
handle->saved_position.Y,
0,
error) != 0) {
return -1;
}
}
if (restore_attributes &&
(handle->flags & UV_HANDLE_TTY_SAVED_ATTRIBUTES)) {
if (!GetConsoleScreenBufferInfo(handle->handle, &info)) {
*error = GetLastError();
return -1;
}
new_attributes = info.wAttributes;
new_attributes &= ~(FOREGROUND_INTENSITY | BACKGROUND_INTENSITY);
new_attributes |= handle->saved_attributes;
if (!SetConsoleTextAttribute(handle->handle, new_attributes)) {
*error = GetLastError();
return -1;
}
}
return 0;
}
static int uv_tty_write_bufs(uv_tty_t* handle, uv_buf_t bufs[], int bufcnt, static int uv_tty_write_bufs(uv_tty_t* handle, uv_buf_t bufs[], int bufcnt,
DWORD* error) { DWORD* error) {
/* We can only write 8k characters at a time. Windows can't handle */ /* We can only write 8k characters at a time. Windows can't handle */
@ -1204,6 +1332,26 @@ static int uv_tty_write_bufs(uv_tty_t* handle, uv_buf_t bufs[], int bufcnt,
/* Ignore double escape. */ /* Ignore double escape. */
continue; continue;
case 'c':
/* Full console reset. */
uv_tty_reset(handle, error);
ansi_parser_state = ANSI_NORMAL;
continue;
case '7':
/* Save the cursor position and text attributes. */
FLUSH_TEXT();
uv_tty_save_state(handle, 1, error);
ansi_parser_state = ANSI_NORMAL;
continue;
case '8':
/* Restore the cursor position and text attributes */
FLUSH_TEXT();
uv_tty_restore_state(handle, 1, error);
ansi_parser_state = ANSI_NORMAL;
continue;
default: default:
if (utf8_codepoint >= '@' && utf8_codepoint <= '_') { if (utf8_codepoint >= '@' && utf8_codepoint <= '_') {
/* Single-char control. */ /* Single-char control. */
@ -1360,6 +1508,18 @@ static int uv_tty_write_bufs(uv_tty_t* handle, uv_buf_t bufs[], int bufcnt,
FLUSH_TEXT(); FLUSH_TEXT();
uv_tty_set_style(handle, error); uv_tty_set_style(handle, error);
break; break;
case 's':
/* Save the cursor position. */
FLUSH_TEXT();
uv_tty_save_state(handle, 0, error);
break;
case 'u':
/* Restore the cursor position */
FLUSH_TEXT();
uv_tty_restore_state(handle, 0, error);
break;
} }
/* Sequence ended - go back to normal state. */ /* Sequence ended - go back to normal state. */

8
deps/uv/src/win/util.c

@ -103,7 +103,7 @@ void uv_loadavg(double avg[3]) {
} }
double uv_get_free_memory(void) { uint64_t uv_get_free_memory(void) {
MEMORYSTATUSEX memory_status; MEMORYSTATUSEX memory_status;
memory_status.dwLength = sizeof(memory_status); memory_status.dwLength = sizeof(memory_status);
@ -112,11 +112,11 @@ double uv_get_free_memory(void) {
return -1; return -1;
} }
return (double)memory_status.ullAvailPhys; return (uint64_t)memory_status.ullAvailPhys;
} }
double uv_get_total_memory(void) { uint64_t uv_get_total_memory(void) {
MEMORYSTATUSEX memory_status; MEMORYSTATUSEX memory_status;
memory_status.dwLength = sizeof(memory_status); memory_status.dwLength = sizeof(memory_status);
@ -125,7 +125,7 @@ double uv_get_total_memory(void) {
return -1; return -1;
} }
return (double)memory_status.ullTotalPhys; return (uint64_t)memory_status.ullTotalPhys;
} }

6
deps/uv/test/test-get-memory.c

@ -23,10 +23,10 @@
#include "task.h" #include "task.h"
TEST_IMPL(get_memory) { TEST_IMPL(get_memory) {
double free_mem = uv_get_free_memory(); uint64_t free_mem = uv_get_free_memory();
double total_mem = uv_get_total_memory(); uint64_t total_mem = uv_get_total_memory();
printf("free_mem=%.0f, total_mem=%.0f\n", free_mem, total_mem); printf("free_mem=%llu, total_mem=%llu\n", free_mem, total_mem);
ASSERT(free_mem > 0); ASSERT(free_mem > 0);
ASSERT(total_mem > 0); ASSERT(total_mem > 0);

Loading…
Cancel
Save