Skip to content

Commit 336860d

Browse files
committed
Systematically rename loaded_as to load_as (shared_ptr, unique_ptr) as suggested by @laramiel
1 parent 2644d6e commit 336860d

File tree

6 files changed

+17
-20
lines changed

6 files changed

+17
-20
lines changed

include/pybind11/cast.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ struct copyable_holder_caster<
886886

887887
explicit operator std::shared_ptr<type> &() {
888888
if (typeinfo->holder_enum_v == detail::holder_enum_t::smart_holder) {
889-
shared_ptr_holder = sh_load_helper.loaded_as_shared_ptr(value);
889+
shared_ptr_holder = sh_load_helper.load_as_shared_ptr(value);
890890
}
891891
return shared_ptr_holder;
892892
}
@@ -914,7 +914,7 @@ struct copyable_holder_caster<
914914
copyable_holder_caster loader;
915915
loader.load(responsible_parent, /*convert=*/false);
916916
assert(loader.typeinfo->holder_enum_v == detail::holder_enum_t::smart_holder);
917-
return loader.sh_load_helper.loaded_as_shared_ptr(loader.value, responsible_parent);
917+
return loader.sh_load_helper.load_as_shared_ptr(loader.value, responsible_parent);
918918
}
919919

920920
protected:
@@ -1074,7 +1074,7 @@ struct move_only_holder_caster<
10741074

10751075
explicit operator std::unique_ptr<type, deleter>() {
10761076
if (typeinfo->holder_enum_v == detail::holder_enum_t::smart_holder) {
1077-
return sh_load_helper.template loaded_as_unique_ptr<deleter>(value);
1077+
return sh_load_helper.template load_as_unique_ptr<deleter>(value);
10781078
}
10791079
pybind11_fail("Passing std::unique_ptr from Python to C++ requires smart_holder.");
10801080
}

include/pybind11/detail/type_caster_base.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -715,20 +715,20 @@ struct load_helper : value_and_holder_helper {
715715
return std::shared_ptr<T>(raw_ptr, shared_ptr_parent_life_support(parent.ptr()));
716716
}
717717

718-
std::shared_ptr<T> loaded_as_shared_ptr(void *void_raw_ptr,
719-
handle responsible_parent = nullptr) const {
718+
std::shared_ptr<T> load_as_shared_ptr(void *void_raw_ptr,
719+
handle responsible_parent = nullptr) const {
720720
if (!have_holder()) {
721721
return nullptr;
722722
}
723723
throw_if_uninitialized_or_disowned_holder(typeid(T));
724724
holder_type &hld = holder();
725-
hld.ensure_is_not_disowned("loaded_as_shared_ptr");
725+
hld.ensure_is_not_disowned("load_as_shared_ptr");
726726
if (hld.vptr_is_using_noop_deleter) {
727727
if (responsible_parent) {
728728
return make_shared_ptr_with_responsible_parent(static_cast<T *>(void_raw_ptr),
729729
responsible_parent);
730730
}
731-
throw std::runtime_error("Non-owning holder (loaded_as_shared_ptr).");
731+
throw std::runtime_error("Non-owning holder (load_as_shared_ptr).");
732732
}
733733
auto *type_raw_ptr = static_cast<T *>(void_raw_ptr);
734734
if (hld.pointee_depends_on_holder_owner) {
@@ -748,7 +748,7 @@ struct load_helper : value_and_holder_helper {
748748
// This code is reachable only if there are multiple registered_instances for the
749749
// same pointee.
750750
if (reinterpret_cast<PyObject *>(loaded_v_h.inst) == sptsls_ptr->self) {
751-
pybind11_fail("smart_holder_type_caster_support loaded_as_shared_ptr failure: "
751+
pybind11_fail("smart_holder_type_caster_support load_as_shared_ptr failure: "
752752
"loaded_v_h.inst == sptsls_ptr->self");
753753
}
754754
}
@@ -758,20 +758,20 @@ struct load_helper : value_and_holder_helper {
758758
type_raw_ptr, shared_ptr_trampoline_self_life_support(loaded_v_h.inst));
759759
}
760760
if (hld.vptr_is_external_shared_ptr) {
761-
pybind11_fail("smart_holder_type_casters loaded_as_shared_ptr failure: not "
761+
pybind11_fail("smart_holder_type_casters load_as_shared_ptr failure: not "
762762
"implemented: trampoline-self-life-support for external shared_ptr "
763763
"to type inheriting from std::enable_shared_from_this.");
764764
}
765-
pybind11_fail("smart_holder_type_casters: loaded_as_shared_ptr failure: internal "
766-
"inconsistency.");
765+
pybind11_fail(
766+
"smart_holder_type_casters: load_as_shared_ptr failure: internal inconsistency.");
767767
}
768768
std::shared_ptr<void> void_shd_ptr = hld.template as_shared_ptr<void>();
769769
return std::shared_ptr<T>(void_shd_ptr, type_raw_ptr);
770770
}
771771

772772
template <typename D>
773-
std::unique_ptr<T, D> loaded_as_unique_ptr(void *raw_void_ptr,
774-
const char *context = "loaded_as_unique_ptr") {
773+
std::unique_ptr<T, D> load_as_unique_ptr(void *raw_void_ptr,
774+
const char *context = "load_as_unique_ptr") {
775775
if (!have_holder()) {
776776
return unique_with_deleter<T, D>(nullptr, std::unique_ptr<D>());
777777
}

tests/test_class_sh_basic.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ def test_cannot_disown_use_count_ne_1(pass_f, rtrn_f):
135135
stash.Add(obj)
136136
with pytest.raises(ValueError) as exc_info:
137137
pass_f(obj)
138-
assert str(exc_info.value) == (
139-
"Cannot disown use_count != 1 (loaded_as_unique_ptr)."
140-
)
138+
assert str(exc_info.value) == ("Cannot disown use_count != 1 (load_as_unique_ptr).")
141139

142140

143141
def test_unique_ptr_roundtrip(num_round_trips=1000):

tests/test_class_sh_mi_thunks.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,5 @@ def test_get_shared_vec_size_unique():
5252
with pytest.raises(ValueError) as exc_info:
5353
m.vec_size_base0_unique_ptr(obj)
5454
assert (
55-
str(exc_info.value)
56-
== "Cannot disown external shared_ptr (loaded_as_unique_ptr)."
55+
str(exc_info.value) == "Cannot disown external shared_ptr (load_as_unique_ptr)."
5756
)

tests/test_class_sh_property.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_valu_getter(m_attr):
2121
assert field.num == -99
2222
with pytest.raises(ValueError) as excinfo:
2323
m.DisownOuter(outer)
24-
assert str(excinfo.value) == "Cannot disown use_count != 1 (loaded_as_unique_ptr)."
24+
assert str(excinfo.value) == "Cannot disown use_count != 1 (load_as_unique_ptr)."
2525
del field
2626
m.DisownOuter(outer)
2727
with pytest.raises(ValueError, match="Python instance was disowned") as excinfo:

tests/test_class_sh_trampoline_shared_from_this.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def __init__(self, history):
241241
str_exc_info_value = str(exc_info.value)
242242
assert (
243243
str_exc_info_value
244-
== "smart_holder_type_casters loaded_as_shared_ptr failure: not implemented:"
244+
== "smart_holder_type_casters load_as_shared_ptr failure: not implemented:"
245245
" trampoline-self-life-support for external shared_ptr to type inheriting"
246246
" from std::enable_shared_from_this."
247247
)

0 commit comments

Comments
 (0)