From fc5678b08b6df569950f2eed569370b9c1bf3f7c Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 3 Jul 2024 11:26:04 -0700 Subject: [PATCH] Add `value_and_holder loaded_v_h;` member (set, but currently unused). --- include/pybind11/cast.h | 44 +++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index ccf148106..e0fee7557 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -853,12 +853,35 @@ public: src, convert); } - explicit operator type *() { return this->value; } - // static_cast works around compiler error with MSVC 17 and CUDA 10.2 - // see issue #2180 - explicit operator type &() { return *(static_cast(this->value)); } - explicit operator std::shared_ptr *() { return std::addressof(shared_ptr_holder); } - explicit operator std::shared_ptr &() { return shared_ptr_holder; } + explicit operator type *() { + if (typeinfo->default_holder) { + throw std::runtime_error("BAKEIN_WIP: operator type *()"); + } + return this->value; + } + + explicit operator type &() { + if (typeinfo->default_holder) { + throw std::runtime_error("BAKEIN_WIP: operator type &()"); + } + // static_cast works around compiler error with MSVC 17 and CUDA 10.2 + // see issue #2180 + return *(static_cast(this->value)); + } + + explicit operator std::shared_ptr *() { + if (typeinfo->default_holder) { + throw std::runtime_error("BAKEIN_WIP: operator std::shared_ptr *()"); + } + return std::addressof(shared_ptr_holder); + } + + explicit operator std::shared_ptr &() { + if (typeinfo->default_holder) { + throw std::runtime_error("BAKEIN_WIP: operator std::shared_ptr &()"); + } + return shared_ptr_holder; + } static handle cast(const std::shared_ptr &src, return_value_policy policy, handle parent) { @@ -885,8 +908,9 @@ protected: #endif } - bool load_value_smart_holder(value_and_holder && /*v_h*/) { - throw std::runtime_error("BAKEIN_WIP load_value_smart_holder"); + bool load_value_smart_holder(value_and_holder &&v_h) { + loaded_v_h = v_h; + return true; } bool load_value(value_and_holder &&v_h) { @@ -905,6 +929,9 @@ protected: template , detail::enable_if_t::value, int> = 0> bool try_implicit_casts(handle src, bool convert) { + if (typeinfo->default_holder) { + throw std::runtime_error("BAKEIN_WIP: try_implicit_casts"); + } for (auto &cast : typeinfo->implicit_casts) { copyable_holder_caster sub_caster(*cast.first); if (sub_caster.load(src, convert)) { @@ -920,6 +947,7 @@ protected: static bool try_direct_conversions(handle) { return false; } std::shared_ptr shared_ptr_holder; + value_and_holder loaded_v_h; }; /// Specialize for the common std::shared_ptr, so users don't need to