Skip to content

Commit 68f8010

Browse files
authored
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
1 parent 8d14e66 commit 68f8010

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

include/pybind11/iostream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class pythonbuf : public std::streambuf {
100100

101101
if (size > remainder) {
102102
str line(pbase(), size - remainder);
103-
pywrite(line);
103+
pywrite(std::move(line));
104104
pyflush();
105105
}
106106

include/pybind11/pytypes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,8 @@ class capsule : public object {
15811581

15821582
capsule(const void *value, void (*destructor)(void *)) {
15831583
m_ptr = PyCapsule_New(const_cast<void *>(value), nullptr, [](PyObject *o) {
1584+
// guard if destructor called while err indicator is set
1585+
error_scope error_guard;
15841586
auto destructor = reinterpret_cast<void (*)(void *)>(PyCapsule_GetContext(o));
15851587
if (destructor == nullptr) {
15861588
if (PyErr_Occurred()) {

0 commit comments

Comments
 (0)