From 8bc8ffcf3752695bd6240821e483846ef012443a Mon Sep 17 00:00:00 2001 From: Albert Siddhartha Slawinski Date: Tue, 19 Aug 2014 10:04:51 -0700 Subject: [PATCH] Apply suggestions from libuv pull request Thanks saghul: https://github.com/joyent/libuv/pull/1428 --- deps/uv/include/uv.h | 1 - src/node_file.cc | 18 ++++++++++-------- src/node_file.h | 5 +++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/deps/uv/include/uv.h b/deps/uv/include/uv.h index f112dde2b90b..7022bc669fdf 100644 --- a/deps/uv/include/uv.h +++ b/deps/uv/include/uv.h @@ -1556,7 +1556,6 @@ struct uv_fs_s { uv_fs_type fs_type; uv_loop_t* loop; uv_fs_cb cb; - int throw_safe; ssize_t result; void* ptr; const char* path; diff --git a/src/node_file.cc b/src/node_file.cc index 02632a15ddd4..bad4d8e1dc78 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -95,6 +95,8 @@ static void After(uv_fs_t *req) { FSReqWrap* req_wrap = (FSReqWrap*) req->data; assert(&req_wrap->req_ == req); + node_fs_t * req_node = (node_fs_t*) req; + // there is always at least one argument. "error" int argc = 1; @@ -107,7 +109,7 @@ static void After(uv_fs_t *req) { if (req->result == -1) { // If the request doesn't have a path parameter set. - if (req->throw_safe == 1) { + if (req_node->throw_safe == 1) { argc = 2; argv[0] = Local::New(True()); argv[1] = Local::New(False()); @@ -226,11 +228,11 @@ static void After(uv_fs_t *req) { // For async calls FSReqWrap is used. struct fs_req_wrap { fs_req_wrap() {} - ~fs_req_wrap() { uv_fs_req_cleanup(&req); } + ~fs_req_wrap() { uv_fs_req_cleanup(&req.req); } // Ensure that copy ctor and assignment operator are not used. fs_req_wrap(const fs_req_wrap& req); fs_req_wrap& operator=(const fs_req_wrap& req); - uv_fs_t req; + node_fs_t req; }; @@ -246,7 +248,7 @@ struct fs_req_wrap { dest_str, \ dest_len + 1); \ } \ - req_wrap->req_.throw_safe = throw_safe_val; \ + ((node_fs_t*) &req_wrap->req_)->throw_safe = throw_safe_val; \ int r = uv_fs_##func(uv_default_loop(), \ &req_wrap->req_, \ __VA_ARGS__, \ @@ -267,9 +269,9 @@ struct fs_req_wrap { #define SYNC_DEST_CALL(func, path, dest, throw_safe_val, ...) \ fs_req_wrap req_wrap; \ - req_wrap.req.throw_safe = throw_safe_val; \ + req_wrap.req.throw_safe = throw_safe_val; \ int result = uv_fs_##func(uv_default_loop(), \ - &req_wrap.req, \ + &req_wrap.req.req, \ __VA_ARGS__, \ NULL); \ if (result < 0) { \ @@ -290,7 +292,7 @@ struct fs_req_wrap { #define SYNC_CALL(func, path, throw_safe_val, ...) \ SYNC_DEST_CALL(func, path, NULL, throw_safe_val, __VA_ARGS__) \ -#define SYNC_REQ req_wrap.req +#define SYNC_REQ req_wrap.req.req #define SYNC_RESULT result @@ -677,7 +679,7 @@ static Handle ReadDir(const Arguments& args) { SYNC_CALL(readdir, *path, 0, *path, 0 /*flags*/) char *namebuf = static_cast(SYNC_REQ.ptr); - int nnames = req_wrap.req.result; + int nnames = req_wrap.req.req.result; Local names = Array::New(nnames); for (int i = 0; i < nnames; i++) { diff --git a/src/node_file.h b/src/node_file.h index 5757e732b58c..1e22e80c5727 100644 --- a/src/node_file.h +++ b/src/node_file.h @@ -27,6 +27,11 @@ namespace node { +typedef struct node_fs_s { + uv_fs_t req; + int throw_safe; +} node_fs_t; + class File { public: static void Initialize(v8::Handle target);