Replies: 1 comment
|
I would not use a zero-length external Buffer as an opaque pointer carrier. The Node-API contract defines Passing For an opaque native handle, use using Callback = void (*)(void);
struct CallbackHolder { Callback fn; };
// Allocate CallbackHolder, pass CallbackHolder* to napi_create_external,
// and delete it from the napi_finalize callback.Native code can retrieve the holder and call The observed Node 16/18/20 versus 22 difference should therefore be treated as an implementation detail in handling empty backing stores, not as a stable capability to test for. Node-API documents the two intended contracts here:
|
Uh oh!
There was an error while loading. Please reload this page.
Hi all,
I'm trying to understand a difference between node 16/18/20 and node 22.
Specifically, node-ffi-napi uses 0 length buffers to represent function pointers in it's tests.
16/18/20 fail these tests, where napi_create_external_buffer(env, ptr, 0, NULL, NULL, &val) fills val with a null pointer, when ptr is valid.
22 passes the tests, and val contains a valid pointer to ptr, and a length of zero.
I assume this used to pass in node version up to 12 at least...
If I instead call with napi_create_external_buffer(env, ptr, 8, NULL, NULL, &val), tests pass on node 20 (not tried 16 & 18 yet), and the buffer returned has a valid pointer, but has a length of 8.
I'm finding it very difficult to locate a change in the NodeJS sources.
The ACTUAL code in the tests is
but I modified it to use napi_create_external_buffer directly to check one level down, and behaviour is the same in both cases.
So; what is the expected behaviour when passing a valid pointer, and 0 in the length parameter?
In terms of making the tests work for 16/18/20, should I just pass 8 as the length, and can anyone think of a reason this may be bad?
br,
Simon
All reactions