From 04aaf9de9bec5a9f1e66a9a98481601787f8b17b Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Thu, 28 Oct 2021 08:39:19 -0600 Subject: [PATCH] Try to take more steps to ensure proper module registration, use syntactically acceptable target name, and some crude logging, #67 --- binding.gyp | 4 ++-- src/node-lmdb.cpp | 55 +++++++++++++++++++++++++++++------------------ src/node-lmdb.h | 6 ++++++ 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/binding.gyp b/binding.gyp index 96ecb2fc65..9abe400bbc 100644 --- a/binding.gyp +++ b/binding.gyp @@ -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", diff --git a/src/node-lmdb.cpp b/src/node-lmdb.cpp index 78684e793b..0a3d9f8648 100644 --- a/src/node-lmdb.cpp +++ b/src/node-lmdb.cpp @@ -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 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 // @@ -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 exports, - Local module, - Local 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); -} diff --git a/src/node-lmdb.h b/src/node-lmdb.h index 457c42d2e4..37051aa881 100644 --- a/src/node-lmdb.h +++ b/src/node-lmdb.h @@ -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)