Skip to content

Commit a65b11e

Browse files
committed
Dropping a class and simpler code, from @dean0x7d
Squashed commit of the following: commit a310fa30069de7de0b92019e7736939d52fb725e Author: Henry Fredrick Schreiner <[email protected]> Date: Mon Aug 21 14:50:49 2017 -0700 Dropping a class and simpler code, from @dean0x7d commit 2af3855adb781716ed22db1aa07e09226aff3d1f Author: Henry Fredrick Schreiner <[email protected]> Date: Mon Aug 21 14:47:26 2017 -0700 Add license to header
1 parent 282ab32 commit a65b11e

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

include/pybind11/iostream.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
#pragma once
22

3+
/*
4+
pybind11/iostream -- Tools to assist with redirecting cout and cerr to Python
5+
6+
Copyright (c) 2017 Henry F. Schreiner
7+
8+
All rights reserved. Use of this source code is governed by a
9+
BSD-style license that can be found in the LICENSE file.
10+
*/
11+
312
#include "pybind11.h"
413

514
#include <streambuf>
@@ -48,13 +57,6 @@ class pythonbuf : public std::streambuf {
4857
}
4958
};
5059

51-
// Stream that writes to Python instead of C++ file descriptors
52-
class opythonstream : public std::ostream {
53-
public:
54-
opythonstream(object pyostream) : std::ostream(new pythonbuf(pyostream)) { }
55-
virtual ~opythonstream() { delete rdbuf(nullptr); }
56-
};
57-
5860
NAMESPACE_END(detail)
5961

6062

@@ -83,18 +85,19 @@ NAMESPACE_END(detail)
8385
class scoped_ostream_redirect {
8486
std::streambuf * old {nullptr};
8587
std::ostream& costream;
86-
detail::opythonstream buffer;
88+
detail::pythonbuf buffer;
8789

8890
public:
8991
scoped_ostream_redirect(
9092
std::ostream& costream = std::cout,
9193
object pyostream = module::import("sys").attr("stdout") )
9294
: costream(costream), buffer(pyostream) {
93-
old = costream.rdbuf(buffer.rdbuf());
95+
old = costream.rdbuf(&buffer);
9496
}
9597

9698
~scoped_ostream_redirect() {
9799
costream.rdbuf(old);
100+
98101
}
99102

100103
scoped_ostream_redirect(const scoped_ostream_redirect &) = delete;

0 commit comments

Comments
 (0)