Bug fix: Adding have_value() to smart_holder_type_caster_load. With this test_builtin_casters succeeds. (All 42 tests build, 36 tests succeed, 5 run but have some failures, 1 segfault.)

This commit is contained in:
Ralf W. Grosse-Kunstleve 2021-02-05 16:04:58 -08:00
parent 3cc0a8a598
commit 0de26c411a

View File

@ -1220,10 +1220,12 @@ struct smart_holder_type_caster_load {
} }
T *loaded_as_raw_ptr_unowned() const { T *loaded_as_raw_ptr_unowned() const {
if (!have_value()) return nullptr;
return convert_type(holder().template as_raw_ptr_unowned<void>()); return convert_type(holder().template as_raw_ptr_unowned<void>());
} }
T &loaded_as_lvalue_ref() const { T &loaded_as_lvalue_ref() const {
if (!have_value()) throw reference_cast_error();
static const char *context = "loaded_as_lvalue_ref"; static const char *context = "loaded_as_lvalue_ref";
holder().ensure_is_populated(context); holder().ensure_is_populated(context);
holder().ensure_has_pointee(context); holder().ensure_has_pointee(context);
@ -1231,6 +1233,7 @@ struct smart_holder_type_caster_load {
} }
T &&loaded_as_rvalue_ref() const { T &&loaded_as_rvalue_ref() const {
if (!have_value()) throw reference_cast_error();
static const char *context = "loaded_as_rvalue_ref"; static const char *context = "loaded_as_rvalue_ref";
holder().ensure_is_populated(context); holder().ensure_is_populated(context);
holder().ensure_has_pointee(context); holder().ensure_has_pointee(context);
@ -1238,12 +1241,14 @@ struct smart_holder_type_caster_load {
} }
std::shared_ptr<T> loaded_as_shared_ptr() { std::shared_ptr<T> loaded_as_shared_ptr() {
if (!have_value()) return nullptr;
std::shared_ptr<void> void_ptr = holder().template as_shared_ptr<void>(); std::shared_ptr<void> void_ptr = holder().template as_shared_ptr<void>();
return std::shared_ptr<T>(void_ptr, convert_type(void_ptr.get())); return std::shared_ptr<T>(void_ptr, convert_type(void_ptr.get()));
} }
template <typename D> template <typename D>
std::unique_ptr<T, D> loaded_as_unique_ptr(const char *context = "loaded_as_unique_ptr") { std::unique_ptr<T, D> loaded_as_unique_ptr(const char *context = "loaded_as_unique_ptr") {
if (!have_value()) return nullptr;
holder().template ensure_compatible_rtti_uqp_del<T, D>(context); holder().template ensure_compatible_rtti_uqp_del<T, D>(context);
holder().ensure_use_count_1(context); holder().ensure_use_count_1(context);
auto raw_void_ptr = holder().template as_raw_ptr_unowned<void>(); auto raw_void_ptr = holder().template as_raw_ptr_unowned<void>();
@ -1268,6 +1273,8 @@ struct smart_holder_type_caster_load {
private: private:
modified_type_caster_generic_load_impl load_impl; modified_type_caster_generic_load_impl load_impl;
bool have_value() const { return load_impl.loaded_v_h.vh != nullptr; }
holder_type &holder() const { return load_impl.loaded_v_h.holder<holder_type>(); } holder_type &holder() const { return load_impl.loaded_v_h.holder<holder_type>(); }
T *convert_type(void *void_ptr) const { T *convert_type(void *void_ptr) const {