mirror of
https://github.com/pybind/pybind11.git
synced 2025-02-22 00:19:18 +00:00
Merge branch 'pybind:master' into master
This commit is contained in:
commit
8d22552aef
@ -57,10 +57,12 @@ Checks: |
|
|||||||
readability-string-compare,
|
readability-string-compare,
|
||||||
readability-suspicious-call-argument,
|
readability-suspicious-call-argument,
|
||||||
readability-uniqueptr-delete-release,
|
readability-uniqueptr-delete-release,
|
||||||
|
-bugprone-chained-comparison,
|
||||||
-bugprone-easily-swappable-parameters,
|
-bugprone-easily-swappable-parameters,
|
||||||
-bugprone-exception-escape,
|
-bugprone-exception-escape,
|
||||||
-bugprone-reserved-identifier,
|
-bugprone-reserved-identifier,
|
||||||
-bugprone-unused-raii,
|
-bugprone-unused-raii,
|
||||||
|
-performance-enum-size,
|
||||||
|
|
||||||
CheckOptions:
|
CheckOptions:
|
||||||
- key: modernize-use-equals-default.IgnoreMacros
|
- key: modernize-use-equals-default.IgnoreMacros
|
||||||
|
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@ -340,6 +340,12 @@ jobs:
|
|||||||
- clang: 16
|
- clang: 16
|
||||||
std: 20
|
std: 20
|
||||||
container_suffix: "-bullseye"
|
container_suffix: "-bullseye"
|
||||||
|
- clang: 17
|
||||||
|
std: 20
|
||||||
|
container_suffix: "-bookworm"
|
||||||
|
- clang: 18
|
||||||
|
std: 20
|
||||||
|
container_suffix: "-bookworm"
|
||||||
|
|
||||||
name: "🐍 3 • Clang ${{ matrix.clang }} • C++${{ matrix.std }} • x64"
|
name: "🐍 3 • Clang ${{ matrix.clang }} • C++${{ matrix.std }} • x64"
|
||||||
container: "silkeh/clang:${{ matrix.clang }}${{ matrix.container_suffix }}"
|
container: "silkeh/clang:${{ matrix.clang }}${{ matrix.container_suffix }}"
|
||||||
|
2
.github/workflows/format.yml
vendored
2
.github/workflows/format.yml
vendored
@ -41,7 +41,7 @@ jobs:
|
|||||||
# in .github/CONTRIBUTING.md and update as needed.
|
# in .github/CONTRIBUTING.md and update as needed.
|
||||||
name: Clang-Tidy
|
name: Clang-Tidy
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: silkeh/clang:15-bullseye
|
container: silkeh/clang:18-bookworm
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
@ -553,7 +553,7 @@ PYBIND11_NOINLINE internals &get_internals() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
internals_ptr->istate = tstate->interp;
|
internals_ptr->istate = tstate->interp;
|
||||||
state_dict[PYBIND11_INTERNALS_ID] = capsule(internals_pp);
|
state_dict[PYBIND11_INTERNALS_ID] = capsule(reinterpret_cast<void *>(internals_pp));
|
||||||
internals_ptr->registered_exception_translators.push_front(&translate_exception);
|
internals_ptr->registered_exception_translators.push_front(&translate_exception);
|
||||||
internals_ptr->static_property_type = make_static_property_type();
|
internals_ptr->static_property_type = make_static_property_type();
|
||||||
internals_ptr->default_metaclass = make_default_metaclass();
|
internals_ptr->default_metaclass = make_default_metaclass();
|
||||||
|
@ -428,7 +428,7 @@ PYBIND11_NOINLINE void instance::allocate_layout() {
|
|||||||
// NOLINTNEXTLINE(readability-make-member-function-const)
|
// NOLINTNEXTLINE(readability-make-member-function-const)
|
||||||
PYBIND11_NOINLINE void instance::deallocate_layout() {
|
PYBIND11_NOINLINE void instance::deallocate_layout() {
|
||||||
if (!simple_layout) {
|
if (!simple_layout) {
|
||||||
PyMem_Free(nonsimple.values_and_holders);
|
PyMem_Free(reinterpret_cast<void *>(nonsimple.values_and_holders));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,9 +469,6 @@ struct type_caster<Eigen::TensorMap<Type, Options>,
|
|||||||
parent_object = reinterpret_borrow<object>(parent);
|
parent_object = reinterpret_borrow<object>(parent);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case return_value_policy::take_ownership:
|
|
||||||
delete src;
|
|
||||||
// fallthrough
|
|
||||||
default:
|
default:
|
||||||
// move, take_ownership don't make any sense for a ref/map:
|
// move, take_ownership don't make any sense for a ref/map:
|
||||||
pybind11_fail("Invalid return_value_policy for Eigen Map type, must be either "
|
pybind11_fail("Invalid return_value_policy for Eigen Map type, must be either "
|
||||||
|
@ -1050,7 +1050,11 @@ public:
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
array(ShapeContainer shape, StridesContainer strides, const T *ptr, handle base = handle())
|
array(ShapeContainer shape, StridesContainer strides, const T *ptr, handle base = handle())
|
||||||
: array(pybind11::dtype::of<T>(), std::move(shape), std::move(strides), ptr, base) {}
|
: array(pybind11::dtype::of<T>(),
|
||||||
|
std::move(shape),
|
||||||
|
std::move(strides),
|
||||||
|
reinterpret_cast<const void *>(ptr),
|
||||||
|
base) {}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
array(ShapeContainer shape, const T *ptr, handle base = handle())
|
array(ShapeContainer shape, const T *ptr, handle base = handle())
|
||||||
@ -2103,7 +2107,7 @@ private:
|
|||||||
// Pointers to values the function was called with; the vectorized ones set here will start
|
// Pointers to values the function was called with; the vectorized ones set here will start
|
||||||
// out as array_t<T> pointers, but they will be changed them to T pointers before we make
|
// out as array_t<T> pointers, but they will be changed them to T pointers before we make
|
||||||
// call the wrapped function. Non-vectorized pointers are left as-is.
|
// call the wrapped function. Non-vectorized pointers are left as-is.
|
||||||
std::array<void *, N> params{{&args...}};
|
std::array<void *, N> params{{reinterpret_cast<void *>(&args)...}};
|
||||||
|
|
||||||
// The array of `buffer_info`s of vectorized arguments:
|
// The array of `buffer_info`s of vectorized arguments:
|
||||||
std::array<buffer_info, NVectorized> buffers{
|
std::array<buffer_info, NVectorized> buffers{
|
||||||
|
@ -33,6 +33,13 @@
|
|||||||
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||||
PYBIND11_NAMESPACE_BEGIN(detail)
|
PYBIND11_NAMESPACE_BEGIN(detail)
|
||||||
|
|
||||||
|
#ifdef PYPY_VERSION
|
||||||
|
# define PYBIND11_REINTERPRET_CAST_VOID_PTR_IF_NOT_PYPY(...) (__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
# define PYBIND11_REINTERPRET_CAST_VOID_PTR_IF_NOT_PYPY(...) \
|
||||||
|
(reinterpret_cast<void *>(__VA_ARGS__))
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(PYBIND11_HAS_FILESYSTEM) || defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM)
|
#if defined(PYBIND11_HAS_FILESYSTEM) || defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM)
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct path_caster {
|
struct path_caster {
|
||||||
@ -72,7 +79,8 @@ public:
|
|||||||
}
|
}
|
||||||
PyObject *native = nullptr;
|
PyObject *native = nullptr;
|
||||||
if constexpr (std::is_same_v<typename T::value_type, char>) {
|
if constexpr (std::is_same_v<typename T::value_type, char>) {
|
||||||
if (PyUnicode_FSConverter(buf, &native) != 0) {
|
if (PyUnicode_FSConverter(buf, PYBIND11_REINTERPRET_CAST_VOID_PTR_IF_NOT_PYPY(&native))
|
||||||
|
!= 0) {
|
||||||
if (auto *c_str = PyBytes_AsString(native)) {
|
if (auto *c_str = PyBytes_AsString(native)) {
|
||||||
// AsString returns a pointer to the internal buffer, which
|
// AsString returns a pointer to the internal buffer, which
|
||||||
// must not be free'd.
|
// must not be free'd.
|
||||||
@ -80,7 +88,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if constexpr (std::is_same_v<typename T::value_type, wchar_t>) {
|
} else if constexpr (std::is_same_v<typename T::value_type, wchar_t>) {
|
||||||
if (PyUnicode_FSDecoder(buf, &native) != 0) {
|
if (PyUnicode_FSDecoder(buf, PYBIND11_REINTERPRET_CAST_VOID_PTR_IF_NOT_PYPY(&native))
|
||||||
|
!= 0) {
|
||||||
if (auto *c_str = PyUnicode_AsWideCharString(native, nullptr)) {
|
if (auto *c_str = PyUnicode_AsWideCharString(native, nullptr)) {
|
||||||
// AsWideCharString returns a new string that must be free'd.
|
// AsWideCharString returns a new string that must be free'd.
|
||||||
value = c_str; // Copies the string.
|
value = c_str; // Copies the string.
|
||||||
|
@ -180,7 +180,7 @@ void vector_modifiers(
|
|||||||
v.end());
|
v.end());
|
||||||
try {
|
try {
|
||||||
v.shrink_to_fit();
|
v.shrink_to_fit();
|
||||||
} catch (const std::exception &) {
|
} catch (const std::exception &) { // NOLINT(bugprone-empty-catch)
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
throw;
|
throw;
|
||||||
|
@ -190,7 +190,7 @@ public:
|
|||||||
t1 = &p.first;
|
t1 = &p.first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (const std::out_of_range &) {
|
} catch (const std::out_of_range &) { // NOLINT(bugprone-empty-catch)
|
||||||
}
|
}
|
||||||
if (!t1) {
|
if (!t1) {
|
||||||
throw std::runtime_error("Unknown class passed to ConstructorStats::get()");
|
throw std::runtime_error("Unknown class passed to ConstructorStats::get()");
|
||||||
|
@ -147,33 +147,39 @@ void init_tensor_module(pybind11::module &m) {
|
|||||||
|
|
||||||
m.def(
|
m.def(
|
||||||
"take_fixed_tensor",
|
"take_fixed_tensor",
|
||||||
|
|
||||||
[]() {
|
[]() {
|
||||||
Eigen::aligned_allocator<
|
Eigen::aligned_allocator<
|
||||||
Eigen::TensorFixedSize<double, Eigen::Sizes<3, 5, 2>, Options>>
|
Eigen::TensorFixedSize<double, Eigen::Sizes<3, 5, 2>, Options>>
|
||||||
allocator;
|
allocator;
|
||||||
return new (allocator.allocate(1))
|
static auto *obj = new (allocator.allocate(1))
|
||||||
Eigen::TensorFixedSize<double, Eigen::Sizes<3, 5, 2>, Options>(
|
Eigen::TensorFixedSize<double, Eigen::Sizes<3, 5, 2>, Options>(
|
||||||
get_fixed_tensor<Options>());
|
get_fixed_tensor<Options>());
|
||||||
|
return obj; // take_ownership will fail.
|
||||||
},
|
},
|
||||||
py::return_value_policy::take_ownership);
|
py::return_value_policy::take_ownership);
|
||||||
|
|
||||||
m.def(
|
m.def(
|
||||||
"take_tensor",
|
"take_tensor",
|
||||||
[]() { return new Eigen::Tensor<double, 3, Options>(get_tensor<Options>()); },
|
[]() {
|
||||||
|
static auto *obj = new Eigen::Tensor<double, 3, Options>(get_tensor<Options>());
|
||||||
|
return obj; // take_ownership will fail.
|
||||||
|
},
|
||||||
py::return_value_policy::take_ownership);
|
py::return_value_policy::take_ownership);
|
||||||
|
|
||||||
m.def(
|
m.def(
|
||||||
"take_const_tensor",
|
"take_const_tensor",
|
||||||
[]() -> const Eigen::Tensor<double, 3, Options> * {
|
[]() -> const Eigen::Tensor<double, 3, Options> * {
|
||||||
return new Eigen::Tensor<double, 3, Options>(get_tensor<Options>());
|
static auto *obj = new Eigen::Tensor<double, 3, Options>(get_tensor<Options>());
|
||||||
|
return obj; // take_ownership will fail.
|
||||||
},
|
},
|
||||||
py::return_value_policy::take_ownership);
|
py::return_value_policy::take_ownership);
|
||||||
|
|
||||||
m.def(
|
m.def(
|
||||||
"take_view_tensor",
|
"take_view_tensor",
|
||||||
[]() -> const Eigen::TensorMap<Eigen::Tensor<double, 3, Options>> * {
|
[]() -> const Eigen::TensorMap<Eigen::Tensor<double, 3, Options>> * {
|
||||||
return new Eigen::TensorMap<Eigen::Tensor<double, 3, Options>>(get_tensor<Options>());
|
static auto *obj
|
||||||
|
= new Eigen::TensorMap<Eigen::Tensor<double, 3, Options>>(get_tensor<Options>());
|
||||||
|
return obj; // take_ownership will fail.
|
||||||
},
|
},
|
||||||
py::return_value_policy::take_ownership);
|
py::return_value_policy::take_ownership);
|
||||||
|
|
||||||
|
@ -90,32 +90,32 @@ TEST_SUBMODULE(modules, m) {
|
|||||||
try {
|
try {
|
||||||
py::class_<Dupe1>(dm, "Dupe1");
|
py::class_<Dupe1>(dm, "Dupe1");
|
||||||
failures.append("Dupe1 class");
|
failures.append("Dupe1 class");
|
||||||
} catch (std::runtime_error &) {
|
} catch (std::runtime_error &) { // NOLINT(bugprone-empty-catch)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
dm.def("Dupe1", []() { return Dupe1(); });
|
dm.def("Dupe1", []() { return Dupe1(); });
|
||||||
failures.append("Dupe1 function");
|
failures.append("Dupe1 function");
|
||||||
} catch (std::runtime_error &) {
|
} catch (std::runtime_error &) { // NOLINT(bugprone-empty-catch)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
py::class_<Dupe3>(dm, "dupe1_factory");
|
py::class_<Dupe3>(dm, "dupe1_factory");
|
||||||
failures.append("dupe1_factory");
|
failures.append("dupe1_factory");
|
||||||
} catch (std::runtime_error &) {
|
} catch (std::runtime_error &) { // NOLINT(bugprone-empty-catch)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
py::exception<Dupe3>(dm, "Dupe2");
|
py::exception<Dupe3>(dm, "Dupe2");
|
||||||
failures.append("Dupe2");
|
failures.append("Dupe2");
|
||||||
} catch (std::runtime_error &) {
|
} catch (std::runtime_error &) { // NOLINT(bugprone-empty-catch)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
dm.def("DupeException", []() { return 30; });
|
dm.def("DupeException", []() { return 30; });
|
||||||
failures.append("DupeException1");
|
failures.append("DupeException1");
|
||||||
} catch (std::runtime_error &) {
|
} catch (std::runtime_error &) { // NOLINT(bugprone-empty-catch)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
py::class_<DupeException>(dm, "DupeException");
|
py::class_<DupeException>(dm, "DupeException");
|
||||||
failures.append("DupeException2");
|
failures.append("DupeException2");
|
||||||
} catch (std::runtime_error &) {
|
} catch (std::runtime_error &) { // NOLINT(bugprone-empty-catch)
|
||||||
}
|
}
|
||||||
|
|
||||||
return failures;
|
return failures;
|
||||||
|
@ -266,6 +266,8 @@ py::array_t<int32_t, 0> test_array_ctors(int i) {
|
|||||||
return fill(arr_t(buf_ndim1_null));
|
return fill(arr_t(buf_ndim1_null));
|
||||||
case 44:
|
case 44:
|
||||||
return fill(py::array(buf_ndim1_null));
|
return fill(py::array(buf_ndim1_null));
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return arr_t();
|
return arr_t();
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ TEST_SUBMODULE(opaque_types, m) {
|
|||||||
|
|
||||||
m.def("return_unique_ptr", []() -> std::unique_ptr<StringList> {
|
m.def("return_unique_ptr", []() -> std::unique_ptr<StringList> {
|
||||||
auto *result = new StringList();
|
auto *result = new StringList();
|
||||||
result->push_back("some value");
|
result->emplace_back("some value");
|
||||||
return std::unique_ptr<StringList>(result);
|
return std::unique_ptr<StringList>(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -74,6 +74,7 @@ std::vector<std::unique_ptr<Animal>> create_zoo() {
|
|||||||
// simulate some new type of Dog that the Python bindings
|
// simulate some new type of Dog that the Python bindings
|
||||||
// haven't been updated for; it should still be considered
|
// haven't been updated for; it should still be considered
|
||||||
// a Dog, not just an Animal.
|
// a Dog, not just an Animal.
|
||||||
|
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
|
||||||
ret.emplace_back(new Dog("Ginger", Dog::Kind(150)));
|
ret.emplace_back(new Dog("Ginger", Dog::Kind(150)));
|
||||||
|
|
||||||
ret.emplace_back(new Chihuahua("Hertzl"));
|
ret.emplace_back(new Chihuahua("Hertzl"));
|
||||||
|
Loading…
Reference in New Issue
Block a user