mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 14:45:12 +00:00
MESSY but success for: test_get_vec_size_raw_shared[get_drvd_as_base0_raw_ptr-vec_size_base0_shared_ptr]
scons -j 48 selected_test_cpp=test_class_sh_mi_thunks.cpp && "$(cat PYROOT)"/bin/python3 $HOME/clone/pybind11_scons/run_tests.py ../pybind11 test_class_sh_mi_thunks.py -s -vv -k 'test_get_vec_size_raw_shared[get_drvd_as_base0_raw_ptr-vec_size_base0_shared_ptr]' ``` =========================================================== test session starts ============================================================ platform linux -- Python 3.11.8, pytest-7.4.4, pluggy-1.5.0 -- /usr/bin/python3 cachedir: .pytest_cache C++ Info: 13.2.0 C++20 __pybind11_internals_v10000000_gcc_libstdcpp_cxxabi1018__ PYBIND11_SIMPLE_GIL_MANAGEMENT=False PYBIND11_NUMPY_1_ONLY=False rootdir: /usr/local/google/home/rwgk/forked/pybind11/tests configfile: pytest.ini plugins: xdist-3.5.0 collected 10 items / 9 deselected / 1 selected test_class_sh_mi_thunks.py::test_get_vec_size_raw_shared[get_drvd_as_base0_raw_ptr-vec_size_base0_shared_ptr] LOOOK A LOOOK get raw drvd 47927280 LOOOK get raw base 47927312 LOOOK B LOOOK shd load(src, convert) X LOOOK shd try_implicit_casts(src, convert) Q LOOOK shd try_implicit_casts(src, convert) R LOOOK shd load(src, convert) X LOOOK shd load_value(v_h) ENTRY LOOOK shd load_value(v_h) A LOOOK shd load_value(v_h) B LOOOK shd load(src, convert) Y 47927280 LOOOK shd try_implicit_casts(src, convert) S LOOOK shd load(src, convert) Y 47927312 LOOOK operator std::shared_ptr<type> & A 47927312 /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/../cast.h:891 LOOOK /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/../detail/type_caster_base.h:838 LOOOK /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/../detail/type_caster_base.h:842 LOOOK operator std::shared_ptr<type> & B 47927312 /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/../cast.h:893 LOOOK shd const Base0 *obj 47927312 LOOOK shd const auto *obj_der 47927280 LOOOK C PASSED ===================================================== 1 passed, 9 deselected in 0.01s ====================================================== ```
This commit is contained in:
parent
eb15f1a384
commit
bb6b429a2f
@ -848,11 +848,19 @@ public:
|
|||||||
using base::value;
|
using base::value;
|
||||||
|
|
||||||
bool load(handle src, bool convert) {
|
bool load(handle src, bool convert) {
|
||||||
|
#ifdef JUNK
|
||||||
if (typeinfo->default_holder) {
|
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<copyable_holder_caster<type, std::shared_ptr<type>>>(
|
#endif
|
||||||
|
printf("\nLOOOK shd load(src, convert) X\n"); fflush(stdout); // NOLINT
|
||||||
|
bool retval = base::template load_impl<copyable_holder_caster<type, std::shared_ptr<type>>>(
|
||||||
src, convert);
|
src, convert);
|
||||||
|
printf("\nLOOOK shd load(src, convert) Y %ld\n", (long) value); fflush(stdout); // NOLINT
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit operator type *() {
|
explicit operator type *() {
|
||||||
@ -880,7 +888,9 @@ public:
|
|||||||
|
|
||||||
explicit operator std::shared_ptr<type> &() {
|
explicit operator std::shared_ptr<type> &() {
|
||||||
if (typeinfo->default_holder) {
|
if (typeinfo->default_holder) {
|
||||||
|
printf("\nLOOOK operator std::shared_ptr<type> & A %ld %s:%d\n", (long) value, __FILE__, __LINE__); fflush(stdout); // NOLINT
|
||||||
shared_ptr_holder = sh_load_helper.loaded_as_shared_ptr(value);
|
shared_ptr_holder = sh_load_helper.loaded_as_shared_ptr(value);
|
||||||
|
printf("\nLOOOK operator std::shared_ptr<type> & B %ld %s:%d\n", (long) shared_ptr_holder.get(), __FILE__, __LINE__); fflush(stdout); // NOLINT
|
||||||
}
|
}
|
||||||
return shared_ptr_holder;
|
return shared_ptr_holder;
|
||||||
}
|
}
|
||||||
@ -920,9 +930,12 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void load_value(value_and_holder &&v_h) {
|
void load_value(value_and_holder &&v_h) {
|
||||||
|
printf("\nLOOOK shd load_value(v_h) ENTRY\n"); fflush(stdout); // NOLINT
|
||||||
if (typeinfo->default_holder) {
|
if (typeinfo->default_holder) {
|
||||||
|
printf("\nLOOOK shd load_value(v_h) A\n"); fflush(stdout); // NOLINT
|
||||||
sh_load_helper.loaded_v_h = v_h;
|
sh_load_helper.loaded_v_h = v_h;
|
||||||
type_caster_generic::load_value(std::move(v_h));
|
type_caster_generic::load_value(std::move(v_h));
|
||||||
|
printf("\nLOOOK shd load_value(v_h) B\n"); fflush(stdout); // NOLINT
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
load_value_shared_ptr(v_h);
|
load_value_shared_ptr(v_h);
|
||||||
@ -938,7 +951,24 @@ protected:
|
|||||||
detail::enable_if_t<std::is_constructible<T, const T &, type *>::value, int> = 0>
|
detail::enable_if_t<std::is_constructible<T, const T &, type *>::value, int> = 0>
|
||||||
bool try_implicit_casts(handle src, bool convert) {
|
bool try_implicit_casts(handle src, bool convert) {
|
||||||
if (typeinfo->default_holder) {
|
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) {
|
for (auto &cast : typeinfo->implicit_casts) {
|
||||||
copyable_holder_caster sub_caster(*cast.first);
|
copyable_holder_caster sub_caster(*cast.first);
|
||||||
|
@ -835,9 +835,11 @@ struct load_helper : value_and_holder_helper {
|
|||||||
|
|
||||||
std::shared_ptr<T> loaded_as_shared_ptr(void *void_raw_ptr,
|
std::shared_ptr<T> loaded_as_shared_ptr(void *void_raw_ptr,
|
||||||
handle responsible_parent = nullptr) const {
|
handle responsible_parent = nullptr) const {
|
||||||
|
printf("\nLOOOK %s:%d\n", __FILE__, __LINE__); fflush(stdout); // NOLINT
|
||||||
if (!have_holder()) {
|
if (!have_holder()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
printf("\nLOOOK %s:%d\n", __FILE__, __LINE__); fflush(stdout); // NOLINT
|
||||||
throw_if_uninitialized_or_disowned_holder(typeid(T));
|
throw_if_uninitialized_or_disowned_holder(typeid(T));
|
||||||
holder_type &hld = holder();
|
holder_type &hld = holder();
|
||||||
hld.ensure_is_not_disowned("loaded_as_shared_ptr");
|
hld.ensure_is_not_disowned("loaded_as_shared_ptr");
|
||||||
@ -1110,6 +1112,7 @@ public:
|
|||||||
type_caster_generic sub_caster(*cast.first);
|
type_caster_generic sub_caster(*cast.first);
|
||||||
if (sub_caster.load(src, convert)) {
|
if (sub_caster.load(src, convert)) {
|
||||||
value = cast.second(sub_caster.value);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,8 @@ TEST_SUBMODULE(class_sh_mi_thunks, m) {
|
|||||||
[]() {
|
[]() {
|
||||||
auto *drvd = new Derived;
|
auto *drvd = new Derived;
|
||||||
auto *base0 = dynamic_cast<Base0 *>(drvd);
|
auto *base0 = dynamic_cast<Base0 *>(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;
|
return base0;
|
||||||
},
|
},
|
||||||
py::return_value_policy::take_ownership);
|
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", []() {
|
m.def("get_drvd_as_base0_shared_ptr", []() {
|
||||||
auto drvd = std::make_shared<Derived>();
|
auto drvd = std::make_shared<Derived>();
|
||||||
auto base0 = std::dynamic_pointer_cast<Base0>(drvd);
|
auto base0 = std::dynamic_pointer_cast<Base0>(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;
|
return base0;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -75,7 +79,9 @@ TEST_SUBMODULE(class_sh_mi_thunks, m) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
m.def("vec_size_base0_raw_ptr", [](const Base0 *obj) {
|
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<const Derived *>(obj);
|
const auto *obj_der = dynamic_cast<const Derived *>(obj);
|
||||||
|
printf("\nLOOOK raw const auto *obj_der %ld\n", (long) obj_der); fflush(stdout); // NOLINT
|
||||||
if (obj_der == nullptr) {
|
if (obj_der == nullptr) {
|
||||||
return std::size_t(0);
|
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<Base0> &obj) -> std::size_t {
|
m.def("vec_size_base0_shared_ptr", [](const std::shared_ptr<Base0> &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<Derived>(obj);
|
const auto obj_der = std::dynamic_pointer_cast<Derived>(obj);
|
||||||
|
printf("\nLOOOK shd const auto *obj_der %ld\n", (long) obj_der.get()); fflush(stdout); // NOLINT
|
||||||
if (!obj_der) {
|
if (!obj_der) {
|
||||||
return std::size_t(0);
|
return std::size_t(0);
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,11 @@ def test_ptrdiff_drvd_base0():
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_get_vec_size_raw_shared(get_fn, vec_size_fn):
|
def test_get_vec_size_raw_shared(get_fn, vec_size_fn):
|
||||||
|
print(f"\nLOOOK A", flush=True)
|
||||||
obj = get_fn()
|
obj = get_fn()
|
||||||
|
print(f"\nLOOOK B", flush=True)
|
||||||
assert vec_size_fn(obj) == 5
|
assert vec_size_fn(obj) == 5
|
||||||
|
print(f"\nLOOOK C", flush=True)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
Loading…
Reference in New Issue
Block a user