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
[ Show hidden characters]({{ revealButtonHref }})
Original file line number
Diff line number
Diff line change
Expand Up
@@ -1521,10 +1521,7 @@ struct copyable_holder_caster : public type_caster_base {
protected:
friend class type_caster_generic;
void check_holder_compat() {
if (typeinfo->default_holder)
throw cast_error("Unable to load a custom holder type from a default-holder instance");
Copy link Collaborator EricCousineau-TRIDec 22, 2020 • edited Loading Choose a reason for hiding this comment The reason will be displayed to describe this comment to others. Learn more. nit To me, it looks like holder is really holder_caster. Should this be is_holder_caster? Copy link Collaborator YannickJadoulJan 5, 2021 Choose a reason for hiding this comment The reason will be displayed to describe this comment to others. Learn more. This already exists in cast.h, it seems? // PYBIND11_DECLARE_HOLDER_TYPE holder types: template <typename base, typename holder> struct is_holder_type : std::is_base_of<detail::type_caster_holder<base, holder>, detail::type_caster> {}; // Specialization for always-supported unique_ptr holders: template <typename base, typename deleter> struct is_holder_type<base, std::unique_ptr<base, deleter>> : std::true_type {}; Copy link Contributor Author rhaschkeJan 6, 2021 Choose a reason for hiding this comment The reason will be displayed to describe this comment to others. Learn more. Yeah, I missed that. The existing definition should serve my purpose. YannickJadoul reacted with thumbs up emoji
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
/* True if there is no multiple inheritance in this type's inheritance tree */
bool simple_ancestors : 1;
/* for base vs derived holder_type checks */
bool default_holder : 1;
/* true if this is a type registered with py::module_local */
bool module_local : 1;
};
/// Tracks the `internals` and `type_info` ABI version independent of the main library version
#define PYBIND11_INTERNALS_VERSION 4
#define PYBIND11_INTERNALS_VERSION 5
Copy link Collaborator YannickJadoulJan 5, 2021 Choose a reason for hiding this comment The reason will be displayed to describe this comment to others. Learn more. This breaks ABI, so should ideally be part of a batch of ABI-breaking PRs.
/// On MSVC, debug and release builds are not ABI-compatible!
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
[ Show hidden characters]({{ revealButtonHref }})
Original file line number
Diff line number
Diff line change
Expand Up
@@ -157,6 +157,13 @@ class cpp_function : public function {
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
m.def("register_mismatch_return", [](py::module m) {
Copy link Collaborator EricCousineau-TRIDec 22, 2020 • edited Loading Choose a reason for hiding this comment The reason will be displayed to describe this comment to others. Learn more. My brief reading of this PR leads me to believe that there's a sharp edge: a user could still hit a segfault if they call py::cast<mismatched_holder_type>(my_object). Totes get the idea of wanting to shift overhead from py::cast<>() (runtime) to function declarations (binding-time, e.g. .def()), but it now means there are now distinct entry points to this type-checking that users can trigger :( Possible resolutions: if it's worth the risk, then just mention it in the holder / smart pointer docs (as a diff in this PR) If it's not worth the risk, somehow enable raw py::cast<>() to do a runtime check. This may make for some crazy dumb plumbing, though :( Alternatively, eat the cost of runtime casts and funnel it through type_caster<>. That's what we do for our fork (RobotLocomotion/pybind11), and we haven't yet had to point fingers at performance there (though our use case may be simpler). @YannickJadoul or @rwgk Any chance y'all have a good (and mebbe easy?) timing performance benchmark for this, to see what the risk is in these terms? EDIT: Hm... for docs/benchmark.py, it's only for compilation time and size, and doesn't really dip into the more nuanced things (e.g. inheritance, custom type casters). Copy link Collaborator rwgkDec 24, 2020 Choose a reason for hiding this comment The reason will be displayed to describe this comment to others. Learn more. @EricCousineau-TRI wrote: Any chance y'all have a good (and mebbe easy?) timing performance benchmark for this, to see what the risk is in these terms? The TensorFlow core team has very sophisticated pybind11 benchmarks, but it's currently Google-internal only. The author already gave me permission to extract most of it for external view, including sources, but it may take me a few days (I want to show what I extract to the author for approval). Copy link Collaborator EricCousineau-TRIDec 28, 2020 Choose a reason for hiding this comment The reason will be displayed to describe this comment to others. Learn more. Sweet!!! That'd be awesome! I'll see if I can gather some common "complex" patterns in Drake to see if I can get some patterns we have (but maintain feature-parity with upstream). Have you thought any about where your benchmarks might live? I think the ones I'd generate would be simple enough (i.e. just pybind11 bits) to be in a benchmarking subdirectory. Copy link Contributor Author rhaschkeJan 6, 2021 Choose a reason for hiding this comment The reason will be displayed to describe this comment to others. Learn more. I explicitly converted my previous code doing compatibility checks at cast time to this code, doing these tests at definition time only, because of efficiency concerns raised elsewhere.
// Fails: the class was already registered with a shared_ptr holder
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