Skip to content
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

Documentation mismatch for napi_get_value_string_* functions #14398

Closed
RReverser opened this issue Jul 20, 2017 · 6 comments
Closed

Documentation mismatch for napi_get_value_string_* functions #14398

RReverser opened this issue Jul 20, 2017 · 6 comments
Labels
addons Issues and PRs related to native addons. doc Issues and PRs related to the documentations. node-api Issues and PRs related to the Node-API.

Comments

@RReverser
Copy link
Member

napi_get_value_string_* say e.g.:

[out] result: Number of bytes copied into the buffer including the null. terminator.

However, the actual implementation in Node returns the number of bytes excluding the null terminator (so for an empty string, it will return 0 and not 1).

Not sure if it's implementation or documentation issue, or I was just confused by the wording. cc @nodejs/n-api

@RReverser RReverser added addons Issues and PRs related to native addons. doc Issues and PRs related to the documentations. node-api Issues and PRs related to the Node-API. labels Jul 20, 2017
@jasongin
Copy link
Member

It's a doc issue. I think the doc was originally written when there were separate APIs for getting the string length vs string contents, and then it was not updated correctly when the APIs were redesigned.

The string APIs now are intentionally designed so they can be used to just get the string length (not including null terminator) by passing in a null buffer. So even when you do provide a buffer, the returned value, which is the number of characters copied, does not include the null terminator for consistency.

@RReverser
Copy link
Member Author

RReverser commented Jul 20, 2017

The string APIs now are intentionally designed so they can be used to just get the string length (not including null terminator) by passing in a null buffer.

Yup, I agree it's more convenient that way, just wanted to know whether it's docs or implementation that got out of sync.

By the way, is there a specific reason this API is not aligned with napi_get_cb_info? In the latter, you can pass initial count and retrieve actual one via the same pointer to size_t, while string functions accept these as separate arguments.

Given what you said, I suspect the reason was exactly that one referred to initial length excluding null, while the other returned total size of written bytes, but now that in/out have the same meaning, would it be reasonable to align these APIs for consistency? (I can raise a separate issue for that)

@jasongin
Copy link
Member

The bufsize input parameter is the size of the buffer, which must include space for the null terminator. So I'm not sure it would make sense to combine that with the output parameter.

@RReverser
Copy link
Member Author

Makes sense I guess...

@taveras
Copy link

taveras commented Jul 28, 2017

hello! i'm a first-time contributor, and it seems that the issue highlights a change needed in the
following documentation: doc/api/n-api.md

is it okay if I open a PR for this change?

@gabrielschulhof
Copy link
Contributor

@taveras Absolutely :)

addaleax pushed a commit to addaleax/ayo that referenced this issue Aug 25, 2017
The API for napi_get_value_string_utf8() appears to have been
previously changed. This improves the doc reflect the current design.

PR-URL: nodejs/node#14529
Fixes: nodejs/node#14398
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
addaleax pushed a commit to ayojs/ayo that referenced this issue Aug 28, 2017
The API for napi_get_value_string_utf8() appears to have been
previously changed. This improves the doc reflect the current design.

PR-URL: nodejs/node#14529
Fixes: nodejs/node#14398
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
MylesBorins pushed a commit that referenced this issue Sep 10, 2017
The API for napi_get_value_string_utf8() appears to have been
previously changed. This improves the doc reflect the current design.

PR-URL: #14529
Fixes: #14398
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
MylesBorins pushed a commit that referenced this issue Sep 12, 2017
The API for napi_get_value_string_utf8() appears to have been
previously changed. This improves the doc reflect the current design.

PR-URL: #14529
Fixes: #14398
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this issue Apr 10, 2018
The API for napi_get_value_string_utf8() appears to have been
previously changed. This improves the doc reflect the current design.

PR-URL: nodejs#14529
Fixes: nodejs#14398
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
MylesBorins pushed a commit that referenced this issue Apr 16, 2018
The API for napi_get_value_string_utf8() appears to have been
previously changed. This improves the doc reflect the current design.

Backport-PR-URL: #19447
PR-URL: #14529
Fixes: #14398
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addons Issues and PRs related to native addons. doc Issues and PRs related to the documentations. node-api Issues and PRs related to the Node-API.
Projects
None yet
Development

No branches or pull requests

4 participants