Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Produce a unique namespace at compile time #687

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
#include <map>
#include <vector>

/**
* 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.
*/
Expand Down Expand Up @@ -1765,3 +1775,5 @@ NAPI_INIT() {
NAPI_EXPORT_FUNCTION(batch_clear);
NAPI_EXPORT_FUNCTION(batch_write);
}

}
3 changes: 3 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"targets": [{
"target_name": "leveldown",
"defines": [
"MODULE_SEED=<!(node -p \"crypto.randomBytes(16).toString('hex')\")"
],
"conditions": [
["OS == 'win'", {
"defines": [
Expand Down