Merge branch 'master' into smart_holder

This commit is contained in:
Ralf W. Grosse-Kunstleve
2021-07-27 15:38:09 -07:00
22 changed files with 105 additions and 53 deletions

View File

@@ -146,6 +146,16 @@ def test_build_sdist(monkeypatch, tmpdir):
) as f:
pyproject_toml = f.read()
with contextlib.closing(
tar.extractfile(
tar.getmember(
start + "pybind11/share/cmake/pybind11/pybind11Config.cmake"
)
)
) as f:
contents = f.read().decode("utf8")
assert 'set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")' in contents
files = {"pybind11/{}".format(n) for n in all_files}
files |= sdist_files
files |= {"pybind11{}".format(n) for n in local_sdist_files}
@@ -159,11 +169,11 @@ def test_build_sdist(monkeypatch, tmpdir):
.substitute(version=version, extra_cmd="")
.encode()
)
assert setup_py == contents
assert setup_py == contents
with open(os.path.join(MAIN_DIR, "tools", "pyproject.toml"), "rb") as f:
contents = f.read()
assert pyproject_toml == contents
assert pyproject_toml == contents
def test_build_global_dist(monkeypatch, tmpdir):

View File

@@ -133,7 +133,14 @@ TEST_SUBMODULE(constants_and_functions, m) {
;
m.def("f1", f1);
m.def("f2", f2);
#if defined(__INTEL_COMPILER)
# pragma warning push
# pragma warning disable 878 // incompatible exception specifications
#endif
m.def("f3", f3);
#if defined(__INTEL_COMPILER)
# pragma warning pop
#endif
m.def("f4", f4);
// test_function_record_leaks

View File

@@ -103,7 +103,7 @@ bool has_pybind11_internals_builtin() {
bool has_pybind11_internals_static() {
auto **&ipp = py::detail::get_internals_pp();
return ipp && *ipp;
return (ipp != nullptr) && (*ipp != nullptr);
}
TEST_CASE("Restart the interpreter") {

View File

@@ -43,6 +43,7 @@ public:
void add6(int other) { value += other; } // passing by value
void add7(int &other) { value += other; } // passing by reference
void add8(const int &other) { value += other; } // passing by const reference
// NOLINTNEXTLINE(readability-non-const-parameter) Deliberately non-const for testing
void add9(int *other) { value += *other; } // passing by pointer
void add10(const int *other) { value += *other; } // passing by const pointer

View File

@@ -108,9 +108,11 @@ PYBIND11_PACKED(struct EnumStruct {
std::ostream& operator<<(std::ostream& os, const StringStruct& v) {
os << "a='";
for (size_t i = 0; i < 3 && v.a[i]; i++) os << v.a[i];
for (size_t i = 0; i < 3 && (v.a[i] != 0); i++)
os << v.a[i];
os << "',b='";
for (size_t i = 0; i < 3 && v.b[i]; i++) os << v.b[i];
for (size_t i = 0; i < 3 && (v.b[i] != 0); i++)
os << v.b[i];
return os << "'";
}

View File

@@ -59,7 +59,7 @@ TEST_SUBMODULE(numpy_vectorize, m) {
.def(py::init<int>())
.def_readwrite("value", &NonPODClass::value);
m.def("vec_passthrough",
py::vectorize([](double *a,
py::vectorize([](const double *a,
double b,
// Changing this broke things
// NOLINTNEXTLINE(performance-unnecessary-value-param)

View File

@@ -101,7 +101,7 @@ private:
// test_unique_nodelete
// Object with a private destructor
class MyObject4;
static std::unordered_set<MyObject4 *> myobject4_instances;
std::unordered_set<MyObject4 *> myobject4_instances;
class MyObject4 {
public:
MyObject4(int value) : value{value} {
@@ -127,7 +127,7 @@ private:
// Object with std::unique_ptr<T, D> where D is not matching the base class
// Object with a protected destructor
class MyObject4a;
static std::unordered_set<MyObject4a *> myobject4a_instances;
std::unordered_set<MyObject4a *> myobject4a_instances;
class MyObject4a {
public:
MyObject4a(int i) {

View File

@@ -102,7 +102,7 @@ TEST_SUBMODULE(stl, m) {
// test_set
m.def("cast_set", []() { return std::set<std::string>{"key1", "key2"}; });
m.def("load_set", [](const std::set<std::string> &set) {
return set.count("key1") && set.count("key2") && set.count("key3");
return (set.count("key1") != 0u) && (set.count("key2") != 0u) && (set.count("key3") != 0u);
});
// test_recursive_casting
@@ -196,9 +196,7 @@ TEST_SUBMODULE(stl, m) {
m.def("double_or_zero", [](const opt_int& x) -> int {
return x.value_or(0) * 2;
});
m.def("half_or_none", [](int x) -> opt_int {
return x ? opt_int(x / 2) : opt_int();
});
m.def("half_or_none", [](int x) -> opt_int { return x != 0 ? opt_int(x / 2) : opt_int(); });
m.def("test_nullopt", [](opt_int x) {
return x.value_or(42);
}, py::arg_v("x", std::nullopt, "None"));