https://github.com/python/cpython/commit/4e147caf3fcb6af9ed28b87a09c72f294d8f60bd
commit: 4e147caf3fcb6af9ed28b87a09c72f294d8f60bd
branch: 3.13
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2024-06-01T17:08:23+02:00
summary:

[3.13] Revert "[3.13] gh-69214: Fix fcntl.ioctl() request type (GH-119498) (… 
(#119906)

Revert "[3.13] gh-69214: Fix fcntl.ioctl() request type (GH-119498) (#119504)"

This reverts commit 0bab0b3a53da735838720f96f3d3bf86ca6ba125.

The change modified how negative values, like termios.TIOCSWINSZ, was
treated and is actually backward incompatible.

files:
D Misc/NEWS.d/next/Library/2024-05-24-11-47-08.gh-issue-69214.Grl6zF.rst
M Modules/clinic/fcntlmodule.c.h
M Modules/fcntlmodule.c

diff --git 
a/Misc/NEWS.d/next/Library/2024-05-24-11-47-08.gh-issue-69214.Grl6zF.rst 
b/Misc/NEWS.d/next/Library/2024-05-24-11-47-08.gh-issue-69214.Grl6zF.rst
deleted file mode 100644
index 8c3a36c9f56475..00000000000000
--- a/Misc/NEWS.d/next/Library/2024-05-24-11-47-08.gh-issue-69214.Grl6zF.rst
+++ /dev/null
@@ -1,3 +0,0 @@
-Fix ``fcntl.ioctl()`` *request* parameter: use an ``unsigned long`` instead of
-an ``unsigned int`` for the *request* parameter of :func:`fcntl.ioctl` to
-support requests larger than ``UINT_MAX``. Patch by Victor Stinner.
diff --git a/Modules/clinic/fcntlmodule.c.h b/Modules/clinic/fcntlmodule.c.h
index 53b139e09afdf1..d4846ddf8df7e4 100644
--- a/Modules/clinic/fcntlmodule.c.h
+++ b/Modules/clinic/fcntlmodule.c.h
@@ -96,7 +96,7 @@ PyDoc_STRVAR(fcntl_ioctl__doc__,
     {"ioctl", (PyCFunction)(void(*)(void))fcntl_ioctl, METH_FASTCALL, 
fcntl_ioctl__doc__},
 
 static PyObject *
-fcntl_ioctl_impl(PyObject *module, int fd, unsigned long code,
+fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code,
                  PyObject *ob_arg, int mutate_arg);
 
 static PyObject *
@@ -104,7 +104,7 @@ fcntl_ioctl(PyObject *module, PyObject *const *args, 
Py_ssize_t nargs)
 {
     PyObject *return_value = NULL;
     int fd;
-    unsigned long code;
+    unsigned int code;
     PyObject *ob_arg = NULL;
     int mutate_arg = 1;
 
@@ -120,11 +120,10 @@ fcntl_ioctl(PyObject *module, PyObject *const *args, 
Py_ssize_t nargs)
     if (fd < 0) {
         goto exit;
     }
-    if (!PyLong_Check(args[1])) {
-        PyErr_Format(PyExc_TypeError, "ioctl() argument 2 must be int, not 
%T", args[1]);
+    code = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
+    if (code == (unsigned int)-1 && PyErr_Occurred()) {
         goto exit;
     }
-    code = PyLong_AsUnsignedLongMask(args[1]);
     if (nargs < 3) {
         goto skip_optional;
     }
@@ -264,4 +263,4 @@ fcntl_lockf(PyObject *module, PyObject *const *args, 
Py_ssize_t nargs)
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=45a56f53fd17ff3c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=26793691ab1c75ba input=a9049054013a1b77]*/
diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c
index 873bdf2ac0657a..b6eeec2c66f6e5 100644
--- a/Modules/fcntlmodule.c
+++ b/Modules/fcntlmodule.c
@@ -112,7 +112,7 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, 
PyObject *arg)
 fcntl.ioctl
 
     fd: fildes
-    request as code: unsigned_long(bitwise=True)
+    request as code: unsigned_int(bitwise=True)
     arg as ob_arg: object(c_default='NULL') = 0
     mutate_flag as mutate_arg: bool = True
     /
@@ -148,9 +148,9 @@ code.
 [clinic start generated code]*/
 
 static PyObject *
-fcntl_ioctl_impl(PyObject *module, int fd, unsigned long code,
+fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code,
                  PyObject *ob_arg, int mutate_arg)
-/*[clinic end generated code: output=3d8eb6828666cea1 input=cee70f6a27311e58]*/
+/*[clinic end generated code: output=7f7f5840c65991be input=967b4a4cbeceb0a8]*/
 {
 #define IOCTL_BUFSZ 1024
     /* We use the unsigned non-checked 'I' format for the 'code' parameter

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to