10000 gh-129205: Add os.readinto API for reading data into a caller provided buffer by cmaloney · Pull Request #129211 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-129205: Add os.readinto API for reading data into a caller provided buffer #129211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Sync Doc and help
  • Loading branch information
cmaloney committed Jan 24, 2025
commit 06e98e837d1521de9670d0fe78faf53ec1cca4b0
2 changes: 1 addition & 1 deletion Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ or `the MSDN <https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Windo

Returns 0 if *fd* is at end of file or if the provided *buffer* has
length 0 (which can be used to check for errors without reading data).
A negative value is never returned by this function.
Never returns negative.

.. note::

Expand Down
18 changes: 9 additions & 9 deletions Modules/clinic/posixmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -11441,20 +11441,20 @@ os.readinto -> Py_ssize_t

Read into a buffer object from a file descriptor.

The buffer should be mutable and bytes-like.

On success, returns the number of bytes read. Less bytes may be read than the
size of the buffer without reaching end of stream. Will retry the underlying
system call when interrupted by a signal. Other errors will not be retried and
an error will be raised.

Returns 0 if the fd is at end of file or the provided buffer is length 0 (can be
used to check for errors without reading data). Never returns a negative value.
The buffer should be mutable and bytes-like. On success, returns the number of
bytes read. Less bytes may be read than the size of the buffer. The underlying
system call will be retried when interrupted by a signal, unless the signal
handler raises an exception. Other errors will not be retried and an error will
be raised.

Returns 0 if *fd* is at end of file or if the provided *buffer* has length 0
(which can be used to check for errors without reading data). Never returns
negative.
[clinic start generated code]*/

static Py_ssize_t
os_readinto_impl(PyObject *module, int fd, Py_buffer *buffer)
/*[clinic end generated code: output=8091a3513c683a80 input=2a0ac4256f469f93]*/
/*[clinic end generated code: output=8091a3513c683a80 input=d40074d0a68de575]*/
{
assert(buffer->len >= 0);
Py_ssize_t result = _Py_read(fd, buffer->buf, buffer->len);
Expand Down
0