Skip to content

Conversation

@cmaloney
Copy link
Contributor

@cmaloney cmaloney commented Jan 26, 2025

os.read allocated and filled a buffer by calling read(2), than that data was copied into the user provied buffer. Read directly into the caller's buffer instead by using os.readinto.

os.readinto uses PyObject_GetBuffer to make sure the passed in buffer is writeable and bytes-like, drop the manual check.

`os.read` allocated and filled a buffer by calling `read(2)`, than that
data was copied into the user provied buffer. Read directly into the
caller's buffer instead by using `os.readinto`.

`os.readinto` uses `PyObject_GetBuffer` to make sure the passed in
buffer is writeable and bytes-like, drop the manual check.
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vstinner vstinner merged commit 180ee43 into python:main Jan 28, 2025
44 checks passed
@vstinner
Copy link
Member

Merged, thank you.

@cmaloney cmaloney deleted the cmaloney/pyio_to_os_readinto branch January 28, 2025 17:34
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.

2 participants