From 07eba034029d987613b189306ff23510cdebf2c9 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Fri, 18 Oct 2019 18:56:27 +0200 Subject: [PATCH] Produce a unique namespace at compile time Closes #686. --- binding.cc | 12 ++++++++++++ binding.gyp | 3 +++ 2 files changed, 15 insertions(+) diff --git a/binding.cc b/binding.cc index 26de429e..b5aea82b 100644 --- a/binding.cc +++ b/binding.cc @@ -12,6 +12,16 @@ #include #include +/** + * Produce a unique namespace at compile time so that symbols don't + * clash when multiple versions of the addon are loaded into node. + */ +#define CONCAT_(a,b) a##b +#define CONCAT(a,b) CONCAT_(a,b) +#define NS CONCAT(NODE_GYP_MODULE_NAME,MODULE_SEED) + +namespace NS { + /** * Forward declarations. */ @@ -1765,3 +1775,5 @@ NAPI_INIT() { NAPI_EXPORT_FUNCTION(batch_clear); NAPI_EXPORT_FUNCTION(batch_write); } + +} diff --git a/binding.gyp b/binding.gyp index 63c59975..26ad56f0 100644 --- a/binding.gyp +++ b/binding.gyp @@ -1,6 +1,9 @@ { "targets": [{ "target_name": "leveldown", + "defines": [ + "MODULE_SEED=