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

src: use smart pointers in cares_wrap.cc #23813

Closed
wants to merge 6 commits into from

Conversation

danbev
Copy link
Contributor

@danbev danbev commented Oct 22, 2018

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. cares Issues and PRs related to the c-ares dependency or the cares_wrap binding. labels Oct 22, 2018
@danbev
Copy link
Contributor Author

danbev commented Oct 22, 2018

@@ -1990,8 +1990,8 @@ void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
*hostname,
nullptr,
&hints);
if (err)
delete req_wrap;
if (!err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err == 0 (ditto line 2025)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll fix this shortly.

@danbev
Copy link
Contributor Author

danbev commented Oct 23, 2018

src/cares_wrap.cc Show resolved Hide resolved
src/cares_wrap.cc Outdated Show resolved Hide resolved
src/cares_wrap.cc Outdated Show resolved Hide resolved
src/cares_wrap.cc Outdated Show resolved Hide resolved
@refack
Copy link
Contributor

refack commented Oct 23, 2018

I'm not sure this code is correct. unique_ptr has ownership semantics, it's not an RAII tool. It's not clear who owns the wraps.

From our style guide:
R.20: Use unique_ptr or shared_ptr to represent ownership

refack
refack previously requested changes Oct 23, 2018
Copy link
Contributor

@refack refack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use RAII without ownership semantics

@refack refack dismissed their stale review October 23, 2018 16:11

I'm not sure...

@danbev
Copy link
Contributor Author

danbev commented Oct 29, 2018

Please use RAII without ownership semantics

I think the code is clear as it is without using RAII, and there have been quite a few approvals for this PR. I'm happy to change if others feel the same way though.

src/cares_wrap.cc Outdated Show resolved Hide resolved
src/cares_wrap.cc Outdated Show resolved Hide resolved
@refack
Copy link
Contributor

refack commented Oct 29, 2018

Please use RAII without ownership semantics

I think the code is clear as it is without using RAII, and there have been quite a few approvals for this PR. I'm happy to change if others feel the same way though.

IIUC you are using unique_ptr for RAII. IMHO it's not the best pattern, but AFAICT it is the best we have implemented in our code ATM. So I withdrew my objections.

Since our style guide states:
R.30: Take smart pointers as parameters only to explicitly express lifetime semantics
R.20: Use unique_ptr or shared_ptr to represent ownership
All I ask is for clarifying comments, about why that guideline is broken.

@danbev
Copy link
Contributor Author

danbev commented Oct 30, 2018

@danbev
Copy link
Contributor Author

danbev commented Nov 2, 2018

Landed in 226a41a.

@danbev danbev closed this Nov 2, 2018
@danbev danbev deleted the cares_smart_pointers branch November 2, 2018 09:54
danbev added a commit that referenced this pull request Nov 2, 2018
PR-URL: #23813
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
targos pushed a commit that referenced this pull request Nov 18, 2018
PR-URL: #23813
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
rvagg pushed a commit that referenced this pull request Nov 28, 2018
PR-URL: #23813
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
@BridgeAR BridgeAR mentioned this pull request Dec 5, 2018
4 tasks
codebytere pushed a commit that referenced this pull request Jan 13, 2019
PR-URL: #23813
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
@codebytere codebytere mentioned this pull request Jan 15, 2019
codebytere pushed a commit that referenced this pull request Jan 29, 2019
PR-URL: #23813
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. cares Issues and PRs related to the c-ares dependency or the cares_wrap binding.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants