-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
n-api: Add optional length to functions accepting const char * #15108
Comments
The following APIs would be affected by this change:
These APIs would (presumably) not be changed, because they have functionally equivalent alternatives that take
The
Also, the |
#15343 |
Discussed with @sampsongao will likely just use stack allocated string to add null terminator if needed. |
Both PRs have landed so it's looks like this can be closed out now. |
Migrating nodejs/abi-stable-node#254 opened by @RReverser to this repo for better visibility:
As discussed in the last meeting, zero-terminated
const char*
, while popular in C land, might be problematic for consumers in other languages having different string representation (for example, Rust with non-zero-terminated string slices represented asdata
+length
).Some N-API functions already accept optional
length
that, when set to-1
, would mean a length calculated from zero-terminated string and explicit byte length otherwise.It's worth to go through a list of functions that accept
const char*
and addlength
parameter where it's missing, especially for functions that don't provide variants withnapi_value
as a string, namely:napi_create_function
napi_define_class
napi_module_register
->napi_module
structThe text was updated successfully, but these errors were encountered: