This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

convert to NAN, fix & prepare for release

  • Loading branch information...
rvagg committed Sep 1, 2013
1 parent e8431d5 commit e722b1372bd2e506a0470ad119e165842edce8f8
Showing with 575 additions and 718 deletions.
  1. +15 −13 binding.gyp
  2. +25 −25 deps/liblmdb.gyp
  3. +6 −5 package.json
  4. +0 −75 src/async.cc
  5. +34 −17 src/async.h
  6. +97 −99 src/batch.cc
  7. +13 −14 src/batch.h
  8. +3 −5 src/batch_async.cc
  9. +2 −4 src/batch_async.h
  10. +161 −181 src/database.cc
  11. +27 −33 src/database.h
  12. +47 −42 src/database_async.cc
  13. +20 −19 src/database_async.h
  14. +63 −65 src/iterator.cc
  15. +7 −15 src/iterator.h
  16. +13 −25 src/iterator_async.cc
  17. +3 −2 src/iterator_async.h
  18. +37 −50 src/nlmdb.h
  19. +0 −28 test.js
  20. +2 −1 test/mapsize-test.js
View
@@ -1,18 +1,20 @@
{
- "targets": [{
- "target_name": "nlmdb"
- , "dependencies": [
- "<(module_root_dir)/deps/liblmdb.gyp:liblmdb"
+ 'targets': [{
+ 'target_name': 'nlmdb'
+ , 'dependencies': [
+ '<(module_root_dir)/deps/liblmdb.gyp:liblmdb'
]
- , "sources": [
- "src/nlmdb.cc"
- , "src/async.cc"
- , "src/database.cc"
- , "src/database_async.cc"
- , "src/batch.cc"
- , "src/batch_async.cc"
- , "src/iterator.cc"
- , "src/iterator_async.cc"
+ , 'include_dirs' : [
+ '<!(node -p -e "require(\'path\').dirname(require.resolve(\'nan\'))")'
+ ]
+ , 'sources': [
+ 'src/nlmdb.cc'
+ , 'src/database.cc'
+ , 'src/database_async.cc'
+ , 'src/batch.cc'
+ , 'src/batch_async.cc'
+ , 'src/iterator.cc'
+ , 'src/iterator_async.cc'
]
}]
}
View
@@ -1,39 +1,39 @@
{
- "targets": [{
- "target_name": "liblmdb"
- , "variables": {
- "lmdbversion": "20130601"
+ 'targets': [{
+ 'target_name': 'liblmdb'
+ , 'variables': {
+ 'lmdbversion': '20130601'
}
- , "defines": [ "MDB_DEBUG=1" ]
- , "type": "static_library"
- , "standalone_static_library": 1
+ , 'defines': [ 'MDB_DEBUG=1' ]
+ , 'type': 'static_library'
+ , 'standalone_static_library': 1
, 'direct_dependent_settings': {
'include_dirs': [
'liblmdb-<(lmdbversion)'
]
}
- , "conditions": [
- ["OS == 'linux'", {
- "cflags": [
- "-Waddress"
- , "-Wno-unused-but-set-variable"
+ , 'conditions': [
+ ['OS == "linux"', {
+ 'cflags': [
+ '-Waddress'
+ , '-Wno-unused-but-set-variable'
]
}]
]
- , "sources": [
- "liblmdb-<(lmdbversion)/mdb.c"
- , "liblmdb-<(lmdbversion)/mdb_copy.c"
- , "liblmdb-<(lmdbversion)/mdb_stat.c"
- , "liblmdb-<(lmdbversion)/midl.c"
+ , 'sources': [
+ 'liblmdb-<(lmdbversion)/mdb.c'
+ , 'liblmdb-<(lmdbversion)/mdb_copy.c'
+ , 'liblmdb-<(lmdbversion)/mdb_stat.c'
+ , 'liblmdb-<(lmdbversion)/midl.c'
]
- , "test-sources": [
- "liblmdb-<(lmdbversion)/mtest2.c"
- , "liblmdb-<(lmdbversion)/mtest3.c"
- , "liblmdb-<(lmdbversion)/mtest4.c"
- , "liblmdb-<(lmdbversion)/mtest5.c"
- , "liblmdb-<(lmdbversion)/mtest6.c"
- , "liblmdb-<(lmdbversion)/mtest.c"
- , "liblmdb-<(lmdbversion)/sample-mdb.c"
+ , 'test-sources': [
+ 'liblmdb-<(lmdbversion)/mtest2.c'
+ , 'liblmdb-<(lmdbversion)/mtest3.c'
+ , 'liblmdb-<(lmdbversion)/mtest4.c'
+ , 'liblmdb-<(lmdbversion)/mtest5.c'
+ , 'liblmdb-<(lmdbversion)/mtest6.c'
+ , 'liblmdb-<(lmdbversion)/mtest.c'
+ , 'liblmdb-<(lmdbversion)/sample-mdb.c'
]
}]
}
View
@@ -9,19 +9,20 @@
, "version" : "0.0.3"
, "main" : "lmdb.js"
, "dependencies" : {
- "bindings" : "~1.1.0"
+ "bindings" : "~1.1.0"
+ , "nan" : "~0.3.1"
}
, "devDependencies" : {
- "tap" : "*"
+ "tap" : "*"
, "rimraf" : "*"
, "abstract-leveldown" : "*"
}
, "repository" : {
- "type" : "git"
- , "url" : "https://github.com/rvagg/lmdb.git"
+ "type" : "git"
+ , "url" : "https://github.com/rvagg/lmdb.git"
}
, "scripts" : {
- "test" : "tap ./test.js test/*-test.js --stderr"
+ "test" : "tap ./test.js test/*-test.js --stderr"
}
, "license" : "MIT"
}
View
@@ -1,75 +0,0 @@
-/* Copyright (c) 2013 Rod Vagg
- * MIT +no-false-attribs License <https://github.com/rvagg/lmdb/blob/master/LICENSE>
- */
-
-#include <node.h>
-
-#include "database.h"
-#include "nlmdb.h"
-#include "async.h"
-
-namespace nlmdb {
-
-/** ASYNC BASE **/
-
-AsyncWorker::AsyncWorker (
- Database* database
- , v8::Persistent<v8::Function> callback
-) : database(database)
- , callback(callback)
-{
- request.data = this;
- status.code = 0;
-};
-
-AsyncWorker::~AsyncWorker () {}
-
-void AsyncWorker::WorkComplete () {
- v8::HandleScope scope;
- if (status.code == 0 && status.error.length() == 0)
- HandleOKCallback();
- else
- HandleErrorCallback();
- callback.Dispose(NL_NODE_ISOLATE);
-}
-
-void AsyncWorker::HandleOKCallback () {
- NL_RUN_CALLBACK(callback, NULL, 0);
-}
-
-void AsyncWorker::HandleErrorCallback () {
- v8::HandleScope scope;
- const char* err;
- if (status.error.length() != 0)
- err = status.error.c_str();
- else
- err = mdb_strerror(status.code);
-
- v8::Local<v8::Value> argv[] = {
- v8::Local<v8::Value>::New(
- v8::Exception::Error(v8::String::New(err))
- )
- };
- NL_RUN_CALLBACK(callback, argv, 1);
-}
-
-void AsyncExecute (uv_work_t* req) {
- static_cast<AsyncWorker*>(req->data)->Execute();
-}
-
-void AsyncExecuteComplete (uv_work_t* req) {
- AsyncWorker* worker = static_cast<AsyncWorker*>(req->data);
- worker->WorkComplete();
- delete worker;
-}
-
-void AsyncQueueWorker (AsyncWorker* worker) {
- uv_queue_work(
- uv_default_loop()
- , &worker->request
- , AsyncExecute
- , (uv_after_work_cb)AsyncExecuteComplete
- );
-}
-
-} // namespace nlmdb
View
@@ -2,38 +2,55 @@
* MIT +no-false-attribs License <https://github.com/rvagg/lmdb/blob/master/LICENSE>
*/
-#ifndef NL_ASYNC_H
-#define NL_ASYNC_H
+#ifndef LD_ASYNC_H
+#define LD_ASYNC_H
#include <node.h>
+#include "nan.h"
#include "database.h"
namespace nlmdb {
-/* abstract */ class AsyncWorker {
+class Database;
+
+/* abstract */ class AsyncWorker : public NanAsyncWorker {
public:
AsyncWorker (
nlmdb::Database* database
- , v8::Persistent<v8::Function> callback
- );
-
- virtual ~AsyncWorker ();
- uv_work_t request;
- virtual void WorkComplete ();
- virtual void Execute () =0;
+ , NanCallback *callback
+ ) : NanAsyncWorker(callback), database(database) {
+ NanScope();
+ v8::Local<v8::Object> obj = v8::Object::New();
+ NanAssignPersistent(v8::Object, persistentHandle, obj);
+ }
protected:
+ void SetStatus (md_status status) {
+ this->status = status;
+
+ if (status.error.length() != 0) {
+ char *e = new char[status.error.length() + 1];
+ strcpy(e, status.error.c_str());
+ this->errmsg = e;
+ } else if (status.code != 0) {
+ const char *me = mdb_strerror(status.code);
+ char *e = new char[strlen(me) + 1];
+ strcpy(e, me);
+ this->errmsg = e;
+ }
+ }
+
+ void SetStatus (int code) {
+ md_status status;
+ status.code = code;
+ SetStatus(status);
+ }
+
Database* database;
- v8::Persistent<v8::Function> callback;
+
md_status status;
- virtual void HandleOKCallback ();
- virtual void HandleErrorCallback ();
};
-void AsyncExecute (uv_work_t* req);
-void AsyncExecuteComplete (uv_work_t* req);
-void AsyncQueueWorker (AsyncWorker* worker);
-
} // namespace nlmdb
#endif
Oops, something went wrong.

0 comments on commit e722b13

Please sign in to comment.