Skip to content

Commit

Permalink
fix: apply patch from node-ffi-napi#73
Browse files Browse the repository at this point in the history
NOTE: ref-napi now requires node >= 18, as this is not working in previous versions

Signed-off-by: Ariel Gentile <[email protected]>
  • Loading branch information
genaris committed Feb 6, 2023
1 parent a7f62a4 commit 4b824fd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
6 changes: 2 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ environment:
# Test against these versions of Node.js and io.js
matrix:
# node.js
- nodejs_version: "10"
- nodejs_version: "12"
- nodejs_version: "14"
- nodejs_version: "18"

platform:
- x86
Expand Down Expand Up @@ -52,4 +50,4 @@ deploy:
auth_token: $(PREBUILD_GITHUB_TOKEN)
on:
appveyor_repo_tag: true
nodejs_version: "12"
nodejs_version: "18"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ref-napi",
"description": "Turn Buffer instances into \"pointers\"",
"engines": {
"node": ">= 10.0"
"node": ">= 18.0"
},
"keywords": [
"native",
Expand Down
9 changes: 6 additions & 3 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ class InstanceData final : public RefNapi::Instance {

auto it = pointer_to_orig_buffer.find(ptr);
if (it != pointer_to_orig_buffer.end()) {
it->second.finalizer_count++;
if (!it->second.ab.Value().IsEmpty()) {
// Already have a valid entry, nothing to do.
return;
}
it->second.ab.Reset(buf, 0);
it->second.finalizer_count++;
} else {
pointer_to_orig_buffer.emplace(ptr, ArrayBufferEntry {
Reference<ArrayBuffer>::New(buf, 0),
Expand Down Expand Up @@ -140,8 +140,9 @@ class InstanceData final : public RefNapi::Instance {
if (it != pointer_to_orig_buffer.end())
ab = it->second.ab.Value();

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

char* val = *reinterpret_cast<char**>(ptr);
if(val != nullptr && size == 0) size = 1;

return WrapPointer(env, val, size);
}

Expand Down

0 comments on commit 4b824fd

Please sign in to comment.