From 68f80105007a574f114cfe899243bb3d96272a2e Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Fri, 27 May 2022 14:32:57 -0400 Subject: [PATCH] chore: add err guard to capsule destructor and add a move to iostream (#3958) * Add err guard to capsule destructor * only uses ostream currently * can these be noexcept * Add back header * fix for older compilers * This should at least be noexcept * Add missing move * Apparently not noexcept for old llvm --- include/pybind11/iostream.h | 2 +- include/pybind11/pytypes.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) 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()) {