Skip to content

Commit

Permalink
ffi_test.cc wrap pointer fixd
Browse files Browse the repository at this point in the history
  • Loading branch information
unbornchikken committed Aug 27, 2015
1 parent 01ea563 commit a6d494e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/callback_info.cc
Expand Up @@ -150,7 +150,7 @@ NAN_METHOD(CallbackInfo::Callback) {
}

info.GetReturnValue().Set(
Nan::NewBuffer((char *)code, sizeof(void *), closure_pointer_cb, cbInfo).ToLocalChecked()
Nan::NewBuffer((char *)code, sizeof(void*), closure_pointer_cb, cbInfo).ToLocalChecked()
);
}

Expand Down
14 changes: 9 additions & 5 deletions src/ffi.cc
Expand Up @@ -294,12 +294,12 @@ NAN_METHOD(FFI::FFICallAsync) {
p->result = FFI_OK;

// store a persistent references to all the Buffers and the callback function
p->cif = Buffer::Data(info[0]->ToObject());
p->fn = Buffer::Data(info[1]->ToObject());
p->res = Buffer::Data(info[2]->ToObject());
p->argv = Buffer::Data(info[3]->ToObject());
p->cif = Buffer::Data(info[0]->ToObject());
p->fn = Buffer::Data(info[1]->ToObject());
p->res = Buffer::Data(info[2]->ToObject());
p->argv = Buffer::Data(info[3]->ToObject());

Local<Function> callback = Local<Function>::Cast(info[4]);
Local<Function> callback = Local<Function>::Cast(info[4]);
p->callback = new Nan::Callback(callback);

uv_work_t *req = new uv_work_t;
Expand Down Expand Up @@ -365,7 +365,11 @@ void FFI::FinishAsyncFFICall(uv_work_t *req) {
delete req;

if (try_catch.HasCaught()) {
#if NODE_VERSION_AT_LEAST(0, 12, 0)
Nan::FatalException(try_catch);
#else
FatalException(try_catch);
#endif
}
}

Expand Down
10 changes: 7 additions & 3 deletions test/ffi_tests.cc
Expand Up @@ -247,11 +247,15 @@ void play_ping_pong (const char* (*callback) (const char*)) {
}

void wrap_pointer_cb(char *data, void *hint) {
//fprintf(stderr, "wrap_pointer_cb\n");
}

Local<Value> WrapPointer(char *ptr) {
return Nan::NewBuffer(ptr, 0, wrap_pointer_cb, NULL).ToLocalChecked();
inline Local<Value> WrapPointer(char *ptr, size_t length) {
Nan::EscapableHandleScope scope;
return scope.Escape(Nan::NewBuffer(ptr, length, wrap_pointer_cb, NULL).ToLocalChecked());
}

inline Local<Value> WrapPointer(char *ptr) {
return WrapPointer(ptr, 0);
}

void Initialize(Handle<Object> target) {
Expand Down

0 comments on commit a6d494e

Please sign in to comment.