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: add BaseObjectPtr nullptr operations #56585

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

legendecas
Copy link
Member

Allow comparing a BaseObjectPtr or implicitly construct a
BaseObjectPtr with nullptr.

Allow comparing a `BaseObjectPtr` or implicitly construct a
`BaseObjectPtr` with `nullptr`.
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/http2
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jan 13, 2025
@legendecas legendecas added the request-ci Add this label to start a Jenkins CI on a PR. label Jan 13, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 13, 2025
@nodejs-github-bot
Copy link
Collaborator

Copy link

codecov bot commented Jan 13, 2025

Codecov Report

Attention: Patch coverage is 28.00000% with 18 lines in your changes missing coverage. Please review.

Project coverage is 89.19%. Comparing base (19c8cc1) to head (7d35dba).
Report is 26 commits behind head on main.

Files with missing lines Patch % Lines
src/node_contextify.cc 0.00% 7 Missing ⚠️
src/histogram.cc 0.00% 3 Missing ⚠️
src/node_blob.cc 0.00% 2 Missing and 1 partial ⚠️
src/node_sockaddr.cc 0.00% 3 Missing ⚠️
src/node_sqlite.cc 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #56585      +/-   ##
==========================================
+ Coverage   89.16%   89.19%   +0.03%     
==========================================
  Files         662      662              
  Lines      191745   191797      +52     
  Branches    36902    36919      +17     
==========================================
+ Hits       170971   171082     +111     
+ Misses      13627    13562      -65     
- Partials     7147     7153       +6     
Files with missing lines Coverage Δ
src/base_object-inl.h 89.67% <100.00%> (+0.41%) ⬆️
src/base_object.h 90.90% <ø> (ø)
src/node_http2.cc 84.83% <100.00%> (-0.25%) ⬇️
src/quic/session.h 43.75% <ø> (-3.31%) ⬇️
src/node_sqlite.cc 79.65% <0.00%> (ø)
src/histogram.cc 73.52% <0.00%> (ø)
src/node_blob.cc 77.59% <0.00%> (+0.77%) ⬆️
src/node_sockaddr.cc 72.17% <0.00%> (ø)
src/node_contextify.cc 81.45% <0.00%> (+0.08%) ⬆️

... and 40 files with indirect coverage changes

@@ -140,7 +140,7 @@ BaseObjectPtr<ContextifyContext> ContextifyContext::New(
if (!(CreateV8Context(env->isolate(), object_template, snapshot_data, queue)
.ToLocal(&v8_context))) {
// Allocation failure, maximum call stack size reached, termination, etc.
return BaseObjectPtr<ContextifyContext>();
return nullptr;
Copy link
Member

Choose a reason for hiding this comment

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

I think I'd prefer return {}; for the pattern here using the default constructor. That would match the style we've used elsewhere and, IMO makes things a bit clearer.

Copy link
Member Author

@legendecas legendecas Jan 13, 2025

Choose a reason for hiding this comment

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

IMO BaseObjectPtr is similar to a smart pointer, i.e. shared_ptr, and nullptr shall be prefered to represent a null pointer. Like what's documented here: https://github.com/nodejs/node/blob/main/src/README.md#lifetime-management

Copy link
Member

Choose a reason for hiding this comment

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

I'd agree with @jasnell but that also extends to keeping it consistent with shared_ptr, weak_ptr and friends 🙂

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, consider it a non-blocking nit. I rather which the shared_ptr, etc cases could use the return {} approach also.

Comment on lines +260 to +261
this->~BaseObjectPtrImpl();
return *this;
Copy link
Member

Choose a reason for hiding this comment

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

I think this is technically UB? I'd maybe just make this

Suggested change
this->~BaseObjectPtrImpl();
return *this;
return *this = BaseObjectPtrImpl();

so that it's more obviously correct

Copy link
Member

Choose a reason for hiding this comment

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

Ah, right.. good catch. It looked a bit funny on review.

@@ -140,7 +140,7 @@ BaseObjectPtr<ContextifyContext> ContextifyContext::New(
if (!(CreateV8Context(env->isolate(), object_template, snapshot_data, queue)
.ToLocal(&v8_context))) {
// Allocation failure, maximum call stack size reached, termination, etc.
return BaseObjectPtr<ContextifyContext>();
return nullptr;
Copy link
Member

Choose a reason for hiding this comment

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

I'd agree with @jasnell but that also extends to keeping it consistent with shared_ptr, weak_ptr and friends 🙂

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++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants