-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix: #3851 allow holder other than std::shared_ptr
to be used with class inherit from std::enable_shared_from_this
#5027
Conversation
static void init_holder(detail::instance *inst, | ||
detail::value_and_holder &v_h, | ||
const holder_type * /* unused */, | ||
const std::shared_ptr<U> * /* dummy */, |
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.
Is it conceivable that someone out there is currently using a holder_type
that needs this "variant 1"?
(It's just that we don't have a corresponding unit test?)
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.
I'm not sure, but I don't think someone would use a custom holder type that expects to be constructed from a std::shared_ptr<T>&&
rather than a T*
. If the custom holder type wraps a std::shared_ptr<T>
and utilizes std::enable_shared_from_this
, it could call shared_from_this
manually in the T*
constructor.
I apologize if I'm wrong. I'm not very familiar with this project and just happened to encounter the issue.
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.
I'm not sure
I'm not sure, too. (That's not a great basis for making a decision about this PR.)
Looking in another direction, is it true that you need this PR to support your use case here?
My reading of it:
- You are manufacturing a pybind11 holder to tie the lifetime of
ov::Model
to the lifetime ofov::CompiledModel
.
Is that a correct interpretation?
If yes, that's a very unobvious and convoluted way to implement a lifetime dependency.
If model
does indeed have to outlive compiled_model
, the obvious solution would be to simply add a private member here and populate if from the icompiled_model
ctor (which already receives a std::shared_ptr<model>
):
std::shared_ptr<model> m_input_model;
That will also ensure pure C++ code is memory-safer in general.
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.
Thanks for the advice. This is indeed a convoluted way to do that. I've figured out a way to solve that issue, and this PR would not need to be merged now. Should I close this PR?
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.
Sounds great! Yes, please close this PR if you no longer need it.
Description
Hi, this pr is to fix issue #3851. The
variant 1
here should only be executed when the holder type is astd::shared_ptr
, as explained in the issue page.pybind11/include/pybind11/pybind11.h
Lines 1851 to 1869 in 8b48ff8
pybind11/include/pybind11/pybind11.h
Lines 1885 to 1898 in 8b48ff8
A test is also created, which can only be compiled with the bug fixed.
Suggested changelog entry: