-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Missing cast from const unique_ptr& #2904
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
Merged
rwgk
merged 2 commits into
pybind:smart_holder
from
rhaschke:cast-unique-ptr-const-reference
Mar 17, 2021
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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.
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.
Aha :-)
That makes everything clear immediately, thanks!
Initial thought: This is very similar to
static handle cast(const T *src, ...)
. We could mimic that implementation, or maybe even reuse? The easy case is that an instance exists already and we just incref as you suggest. Or there needs to bereturn_value_policy::reference_internal
or an explicitkeep_alive
.Is there a chance you could help with that implementation? It's unlikely that I can prioritize working on this myself anytime soon, unless I hit on a use case in PyCLIF (difficult to predict). But I will review & merge very quickly if you take the lead.
My revised suggestion for a separate new unit test name iff we cannot reuse
static handle cast(const T *src, ...)
: test_class_sh_const_unique_returnKeeping the tests separate helps minimizing merge issues (between master, drake, smart_holder) and is best practice IMO regardless.
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.
Done. Thanks for the hint to
cast(const T*)
. Regarding the unit test: I think we should have a unit test in any case.Do you suggest to move the test into a new file, named
test_class_sh_const_unique_return.cpp
or to include a test namedtest_class_sh_const_unique_return
into some existing file?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.
Hm. I don't understand why CI fails, while locally it works fine. Need to investigate later...
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.
Oh, sorry to be ambiguous: I was thinking of
test_class_sh_const_unique_return.cpp
and.py
.I think I also want to add a few lines to
test_class_sh_basic.cpp
and.py
, but that's a small enough effort I could squeeze that in myself.