-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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 string length parameter #15343
Conversation
We need new test cases that verify the behavior of each of these APIs with lengths other than -1. For each API a test should pass in a longer string value and then check that the result is truncated according to the length. |
5f8d256
to
d9cab83
Compare
d9cab83
to
cf0f4fa
Compare
There seem to be ci failures on BSD: https://ci.nodejs.org/job/node-test-commit-freebsd/11584/nodes=freebsd10-64/console
|
doc/api/n-api.md
Outdated
@@ -552,11 +552,18 @@ thrown to immediately terminate the process. | |||
added: v8.2.0 | |||
--> | |||
```C | |||
NAPI_NO_RETURN void napi_fatal_error(const char* location, const char* message); | |||
NAPI_EXTERN NAPI_NO_RETURN void napi_fatal_error(const char* location, | |||
size_t location_len, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should NAPI_EXTERN be added here ?
src/node_api.cc
Outdated
char* location_string = const_cast<char*>(location); | ||
char* message_string = const_cast<char*>(message); | ||
if (location_len != -1) { | ||
location_string = (char*) malloc(location_len * sizeof(char) + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we were going to use stack allocation, won't the malloc's result in a memory leak ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sampsongao pointed out that the process will terminate when we call napi_fatal_error so it should be ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Still failures on freebsd
|
225289d
to
b0175ae
Compare
CI looks good except for linter failure. I believe that was a problem either in CI or in master as the previous few linter jobs failed in the same way. |
Seems like lint issue was not ci related:
|
6bd811d
to
cffe74e
Compare
cffe74e
to
8e7bf47
Compare
Another CI run: https://ci.nodejs.org/job/node-test-pull-request/10126/ |
Arm failure was: nodejs/build#884 |
CI was good going to land. |
PR-URL: #15343 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Landed as 1976654 |
PR-URL: #15343 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
PR-URL: nodejs/node#15343 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
PR-URL: nodejs/node#15343 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
PR-URL: nodejs#15343 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Backport-PR-URL: #19447 PR-URL: #15343 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)