Skip to content

Commit

Permalink
Try to take more steps to ensure proper module registration, use synt…
Browse files Browse the repository at this point in the history
…actically acceptable target name, and some crude logging, #67
  • Loading branch information
kriszyp committed Oct 28, 2021
1 parent de03f6e commit 04aaf9d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
4 changes: 2 additions & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
},
"targets": [
{
"target_name": "lmdb-store",
"target_name": "lmdb",
"win_delay_load_hook": "false",
"sources": [
"src/node-lmdb.cpp",
"dependencies/lmdb/libraries/liblmdb/midl.c",
"dependencies/lmdb/libraries/liblmdb/chacha8.c",
"dependencies/lz4/lib/lz4.h",
"dependencies/lz4/lib/lz4.c",
"src/node-lmdb.cpp",
"src/env.cpp",
"src/compression.cpp",
"src/ordered-binary.cpp",
Expand Down
55 changes: 34 additions & 21 deletions src/node-lmdb.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
#include "node-lmdb.h"
#include "node-lmdb.h"

using namespace v8;
using namespace node;

int Logging::initLogging() {
char* logging = getenv("LMDB_STORE_LOGGING");
if (logging)
fprintf(stderr, "Start logging for lmdb-store\n");
return !!logging;
}
int Logging::debugLogging = Logging::initLogging();

NODE_MODULE_INIT(/* exports, module, context */) {
if (Logging::debugLogging)
fprintf(stderr, "Start initialization\n");
// Initializes the module
// Export Env as constructor for EnvWrap
EnvWrap::setupExports(exports);

// Export Cursor as constructor for CursorWrap
CursorWrap::setupExports(exports);

// This file is part of node-lmdb, the Node.js binding for lmdb
// Export misc things
setupExportMisc(exports);
if (Logging::debugLogging)
fprintf(stderr, "Finished initialization\n");
}
/*void TestInitialize(Local<Object> exports) {
fprintf(stderr, "Running non-context aware initialization\n");
}
NODE_MODULE(NODE_GYP_MODULE_NAME, TestInitialize)*/

// This file contains code from the node-lmdb project
// Copyright (c) 2013-2017 Timur Kristóf
// Licensed to you under the terms of the MIT license
//
Expand All @@ -20,23 +53,3 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#include "node-lmdb.h"

using namespace v8;
using namespace node;

extern "C" NODE_MODULE_EXPORT void
NODE_MODULE_INITIALIZER(Local<Object> exports,
Local<Value> module,
Local<Context> context) {
// Initializes the module
// Export Env as constructor for EnvWrap
EnvWrap::setupExports(exports);

// Export Cursor as constructor for CursorWrap
CursorWrap::setupExports(exports);

// Export misc things
setupExportMisc(exports);
}
6 changes: 6 additions & 0 deletions src/node-lmdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
using namespace v8;
using namespace node;

class Logging {
public:
static int debugLogging;
static int initLogging();
};

enum class NodeLmdbKeyType {

// Invalid key (used internally by node-lmdb)
Expand Down

0 comments on commit 04aaf9d

Please sign in to comment.