diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 18c96d293..ab9447d2d 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -848,11 +848,19 @@ public: using base::value; bool load(handle src, bool convert) { +#ifdef JUNK if (typeinfo->default_holder) { - return type_caster_generic::load(src, convert); + printf("\nLOOOK shd load(src, convert) A\n"); fflush(stdout); // NOLINT + bool retval = type_caster_generic::load(src, convert); + printf("\nLOOOK shd load(src, convert) B %ld\n", (long) value); fflush(stdout); // NOLINT + return retval; } - return base::template load_impl>>( +#endif + printf("\nLOOOK shd load(src, convert) X\n"); fflush(stdout); // NOLINT + bool retval = base::template load_impl>>( src, convert); + printf("\nLOOOK shd load(src, convert) Y %ld\n", (long) value); fflush(stdout); // NOLINT + return retval; } explicit operator type *() { @@ -880,7 +888,9 @@ public: explicit operator std::shared_ptr &() { if (typeinfo->default_holder) { +printf("\nLOOOK operator std::shared_ptr & A %ld %s:%d\n", (long) value, __FILE__, __LINE__); fflush(stdout); // NOLINT shared_ptr_holder = sh_load_helper.loaded_as_shared_ptr(value); +printf("\nLOOOK operator std::shared_ptr & B %ld %s:%d\n", (long) shared_ptr_holder.get(), __FILE__, __LINE__); fflush(stdout); // NOLINT } return shared_ptr_holder; } @@ -920,9 +930,12 @@ protected: } void load_value(value_and_holder &&v_h) { +printf("\nLOOOK shd load_value(v_h) ENTRY\n"); fflush(stdout); // NOLINT if (typeinfo->default_holder) { +printf("\nLOOOK shd load_value(v_h) A\n"); fflush(stdout); // NOLINT sh_load_helper.loaded_v_h = v_h; type_caster_generic::load_value(std::move(v_h)); +printf("\nLOOOK shd load_value(v_h) B\n"); fflush(stdout); // NOLINT return; } load_value_shared_ptr(v_h); @@ -938,7 +951,24 @@ protected: detail::enable_if_t::value, int> = 0> bool try_implicit_casts(handle src, bool convert) { if (typeinfo->default_holder) { - return type_caster_generic::try_implicit_casts(src, convert); +#ifdef JUNK + printf("\nLOOOK shd try_implicit_casts(src, convert) E\n"); fflush(stdout); // NOLINT + bool retval = type_caster_generic::try_implicit_casts(src, convert); + printf("\nLOOOK shd try_implicit_casts(src, convert) F\n"); fflush(stdout); // NOLINT + return retval; +#endif + printf("\nLOOOK shd try_implicit_casts(src, convert) Q\n"); fflush(stdout); // NOLINT + for (auto &cast : typeinfo->implicit_casts) { + printf("\nLOOOK shd try_implicit_casts(src, convert) R\n"); fflush(stdout); // NOLINT + copyable_holder_caster sub_caster(*cast.first); + if (sub_caster.load(src, convert)) { + printf("\nLOOOK shd try_implicit_casts(src, convert) S\n"); fflush(stdout); // NOLINT + value = cast.second(sub_caster.value); + sh_load_helper.loaded_v_h = sub_caster.sh_load_helper.loaded_v_h; + return true; + } + } + return false; } for (auto &cast : typeinfo->implicit_casts) { copyable_holder_caster sub_caster(*cast.first); diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index 779bb15a4..f6cbbbce2 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -835,9 +835,11 @@ struct load_helper : value_and_holder_helper { std::shared_ptr loaded_as_shared_ptr(void *void_raw_ptr, handle responsible_parent = nullptr) const { +printf("\nLOOOK %s:%d\n", __FILE__, __LINE__); fflush(stdout); // NOLINT if (!have_holder()) { return nullptr; } +printf("\nLOOOK %s:%d\n", __FILE__, __LINE__); fflush(stdout); // NOLINT throw_if_uninitialized_or_disowned_holder(typeid(T)); holder_type &hld = holder(); hld.ensure_is_not_disowned("loaded_as_shared_ptr"); @@ -1110,6 +1112,7 @@ public: type_caster_generic sub_caster(*cast.first); if (sub_caster.load(src, convert)) { value = cast.second(sub_caster.value); + printf("\nLOOOK implicit from %ld to %ld\n", (long) sub_caster.value, (long) value); fflush(stdout); // NOLINT return true; } } diff --git a/tests/test_class_sh_mi_thunks.cpp b/tests/test_class_sh_mi_thunks.cpp index c4f430e86..a34ef308a 100644 --- a/tests/test_class_sh_mi_thunks.cpp +++ b/tests/test_class_sh_mi_thunks.cpp @@ -58,6 +58,8 @@ TEST_SUBMODULE(class_sh_mi_thunks, m) { []() { auto *drvd = new Derived; auto *base0 = dynamic_cast(drvd); +printf("\nLOOOK get raw drvd %ld\n", (long) drvd); fflush(stdout); // NOLINT +printf("\nLOOOK get raw base %ld\n", (long) base0); fflush(stdout); // NOLINT return base0; }, py::return_value_policy::take_ownership); @@ -65,6 +67,8 @@ TEST_SUBMODULE(class_sh_mi_thunks, m) { m.def("get_drvd_as_base0_shared_ptr", []() { auto drvd = std::make_shared(); auto base0 = std::dynamic_pointer_cast(drvd); +printf("\nLOOOK get shd drvd %ld\n", (long) drvd.get()); fflush(stdout); // NOLINT +printf("\nLOOOK get shd base %ld\n", (long) base0.get()); fflush(stdout); // NOLINT return base0; }); @@ -75,7 +79,9 @@ TEST_SUBMODULE(class_sh_mi_thunks, m) { }); m.def("vec_size_base0_raw_ptr", [](const Base0 *obj) { +printf("\nLOOOK raw const Base0 *obj %ld\n", (long) obj); fflush(stdout); // NOLINT const auto *obj_der = dynamic_cast(obj); +printf("\nLOOOK raw const auto *obj_der %ld\n", (long) obj_der); fflush(stdout); // NOLINT if (obj_der == nullptr) { return std::size_t(0); } @@ -83,7 +89,9 @@ TEST_SUBMODULE(class_sh_mi_thunks, m) { }); m.def("vec_size_base0_shared_ptr", [](const std::shared_ptr &obj) -> std::size_t { +printf("\nLOOOK shd const Base0 *obj %ld\n", (long) obj.get()); fflush(stdout); // NOLINT const auto obj_der = std::dynamic_pointer_cast(obj); +printf("\nLOOOK shd const auto *obj_der %ld\n", (long) obj_der.get()); fflush(stdout); // NOLINT if (!obj_der) { return std::size_t(0); } diff --git a/tests/test_class_sh_mi_thunks.py b/tests/test_class_sh_mi_thunks.py index c1c8a3043..9f1957700 100644 --- a/tests/test_class_sh_mi_thunks.py +++ b/tests/test_class_sh_mi_thunks.py @@ -30,8 +30,11 @@ def test_ptrdiff_drvd_base0(): ], ) def test_get_vec_size_raw_shared(get_fn, vec_size_fn): + print(f"\nLOOOK A", flush=True) obj = get_fn() + print(f"\nLOOOK B", flush=True) assert vec_size_fn(obj) == 5 + print(f"\nLOOOK C", flush=True) @pytest.mark.parametrize(