Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
src: DecodeBytes & DecodeWrite return ptrdiff_t
  • Loading branch information
Christopher J. Brody committed Dec 6, 2016
commit 0deee265fd240598c7ce8b07296079f3a5791485
16 changes: 8 additions & 8 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1455,20 +1455,20 @@ Local<Value> Encode(Isolate* isolate, const uint16_t* buf, size_t len) {
}

// Returns -1 if the handle was not valid for decoding
ssize_t DecodeBytes(Isolate* isolate,
Local<Value> val,
enum encoding encoding) {
ptrdiff_t DecodeBytes(Isolate* isolate,
Local<Value> val,
enum encoding encoding) {
HandleScope scope(isolate);

return StringBytes::Size(isolate, val, encoding);
}

// Returns number of bytes written.
ssize_t DecodeWrite(Isolate* isolate,
char* buf,
size_t buflen,
Local<Value> val,
enum encoding encoding) {
ptrdiff_t DecodeWrite(Isolate* isolate,
char* buf,
size_t buflen,
Local<Value> val,
enum encoding encoding) {
return StringBytes::Write(isolate, buf, buflen, val, encoding, nullptr);
}

Expand Down
37 changes: 13 additions & 24 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,6 @@ NODE_EXTERN v8::Local<v8::Value> MakeCallback(
#define NODE_STRINGIFY_HELPER(n) #n
#endif

#ifdef _WIN32
// TODO(tjfontaine) consider changing the usage of ssize_t to ptrdiff_t
#if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED)
typedef intptr_t ssize_t;
# define _SSIZE_T_
# define _SSIZE_T_DEFINED
#endif
#else // !_WIN32
# include <sys/types.h> // size_t, ssize_t
#endif // _WIN32


namespace node {

Expand Down Expand Up @@ -327,27 +316,27 @@ NODE_DEPRECATED("Use Encode(isolate, ...)",
})

// Returns -1 if the handle was not valid for decoding
NODE_EXTERN ssize_t DecodeBytes(v8::Isolate* isolate,
v8::Local<v8::Value>,
enum encoding encoding = LATIN1);
NODE_EXTERN ptrdiff_t DecodeBytes(v8::Isolate* isolate,
v8::Local<v8::Value>,
enum encoding encoding = LATIN1);
NODE_DEPRECATED("Use DecodeBytes(isolate, ...)",
inline ssize_t DecodeBytes(
inline ptrdiff_t DecodeBytes(
v8::Local<v8::Value> val,
enum encoding encoding = LATIN1) {
return DecodeBytes(v8::Isolate::GetCurrent(), val, encoding);
})

// returns bytes written.
NODE_EXTERN ssize_t DecodeWrite(v8::Isolate* isolate,
char* buf,
size_t buflen,
v8::Local<v8::Value>,
enum encoding encoding = LATIN1);
NODE_EXTERN ptrdiff_t DecodeWrite(v8::Isolate* isolate,
char* buf,
size_t buflen,
v8::Local<v8::Value>,
enum encoding encoding = LATIN1);
NODE_DEPRECATED("Use DecodeWrite(isolate, ...)",
inline ssize_t DecodeWrite(char* buf,
size_t buflen,
v8::Local<v8::Value> val,
enum encoding encoding = LATIN1) {
inline ptrdiff_t DecodeWrite(char* buf,
size_t buflen,
v8::Local<v8::Value> val,
enum encoding encoding = LATIN1) {
return DecodeWrite(v8::Isolate::GetCurrent(), buf, buflen, val, encoding);
})

Expand Down