Call new load_helper.get_void_ptr_or_nullptr() instead of calling type_caster_generic::load_value() in shared_ptr and unique_ptr casters.

This commit is contained in:
Ralf W. Grosse-Kunstleve 2024-07-09 15:07:10 -07:00
parent 36bbac1b47
commit c6a87e8897
2 changed files with 12 additions and 2 deletions

View File

@ -903,7 +903,7 @@ protected:
void load_value(value_and_holder &&v_h) { void load_value(value_and_holder &&v_h) {
if (typeinfo->default_holder) { if (typeinfo->default_holder) {
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)); // NOLINT(performance-move-const-arg) value = sh_load_helper.get_void_ptr_or_nullptr();
return; return;
} }
if (v_h.holder_constructed()) { if (v_h.holder_constructed()) {
@ -1028,7 +1028,7 @@ public:
if (typeinfo->default_holder) { if (typeinfo->default_holder) {
sh_load_helper.loaded_v_h = v_h; sh_load_helper.loaded_v_h = v_h;
sh_load_helper.loaded_v_h.type = get_type_info(typeid(type)); sh_load_helper.loaded_v_h.type = get_type_info(typeid(type));
type_caster_generic::load_value(std::move(v_h)); // NOLINT(performance-move-const-arg) value = sh_load_helper.get_void_ptr_or_nullptr();
return; return;
} }
throw std::runtime_error("BAKEIN_WIP: What is the best behavior here (load_value)?"); throw std::runtime_error("BAKEIN_WIP: What is the best behavior here (load_value)?");

View File

@ -617,6 +617,16 @@ printf("\nLOOOK throw(Python instance was disowned.)\n"); fflush(stdout); // NO
throw value_error("Python instance is currently owned by a std::shared_ptr."); throw value_error("Python instance is currently owned by a std::shared_ptr.");
} }
} }
void *get_void_ptr_or_nullptr() const {
if (have_holder()) {
auto &hld = holder();
if (hld.is_populated && hld.has_pointee()) {
return hld.template as_raw_ptr_unowned<void>();
}
}
return nullptr;
}
}; };
template <typename T, typename D> template <typename T, typename D>