diff --git a/include/pybind11/iostream.h b/include/pybind11/iostream.h index 12e1f19f0..1878089e3 100644 --- a/include/pybind11/iostream.h +++ b/include/pybind11/iostream.h @@ -100,7 +100,7 @@ private: if (size > remainder) { str line(pbase(), size - remainder); - pywrite(line); + pywrite(std::move(line)); pyflush(); } diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 256a2441b..5b1c60e33 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -1581,6 +1581,8 @@ public: capsule(const void *value, void (*destructor)(void *)) { m_ptr = PyCapsule_New(const_cast(value), nullptr, [](PyObject *o) { + // guard if destructor called while err indicator is set + error_scope error_guard; auto destructor = reinterpret_cast(PyCapsule_GetContext(o)); if (destructor == nullptr) { if (PyErr_Occurred()) {