mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-24 14:15:11 +00:00
Add missing clang-tidy fixes (#3715)
This commit is contained in:
parent
7f9758165d
commit
dc9803cef2
@ -445,13 +445,16 @@ template <> struct process_attribute<arg_v> : process_attribute_default<arg_v> {
|
|||||||
if (!a.value) {
|
if (!a.value) {
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
std::string descr("'");
|
std::string descr("'");
|
||||||
if (a.name) descr += std::string(a.name) + ": ";
|
if (a.name) {
|
||||||
|
descr += std::string(a.name) + ": ";
|
||||||
|
}
|
||||||
descr += a.type + "'";
|
descr += a.type + "'";
|
||||||
if (r->is_method) {
|
if (r->is_method) {
|
||||||
if (r->name)
|
if (r->name) {
|
||||||
descr += " in method '" + (std::string) str(r->scope) + "." + (std::string) r->name + "'";
|
descr += " in method '" + (std::string) str(r->scope) + "." + (std::string) r->name + "'";
|
||||||
else
|
} else {
|
||||||
descr += " in method of '" + (std::string) str(r->scope) + "'";
|
descr += " in method of '" + (std::string) str(r->scope) + "'";
|
||||||
|
}
|
||||||
} else if (r->name) {
|
} else if (r->name) {
|
||||||
descr += " in function '" + (std::string) r->name + "'";
|
descr += " in function '" + (std::string) r->name + "'";
|
||||||
}
|
}
|
||||||
|
@ -628,9 +628,11 @@ protected:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
for (bool r : {std::get<Is>(subcasters).load(seq[Is], convert)...})
|
for (bool r : {std::get<Is>(subcasters).load(seq[Is], convert)...}) {
|
||||||
if (!r)
|
if (!r) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -118,8 +118,9 @@ struct type_hash {
|
|||||||
size_t operator()(const std::type_index &t) const {
|
size_t operator()(const std::type_index &t) const {
|
||||||
size_t hash = 5381;
|
size_t hash = 5381;
|
||||||
const char *ptr = t.name();
|
const char *ptr = t.name();
|
||||||
while (auto c = static_cast<unsigned char>(*ptr++))
|
while (auto c = static_cast<unsigned char>(*ptr++)) {
|
||||||
hash = (hash * 33) ^ c;
|
hash = (hash * 33) ^ c;
|
||||||
|
}
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -388,7 +389,9 @@ inline void translate_exception(std::exception_ptr p) {
|
|||||||
#if !defined(__GLIBCXX__)
|
#if !defined(__GLIBCXX__)
|
||||||
inline void translate_local_exception(std::exception_ptr p) {
|
inline void translate_local_exception(std::exception_ptr p) {
|
||||||
try {
|
try {
|
||||||
if (p) std::rethrow_exception(p);
|
if (p) {
|
||||||
|
std::rethrow_exception(p);
|
||||||
|
}
|
||||||
} catch (error_already_set &e) { e.restore(); return;
|
} catch (error_already_set &e) { e.restore(); return;
|
||||||
} catch (const builtin_exception &e) { e.set_error(); return;
|
} catch (const builtin_exception &e) { e.set_error(); return;
|
||||||
}
|
}
|
||||||
|
@ -65,8 +65,9 @@ public:
|
|||||||
if (!tstate) {
|
if (!tstate) {
|
||||||
tstate = PyThreadState_New(internals.istate);
|
tstate = PyThreadState_New(internals.istate);
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
if (!tstate)
|
if (!tstate) {
|
||||||
pybind11_fail("scoped_acquire: could not create thread state!");
|
pybind11_fail("scoped_acquire: could not create thread state!");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
tstate->gilstate_counter = 0;
|
tstate->gilstate_counter = 0;
|
||||||
PYBIND11_TLS_REPLACE_VALUE(internals.tstate, tstate);
|
PYBIND11_TLS_REPLACE_VALUE(internals.tstate, tstate);
|
||||||
@ -88,15 +89,18 @@ public:
|
|||||||
PYBIND11_NOINLINE void dec_ref() {
|
PYBIND11_NOINLINE void dec_ref() {
|
||||||
--tstate->gilstate_counter;
|
--tstate->gilstate_counter;
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
if (detail::get_thread_state_unchecked() != tstate)
|
if (detail::get_thread_state_unchecked() != tstate) {
|
||||||
pybind11_fail("scoped_acquire::dec_ref(): thread state must be current!");
|
pybind11_fail("scoped_acquire::dec_ref(): thread state must be current!");
|
||||||
if (tstate->gilstate_counter < 0)
|
}
|
||||||
|
if (tstate->gilstate_counter < 0) {
|
||||||
pybind11_fail("scoped_acquire::dec_ref(): reference count underflow!");
|
pybind11_fail("scoped_acquire::dec_ref(): reference count underflow!");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (tstate->gilstate_counter == 0) {
|
if (tstate->gilstate_counter == 0) {
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
if (!release)
|
if (!release) {
|
||||||
pybind11_fail("scoped_acquire::dec_ref(): internal error!");
|
pybind11_fail("scoped_acquire::dec_ref(): internal error!");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
PyThreadState_Clear(tstate);
|
PyThreadState_Clear(tstate);
|
||||||
if (active) {
|
if (active) {
|
||||||
|
@ -873,8 +873,9 @@ protected:
|
|||||||
// 5. Put everything in a vector. Not technically step 5, we've been building it
|
// 5. Put everything in a vector. Not technically step 5, we've been building it
|
||||||
// in `call.args` all along.
|
// in `call.args` all along.
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
if (call.args.size() != func.nargs || call.args_convert.size() != func.nargs)
|
if (call.args.size() != func.nargs || call.args_convert.size() != func.nargs) {
|
||||||
pybind11_fail("Internal error: function call dispatcher inserted wrong number of arguments!");
|
pybind11_fail("Internal error: function call dispatcher inserted wrong number of arguments!");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::vector<bool> second_pass_convert;
|
std::vector<bool> second_pass_convert;
|
||||||
@ -2527,9 +2528,10 @@ inline function get_type_override(const void *this_ptr, const type_info *this_ty
|
|||||||
PyFrame_FastToLocals(frame);
|
PyFrame_FastToLocals(frame);
|
||||||
PyObject *self_caller = dict_getitem(
|
PyObject *self_caller = dict_getitem(
|
||||||
frame->f_locals, PyTuple_GET_ITEM(frame->f_code->co_varnames, 0));
|
frame->f_locals, PyTuple_GET_ITEM(frame->f_code->co_varnames, 0));
|
||||||
if (self_caller == self.ptr())
|
if (self_caller == self.ptr()) {
|
||||||
return function();
|
return function();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -6,15 +6,17 @@ PYBIND11_EMBEDDED_MODULE(test_cmake_build, m) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if (argc != 2)
|
if (argc != 2) {
|
||||||
throw std::runtime_error("Expected test.py file as the first argument");
|
throw std::runtime_error("Expected test.py file as the first argument");
|
||||||
auto test_py_file = argv[1];
|
}
|
||||||
|
auto *test_py_file = argv[1];
|
||||||
|
|
||||||
py::scoped_interpreter guard{};
|
py::scoped_interpreter guard{};
|
||||||
|
|
||||||
auto m = py::module_::import("test_cmake_build");
|
auto m = py::module_::import("test_cmake_build");
|
||||||
if (m.attr("add")(1, 2).cast<int>() != 3)
|
if (m.attr("add")(1, 2).cast<int>() != 3) {
|
||||||
throw std::runtime_error("embed.cpp failed");
|
throw std::runtime_error("embed.cpp failed");
|
||||||
|
}
|
||||||
|
|
||||||
py::module_::import("sys").attr("argv") = py::make_tuple("test.py", "embed.cpp");
|
py::module_::import("sys").attr("argv") = py::make_tuple("test.py", "embed.cpp");
|
||||||
py::eval_file(test_py_file, py::globals());
|
py::eval_file(test_py_file, py::globals());
|
||||||
|
Loading…
Reference in New Issue
Block a user