diff --git a/include/pybind11/iostream.h b/include/pybind11/iostream.h index 182e8eefd..9119270e2 100644 --- a/include/pybind11/iostream.h +++ b/include/pybind11/iostream.h @@ -25,7 +25,8 @@ class pythonbuf : public std::streambuf { private: using traits_type = std::streambuf::traits_type; - char d_buffer[1024]; + const size_t buf_size; + std::unique_ptr d_buffer; object pywrite; object pyflush; @@ -51,10 +52,13 @@ private: } public: - pythonbuf(object pyostream) - : pywrite(pyostream.attr("write")), + + pythonbuf(object pyostream, size_t buffer_size = 1024) + : buf_size(buffer_size), + d_buffer(new char[buf_size]), + pywrite(pyostream.attr("write")), pyflush(pyostream.attr("flush")) { - setp(d_buffer, d_buffer + sizeof(d_buffer) - 1); + setp(d_buffer.get(), d_buffer.get() + buf_size - 1); } /// Sync before destroy