From 72b3c0bae4c1d5510506ddb0609729d5310026d0 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 and some crude logging, #67 --- binding.gyp | 2 +- src/lmdb-store.cpp | 22 +++++++++++++++++++--- src/lmdb-store.h | 6 +++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/binding.gyp b/binding.gyp index d0f5f1356d..27bee760d4 100644 --- a/binding.gyp +++ b/binding.gyp @@ -14,11 +14,11 @@ "target_name": "lmdb-store", "win_delay_load_hook": "false", "sources": [ + "src/lmdb-store.cpp", "dependencies/lmdb/libraries/liblmdb/midl.c", "dependencies/lmdb/libraries/liblmdb/chacha8.c", "dependencies/lz4/lib/lz4.h", "dependencies/lz4/lib/lz4.c", - "src/lmdb-store.cpp", "src/writer.cpp", "src/env.cpp", "src/compression.cpp", diff --git a/src/lmdb-store.cpp b/src/lmdb-store.cpp index 55d3033dc2..c1fc1dffa2 100644 --- a/src/lmdb-store.cpp +++ b/src/lmdb-store.cpp @@ -3,10 +3,24 @@ 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(); + extern "C" NODE_MODULE_EXPORT void -NODE_MODULE_INITIALIZER(Local exports, - Local module, - Local context) { +NODE_MODULE_INITIALIZER(v8::Local exports, + v8::Local module, + v8::Local context); +NODE_MODULE_CONTEXT_AWARE_X(NODE_GYP_MODULE_NAME, NODE_MODULE_INITIALIZER, NULL, 0) +void NODE_MODULE_INITIALIZER(v8::Local exports, + v8::Local module, + v8::Local context) { + if (Logging::debugLogging) + fprintf(stderr, "Start initialization\n"); // Initializes the module // Export Env as constructor for EnvWrap EnvWrap::setupExports(exports); @@ -16,6 +30,8 @@ NODE_MODULE_INITIALIZER(Local exports, // Export misc things setupExportMisc(exports); + if (Logging::debugLogging) + fprintf(stderr, "Finished initialization\n"); } diff --git a/src/lmdb-store.h b/src/lmdb-store.h index ad052a85fc..523efc4487 100644 --- a/src/lmdb-store.h +++ b/src/lmdb-store.h @@ -92,7 +92,11 @@ int cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, uint64_t ns); #endif /* __CPTHREAD_H__ */ - +class Logging { + public: + static int debugLogging; + static int initLogging(); +}; enum class NodeLmdbKeyType {