Last active
September 18, 2015 19:39
-
-
Save TooTallNate/e0eb7a55546c25a58990 to your computer and use it in GitHub Desktop.
OS X Yosemite / Node.js v4.0.0 / Segfault - See https://github.com/node-ffi/node-ffi/issues/239
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <node.h> | |
#include <node_buffer.h> | |
#include <nan.h> | |
#include <dlfcn.h> | |
#include <stdio.h> | |
using namespace v8; | |
using namespace node; | |
/* | |
* Called when the wrapped pointer is garbage collected. | |
* We never have to do anything here... | |
*/ | |
void wrap_pointer_cb(char *data, void *hint) { | |
//fprintf(stderr, "wrap_pointer_cb\n"); | |
} | |
/* | |
* Converts an arbitrary pointer to a node Buffer with 0-length | |
*/ | |
Local<Value> WrapPointer(char *ptr) { | |
Nan::EscapableHandleScope scope; | |
return scope.Escape(Nan::NewBuffer(ptr, 0, wrap_pointer_cb, NULL).ToLocalChecked()); | |
} | |
NAN_MODULE_INIT(init) { | |
Nan::HandleScope scope; | |
// dl functions used by the DynamicLibrary JS class | |
target->Set(Nan::New<String>("dlopen").ToLocalChecked(), WrapPointer((char *)printf)); | |
target->Set(Nan::New<String>("dlclose").ToLocalChecked(), WrapPointer((char *)dlclose)); | |
target->Set(Nan::New<String>("dlsym").ToLocalChecked(), WrapPointer((char *)dlsym)); | |
target->Set(Nan::New<String>("dlerror").ToLocalChecked(), WrapPointer((char *)dlerror)); | |
} | |
NODE_MODULE(binding, init) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
'targets': [ | |
{ | |
'target_name': 'binding', | |
'sources': [ | |
'binding.cc' | |
], | |
'include_dirs': [ | |
'<!(node -e "require(\'nan\')")' | |
], | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "node-v4-buffer-segfault-osx", | |
"version": "1.0.0", | |
"description": "Reduced test case for weird Node.js v4 segfault on OS X related to Buffer usage in C++", | |
"main": "t.js", | |
"repository": { | |
"type": "git", | |
"url": "git://gist.github.com/e0eb7a55546c25a58990.git" | |
}, | |
"license": "MIT" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node --expose-gc | |
/** | |
* Run with `--expose-gc` flag. | |
*/ | |
var b = require('./build/Release/binding'); | |
gc(); | |
// gc() causes a `Segmentation fault: 11` on OS X 10.10.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed (a week ago) in nodejs/node#2791.