From 247d0da188e70949a48739fc42dbf5da4d7b8b40 Mon Sep 17 00:00:00 2001
From: Igor Zinkovsky
Date: Wed, 11 Jan 2012 19:34:56 -0800
Subject: [PATCH 1/6] update libuv to 855764406e fixes #2521
---
deps/uv/src/win/fs.c | 72 +++++++++++++++++++++++++++-----------
deps/uv/src/win/internal.h | 4 +--
deps/uv/src/win/util.c | 23 ++++++++++++
3 files changed, 76 insertions(+), 23 deletions(-)
diff --git a/deps/uv/src/win/fs.c b/deps/uv/src/win/fs.c
index 78ccffab6..d7087b1f5 100644
--- a/deps/uv/src/win/fs.c
+++ b/deps/uv/src/win/fs.c
@@ -490,38 +490,69 @@ void fs__readdir(uv_fs_t* req, const wchar_t* path, int flags) {
void fs__stat(uv_fs_t* req, const wchar_t* path) {
+ HANDLE file;
+ WIN32_FIND_DATAW ent;
int result;
- unsigned short mode;
- fs__open(req, path, _O_RDONLY, 0);
- if (req->result == -1) {
+ req->ptr = NULL;
+
+ file = FindFirstFileExW(path, FindExInfoStandard, &ent,
+ FindExSearchNameMatch, NULL, 0);
+
+ if (file == INVALID_HANDLE_VALUE) {
+ SET_REQ_RESULT_WIN32_ERROR(req, GetLastError());
return;
}
- result = _fstati64(req->result, &req->stat);
- if (result == -1) {
- req->ptr = NULL;
- } else {
+ FindClose(file);
- /*
- * VC CRT doesn't properly set S_IFDIR in _fstati64,
- * so we set it here if path is a directory.
- */
- if (GetFileAttributesW(path) & FILE_ATTRIBUTE_DIRECTORY) {
- mode = req->stat.st_mode;
- mode &= ~_S_IFMT;
- mode |= _S_IFDIR;
+ if (ent.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT &&
+ ent.dwReserved0 == IO_REPARSE_TAG_SYMLINK) {
+ fs__open(req, path, _O_RDONLY, 0);
+ if (req->result != -1) {
+ result = _fstati64(req->result, &req->stat);
+ _close(req->result);
- req->stat.st_mode = mode;
- assert((req->stat.st_mode & _S_IFMT) == _S_IFDIR);
+ if (result != -1) {
+ req->ptr = &req->stat;
+ }
+
+ SET_REQ_RESULT(req, result);
}
- req->ptr = &req->stat;
+ return;
}
- _close(req->result);
+ req->stat.st_ino = 0;
+ req->stat.st_uid = 0;
+ req->stat.st_gid = 0;
+ req->stat.st_mode = 0;
+ req->stat.st_rdev = 0;
+ req->stat.st_dev = 0;
+ req->stat.st_nlink = 1;
- SET_REQ_RESULT(req, result);
+ if (ent.dwFileAttributes & FILE_ATTRIBUTE_READONLY ) {
+ req->stat.st_mode |= (_S_IREAD + (_S_IREAD >> 3) + (_S_IREAD >> 6));
+ } else {
+ req->stat.st_mode |= ((_S_IREAD|_S_IWRITE) + ((_S_IREAD|_S_IWRITE) >> 3) +
+ ((_S_IREAD|_S_IWRITE) >> 6));
+ }
+
+ if (ent.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
+ req->stat.st_mode |= _S_IFDIR;
+ } else {
+ req->stat.st_mode |= _S_IFREG;
+ }
+
+ uv_filetime_to_time_t(&ent.ftLastWriteTime, &(req->stat.st_mtime));
+ uv_filetime_to_time_t(&ent.ftLastAccessTime, &(req->stat.st_atime));
+ uv_filetime_to_time_t(&ent.ftCreationTime, &(req->stat.st_ctime));
+
+ req->stat.st_size = ((int64_t)ent.nFileSizeHigh << 32) +
+ (int64_t)ent.nFileSizeLow;
+
+ req->ptr = &req->stat;
+ req->result = 0;
}
@@ -1543,3 +1574,4 @@ void uv_fs_req_cleanup(uv_fs_t* req) {
req->flags |= UV_FS_CLEANEDUP;
}
+
diff --git a/deps/uv/src/win/internal.h b/deps/uv/src/win/internal.h
index deb8972c5..336349b1f 100644
--- a/deps/uv/src/win/internal.h
+++ b/deps/uv/src/win/internal.h
@@ -284,10 +284,8 @@ void uv_fs_event_endgame(uv_loop_t* loop, uv_fs_event_t* handle);
/* Utils */
int uv_parent_pid();
-
-
+void uv_filetime_to_time_t(FILETIME* file_time, time_t* stat_time);
void uv_fatal_error(const int errorno, const char* syscall);
-
uv_err_code uv_translate_sys_error(int sys_errno);
#define SET_REQ_STATUS(req, status) \
diff --git a/deps/uv/src/win/util.c b/deps/uv/src/win/util.c
index fcdeafc72..0fcfb9c3d 100644
--- a/deps/uv/src/win/util.c
+++ b/deps/uv/src/win/util.c
@@ -23,6 +23,7 @@
#include
#include
#include
+#include
#include "uv.h"
#include "internal.h"
@@ -236,3 +237,25 @@ int uv_parent_pid() {
CloseHandle(handle);
return parent_pid;
}
+
+
+void uv_filetime_to_time_t(FILETIME* file_time, time_t* stat_time) {
+ FILETIME local_time;
+ SYSTEMTIME system_time;
+ struct tm time;
+
+ if ((file_time->dwLowDateTime || file_time->dwHighDateTime) &&
+ FileTimeToLocalFileTime(file_time, &local_time) &&
+ FileTimeToSystemTime(&local_time, &system_time)) {
+ time.tm_year = system_time.wYear - 1900;
+ time.tm_mon = system_time.wMonth - 1;
+ time.tm_mday = system_time.wDay;
+ time.tm_hour = system_time.wHour;
+ time.tm_min = system_time.wMinute;
+ time.tm_sec = system_time.wSecond;
+
+ *stat_time = mktime(&time);
+ } else {
+ *stat_time = 0;
+ }
+}
From 465e22e62f8eb927464bb6210ec786ab289813f9 Mon Sep 17 00:00:00 2001
From: Ben Noordhuis
Date: Thu, 12 Jan 2012 14:41:04 +0100
Subject: [PATCH 2/6] docs: clarify filename argument of vm.* functions
---
doc/api/vm.markdown | 34 ++++++++++++++++++----------------
1 file changed, 18 insertions(+), 16 deletions(-)
diff --git a/doc/api/vm.markdown b/doc/api/vm.markdown
index d3e3606ef..3d3c16845 100644
--- a/doc/api/vm.markdown
+++ b/doc/api/vm.markdown
@@ -9,8 +9,9 @@ JavaScript code can be compiled and run immediately or compiled, saved, and run
### vm.runInThisContext(code, [filename])
-`vm.runInThisContext()` compiles `code` as if it were loaded from `filename`,
-runs it and returns the result. Running code does not have access to local scope. `filename` is optional.
+`vm.runInThisContext()` compiles `code`, runs it and returns the result. Running
+code does not have access to local scope. `filename` is optional, it's used only
+in stack traces.
Example of using `vm.runInThisContext` and `eval` to run the same code:
@@ -38,10 +39,10 @@ and throws an exception.
### vm.runInNewContext(code, [sandbox], [filename])
-`vm.runInNewContext` compiles `code` to run in `sandbox` as if it were loaded from `filename`,
-then runs it and returns the result. Running code does not have access to local scope and
-the object `sandbox` will be used as the global object for `code`.
-`sandbox` and `filename` are optional.
+`vm.runInNewContext` compiles `code`, then runs it in `sandbox` and returns the
+result. Running code does not have access to local scope. The object `sandbox`
+will be used as the global object for `code`.
+`sandbox` and `filename` are optional, `filename` is only used in stack traces.
Example: compile and execute code that increments a global variable and sets a new one.
These globals are contained in the sandbox.
@@ -67,11 +68,12 @@ and throws an exception.
### vm.runInContext(code, context, [filename])
-`vm.runInContext` compiles `code` to run in context `context` as if it were loaded from `filename`,
-then runs it and returns the result. A (V8) context comprises a global object, together with a
-set of built-in objects and functions. Running code does not have access to local scope and
-the global object held within `context` will be used as the global object for `code`.
-`filename` is optional.
+`vm.runInContext` compiles `code`, then runs it in `context` and returns the
+result. A (V8) context comprises a global object, together with a set of
+built-in objects and functions. Running code does not have access to local scope
+and the global object held within `context` will be used as the global object
+for `code`.
+`filename` is optional, it's used only in stack traces.
Example: compile and execute code in a existing context.
@@ -107,11 +109,11 @@ to seed the initial contents of the global object used by the context.
### vm.createScript(code, [filename])
-`createScript` compiles `code` as if it were loaded from `filename`,
-but does not run it. Instead, it returns a `vm.Script` object representing this compiled code.
-This script can be run later many times using methods below.
-The returned script is not bound to any global object.
-It is bound before each run, just for that run. `filename` is optional.
+`createScript` compiles `code` but does not run it. Instead, it returns a
+`vm.Script` object representing this compiled code. This script can be run
+later many times using methods below. The returned script is not bound to any
+global object. It is bound before each run, just for that run. `filename` is
+optional, it's only used in stack traces.
In case of syntax error in `code`, `createScript` prints the syntax error to stderr
and throws an exception.
From bd9fa2e8419dda3ecff55ca7d801af3db4aeb5b2 Mon Sep 17 00:00:00 2001
From: mrb
Date: Wed, 11 Jan 2012 23:42:24 -0500
Subject: [PATCH 3/6] dgram: use slab memory allocator
Change udp memory allocation scheme from uv_buf_init to slab allocation. Takes
slab allocation scheme from stream_wrap.
---
src/udp_wrap.cc | 68 ++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 59 insertions(+), 9 deletions(-)
diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc
index 741e4ed46..aa5160ceb 100644
--- a/src/udp_wrap.cc
+++ b/src/udp_wrap.cc
@@ -59,10 +59,14 @@ namespace node {
return scope.Close(Integer::New(-1)); \
}
+#define SLAB_SIZE (1024 * 1024)
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+
// TODO share with tcp_wrap.cc
Persistent address_symbol;
Persistent port_symbol;
Persistent buffer_sym;
+static Persistent udp_slab_sym;
void AddressToJS(Handle