Skip to content

Commit 052aaa4

Browse files
author
Igor Zinkovsky
committed
windows: use 64bit offsets for uv_fs apis
1 parent ffee873 commit 052aaa4

File tree

2 files changed

+70
-36
lines changed

2 files changed

+70
-36
lines changed

src/node.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@
9191
#define NODE_STRINGIFY_HELPER(n) #n
9292
#endif
9393

94+
#ifndef STATIC_ASSERT
95+
#if defined(_MSC_VER)
96+
# define STATIC_ASSERT(expr) static_assert(expr, "")
97+
# else
98+
# define STATIC_ASSERT(expr) static_cast<void>((sizeof(char[-1 + !!(expr)])))
99+
# endif
100+
#endif
101+
94102
namespace node {
95103

96104
int Start(int argc, char *argv[]);

src/node_file.cc

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
# include <platform_win32.h>
4141
#endif
4242

43-
4443
namespace node {
4544

4645
using namespace v8;
@@ -68,10 +67,41 @@ static Persistent<String> buf_symbol;
6867
static Persistent<String> oncomplete_sym;
6968

7069

71-
#ifdef _LARGEFILE_SOURCE
72-
static inline int IsInt64(double x) {
73-
return x == static_cast<double>(static_cast<int64_t>(x));
74-
}
70+
#ifndef _LARGEFILE_SOURCE
71+
typedef off_t node_off_t;
72+
# define ASSERT_OFFSET(a) \
73+
STATIC_ASSERT(sizeof(node_off_t) * CHAR_BIT >= 32); \
74+
if (!(a)->IsUndefined() && !(a)->IsNull() && !(a)->IsInt32()) { \
75+
return ThrowException(Exception::TypeError(String::New("Not an integer"))); \
76+
}
77+
# define ASSERT_TRUNCATE_LENGTH(a) \
78+
if (!(a)->IsUndefined() && !(a)->IsNull() && !(a)->IsUint32()) { \
79+
return ThrowException(Exception::TypeError(String::New("Not an integer"))); \
80+
}
81+
# define GET_OFFSET(a) ((a)->IsNumber() ? (a)->Int32Value() : -1)
82+
# define GET_TRUNCATE_LENGTH(a) ((a)->Uint32Value())
83+
#else
84+
# ifdef _WIN32
85+
# define NODE_USE_64BIT_UV_FS_API
86+
typedef int64_t node_off_t;
87+
# else
88+
typedef off_t node_off_t;
89+
# endif
90+
# define ASSERT_OFFSET(a) \
91+
STATIC_ASSERT(sizeof(node_off_t) * CHAR_BIT >= 64); \
92+
if (!(a)->IsUndefined() && !(a)->IsNull() && !IsInt64((a)->NumberValue())) { \
93+
return ThrowException(Exception::TypeError(String::New("Not an integer"))); \
94+
}
95+
# define ASSERT_TRUNCATE_LENGTH(a) \
96+
if (!(a)->IsUndefined() && !(a)->IsNull() && !IsInt64((a)->NumberValue())) { \
97+
return ThrowException(Exception::TypeError(String::New("Not an integer"))); \
98+
}
99+
# define GET_OFFSET(a) ((a)->IsNumber() ? (a)->IntegerValue() : -1)
100+
# define GET_TRUNCATE_LENGTH(a) ((a)->IntegerValue())
101+
102+
static inline int IsInt64(double x) {
103+
return x == static_cast<double>(static_cast<int64_t>(x));
104+
}
75105
#endif
76106

77107

@@ -470,20 +500,6 @@ static Handle<Value> Rename(const Arguments& args) {
470500
}
471501
}
472502

473-
#ifndef _LARGEFILE_SOURCE
474-
#define ASSERT_TRUNCATE_LENGTH(a) \
475-
if (!(a)->IsUndefined() && !(a)->IsNull() && !(a)->IsUint32()) { \
476-
return ThrowException(Exception::TypeError(String::New("Not an integer"))); \
477-
}
478-
#define GET_TRUNCATE_LENGTH(a) ((a)->Uint32Value())
479-
#else
480-
#define ASSERT_TRUNCATE_LENGTH(a) \
481-
if (!(a)->IsUndefined() && !(a)->IsNull() && !IsInt64((a)->NumberValue())) { \
482-
return ThrowException(Exception::TypeError(String::New("Not an integer"))); \
483-
}
484-
#define GET_TRUNCATE_LENGTH(a) ((a)->IntegerValue())
485-
#endif
486-
487503
static Handle<Value> Truncate(const Arguments& args) {
488504
HandleScope scope;
489505

@@ -494,12 +510,20 @@ static Handle<Value> Truncate(const Arguments& args) {
494510
int fd = args[0]->Int32Value();
495511

496512
ASSERT_TRUNCATE_LENGTH(args[1]);
497-
off_t len = GET_TRUNCATE_LENGTH(args[1]);
513+
node_off_t len = GET_TRUNCATE_LENGTH(args[1]);
498514

499515
if (args[2]->IsFunction()) {
516+
#ifdef NODE_USE_64BIT_UV_FS_API
517+
ASYNC_CALL(ftruncate64, args[2], fd, len)
518+
#else
500519
ASYNC_CALL(ftruncate, args[2], fd, len)
520+
#endif
501521
} else {
522+
#ifdef NODE_USE_64BIT_UV_FS_API
523+
SYNC_CALL(ftruncate64, 0, fd, len)
524+
#else
502525
SYNC_CALL(ftruncate, 0, fd, len)
526+
#endif
503527
return Undefined();
504528
}
505529
}
@@ -671,20 +695,6 @@ static Handle<Value> Open(const Arguments& args) {
671695
}
672696
}
673697

674-
#ifndef _LARGEFILE_SOURCE
675-
#define ASSERT_OFFSET(a) \
676-
if (!(a)->IsUndefined() && !(a)->IsNull() && !(a)->IsInt32()) { \
677-
return ThrowException(Exception::TypeError(String::New("Not an integer"))); \
678-
}
679-
#define GET_OFFSET(a) ((a)->IsNumber() ? (a)->Int32Value() : -1)
680-
#else
681-
#define ASSERT_OFFSET(a) \
682-
if (!(a)->IsUndefined() && !(a)->IsNull() && !IsInt64((a)->NumberValue())) { \
683-
return ThrowException(Exception::TypeError(String::New("Not an integer"))); \
684-
}
685-
#define GET_OFFSET(a) ((a)->IsNumber() ? (a)->IntegerValue() : -1)
686-
#endif
687-
688698
// bytesWritten = write(fd, data, position, enc, callback)
689699
// Wrapper for write(2).
690700
//
@@ -725,15 +735,23 @@ static Handle<Value> Write(const Arguments& args) {
725735
}
726736

727737
ASSERT_OFFSET(args[4]);
728-
off_t pos = GET_OFFSET(args[4]);
738+
node_off_t pos = GET_OFFSET(args[4]);
729739

730740
char * buf = (char*)buffer_data + off;
731741
Local<Value> cb = args[5];
732742

733743
if (cb->IsFunction()) {
744+
#ifdef NODE_USE_64BIT_UV_FS_API
745+
ASYNC_CALL(write64, cb, fd, buf, len, pos)
746+
#else
734747
ASYNC_CALL(write, cb, fd, buf, len, pos)
748+
#endif
735749
} else {
750+
#ifdef NODE_USE_64BIT_UV_FS_API
751+
SYNC_CALL(write64, 0, fd, buf, len, pos)
752+
#else
736753
SYNC_CALL(write, 0, fd, buf, len, pos)
754+
#endif
737755
return scope.Close(Integer::New(SYNC_RESULT));
738756
}
739757
}
@@ -762,7 +780,7 @@ static Handle<Value> Read(const Arguments& args) {
762780
Local<Value> cb;
763781

764782
size_t len;
765-
off_t pos;
783+
node_off_t pos;
766784

767785
char * buf = NULL;
768786

@@ -794,9 +812,17 @@ static Handle<Value> Read(const Arguments& args) {
794812
cb = args[5];
795813

796814
if (cb->IsFunction()) {
815+
#ifdef NODE_USE_64BIT_UV_FS_API
816+
ASYNC_CALL(read64, cb, fd, buf, len, pos);
817+
#else
797818
ASYNC_CALL(read, cb, fd, buf, len, pos);
819+
#endif
798820
} else {
821+
#ifdef NODE_USE_64BIT_UV_FS_API
822+
SYNC_CALL(read64, 0, fd, buf, len, pos)
823+
#else
799824
SYNC_CALL(read, 0, fd, buf, len, pos)
825+
#endif
800826
Local<Integer> bytesRead = Integer::New(SYNC_RESULT);
801827
return scope.Close(bytesRead);
802828
}

0 commit comments

Comments
 (0)