Skip to content

Commit

Permalink
Merges
Browse files Browse the repository at this point in the history
  • Loading branch information
rbranson committed Oct 17, 2010
2 parents 875df03 + fca34af commit b4a6ff4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 29 deletions.
10 changes: 6 additions & 4 deletions _ffi.cc
Expand Up @@ -129,7 +129,7 @@ Handle<Value> Pointer::New(const Arguments& args)
{
HandleScope scope;
Pointer *self = new Pointer(NULL);

if (args.Length() == 1 && args[0]->IsNumber()) {
unsigned int sz = args[0]->Uint32Value();
self->Alloc(sz);
Expand Down Expand Up @@ -675,11 +675,13 @@ int FFI::AsyncFFICall(eio_req *req)
int FFI::FinishAsyncFFICall(eio_req *req)
{
AsyncCallParams *p = (AsyncCallParams *)req->data;
Local<Value> argv[0];
Local<Value> argv[1];

argv[0] = Local<Value>::New(String::New("success"));

// emit a success event
Local<Function> emit = Local<Function>::Cast(p->emitter->Get(String::NewSymbol("emit")));
emit->Call(p->emitter, 0, argv);
emit->Call(p->emitter, 1, argv);

// unref the event loop (ref'd in FFICall)
ev_unref(EV_DEFAULT_UC);
Expand Down Expand Up @@ -941,7 +943,7 @@ void CallbackInfo::Invoke(ffi_cif *cif, void *retval, void **parameters, void *u

// send a message to our main thread to wake up the WatchCallback loop
ev_async_send(EV_DEFAULT_UC_ &g_async);

// wait for signal from calling thread
inv->WaitForExecution();

Expand Down
7 changes: 4 additions & 3 deletions node-ffi.js
Expand Up @@ -14,7 +14,7 @@ FFI.TYPE_TO_POINTER_METHOD_MAP = {
"int32": "Int32",
"uint32": "UInt32",
"int64": "Int64",
"uin64": "UInt64",
"uint64": "UInt64",
"float": "Float",
"double": "Double",
"string": "CString",
Expand All @@ -23,7 +23,8 @@ FFI.TYPE_TO_POINTER_METHOD_MAP = {

FFI.PLATFORM_LIBRARY_EXTENSIONS = {
"linux2": ".so",
"darwin": ".dylib"
"darwin": ".dylib",
"sunos": ".so",
};

// create fast dispatch tables for type calls
Expand Down Expand Up @@ -419,4 +420,4 @@ FFI.errno = function() {
// Export Everything
for (var k in FFI) { exports[k] = FFI[k]; }

}());
}());
6 changes: 3 additions & 3 deletions sqlite-example.js
@@ -1,4 +1,4 @@
var FFI = require("./ffi");
var FFI = require("./node-ffi");
var sys = require("sys");

var SQLite3 = new FFI.Library("libsqlite3", {
Expand Down Expand Up @@ -48,12 +48,12 @@ var callback = new FFI.Callback(["int32", ["pointer", "int32", "pointer", "point

var fin = false;

SQLite3Async.sqlite3_exec(dbh, "SELECT * FROM foo;", callback.getPointer(), null, null).addCallback(function(ret) {
SQLite3Async.sqlite3_exec(dbh, "SELECT * FROM foo;", callback.getPointer(), null, null).on("success", function(ret) {
sys.puts("Total Rows: " + rowCount);
sys.puts("Changes: " + SQLite3.sqlite3_changes(dbh));
sys.puts("Closing...");
fin = true;
SQLite3.sqlite3_close(dbh);
});

setTimeout(2000, function() { });
setTimeout(2000, function() { });
21 changes: 3 additions & 18 deletions test.js
Expand Up @@ -323,27 +323,12 @@ var clz = new FFI.CallbackInfo(cifPtr.getPointer(), function(result, args) {

var callMyTestClosure = FFI.ForeignFunction.build(clz.pointer, "int32", [ "int32" ]);
callMyTestClosure(1);
assert.equal(1, closureCalled);
callMyTestClosure(1);
assert.equal(2, closureCalled);

///////////////////////

var asyncClosureCalled = 0;
var cifPtr = new FFI.CIF("int32", [ "int32" ]);
var clz = new FFI.CallbackInfo(cifPtr.getPointer(), function(result, args) {
asyncClosureCalled++;
result.putInt32(1234);
});


var callMyTestClosure = FFI.ForeignFunction.build(clz.pointer, "int32", [ "int32" ], true);

callMyTestClosure(1).on("success", function(res) {
assert.equal(1234, res);
});

///////////////////////

var callback = new FFI.Callback(["int32", ["int32"]], function(inValue) {
return Math.abs(inValue);
});
Expand Down Expand Up @@ -371,6 +356,7 @@ var libmCeilAsyncCallExecuted = false;
var libm = new FFI.Library("libm", { "ceil": [ "double", [ "double" ], {"async": true } ] });
assert.ok(libm instanceof FFI.Library);
assert.ok(libm.ceil instanceof Function);

libm.ceil(1.5).on("success", function(res) {
libmCeilAsyncCallExecuted = true;
assert.equal(1, res);
Expand All @@ -390,8 +376,7 @@ assert.equal(2, FFI.errno());
setTimeout(function() {
assert.ok(asyncAbsCallExecuted);
assert.ok(libmCeilAsyncCallExecuted);
assert.equal(1, asyncClosureCalled);
sys.puts("Tests pass!");
}, 2000);
}, 250);

sys.puts("Heap increased by " + ((process.memoryUsage()["rss"] - rss) / 1024) + " KB");
4 changes: 3 additions & 1 deletion wscript
Expand Up @@ -18,8 +18,10 @@ def configure(conf):
conf.env['USE_DEBUG'] = Options.options.debug

if not conf.check(lib='ffi'):
fatal("libffi not found.")
if not conf.check(lib="ffi", libpath=['/usr/local/lib', '/opt/local/lib'], uselib_store="FFI"):
fatal("libffi not found.")

conf.env.append_value("CPPPATH_FFI", "/opt/local/include")
conf.env.append_value("LIB_FFI", "ffi")
conf.env.append_value("LIB_DL", "dl")

Expand Down

0 comments on commit b4a6ff4

Please sign in to comment.