Skip to content

Commit

Permalink
Automatic pre-commit run --all-files and clang-tidy changes (NO man…
Browse files Browse the repository at this point in the history
…ual changes).
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Feb 15, 2022
1 parent d5e302c commit 05c8b9b
Show file tree
Hide file tree
Showing 36 changed files with 236 additions and 227 deletions.
6 changes: 4 additions & 2 deletions include/pybind11/detail/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,10 @@ void construct(value_and_holder &v_h, std::unique_ptr<Cpp<Class>, D> &&unq_ptr,
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(need_alias);
auto *ptr = unq_ptr.get();
no_nullptr(ptr);
if (PYBIND11_SILENCE_MSVC_C4127(Class::has_alias) && need_alias && !is_alias<Class>(ptr))
if (PYBIND11_SILENCE_MSVC_C4127(Class::has_alias) && need_alias && !is_alias<Class>(ptr)) {
throw type_error("pybind11::init(): construction failed: returned std::unique_ptr pointee "
"is not an alias instance");
}
// Here and below: if the new object is a trampoline, the shared_from_this mechanism needs
// to be prevented from accessing the smart_holder vptr, because it does not keep the
// trampoline Python object alive. For types that don't inherit from enable_shared_from_this
Expand Down Expand Up @@ -242,9 +243,10 @@ void construct(value_and_holder &v_h, std::shared_ptr<Cpp<Class>> &&shd_ptr, boo
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(need_alias);
auto *ptr = shd_ptr.get();
no_nullptr(ptr);
if (PYBIND11_SILENCE_MSVC_C4127(Class::has_alias) && need_alias && !is_alias<Class>(ptr))
if (PYBIND11_SILENCE_MSVC_C4127(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);
v_h.value_ptr() = ptr;
v_h.type->init_instance(v_h.inst, &smhldr);
Expand Down
23 changes: 14 additions & 9 deletions include/pybind11/detail/smart_holder_poc.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ struct guarded_delete {
guarded_delete(void (*del_ptr)(void *), bool armed_flag)
: del_ptr{del_ptr}, armed_flag{armed_flag} {}
void operator()(void *raw_ptr) const {
if (armed_flag)
if (armed_flag) {
(*del_ptr)(raw_ptr);
}
}
};

Expand Down Expand Up @@ -138,9 +139,10 @@ struct smart_holder {

template <typename T>
static void ensure_pointee_is_destructible(const char *context) {
if (!std::is_destructible<T>::value)
if (!std::is_destructible<T>::value) {
throw std::invalid_argument(std::string("Pointee is not destructible (") + context
+ ").");
}
}

void ensure_is_populated(const char *context) const {
Expand Down Expand Up @@ -207,7 +209,7 @@ struct smart_holder {
}

void reset_vptr_deleter_armed_flag(bool armed_flag) const {
auto vptr_del_ptr = std::get_deleter<guarded_delete>(vptr);
auto *vptr_del_ptr = std::get_deleter<guarded_delete>(vptr);
if (vptr_del_ptr == nullptr) {
throw std::runtime_error(
"smart_holder::reset_vptr_deleter_armed_flag() called in an invalid context.");
Expand Down Expand Up @@ -249,10 +251,11 @@ struct smart_holder {
ensure_pointee_is_destructible<T>("from_raw_ptr_take_ownership");
smart_holder hld;
auto gd = make_guarded_builtin_delete<T>(true);
if (void_cast_raw_ptr)
if (void_cast_raw_ptr) {
hld.vptr.reset(static_cast<void *>(raw_ptr), std::move(gd));
else
} else {
hld.vptr.reset(raw_ptr, std::move(gd));
}
hld.vptr_is_using_builtin_delete = true;
hld.is_populated = true;
return hld;
Expand Down Expand Up @@ -301,14 +304,16 @@ struct smart_holder {
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)
if (hld.vptr_is_using_builtin_delete) {
gd = make_guarded_builtin_delete<T>(true);
else
} else {
gd = make_guarded_custom_deleter<T, D>(true);
if (void_cast_raw_ptr)
}
if (void_cast_raw_ptr) {
hld.vptr.reset(static_cast<void *>(unq_ptr.get()), std::move(gd));
else
} else {
hld.vptr.reset(unq_ptr.get(), std::move(gd));
}
(void) unq_ptr.release();
hld.is_populated = true;
return hld;
Expand Down
222 changes: 130 additions & 92 deletions include/pybind11/detail/smart_holder_type_casters.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion include/pybind11/smart_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#pragma once

#include "pybind11.h"
#include "detail/common.h"
#include "detail/smart_holder_type_casters.h"
#include "pybind11.h"

#undef PYBIND11_SH_AVL // Undoing #define in pybind11.h

Expand Down
4 changes: 2 additions & 2 deletions tests/test_class_sh_basic.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "pybind11_tests.h"

#include <pybind11/smart_holder.h>

#include "pybind11_tests.h"

#include <memory>
#include <string>
#include <vector>
Expand Down
1 change: 0 additions & 1 deletion tests/test_class_sh_basic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Importing re before pytest after observing a PyPy CI flake when importing pytest first.
import re

Expand Down
4 changes: 2 additions & 2 deletions tests/test_class_sh_disowning.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "pybind11_tests.h"

#include <pybind11/smart_holder.h>

#include "pybind11_tests.h"

#include <memory>

namespace pybind11_tests {
Expand Down
3 changes: 0 additions & 3 deletions tests/test_class_sh_disowning.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import print_function

import pytest

from pybind11_tests import class_sh_disowning as m
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
@@ -1,7 +1,7 @@
#include "pybind11_tests.h"

#include <pybind11/smart_holder.h>

#include "pybind11_tests.h"

#include <memory>

namespace pybind11_tests {
Expand Down
5 changes: 2 additions & 3 deletions tests/test_class_sh_disowning_mi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import pytest

import env # noqa: F401
Expand Down Expand Up @@ -77,7 +76,7 @@ def __init__(self, i, j):
m.Base2.__init__(self, j)


class B1(object):
class B1:
def v(self):
return 1

Expand Down Expand Up @@ -119,7 +118,7 @@ def v(self):
return 2


class B3(object):
class B3:
def v(self):
return 3

Expand Down
4 changes: 2 additions & 2 deletions tests/test_class_sh_factory_constructors.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "pybind11_tests.h"

#include <pybind11/smart_holder.h>

#include "pybind11_tests.h"

#include <memory>
#include <string>

Expand Down
1 change: 0 additions & 1 deletion tests/test_class_sh_factory_constructors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import pytest

from pybind11_tests import class_sh_factory_constructors as m
Expand Down
4 changes: 2 additions & 2 deletions tests/test_class_sh_inheritance.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "pybind11_tests.h"

#include <pybind11/smart_holder.h>

#include "pybind11_tests.h"

#include <memory>

namespace pybind11_tests {
Expand Down
2 changes: 0 additions & 2 deletions tests/test_class_sh_inheritance.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from pybind11_tests import class_sh_inheritance as m


Expand Down
1 change: 0 additions & 1 deletion tests/test_class_sh_module_local.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import class_sh_module_local_0 as m0
import class_sh_module_local_1 as m1
import class_sh_module_local_2 as m2
Expand Down
4 changes: 2 additions & 2 deletions tests/test_class_sh_shared_ptr_copy_move.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "pybind11_tests.h"

#include <pybind11/smart_holder.h>

#include "pybind11_tests.h"

#include <memory>
#include <string>
#include <vector>
Expand Down
6 changes: 2 additions & 4 deletions tests/test_class_sh_shared_ptr_copy_move.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from pybind11_tests import class_sh_shared_ptr_copy_move as m


Expand All @@ -25,8 +23,8 @@ def test_smhld_move():

def _check_property(foo_typ, prop_typ, policy):
o = m.Outer()
name = "{}_{}_{}".format(foo_typ, prop_typ, policy)
history = "Foo{}_Outer".format(foo_typ)
name = f"{foo_typ}_{prop_typ}_{policy}"
history = f"Foo{foo_typ}_Outer"
f = getattr(o, name)
assert f.get_history() == history
# and try again to check that o did not get changed
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
@@ -1,7 +1,7 @@
#include "pybind11_tests.h"

#include <pybind11/smart_holder.h>

#include "pybind11_tests.h"

#include <memory>

namespace pybind11_tests {
Expand Down
5 changes: 2 additions & 3 deletions tests/test_class_sh_trampoline_basic.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# -*- coding: utf-8 -*-
import pytest

from pybind11_tests import class_sh_trampoline_basic as m


class PyDrvd0(m.Abase0):
def __init__(self, val):
super(PyDrvd0, self).__init__(val)
super().__init__(val)

def Add(self, other_val): # noqa: N802
return self.Get() * 100 + other_val


class PyDrvd1(m.Abase1):
def __init__(self, val):
super(PyDrvd1, self).__init__(val)
super().__init__(val)

def Add(self, other_val): # noqa: N802
return self.Get() * 200 + other_val
Expand Down
2 changes: 1 addition & 1 deletion tests/test_class_sh_trampoline_self_life_support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ TEST_SUBMODULE(class_sh_trampoline_self_life_support, m) {
py::object o2 = py::none();
// This is very unusual, but needed to directly exercise the trampoline_self_life_support
// CpCtor, MvCtor, operator= lvalue, operator= rvalue.
auto obj_trampoline = dynamic_cast<Big5Trampoline *>(obj.get());
auto *obj_trampoline = dynamic_cast<Big5Trampoline *>(obj.get());
if (obj_trampoline != nullptr) {
switch (action_id) {
case 0: { // CpCtor
Expand Down
1 change: 0 additions & 1 deletion tests/test_class_sh_trampoline_self_life_support.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import pytest

import pybind11_tests.class_sh_trampoline_self_life_support as m
Expand Down
6 changes: 4 additions & 2 deletions tests/test_class_sh_trampoline_shared_from_this.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ struct SftSharedPtrStash {
stash.push_back(sft);
}
std::string history(unsigned i) {
if (i < stash.size())
if (i < stash.size()) {
return stash[i]->history;
}
return "OutOfRange";
}
long use_count(unsigned i) {
if (i < stash.size())
if (i < stash.size()) {
return stash[i].use_count();
}
return -1;
}
};
Expand Down
3 changes: 1 addition & 2 deletions tests/test_class_sh_trampoline_shared_from_this.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import sys
import weakref

Expand Down Expand Up @@ -220,7 +219,7 @@ def test_multiple_registered_instances_for_same_pointee_recursive():
def test_std_make_shared_factory():
class PySftMakeShared(m.Sft):
def __init__(self, history):
super(PySftMakeShared, self).__init__(history, 0)
super().__init__(history, 0)

obj = PySftMakeShared("PySftMakeShared")
assert obj.history == "PySftMakeShared"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

#include <utility>

#include "pybind11/smart_holder.h"
#include "pybind11_tests.h"

#include <utility>

namespace {

// For testing whether a python subclass of a C++ object dies when the
Expand All @@ -17,7 +17,7 @@ struct SpBase {

// returns true if there's an associated python instance
bool has_python_instance() {
auto tinfo = py::detail::get_type_info(typeid(SpBase));
auto *tinfo = py::detail::get_type_info(typeid(SpBase));
return (bool) py::detail::get_object_handle(this, tinfo);
}

Expand Down
3 changes: 1 addition & 2 deletions tests/test_class_sh_trampoline_shared_ptr_cpp_arg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import pytest

import pybind11_tests.class_sh_trampoline_shared_ptr_cpp_arg as m
Expand Down Expand Up @@ -136,7 +135,7 @@ def test_infinite():
def test_std_make_shared_factory():
class PyChild(m.SpBase):
def __init__(self):
super(PyChild, self).__init__(0)
super().__init__(0)

obj = PyChild()
while True:
Expand Down
2 changes: 0 additions & 2 deletions tests/test_class_sh_trampoline_unique_ptr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import pybind11_tests.class_sh_trampoline_unique_ptr as m


Expand Down
4 changes: 2 additions & 2 deletions tests/test_class_sh_unique_ptr_member.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "pybind11_tests.h"

#include <pybind11/smart_holder.h>

#include "pybind11_tests.h"

#include <memory>

namespace pybind11_tests {
Expand Down
1 change: 0 additions & 1 deletion tests/test_class_sh_unique_ptr_member.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import pytest

from pybind11_tests import class_sh_unique_ptr_member as m
Expand Down
4 changes: 2 additions & 2 deletions tests/test_class_sh_virtual_py_cpp_mix.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "pybind11_tests.h"

#include <pybind11/smart_holder.h>

#include "pybind11_tests.h"

#include <memory>

namespace pybind11_tests {
Expand Down
1 change: 0 additions & 1 deletion tests/test_class_sh_virtual_py_cpp_mix.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import pytest

from pybind11_tests import class_sh_virtual_py_cpp_mix as m
Expand Down
Loading

0 comments on commit 05c8b9b

Please sign in to comment.