[PR #71] [python] fix unbuffered binary mode for I/O streams in Windows pypy #669

Closed
opened 2026-01-29 20:50:15 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/google/brotli/pull/71

State: closed
Merged: Yes


Hello,

I tried to build the brotli extension under PyPy and everything seems fine.
I tested the latest Python2.7-compatible release (PyPy version 2.5.1) on OS X, Ubuntu and Windows.
The extension compiles correctly, and both the compatibility and roundtrip tests pass just like with the CPython implementation.

I only found a small issue when running tests under pypy for Windows. It has to do with the "bro.py" script used for the tests. In PyPy, the msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY trick does not seem to produce any effect (unlike under Windows CPython), and so brotli fails because the standard input/output streams are not read/written in binary mode, but in the default text mode (with \n line endings converted to \r\n).

I modified the "bro.py" script to use a different method (os.fdopen) to reopen standard streams in binary mode only when it is run from PyPy on Windows. For some reasons, the latter trick does not work from Windows CPython, so for the latter I still use the msvcrt.setmode method.

Cheers,

Cosimo

**Original Pull Request:** https://github.com/google/brotli/pull/71 **State:** closed **Merged:** Yes --- Hello, I tried to build the brotli extension under PyPy and everything seems fine. I tested the latest Python2.7-compatible release (PyPy version 2.5.1) on OS X, Ubuntu and Windows. The extension compiles correctly, and both the compatibility and roundtrip tests pass just like with the CPython implementation. I only found a small issue when running tests under pypy for Windows. It has to do with the "bro.py" script used for the tests. In PyPy, the `msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY` trick does not seem to produce any effect (unlike under Windows CPython), and so brotli fails because the standard input/output streams are not read/written in binary mode, but in the default text mode (with `\n` line endings converted to `\r\n`). I modified the "bro.py" script to use a different method (`os.fdopen`) to reopen standard streams in binary mode only when it is run from PyPy on Windows. For some reasons, the latter trick does not work from Windows CPython, so for the latter I still use the `msvcrt.setmode` method. Cheers, Cosimo
claunia added the pull-request label 2026-01-29 20:50:15 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/brotli#669