src: cleanup uv_fs_t regardless of success or not#38996
Closed
legendecas wants to merge 1 commit intonodejs:masterfrom
Closed
src: cleanup uv_fs_t regardless of success or not#38996legendecas wants to merge 1 commit intonodejs:masterfrom
legendecas wants to merge 1 commit intonodejs:masterfrom
Conversation
Collaborator
|
joyeecheung
approved these changes
Jun 10, 2021
Collaborator
|
jasnell
reviewed
Jun 11, 2021
| uv_fs_t req; | ||
| auto defer_req_cleanup = OnScopeLeave([&req]() { | ||
| uv_fs_req_cleanup(&req); | ||
| }); |
Member
There was a problem hiding this comment.
An alternative approach (that may be a bit nicer here) is to use a smart-pointer type of mechanism like we use elsewhere... something like...
struct UvFsReq {
uv_fs_t req;
~UvFsReq() {
uv_fs_req_cleanup(&req);
}
}
Member
Author
There was a problem hiding this comment.
Sounds great, I'll do an update.
Member
Author
There was a problem hiding this comment.
After several tries, I found that wrapping with a naive data struct did not work well in the case. We have to access members of uv_fs_t and passing the pointer of uv_fs_t back to uv, like:
uv_fs_t req;
uv_fs_open(nullptr, &req, path, O_RDONLY, 0, nullptr); // <- either we write with `&UvFsReq.req` or using operators to automatically convert (which might not be very straightforward since it implicit converting from data type to pointer type)
if (req.result < 0); // <- accessing member of `uv_fs_t`, either we write with UvFsReq.req.result or explicitly declare the member proxy in UvFsReq like `UvFsReq.result()`. This is too much for the intent, a OnScopeLeave just fit in well.
As such, I'd believe it is more readable and straightforward to use uv_fs_t here. And there are a lot of precedents in the code base.
fhinkel
approved these changes
Jun 16, 2021
Member
Author
|
Landed in e4eadb2 |
legendecas
added a commit
that referenced
this pull request
Jun 16, 2021
PR-URL: #38996 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
danielleadams
pushed a commit
that referenced
this pull request
Jun 21, 2021
PR-URL: #38996 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Merged
richardlau
pushed a commit
that referenced
this pull request
Jul 19, 2021
PR-URL: #38996 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
richardlau
pushed a commit
that referenced
this pull request
Jul 20, 2021
PR-URL: #38996 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Merged
foxxyz
pushed a commit
to foxxyz/node
that referenced
this pull request
Oct 18, 2021
PR-URL: nodejs#38996 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
uv_fs_tregardless of success or not.uv_fs_tafter cleanup.This is a quite recent change, so I'm requesting original author @joyeecheung 's review.