diff --git a/include/pybind11/detail/smart_holder_poc.h b/include/pybind11/detail/smart_holder_poc.h index 223e1b1f3..5c4f565fc 100644 --- a/include/pybind11/detail/smart_holder_poc.h +++ b/include/pybind11/detail/smart_holder_poc.h @@ -48,38 +48,18 @@ Details: #pragma once -#include #include #include #include #include #include -// #include -// inline void to_cout(const std::string &msg) { std::cout << msg << std::endl; } -inline void to_cout(const std::string &) {} - // pybindit = Python Bindings Innovation Track. // Currently not in pybind11 namespace to signal that this POC does not depend // on any existing pybind11 functionality. namespace pybindit { namespace memory { -inline int shared_from_this_status(...) { return 0; } - -template -#if defined(__cpp_lib_enable_shared_from_this) && (!defined(_MSC_VER) || _MSC_VER >= 1912) -inline int shared_from_this_status(const std::enable_shared_from_this *ptr) { - if (ptr->weak_from_this().lock()) - return 1; - return -1; -} -#else -inline int shared_from_this_status(const std::enable_shared_from_this *) { - return 999; -} -#endif - struct guarded_delete { std::weak_ptr released_ptr; // Trick to keep the smart_holder memory footprint small. void (*del_ptr)(void *); @@ -259,9 +239,6 @@ struct smart_holder { template static smart_holder from_raw_ptr_take_ownership(T *raw_ptr, bool void_cast_raw_ptr = false) { - to_cout(""); - to_cout("LOOOK smart_holder from_raw_ptr_take_ownership " + std::to_string(__LINE__) + " " - + __FILE__); ensure_pointee_is_destructible("from_raw_ptr_take_ownership"); smart_holder hld; auto gd = make_guarded_builtin_delete(true); @@ -304,8 +281,6 @@ struct smart_holder { template T *as_raw_ptr_release_ownership(const char *context = "as_raw_ptr_release_ownership") { - to_cout("LOOOK smart_holder as_raw_ptr_release_ownership " + std::to_string(__LINE__) + " " - + __FILE__); ensure_can_release_ownership(context); T *raw_ptr = as_raw_ptr_unowned(); release_ownership(); @@ -315,7 +290,6 @@ struct smart_holder { template static smart_holder from_unique_ptr(std::unique_ptr &&unq_ptr, bool void_cast_raw_ptr = false) { - to_cout("LOOOK smart_holder from_unique_ptr " + std::to_string(__LINE__) + " " + __FILE__); smart_holder hld; hld.rtti_uqp_del = &typeid(D); hld.vptr_is_using_builtin_delete = is_std_default_delete(*hld.rtti_uqp_del); @@ -335,7 +309,6 @@ struct smart_holder { template > std::unique_ptr as_unique_ptr() { - to_cout("LOOOK smart_holder as_unique_ptr " + std::to_string(__LINE__) + " " + __FILE__); static const char *context = "as_unique_ptr"; ensure_compatible_rtti_uqp_del(context); ensure_use_count_1(context); @@ -346,7 +319,6 @@ struct smart_holder { template static smart_holder from_shared_ptr(std::shared_ptr shd_ptr) { - to_cout("LOOOK smart_holder from_shared_ptr " + std::to_string(__LINE__) + " " + __FILE__); smart_holder hld; hld.vptr = std::static_pointer_cast(shd_ptr); hld.vptr_is_external_shared_ptr = true; @@ -356,7 +328,6 @@ struct smart_holder { template std::shared_ptr as_shared_ptr() const { - to_cout("LOOOK smart_holder as_shared_ptr " + std::to_string(__LINE__) + " " + __FILE__); return std::static_pointer_cast(vptr); } }; diff --git a/include/pybind11/detail/smart_holder_type_casters.h b/include/pybind11/detail/smart_holder_type_casters.h index a906ae642..ba94a158c 100644 --- a/include/pybind11/detail/smart_holder_type_casters.h +++ b/include/pybind11/detail/smart_holder_type_casters.h @@ -18,7 +18,6 @@ #include "type_caster_base.h" #include "typeid.h" -#include #include #include #include @@ -378,8 +377,6 @@ struct smart_holder_type_caster_load { struct shared_ptr_dec_ref_deleter { PyObject *self; void operator()(void *) { - to_cout("LOOOK shared_ptr_dec_ref_deleter call " + std::to_string(__LINE__) + " " - + __FILE__); gil_scoped_acquire gil; Py_DECREF(self); } @@ -707,13 +704,10 @@ struct smart_holder_type_caster> : smart_holder_type_caster_l void *src_raw_void_ptr = static_cast(src_raw_ptr); const detail::type_info *tinfo = st.second; - if (handle existing_inst = find_registered_python_instance(src_raw_void_ptr, tinfo)) { + if (handle existing_inst = find_registered_python_instance(src_raw_void_ptr, tinfo)) // SMART_HOLDER_WIP: MISSING: Enforcement of consistency with existing smart_holder. // SMART_HOLDER_WIP: MISSING: keep_alive. - to_cout("LOOOK shtc sh return existing_inst " + std::to_string(__LINE__) + " " - + __FILE__); return existing_inst; - } auto inst = reinterpret_steal(make_new_instance(tinfo->type)); auto *inst_raw_ptr = reinterpret_cast(inst.ptr()); @@ -727,7 +721,6 @@ struct smart_holder_type_caster> : smart_holder_type_caster_l if (policy == return_value_policy::reference_internal) keep_alive_impl(inst, parent); - to_cout("LOOOK shtc sh return new inst " + std::to_string(__LINE__) + " " + __FILE__); return inst.release(); } diff --git a/tests/test_class_sh_trampoline_shared_from_this.cpp b/tests/test_class_sh_trampoline_shared_from_this.cpp index 81024dc6f..b5686d2f2 100644 --- a/tests/test_class_sh_trampoline_shared_from_this.cpp +++ b/tests/test_class_sh_trampoline_shared_from_this.cpp @@ -75,13 +75,10 @@ struct SftTrampoline : Sft, py::trampoline_self_life_support { long use_count(const std::shared_ptr &obj) { return obj.use_count(); } long pass_shared_ptr(const std::shared_ptr &obj) { - to_cout("pass_shared_ptr BEGIN"); auto sft = obj->shared_from_this(); - to_cout("pass_shared_ptr got sft"); if (!sft->history.empty()) { sft->history += "_PassSharedPtr"; } - to_cout("pass_shared_ptr END"); return sft.use_count(); } @@ -121,5 +118,4 @@ TEST_SUBMODULE(class_sh_trampoline_shared_from_this, m) { m.def("make_pure_cpp_sft_raw_ptr", make_pure_cpp_sft_raw_ptr); m.def("make_pure_cpp_sft_unq_ptr", make_pure_cpp_sft_unq_ptr); m.def("make_pure_cpp_sft_shd_ptr", make_pure_cpp_sft_shd_ptr); - m.def("to_cout", to_cout); }