Skip to content

Commit 9f5994b

Browse files
gh-132742: Refactor fcntl.fcntl() and fcntl.ioctl() (GH-132768)
* Support arbitrary bytes-like objects, not only bytes, in fcntl(). * The fcntl() buffer argument is now null-terminated. * Automatically retry an ioctl() system calls failing with EINTR. * Release the GIL for an ioctl() system call even for large bytes-like object. * Do not silence arbitrary errors whet try to get a buffer. * Optimize argument parsing, check the argument type before trying to get a buffer or convert it to integer. * Fix some error messages.
1 parent 8c975b0 commit 9f5994b

File tree

4 files changed

+142
-137
lines changed

4 files changed

+142
-137
lines changed

Doc/library/fcntl.rst

+9-2
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ The module defines the following functions:
8989
for *cmd* are operating system dependent, and are available as constants
9090
in the :mod:`fcntl` module, using the same names as used in the relevant C
9191
header files. The argument *arg* can either be an integer value, a
92-
:class:`bytes` object, or a string.
92+
:term:`bytes-like object`, or a string.
9393
The type and size of *arg* must match the type and size of
9494
the argument of the operation as specified in the relevant C documentation.
9595

9696
When *arg* is an integer, the function returns the integer
9797
return value of the C :c:func:`fcntl` call.
9898

99-
When the argument is bytes, it represents a binary structure,
99+
When the argument is bytes-like object, it represents a binary structure,
100100
for example, created by :func:`struct.pack`.
101101
A string value is encoded to binary using the UTF-8 encoding.
102102
The binary data is copied to a buffer whose address is
@@ -117,6 +117,10 @@ The module defines the following functions:
117117

118118
.. audit-event:: fcntl.fcntl fd,cmd,arg fcntl.fcntl
119119

120+
.. versionchanged:: next
121+
Add support of arbitrary :term:`bytes-like objects <bytes-like object>`,
122+
not only :class:`bytes`.
123+
120124

121125
.. function:: ioctl(fd, request, arg=0, mutate_flag=True, /)
122126

@@ -173,6 +177,9 @@ The module defines the following functions:
173177

174178
.. audit-event:: fcntl.ioctl fd,request,arg fcntl.ioctl
175179

180+
.. versionchanged:: next
181+
The GIL is always released during a system call.
182+
System calls failing with EINTR are automatically retried.
176183

177184
.. function:: flock(fd, operation, /)
178185

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:func:`fcntl.fcntl` now supports arbitrary :term:`bytes-like objects
2+
<bytes-like object>`, not only :class:`bytes`. :func:`fcntl.ioctl` now
3+
automatically retries system calls failing with EINTR and releases the GIL
4+
during a system call even for large bytes-like object.

Modules/clinic/fcntlmodule.c.h

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)