-
Notifications
You must be signed in to change notification settings - Fork 10
Support ownership transfer between C++ and Python with shared_ptr<T>
and unique_ptr<T>
for pure C++ instances and single-inheritance instances
#2
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
Conversation
shared_ptr<T>
and unique_ptr<T>
for pure C++ instances and single-inheritance instances shared_ptr<T>
and unique_ptr<T>
for pure C++ instances and single-inheritance instances
a1a12b6
to
d8ab611
Compare
+@m-chaturvedi for dev-folder feature review on testing, please. I've paired the review down to the following files:
The tests should now pass on all of TravisCI (I disabled the tests on PyPy for the time being). Review status: 0 of 16 files reviewed at latest revision, all discussions resolved. Comments from Reviewable |
f87b396
to
d7162d8
Compare
docs/advanced/classes.rst, line 1010 at r2 (raw file):
Comments from Reviewable |
tests/test_smart_ptr.cpp, line 43 at r2 (raw file):
Comments from Reviewable |
What would be the expected behavior of something like a smart pointer to a numpy matrix of objects ? Would we need tests for that ? Comments from Reviewable |
Reviewed 12 of 16 files at r1, 5 of 5 files at r2. Comments from Reviewable |
I tried out placing NumPy objects in smart pointers, and For MI, the existing unittests pass; for Would you be OK with a TODO on resolving this? (At present, we are not using any MI within Drake, at least that I'm aware of for the public-facing API.) Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks failed. Comments from Reviewable |
Wow, this is really cool! I'm still concerned about the idea of trying to limit Python objects to a single reference when passing them to a function expecting a > x = NewX()
> foo(x) but the following will result in > x = NewX()
> x # look at x
> foo(x) This would seem to literally create Heisenbugs, since a wrapped object can be constructed and passed, but only if it is never examined. More confusingly, since the default I've still never encountered any Python code that required an object to have a single reference (and googling for things like "python unique reference", I can't find any code either). There are just so many ways for additional references to crop up that getting the refcount to exactly 1 seems impractical. Or am I missing something? |
d7162d8
to
2df39b2
Compare
…` and `unique_ptr<T>` for pure C++ instances and single-inheritance instances
2df39b2
to
93d99ac
Compare
Nope, not at all, you're spot on! My desire was to have the Python bindings play well with the existing Systems framework, but then transition it over to use Review status: 12 of 18 files reviewed at latest revision, 2 unresolved discussions. docs/advanced/classes.rst, line 1010 at r2 (raw file): Previously, m-chaturvedi (Mmanu Chaturvedi) wrote…
Done. tests/test_smart_ptr.cpp, line 43 at r2 (raw file): Previously, m-chaturvedi (Mmanu Chaturvedi) wrote…
Done. Comments from Reviewable |
@m-chaturvedi Seems that the behavior I was trying to test in my branch is also broken in Review status: 12 of 18 files reviewed at latest revision, 2 unresolved discussions. Comments from Reviewable |
Ok, well, I'm convinced that you've given this more thought than I have, so I'll trust your judgment. |
Reviewed 6 of 7 files at r3. Comments from Reviewable |
Review status: all files reviewed at latest revision, all discussions resolved, some commit checks failed. Comments from Reviewable |
Review status: all files reviewed at latest revision, all discussions resolved, some commit checks failed. Comments from Reviewable |
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 via Reviewable.
This uses pybind#1146 to enable the initial PRs for the systems framework Python bindings.
In the future, we may only need a subset (or none of) this PR, and may be able to revert back to upstream
pybind11
.Current state of the unittests:
This change is