node v0.7.x and v0.8.x support #76

Merged
merged 5 commits into from Jun 20, 2012
View
@@ -16,3 +16,4 @@ gyp-mac-tool
.dirstamp
npm-debug.log
test/support/big.db
+test/tmp
View
@@ -14,11 +14,11 @@ db:
ifndef only
test: build db
@rm -rf ./test/tmp && mkdir -p ./test/tmp
- NODE_PATH=./lib:$NODE_PATH expresso -I lib test/*.test.js
+ NODE_PATH="./lib:$(NODE_PATH)" expresso -I lib test/*.test.js
else
test: build db
@rm -rf ./test/tmp && mkdir -p ./test/tmp
- NODE_PATH=./lib:$NODE_PATH expresso -I lib test/${only}.test.js
+ NODE_PATH="./lib:$(NODE_PATH)" expresso -I lib test/${only}.test.js
endif
.PHONY: build clean test
View
@@ -32,7 +32,7 @@
"expresso": "*"
},
"engines": {
- "node": "~0.6.13"
+ "node": ">= 0.6.13 && <= 0.8.x
},
"scripts": {
"test": "expresso -I lib test/*.test.js"
View
@@ -2,6 +2,7 @@
#define NODE_SQLITE3_SRC_ASYNC_H
#include "threading.h"
+#include <node_version.h>
#if defined(NODE_SQLITE3_BOOST_THREADING)
#include <boost/thread/mutex.hpp>
@@ -35,7 +36,11 @@ template <class Item, class Parent> class Async {
rows.swap(async->data);
NODE_SQLITE3_MUTEX_UNLOCK(&async->mutex)
for (unsigned int i = 0, size = rows.size(); i < size; i++) {
+#if NODE_VERSION_AT_LEAST(0, 7, 9)
+ uv_unref((uv_handle_t *)&async->watcher);
+#else
uv_unref(uv_default_loop());
+#endif
async->callback(async->parent, rows[i]);
}
}
@@ -58,7 +63,11 @@ template <class Item, class Parent> class Async {
void add(Item* item) {
// Make sure node runs long enough to deliver the messages.
+#if NODE_VERSION_AT_LEAST(0, 7, 9)
+ uv_ref((uv_handle_t *)&watcher);
+#else
uv_ref(uv_default_loop());
+#endif
NODE_SQLITE3_MUTEX_LOCK(&mutex);
data.push_back(item);
NODE_SQLITE3_MUTEX_UNLOCK(&mutex)
View
@@ -38,13 +38,11 @@ class Database : public ObjectWrap {
Baton(Database* db_, Handle<Function> cb_) :
db(db_), status(SQLITE_OK) {
db->Ref();
- uv_ref(uv_default_loop());
@springmeyer

springmeyer Jun 19, 2012

Member

can you explain why these are not needed?

@TooTallNate

TooTallNate Jun 19, 2012

Contributor

They would have been needed (well ev_ref()/ev_unref()) back in the eio_custom() days, but uv_queue_work() references the event loop for us so you don't have to do it manually.

@springmeyer

springmeyer Jun 19, 2012

Member

interesting - so do these no longer compile, or are they just potentially going to leak (over reference count) ?

@TooTallNate

TooTallNate Jun 19, 2012

Contributor

It will still compile (on node < 0.7.9) and will just ref and unref the event loop twice instead of once, but it has the same effect in the end (prevents node from quitting).

But on >= 0.7.9, the API changed to require a uv_handle_t instance to pass to ref()/unref(), and there is none when working with uv_queue_work(), so you can't apply this new API to that. Thankfully, libuv does what we expect it to anyways in this case, so they can just be removed completely.

@springmeyer

springmeyer Jun 19, 2012

Member

thanks very much for the explanation.

@TooTallNate

TooTallNate Jun 19, 2012

Contributor

Sure, no prob dude!

request.data = this;
callback = Persistent<Function>::New(cb_);
}
virtual ~Baton() {
db->Unref();
- uv_unref(uv_default_loop());
callback.Dispose();
}
};
View
@@ -86,7 +86,6 @@ class Statement : public ObjectWrap {
Baton(Statement* stmt_, Handle<Function> cb_) : stmt(stmt_) {
stmt->Ref();
- uv_ref(uv_default_loop());
request.data = this;
callback = Persistent<Function>::New(cb_);
}
@@ -96,7 +95,6 @@ class Statement : public ObjectWrap {
DELETE_FIELD(field);
}
stmt->Unref();
- uv_unref(uv_default_loop());
callback.Dispose();
}
};
View
@@ -1,6 +1,6 @@
var sqlite3 = require('sqlite3');
var assert = require('assert');
-var path = require('path');
+var exists = require('fs').existsSync || require('path').existsSync
if (process.setMaxListeners) process.setMaxListeners(0);
@@ -10,7 +10,7 @@ exports['test loadExtension'] = function(beforeExit) {
var db = new sqlite3.Database(':memory:');
var completed = false;
- if (path.existsSync(spatialite_ext)) {
+ if (exists(spatialite_ext)) {
db.loadExtension(spatialite_ext, function(err) {
if (err) throw err;
completed = true;