Skip to content

Commit

Permalink
build: fix windows build
Browse files Browse the repository at this point in the history
Be very careful with forward declarations, MSVC is quite picky and
rather stupid about it.

Fixes nodejs#5810.
  • Loading branch information
bnoordhuis committed Jul 11, 2013
1 parent 6acde21 commit c679ac8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ Local<Value> ErrnoException(int errorno,
const char *path) {
Local<Value> e;
Local<String> estring = String::NewSymbol(errno_string(errorno));
if (!msg[0]) {
if (msg == NULL || msg[0] == '\0') {
msg = strerror(errorno);
}
Local<String> message = String::NewSymbol(msg);
Expand Down
57 changes: 30 additions & 27 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,36 @@

#include "node_object_wrap.h"

// Forward-declare these functions now to stop MSVS from becoming
// terminally confused when it's done in node_internals.h
namespace node {

NODE_EXTERN v8::Local<v8::Value> ErrnoException(int errorno,
const char* syscall = NULL,
const char* message = NULL,
const char* path = NULL);
NODE_EXTERN v8::Local<v8::Value> UVException(int errorno,
const char* syscall = NULL,
const char* message = NULL,
const char* path = NULL);
NODE_EXTERN v8::Handle<v8::Value> MakeCallback(
const v8::Handle<v8::Object> recv,
const char* method,
int argc,
v8::Handle<v8::Value>* argv);
NODE_EXTERN v8::Handle<v8::Value> MakeCallback(
const v8::Handle<v8::Object> object,
const v8::Handle<v8::String> symbol,
int argc,
v8::Handle<v8::Value>* argv);
NODE_EXTERN v8::Handle<v8::Value> MakeCallback(
const v8::Handle<v8::Object> object,
const v8::Handle<v8::Function> callback,
int argc,
v8::Handle<v8::Value>* argv);

} // namespace node

#if NODE_WANT_INTERNALS
# include "node_internals.h"
#endif
Expand Down Expand Up @@ -147,16 +177,6 @@ NODE_EXTERN ssize_t DecodeWrite(char *buf,
v8::Local<v8::Object> BuildStatsObject(const uv_stat_t* s);


NODE_EXTERN v8::Local<v8::Value> ErrnoException(int errorno,
const char *syscall = NULL,
const char *msg = "",
const char *path = NULL);

NODE_EXTERN v8::Local<v8::Value> UVException(int errorno,
const char *syscall = NULL,
const char *msg = NULL,
const char *path = NULL);

#ifdef _WIN32
NODE_EXTERN v8::Local<v8::Value> WinapiErrnoException(int errorno,
const char *syscall = NULL, const char *msg = "",
Expand Down Expand Up @@ -217,23 +237,6 @@ node_module_struct* get_builtin_module(const char *name);
NODE_EXTERN void AtExit(void (*cb)(void* arg), void* arg = 0);

NODE_EXTERN void SetErrno(uv_err_t err);
NODE_EXTERN v8::Handle<v8::Value>
MakeCallback(const v8::Handle<v8::Object> object,
const char* method,
int argc,
v8::Handle<v8::Value> argv[]);

NODE_EXTERN v8::Handle<v8::Value>
MakeCallback(const v8::Handle<v8::Object> object,
const v8::Handle<v8::String> symbol,
int argc,
v8::Handle<v8::Value> argv[]);

NODE_EXTERN v8::Handle<v8::Value>
MakeCallback(const v8::Handle<v8::Object> object,
const v8::Handle<v8::Function> callback,
int argc,
v8::Handle<v8::Value> argv[]);

} // namespace node

Expand Down
1 change: 0 additions & 1 deletion src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@


#include "node.h"
#include "node_internals.h"
#include "node_buffer.h"
#include "smalloc.h"
#include "string_bytes.h"
Expand Down
44 changes: 15 additions & 29 deletions src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@

namespace node {

// Forward declarations from node_buffer.h. We can't include node_buffer.h
// in this file because:
//
// a) we're included early on in node.h, and
// b) node_buffer.h depends on the definition of the |encoding| enum that's
// defined further down in node.h...
namespace Buffer {

NODE_EXTERN char* Data(v8::Handle<v8::Value>);
NODE_EXTERN char* Data(v8::Handle<v8::Object>);
NODE_EXTERN size_t Length(v8::Handle<v8::Value>);
NODE_EXTERN size_t Length(v8::Handle<v8::Object>);

} // namespace Buffer

// Defined in node.cc
extern v8::Isolate* node_isolate;

Expand Down Expand Up @@ -177,21 +192,13 @@ inline static void ThrowErrnoException(int errorno,
const char* syscall = NULL,
const char* message = NULL,
const char* path = NULL) {
NODE_EXTERN v8::Local<v8::Value> ErrnoException(int errorno,
const char* syscall = NULL,
const char* message = NULL,
const char* path = NULL);
v8::ThrowException(ErrnoException(errorno, syscall, message, path));
}

inline static void ThrowUVException(int errorno,
const char* syscall = NULL,
const char* message = NULL,
const char* path = NULL) {
NODE_EXTERN v8::Local<v8::Value> UVException(int errorno,
const char* syscall = NULL,
const char* message = NULL,
const char* path = NULL);
v8::ThrowException(UVException(errorno, syscall, message, path));
}

Expand Down Expand Up @@ -309,23 +316,6 @@ inline void Cached<v8::Value>::operator=(v8::Handle<v8::Value> that) {
CachedBase<v8::Value>::operator=(that);
}

// Forward declarations, see node.h
NODE_EXTERN v8::Handle<v8::Value> MakeCallback(
const v8::Handle<v8::Object> recv,
const char* method,
int argc,
v8::Handle<v8::Value>* argv);
NODE_EXTERN v8::Handle<v8::Value> MakeCallback(
const v8::Handle<v8::Object> object,
const v8::Handle<v8::String> symbol,
int argc,
v8::Handle<v8::Value>* argv);
NODE_EXTERN v8::Handle<v8::Value> MakeCallback(
const v8::Handle<v8::Object> object,
const v8::Handle<v8::Function> callback,
int argc,
v8::Handle<v8::Value>* argv);

template <typename TypeName>
v8::Handle<v8::Value> MakeCallback(
const v8::Persistent<v8::Object>& recv,
Expand Down Expand Up @@ -364,15 +354,11 @@ namespace Buffer {

template <typename TypeName>
inline char* Data(v8::Persistent<TypeName>& val) {
NODE_EXTERN char* Data(v8::Handle<v8::Value>);
NODE_EXTERN char* Data(v8::Handle<v8::Object>);
return Data(PersistentToLocal(val));
}

template <typename TypeName>
inline size_t Length(v8::Persistent<TypeName>& val) {
NODE_EXTERN size_t Length(v8::Handle<v8::Value>);
NODE_EXTERN size_t Length(v8::Handle<v8::Object>);
return Length(PersistentToLocal(val));
}

Expand Down
1 change: 0 additions & 1 deletion src/req_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#define REQ_WRAP_H_

#include "queue.h"
#include "node_internals.h"

namespace node {

Expand Down

0 comments on commit c679ac8

Please sign in to comment.