Skip to content

Commit 4b824fd

Browse files
committed
fix: apply patch from node-ffi-napi#73
NOTE: ref-napi now requires node >= 18, as this is not working in previous versions Signed-off-by: Ariel Gentile <gentilester@gmail.com>
1 parent a7f62a4 commit 4b824fd

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

appveyor.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ environment:
55
# Test against these versions of Node.js and io.js
66
matrix:
77
# node.js
8-
- nodejs_version: "10"
9-
- nodejs_version: "12"
10-
- nodejs_version: "14"
8+
- nodejs_version: "18"
119

1210
platform:
1311
- x86
@@ -52,4 +50,4 @@ deploy:
5250
auth_token: $(PREBUILD_GITHUB_TOKEN)
5351
on:
5452
appveyor_repo_tag: true
55-
nodejs_version: "12"
53+
nodejs_version: "18"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "ref-napi",
33
"description": "Turn Buffer instances into \"pointers\"",
44
"engines": {
5-
"node": ">= 10.0"
5+
"node": ">= 18.0"
66
},
77
"keywords": [
88
"native",

src/binding.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ class InstanceData final : public RefNapi::Instance {
105105

106106
auto it = pointer_to_orig_buffer.find(ptr);
107107
if (it != pointer_to_orig_buffer.end()) {
108+
it->second.finalizer_count++;
108109
if (!it->second.ab.Value().IsEmpty()) {
109110
// Already have a valid entry, nothing to do.
110111
return;
111112
}
112113
it->second.ab.Reset(buf, 0);
113-
it->second.finalizer_count++;
114114
} else {
115115
pointer_to_orig_buffer.emplace(ptr, ArrayBufferEntry {
116116
Reference<ArrayBuffer>::New(buf, 0),
@@ -140,8 +140,9 @@ class InstanceData final : public RefNapi::Instance {
140140
if (it != pointer_to_orig_buffer.end())
141141
ab = it->second.ab.Value();
142142

143-
if (ab.IsEmpty()) {
144-
length = std::max<size_t>(length, kMaxLength);
143+
if (ab.IsEmpty() || (ab.ByteLength() < length)) {
144+
length = std::min<size_t>(length, kMaxLength);
145+
length = std::max<size_t>(length,1);
145146
ab = Buffer<char>::New(env, ptr, length, [this](Env env, char* ptr) {
146147
UnregisterArrayBuffer(ptr);
147148
}).ArrayBuffer();
@@ -330,6 +331,8 @@ Value ReadPointer(const CallbackInfo& args) {
330331
int64_t size = args[2].ToNumber();
331332

332333
char* val = *reinterpret_cast<char**>(ptr);
334+
if(val != nullptr && size == 0) size = 1;
335+
333336
return WrapPointer(env, val, size);
334337
}
335338

0 commit comments

Comments
 (0)