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

Allow nonconstructible holders #2067

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

pd-robgee
Copy link

Fixes #1178

This PR implements the fix from 53be819.
That fix by itself leads to an uncaught exception instead of a Python RuntimeError, this is fixed in this PR.
Furthermore test cases have been added.

jagerman and others added 6 commits November 9, 2017 21:48
Fixes pybind#1178

It's possible for a non-destructible base class to be declared; such a
holder *can* be obtained via `std::enable_shared_from_this`, but a
shared_ptr cannot be constructed from a returned pointer.

This commit puts the holder constructor behind a `std::is_destructible`
check, giving a runtime failure if we are ever given such a pointer
without a valid `shared_from_this()` shared pointer.
…struct from existing holder object, if possible'
… with another holder type should still be a compile error.

Manually caught and converted exception to Python exception, otherwise it escapes and std::terminate() is called.
@wanfranck
Copy link

Sorry to interrupt, but is there any progress on this issue? I feel like I'm facing the problem which could be easily fixed as soom as this PR will be merged. Best regards.

@pd-robgee
Copy link
Author

Unfortunately the project maintainers didn't/don't seem very interested in incorporating this suggestion into their code base. As can be seen from this PRs conversation page I requested a review from three suggested reviewers, but to this day none of them have even commented anything at all.

I have accepted this fate and worked around it by incorporating this patch via the build system in the project I used pybind11 in. I have since moved on to other projects and I'm no longer involved in that project. Therefore, attempting to get this PR merged is no longer a high priority for me. I'm sorry @wanfranck, but thank you for your interest in this patch anyway!

@EricCousineau-TRI
Copy link
Collaborator

@rwgk Can you advise on how this may (or may not) be more admissible via the smart_holder based workflow?

At first blush, concerned about performance and code impacts given core part of code (broadly #2760; acutely, should have scoped benchmark).

tomba added a commit to tomba/libcamera that referenced this pull request Jan 24, 2022
pybind11 needs a public destructor for Camera to be able to manage the
shared_ptr. It's not clear why this is needed, and can it be fixed in
pybind11.

Looks like there's a suggested fix, which has not been merged:

pybind/pybind11#2067

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
@pinchartl
Copy link

The libcamera Python bindings are blocked by this issue. A review would be appreciated. If a different approach is needed, we would like to know.

naushir pushed a commit to naushir/libcamera that referenced this pull request Mar 3, 2022
pybind11 needs a public destructor for Camera to be able to manage the
shared_ptr. It's not clear why this is needed, and can it be fixed in
pybind11.

Looks like there's a suggested fix, which has not been merged:

pybind/pybind11#2067

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
naushir pushed a commit to naushir/libcamera that referenced this pull request Mar 4, 2022
pybind11 needs a public destructor for Camera to be able to manage the
shared_ptr. It's not clear why this is needed, and can it be fixed in
pybind11.

Looks like there's a suggested fix, which has not been merged:

pybind/pybind11#2067

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
@rwgk
Copy link
Collaborator

rwgk commented Mar 4, 2022

The libcamera Python bindings are blocked by this issue. A review would be appreciated. If a different approach is needed, we would like to know.

Have you tried the smart_holder branch? It's basically drop-in, use classh<T> instead of class_<T, shared_ptr<T>> where needed (fine to only use where actually needed). At Google we are using the smart_holder code with private destructors.

davidplowman pushed a commit to raspberrypi/libcamera that referenced this pull request Mar 7, 2022
pybind11 needs a public destructor for Camera to be able to manage the
shared_ptr. It's not clear why this is needed, and can it be fixed in
pybind11.

Looks like there's a suggested fix, which has not been merged:

pybind/pybind11#2067

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
davidplowman pushed a commit to raspberrypi/libcamera that referenced this pull request Mar 31, 2022
pybind11 needs a public destructor for Camera to be able to manage the
shared_ptr. It's not clear why this is needed, and can it be fixed in
pybind11.

Looks like there's a suggested fix, which has not been merged:

pybind/pybind11#2067

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
davidplowman pushed a commit to raspberrypi/libcamera that referenced this pull request Apr 26, 2022
pybind11 needs a public destructor for Camera to be able to manage the
shared_ptr. It's not clear why this is needed, and can it be fixed in
pybind11.

Looks like there's a suggested fix, which has not been merged:

pybind/pybind11#2067

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
jhautbois pushed a commit to jhautbois/libcamera that referenced this pull request May 2, 2022
pybind11 needs a public destructor for Camera to be able to manage the
shared_ptr. It's not clear why this is needed, and can it be fixed in
pybind11.

Looks like there's a suggested fix, which has not been merged:

pybind/pybind11#2067

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
kbingham pushed a commit to kbingham/libcamera that referenced this pull request May 10, 2022
Add libcamera Python bindings. pybind11 is used to generate the C++ <->
Python layer.

We use pybind11 'smart_holder' version to avoid issues with private
destructors and shared_ptr. There is also an alternative solution here:

pybind/pybind11#2067

Only a subset of libcamera classes are exposed. Implementing and testing
the wrapper classes is challenging, and as such only classes that I have
needed have been added so far.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
@dean0x7d dean0x7d removed their request for review June 9, 2023 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shared Pointers and Protected Destructors
6 participants