1
1
#include " node_shm.h"
2
+ #include " node.h"
2
3
3
4
// -------------------------------
4
5
@@ -28,8 +29,8 @@ namespace Buffer {
28
29
29
30
30
31
MaybeLocal<Object> NewTyped (
31
- Isolate* isolate,
32
- char * data,
32
+ Isolate* isolate,
33
+ char * data,
33
34
size_t count
34
35
#if NODE_MODULE_VERSION > IOJS_2_0_MODULE_VERSION
35
36
, node::Buffer::FreeCallback callback
@@ -51,9 +52,9 @@ namespace Buffer {
51
52
Local<ArrayBuffer> ab = arr->Buffer();
52
53
*/
53
54
54
- Local<ArrayBuffer> ab = ArrayBuffer::New (isolate, data, length,
55
+ Local<ArrayBuffer> ab = ArrayBuffer::New (isolate, data, length,
55
56
ArrayBufferCreationMode::kExternalized );
56
-
57
+
57
58
Local<Object> ui;
58
59
switch (type) {
59
60
case SHMBT_INT8:
@@ -159,7 +160,11 @@ namespace node_shm {
159
160
static bool hasShmSegmentInfo (int resId);
160
161
static bool removeShmSegmentInfo (int resId);
161
162
static void FreeCallback (char * data, void * hint);
163
+ #if NODE_MODULE_VERSION < NODE_16_0_MODULE_VERSION
162
164
static void Init (Local<Object> target);
165
+ #else
166
+ static void Init (Local<Object> target, Local<Value> module, void * priv);
167
+ #endif
163
168
static void AtNodeExit (void *);
164
169
165
170
@@ -231,10 +236,10 @@ namespace node_shm {
231
236
if (i == shmSegmentsCnt-1 ) {
232
237
// removing last element
233
238
} else {
234
- std::copy (shmSegmentsIds + i + 1 ,
235
- shmSegmentsIds + shmSegmentsCnt,
239
+ std::copy (shmSegmentsIds + i + 1 ,
240
+ shmSegmentsIds + shmSegmentsCnt,
236
241
shmSegmentsIds + i);
237
- std::copy (shmSegmentsAddrs + i + 1 ,
242
+ std::copy (shmSegmentsAddrs + i + 1 ,
238
243
shmSegmentsAddrs + shmSegmentsCnt,
239
244
shmSegmentsAddrs + i);
240
245
}
@@ -307,7 +312,7 @@ namespace node_shm {
307
312
ShmBufferType type = (ShmBufferType) Nan::To<int32_t >(info[4 ]).FromJust ();
308
313
size_t size = count * getSize1ForShmBufferType (type);
309
314
bool isCreate = (size > 0 );
310
-
315
+
311
316
int resId = shmget (key, size, shmflg);
312
317
if (resId == -1 ) {
313
318
switch (errno) {
@@ -330,7 +335,7 @@ namespace node_shm {
330
335
} else
331
336
return Nan::ThrowError (strerror (errno));
332
337
}
333
-
338
+
334
339
void * res = shmat (resId, NULL , at_shmflg);
335
340
if (res == (void *)-1 )
336
341
return Nan::ThrowError (strerror (errno));
@@ -399,9 +404,13 @@ namespace node_shm {
399
404
}
400
405
401
406
// Init module
407
+ #if NODE_MODULE_VERSION < NODE_16_0_MODULE_VERSION
402
408
static void Init (Local<Object> target) {
409
+ #else
410
+ static void Init (Local<Object> target, Local<Value> module, void * priv) {
411
+ #endif
403
412
initShmSegmentsInfo ();
404
-
413
+
405
414
Nan::SetMethod (target, " get" , get);
406
415
Nan::SetMethod (target, " detach" , detach);
407
416
Nan::SetMethod (target, " detachAll" , detachAll);
@@ -424,7 +433,11 @@ namespace node_shm {
424
433
Nan::Set (target, Nan::New (" SHMBT_FLOAT32" ).ToLocalChecked (), Nan::New<Number>(SHMBT_FLOAT32));
425
434
Nan::Set (target, Nan::New (" SHMBT_FLOAT64" ).ToLocalChecked (), Nan::New<Number>(SHMBT_FLOAT64));
426
435
436
+ #if NODE_MODULE_VERSION < NODE_16_0_MODULE_VERSION
427
437
node::AtExit (AtNodeExit);
438
+ #else
439
+ node::AddEnvironmentCleanupHook (target->GetIsolate (), AtNodeExit, nullptr );
440
+ #endif
428
441
}
429
442
430
443
}
0 commit comments