Skip to content

Allow ostream-redirection of more than 1024 characters#1479

Merged
wjakob merged 1 commit into
pybind:masterfrom
Quincunx271:fix-pythonbuf-overflow
Aug 29, 2018
Merged

Allow ostream-redirection of more than 1024 characters#1479
wjakob merged 1 commit into
pybind:masterfrom
Quincunx271:fix-pythonbuf-overflow

Conversation

@Quincunx271

Copy link
Copy Markdown
Contributor

Fixes #1478

In short, detail::pythonbuf::overflow() had its branch for the return statement backwards, since bool(sync()) is true if and only if sync() fails; sync() returns 0 on success. This fixes it by using sync() == 0 as the condition.

@Quincunx271

Copy link
Copy Markdown
Contributor Author

The CI errors seem to be a warning about using a deprecated numpy type (matrix), which has nothing to do with this change. All non-numpy tests seem to be passing.

@wjakob

wjakob commented Aug 28, 2018

Copy link
Copy Markdown
Member

There is something I don't understand about the original implementation, which is somewhat related to the patch here. It looks like sync() can't return any value other than zero -- so what's the purpose of the ternary expression?

@Quincunx271

Copy link
Copy Markdown
Contributor Author

If someone wrote a class which inherits from pythonbuf, sync() could return a non-zero value.

@wjakob

wjakob commented Aug 28, 2018

Copy link
Copy Markdown
Member

Ah, gotcha -- it's a virtual function in the C++ standard. This looks good to me then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scoped_ostream_redirect only works for the first 1024 characters

2 participants