Skip to content

This was meant to be PR #3065: pure clang-format changes. #3073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/pybind11/detail/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void construct(value_and_holder &v_h, std::shared_ptr<Cpp<Class>> &&shd_ptr, boo
if (Class::has_alias && need_alias && !is_alias<Class>(ptr))
throw type_error("pybind11::init(): construction failed: returned std::shared_ptr pointee "
"is not an alias instance");
auto smhldr = type_caster<Cpp<Class>>::template smart_holder_from_shared_ptr(shd_ptr);
auto smhldr = type_caster<Cpp<Class>>::template smart_holder_from_shared_ptr(shd_ptr);
v_h.value_ptr() = ptr;
v_h.type->init_instance(v_h.inst, &smhldr);
}
Expand All @@ -230,7 +230,7 @@ void construct(value_and_holder &v_h,
bool /*need_alias*/) {
auto *ptr = shd_ptr.get();
no_nullptr(ptr);
auto smhldr = type_caster<Alias<Class>>::template smart_holder_from_shared_ptr(shd_ptr);
auto smhldr = type_caster<Alias<Class>>::template smart_holder_from_shared_ptr(shd_ptr);
v_h.value_ptr() = ptr;
v_h.type->init_instance(v_h.inst, &smhldr);
}
Expand Down
12 changes: 6 additions & 6 deletions include/pybind11/detail/smart_holder_poc.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ struct smart_holder {
bool pointee_depends_on_holder_owner : 1; // SMART_HOLDER_WIP: See PR #2839.

// Design choice: smart_holder is movable but not copyable.
smart_holder(smart_holder &&) = default;
smart_holder(smart_holder &&) = default;
smart_holder(const smart_holder &) = delete;
smart_holder &operator=(smart_holder &&) = delete;
smart_holder &operator=(const smart_holder &) = delete;
Expand Down Expand Up @@ -219,7 +219,7 @@ struct smart_holder {
smart_holder hld;
hld.vptr.reset(raw_ptr, [](void *) {});
hld.vptr_is_using_noop_deleter = true;
hld.is_populated = true;
hld.is_populated = true;
return hld;
}

Expand Down Expand Up @@ -254,7 +254,7 @@ struct smart_holder {
else
hld.vptr.reset(raw_ptr, std::move(gd));
hld.vptr_is_using_builtin_delete = true;
hld.is_populated = true;
hld.is_populated = true;
return hld;
}

Expand Down Expand Up @@ -298,7 +298,7 @@ struct smart_holder {
static smart_holder from_unique_ptr(std::unique_ptr<T, D> &&unq_ptr,
bool void_cast_raw_ptr = false) {
smart_holder hld;
hld.rtti_uqp_del = &typeid(D);
hld.rtti_uqp_del = &typeid(D);
hld.vptr_is_using_builtin_delete = is_std_default_delete<T>(*hld.rtti_uqp_del);
guarded_delete gd{nullptr, false};
if (hld.vptr_is_using_builtin_delete)
Expand Down Expand Up @@ -327,9 +327,9 @@ struct smart_holder {
template <typename T>
static smart_holder from_shared_ptr(std::shared_ptr<T> shd_ptr) {
smart_holder hld;
hld.vptr = std::static_pointer_cast<void>(shd_ptr);
hld.vptr = std::static_pointer_cast<void>(shd_ptr);
hld.vptr_is_external_shared_ptr = true;
hld.is_populated = true;
hld.is_populated = true;
return hld;
}

Expand Down
38 changes: 19 additions & 19 deletions include/pybind11/detail/smart_holder_type_casters.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ struct smart_holder_type_caster_class_hooks : smart_holder_type_caster_base_tag
v_h.set_instance_registered();
}
auto uninitialized_location = std::addressof(v_h.holder<holder_type>());
auto value_ptr_w_t = v_h.value_ptr<WrappedType>();
auto value_ptr_w_t = v_h.value_ptr<WrappedType>();
bool pointee_depends_on_holder_owner
= dynamic_raw_ptr_cast_if_possible<AliasType>(value_ptr_w_t) != nullptr;
if (holder_void_ptr) {
Expand Down Expand Up @@ -627,21 +627,21 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
if (handle existing_inst = find_registered_python_instance(src, tinfo))
return existing_inst;

auto inst = reinterpret_steal<object>(make_new_instance(tinfo->type));
auto wrapper = reinterpret_cast<instance *>(inst.ptr());
wrapper->owned = false;
auto inst = reinterpret_steal<object>(make_new_instance(tinfo->type));
auto wrapper = reinterpret_cast<instance *>(inst.ptr());
wrapper->owned = false;
void *&valueptr = values_and_holders(wrapper).begin()->value_ptr();

switch (policy) {
case return_value_policy::automatic:
case return_value_policy::take_ownership:
valueptr = src;
valueptr = src;
wrapper->owned = true;
break;

case return_value_policy::automatic_reference:
case return_value_policy::reference:
valueptr = src;
valueptr = src;
wrapper->owned = false;
break;

Expand Down Expand Up @@ -683,7 +683,7 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
break;

case return_value_policy::reference_internal:
valueptr = src;
valueptr = src;
wrapper->owned = false;
keep_alive_impl(inst, parent);
break;
Expand Down Expand Up @@ -724,22 +724,22 @@ struct smart_holder_type_caster<std::shared_ptr<T>> : smart_holder_type_caster_l
return none().release();

auto src_raw_ptr = src.get();
auto st = type_caster_base<T>::src_and_type(src_raw_ptr);
auto st = type_caster_base<T>::src_and_type(src_raw_ptr);
if (st.second == nullptr)
return handle(); // no type info: error will be set already

void *src_raw_void_ptr = static_cast<void *>(src_raw_ptr);
void *src_raw_void_ptr = static_cast<void *>(src_raw_ptr);
const detail::type_info *tinfo = st.second;
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.
return existing_inst;

auto inst = reinterpret_steal<object>(make_new_instance(tinfo->type));
auto *inst_raw_ptr = reinterpret_cast<instance *>(inst.ptr());
auto inst = reinterpret_steal<object>(make_new_instance(tinfo->type));
auto *inst_raw_ptr = reinterpret_cast<instance *>(inst.ptr());
inst_raw_ptr->owned = true;
void *&valueptr = values_and_holders(inst_raw_ptr).begin()->value_ptr();
valueptr = src_raw_void_ptr;
void *&valueptr = values_and_holders(inst_raw_ptr).begin()->value_ptr();
valueptr = src_raw_void_ptr;

auto smhldr = pybindit::memory::smart_holder::from_shared_ptr(src);
tinfo->init_instance(inst_raw_ptr, static_cast<const void *>(&smhldr));
Expand Down Expand Up @@ -791,11 +791,11 @@ struct smart_holder_type_caster<std::unique_ptr<T, D>> : smart_holder_type_caste
return none().release();

auto src_raw_ptr = src.get();
auto st = type_caster_base<T>::src_and_type(src_raw_ptr);
auto st = type_caster_base<T>::src_and_type(src_raw_ptr);
if (st.second == nullptr)
return handle(); // no type info: error will be set already

void *src_raw_void_ptr = static_cast<void *>(src_raw_ptr);
void *src_raw_void_ptr = static_cast<void *>(src_raw_ptr);
const detail::type_info *tinfo = st.second;
if (handle existing_inst = find_registered_python_instance(src_raw_void_ptr, tinfo)) {
auto *self_life_support
Expand All @@ -819,11 +819,11 @@ struct smart_holder_type_caster<std::unique_ptr<T, D>> : smart_holder_type_caste
throw cast_error("Invalid unique_ptr: another instance owns this pointer already.");
}

auto inst = reinterpret_steal<object>(make_new_instance(tinfo->type));
auto *inst_raw_ptr = reinterpret_cast<instance *>(inst.ptr());
auto inst = reinterpret_steal<object>(make_new_instance(tinfo->type));
auto *inst_raw_ptr = reinterpret_cast<instance *>(inst.ptr());
inst_raw_ptr->owned = true;
void *&valueptr = values_and_holders(inst_raw_ptr).begin()->value_ptr();
valueptr = src_raw_void_ptr;
void *&valueptr = values_and_holders(inst_raw_ptr).begin()->value_ptr();
valueptr = src_raw_void_ptr;

auto smhldr = pybindit::memory::smart_holder::from_unique_ptr(std::move(src),
/*void_cast_raw_ptr*/ false);
Expand Down
2 changes: 1 addition & 1 deletion include/pybind11/trampoline_self_life_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct trampoline_self_life_support {
void *value_void_ptr = v_h.value_ptr();
if (value_void_ptr != nullptr) {
PyGILState_STATE threadstate = PyGILState_Ensure();
v_h.value_ptr() = nullptr;
v_h.value_ptr() = nullptr;
v_h.holder<pybindit::memory::smart_holder>().release_disowned();
detail::deregister_instance(v_h.inst, value_void_ptr, v_h.type);
Py_DECREF((PyObject *) v_h.inst); // Must be after deregister.
Expand Down
32 changes: 16 additions & 16 deletions tests/pure_cpp/smart_holder_poc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct movable_int {
int valu;
movable_int(int v) : valu{v} {}
movable_int(movable_int &&other) noexcept {
valu = other.valu;
valu = other.valu;
other.valu = 91;
}
};
Expand All @@ -36,13 +36,13 @@ struct indestructible_int {

TEST_CASE("from_raw_ptr_unowned+as_raw_ptr_unowned", "[S]") {
static int value = 19;
auto hld = smart_holder::from_raw_ptr_unowned(&value);
auto hld = smart_holder::from_raw_ptr_unowned(&value);
REQUIRE(*hld.as_raw_ptr_unowned<int>() == 19);
}

TEST_CASE("from_raw_ptr_unowned+as_lvalue_ref", "[S]") {
static int value = 19;
auto hld = smart_holder::from_raw_ptr_unowned(&value);
auto hld = smart_holder::from_raw_ptr_unowned(&value);
REQUIRE(hld.as_lvalue_ref<int>() == 19);
}

Expand All @@ -58,28 +58,28 @@ TEST_CASE("from_raw_ptr_unowned+as_rvalue_ref", "[S]") {

TEST_CASE("from_raw_ptr_unowned+as_raw_ptr_release_ownership", "[E]") {
static int value = 19;
auto hld = smart_holder::from_raw_ptr_unowned(&value);
auto hld = smart_holder::from_raw_ptr_unowned(&value);
REQUIRE_THROWS_WITH(hld.as_raw_ptr_release_ownership<int>(),
"Cannot disown non-owning holder (as_raw_ptr_release_ownership).");
}

TEST_CASE("from_raw_ptr_unowned+as_unique_ptr", "[E]") {
static int value = 19;
auto hld = smart_holder::from_raw_ptr_unowned(&value);
auto hld = smart_holder::from_raw_ptr_unowned(&value);
REQUIRE_THROWS_WITH(hld.as_unique_ptr<int>(),
"Cannot disown non-owning holder (as_unique_ptr).");
}

TEST_CASE("from_raw_ptr_unowned+as_unique_ptr_with_deleter", "[E]") {
static int value = 19;
auto hld = smart_holder::from_raw_ptr_unowned(&value);
auto hld = smart_holder::from_raw_ptr_unowned(&value);
REQUIRE_THROWS_WITH((hld.as_unique_ptr<int, helpers::functor_builtin_delete<int>>()),
"Missing unique_ptr deleter (as_unique_ptr).");
}

TEST_CASE("from_raw_ptr_unowned+as_shared_ptr", "[S]") {
static int value = 19;
auto hld = smart_holder::from_raw_ptr_unowned(&value);
auto hld = smart_holder::from_raw_ptr_unowned(&value);
REQUIRE(*hld.as_shared_ptr<int>() == 19);
}

Expand All @@ -90,28 +90,28 @@ TEST_CASE("from_raw_ptr_take_ownership+as_lvalue_ref", "[S]") {
}

TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership1", "[S]") {
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
auto new_owner = std::unique_ptr<int>(hld.as_raw_ptr_release_ownership<int>());
REQUIRE(!hld.has_pointee());
REQUIRE(*new_owner == 19);
}

TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership2", "[E]") {
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
auto shd_ptr = hld.as_shared_ptr<int>();
REQUIRE_THROWS_WITH(hld.as_raw_ptr_release_ownership<int>(),
"Cannot disown use_count != 1 (as_raw_ptr_release_ownership).");
}

TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr1", "[S]") {
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
std::unique_ptr<int> new_owner = hld.as_unique_ptr<int>();
REQUIRE(!hld.has_pointee());
REQUIRE(*new_owner == 19);
}

TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr2", "[E]") {
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
auto shd_ptr = hld.as_shared_ptr<int>();
REQUIRE_THROWS_WITH(hld.as_unique_ptr<int>(), "Cannot disown use_count != 1 (as_unique_ptr).");
}
Expand All @@ -123,7 +123,7 @@ TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr_with_deleter", "[E]") {
}

TEST_CASE("from_raw_ptr_take_ownership+as_shared_ptr", "[S]") {
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
std::shared_ptr<int> new_owner = hld.as_shared_ptr<int>();
REQUIRE(hld.has_pointee());
REQUIRE(*new_owner == 19);
Expand Down Expand Up @@ -155,7 +155,7 @@ TEST_CASE("from_raw_ptr_take_ownership+disown+release_disowned", "[S]") {

TEST_CASE("from_raw_ptr_take_ownership+disown+ensure_is_not_disowned", "[E]") {
const char *context = "test_case";
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
hld.ensure_is_not_disowned(context); // Does not throw.
std::unique_ptr<int> new_owner(hld.as_raw_ptr_unowned<int>());
hld.disown();
Expand Down Expand Up @@ -327,7 +327,7 @@ TEST_CASE("indestructible_int-from_raw_ptr_unowned+as_raw_ptr_unowned", "[S]") {
// Using placement new instead of plain new, to not trigger leak sanitizer errors.
static std::aligned_storage<sizeof(zombie), alignof(zombie)>::type memory_block[1];
auto *value = new (memory_block) zombie(19);
auto hld = smart_holder::from_raw_ptr_unowned(value);
auto hld = smart_holder::from_raw_ptr_unowned(value);
REQUIRE(hld.as_raw_ptr_unowned<zombie>()->valu == 19);
}

Expand All @@ -341,7 +341,7 @@ TEST_CASE("from_raw_ptr_take_ownership+as_shared_ptr-outliving_smart_holder", "[
// Exercises guarded_builtin_delete flag_ptr validity past destruction of smart_holder.
std::shared_ptr<int> longer_living;
{
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
longer_living = hld.as_shared_ptr<int>();
}
REQUIRE(*longer_living == 19);
Expand All @@ -352,7 +352,7 @@ TEST_CASE("from_unique_ptr_with_deleter+as_shared_ptr-outliving_smart_holder", "
std::shared_ptr<int> longer_living;
{
std::unique_ptr<int, helpers::functor_builtin_delete<int>> orig_owner(new int(19));
auto hld = smart_holder::from_unique_ptr(std::move(orig_owner));
auto hld = smart_holder::from_unique_ptr(std::move(orig_owner));
longer_living = hld.as_shared_ptr<int>();
}
REQUIRE(*longer_living == 19);
Expand Down
4 changes: 2 additions & 2 deletions tests/test_class_sh_disowning_mi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace class_sh_disowning_mi {

// Diamond inheritance (copied from test_multiple_inheritance.cpp).
struct B {
int val_b = 10;
B() = default;
int val_b = 10;
B() = default;
B(const B &) = default;
virtual ~B() = default;
};
Expand Down
6 changes: 3 additions & 3 deletions tests/test_class_sh_factory_constructors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ std::unique_ptr<atyp_udcp const, sddc> rtrn_udcp() { return std::unique_ptr<atyp
// Minimalistic approach to achieve full coverage of construct() overloads for constructing
// smart_holder from unique_ptr and shared_ptr returns.
struct with_alias {
int val = 0;
int val = 0;
virtual ~with_alias() = default;
// Some compilers complain about implicitly defined versions of some of the following:
with_alias() = default;
with_alias() = default;
with_alias(const with_alias &) = default;
with_alias(with_alias &&) = default;
with_alias(with_alias &&) = default;
with_alias &operator=(const with_alias &) = default;
with_alias &operator=(with_alias &&) = default;
};
Expand Down
2 changes: 1 addition & 1 deletion tests/test_class_sh_inheritance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct base_template {
int base_id;

// Some compilers complain about implicitly defined versions of some of the following:
base_template(const base_template &) = default;
base_template(const base_template &) = default;
base_template(base_template &&) noexcept = default;
base_template &operator=(const base_template &) = default;
base_template &operator=(base_template &&) noexcept = default;
Expand Down
4 changes: 2 additions & 2 deletions tests/test_class_sh_trampoline_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace class_sh_trampoline_basic {

template <int SerNo> // Using int as a trick to easily generate a series of types.
struct Abase {
int val = 0;
int val = 0;
virtual ~Abase() = default;
Abase(int val_) : val{val_} {}
int Get() const { return val * 10 + 3; }
virtual int Add(int other_val) const = 0;

// Some compilers complain about implicitly defined versions of some of the following:
Abase(const Abase &) = default;
Abase(const Abase &) = default;
Abase(Abase &&) noexcept = default;
Abase &operator=(const Abase &) = default;
Abase &operator=(Abase &&) noexcept = default;
Expand Down
4 changes: 2 additions & 2 deletions tests/test_class_sh_trampoline_self_life_support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ TEST_SUBMODULE(class_sh_trampoline_self_life_support, m) {
case 2: { // operator= lvalue
std::unique_ptr<Big5> lv(new Big5Trampoline);
*lv = *obj_trampoline;
o2 = py::cast(std::move(lv));
o2 = py::cast(std::move(lv));
} break;
case 3: { // operator= rvalue
std::unique_ptr<Big5> rv(new Big5Trampoline);
*rv = std::move(*obj_trampoline);
o2 = py::cast(std::move(rv));
o2 = py::cast(std::move(rv));
} break;
default:
break;
Expand Down
4 changes: 2 additions & 2 deletions tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ struct SpBase {
return (bool) py::detail::get_object_handle(this, tinfo);
}

SpBase() = default;
SpBase() = default;
SpBase(const SpBase &) = delete;
virtual ~SpBase() = default;
virtual ~SpBase() = default;
};

std::shared_ptr<SpBase> pass_through_shd_ptr(const std::shared_ptr<SpBase> &obj) { return obj; }
Expand Down
Loading