Allow nonconstructible holders#2067
Conversation
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.
Known issue: MSVC incorrectly rejects "enable_if_t = 0" SFINAE https://developercommunity.visualstudio.com/content/problem/848104/msvc-incorrectly-rejects-enable-if-t-0-sfinae.html
|
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. |
|
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! |
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>
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>
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>
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>
Have you tried the smart_holder branch? It's basically drop-in, use |
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>
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>
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>
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>
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>
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.