Skip to content

Commit 0d0a70d

Browse files
authored
Update for node v16 (#11)
* ignore clangd files * remove unused cluster import * update for node v16
1 parent 7ca0450 commit 0d0a70d

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ node_modules/
33
npm-debug.log
44
package-lock.json
55
.vscode
6+
.cache
7+
compile_commands.json

index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22
const shm = require('./build/Release/shm.node');
3-
const cluster = require('cluster');
43

54
const uint32Max = Math.pow(2,32) - 1;
65
const keyMin = 1;

src/node_shm.cc

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "node_shm.h"
2+
#include "node.h"
23

34
//-------------------------------
45

@@ -28,8 +29,8 @@ namespace Buffer {
2829

2930

3031
MaybeLocal<Object> NewTyped(
31-
Isolate* isolate,
32-
char* data,
32+
Isolate* isolate,
33+
char* data,
3334
size_t count
3435
#if NODE_MODULE_VERSION > IOJS_2_0_MODULE_VERSION
3536
, node::Buffer::FreeCallback callback
@@ -51,9 +52,9 @@ namespace Buffer {
5152
Local<ArrayBuffer> ab = arr->Buffer();
5253
*/
5354

54-
Local<ArrayBuffer> ab = ArrayBuffer::New(isolate, data, length,
55+
Local<ArrayBuffer> ab = ArrayBuffer::New(isolate, data, length,
5556
ArrayBufferCreationMode::kExternalized);
56-
57+
5758
Local<Object> ui;
5859
switch(type) {
5960
case SHMBT_INT8:
@@ -159,7 +160,11 @@ namespace node_shm {
159160
static bool hasShmSegmentInfo(int resId);
160161
static bool removeShmSegmentInfo(int resId);
161162
static void FreeCallback(char* data, void* hint);
163+
#if NODE_MODULE_VERSION < NODE_16_0_MODULE_VERSION
162164
static void Init(Local<Object> target);
165+
#else
166+
static void Init(Local<Object> target, Local<Value> module, void* priv);
167+
#endif
163168
static void AtNodeExit(void*);
164169

165170

@@ -231,10 +236,10 @@ namespace node_shm {
231236
if (i == shmSegmentsCnt-1) {
232237
//removing last element
233238
} else {
234-
std::copy(shmSegmentsIds + i + 1,
235-
shmSegmentsIds + shmSegmentsCnt,
239+
std::copy(shmSegmentsIds + i + 1,
240+
shmSegmentsIds + shmSegmentsCnt,
236241
shmSegmentsIds + i);
237-
std::copy(shmSegmentsAddrs + i + 1,
242+
std::copy(shmSegmentsAddrs + i + 1,
238243
shmSegmentsAddrs + shmSegmentsCnt,
239244
shmSegmentsAddrs + i);
240245
}
@@ -307,7 +312,7 @@ namespace node_shm {
307312
ShmBufferType type = (ShmBufferType) Nan::To<int32_t>(info[4]).FromJust();
308313
size_t size = count * getSize1ForShmBufferType(type);
309314
bool isCreate = (size > 0);
310-
315+
311316
int resId = shmget(key, size, shmflg);
312317
if (resId == -1) {
313318
switch(errno) {
@@ -330,7 +335,7 @@ namespace node_shm {
330335
} else
331336
return Nan::ThrowError(strerror(errno));
332337
}
333-
338+
334339
void* res = shmat(resId, NULL, at_shmflg);
335340
if (res == (void *)-1)
336341
return Nan::ThrowError(strerror(errno));
@@ -399,9 +404,13 @@ namespace node_shm {
399404
}
400405

401406
// Init module
407+
#if NODE_MODULE_VERSION < NODE_16_0_MODULE_VERSION
402408
static void Init(Local<Object> target) {
409+
#else
410+
static void Init(Local<Object> target, Local<Value> module, void* priv) {
411+
#endif
403412
initShmSegmentsInfo();
404-
413+
405414
Nan::SetMethod(target, "get", get);
406415
Nan::SetMethod(target, "detach", detach);
407416
Nan::SetMethod(target, "detachAll", detachAll);
@@ -424,7 +433,11 @@ namespace node_shm {
424433
Nan::Set(target, Nan::New("SHMBT_FLOAT32").ToLocalChecked(), Nan::New<Number>(SHMBT_FLOAT32));
425434
Nan::Set(target, Nan::New("SHMBT_FLOAT64").ToLocalChecked(), Nan::New<Number>(SHMBT_FLOAT64));
426435

436+
#if NODE_MODULE_VERSION < NODE_16_0_MODULE_VERSION
427437
node::AtExit(AtNodeExit);
438+
#else
439+
node::AddEnvironmentCleanupHook(target->GetIsolate(), AtNodeExit, nullptr);
440+
#endif
428441
}
429442

430443
}

0 commit comments

Comments
 (0)