[Python-checkins] bpo-38265: Update os.pread to accept the length type as Py_ssize_t. (GH-16359)

Serhiy Storchaka webhook-mailer at python.org
Wed Sep 25 01:47:08 EDT 2019


https://github.com/python/cpython/commit/ad7736faf5b82a24374c601a72599adf29951080
commit: ad7736faf5b82a24374c601a72599adf29951080
branch: master
author: Dong-hee Na <donghee.na92 at gmail.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2019-09-25T08:47:04+03:00
summary:

bpo-38265: Update os.pread to accept the length type as Py_ssize_t. (GH-16359)

files:
A Misc/NEWS.d/next/Library/2019-09-25-05-16-19.bpo-38265.X6-gsT.rst
M Modules/clinic/posixmodule.c.h
M Modules/posixmodule.c

diff --git a/Misc/NEWS.d/next/Library/2019-09-25-05-16-19.bpo-38265.X6-gsT.rst b/Misc/NEWS.d/next/Library/2019-09-25-05-16-19.bpo-38265.X6-gsT.rst
new file mode 100644
index 000000000000..bd69a26149d1
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-09-25-05-16-19.bpo-38265.X6-gsT.rst
@@ -0,0 +1,2 @@
+Update the *length* parameter of :func:`os.pread` to accept
+:c:type:`Py_ssize_t` instead of :c:type:`int`.
diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h
index b21d17477ee6..00b05f7989a9 100644
--- a/Modules/clinic/posixmodule.c.h
+++ b/Modules/clinic/posixmodule.c.h
@@ -4799,14 +4799,14 @@ PyDoc_STRVAR(os_pread__doc__,
     {"pread", (PyCFunction)(void(*)(void))os_pread, METH_FASTCALL, os_pread__doc__},
 
 static PyObject *
-os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
+os_pread_impl(PyObject *module, int fd, Py_ssize_t length, Py_off_t offset);
 
 static PyObject *
 os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
 {
     PyObject *return_value = NULL;
     int fd;
-    int length;
+    Py_ssize_t length;
     Py_off_t offset;
 
     if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) {
@@ -4826,9 +4826,17 @@ os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
                         "integer argument expected, got float" );
         goto exit;
     }
-    length = _PyLong_AsInt(args[1]);
-    if (length == -1 && PyErr_Occurred()) {
-        goto exit;
+    {
+        Py_ssize_t ival = -1;
+        PyObject *iobj = PyNumber_Index(args[1]);
+        if (iobj != NULL) {
+            ival = PyLong_AsSsize_t(iobj);
+            Py_DECREF(iobj);
+        }
+        if (ival == -1 && PyErr_Occurred()) {
+            goto exit;
+        }
+        length = ival;
     }
     if (!Py_off_t_converter(args[2], &offset)) {
         goto exit;
@@ -8723,4 +8731,4 @@ os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nar
 #ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF
     #define OS__REMOVE_DLL_DIRECTORY_METHODDEF
 #endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */
-/*[clinic end generated code: output=113d9fbdd18a62f5 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=799c75140d84ace5 input=a9049054013a1b77]*/
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index c60d0c5e39ff..5664027b2d3a 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -8827,11 +8827,10 @@ os_readv_impl(PyObject *module, int fd, PyObject *buffers)
 
 #ifdef HAVE_PREAD
 /*[clinic input]
-# TODO length should be size_t!  but Python doesn't support parsing size_t yet.
 os.pread
 
     fd: int
-    length: int
+    length: Py_ssize_t
     offset: Py_off_t
     /
 
@@ -8842,8 +8841,8 @@ the beginning of the file.  The file offset remains unchanged.
 [clinic start generated code]*/
 
 static PyObject *
-os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset)
-/*[clinic end generated code: output=435b29ee32b54a78 input=084948dcbaa35d4c]*/
+os_pread_impl(PyObject *module, int fd, Py_ssize_t length, Py_off_t offset)
+/*[clinic end generated code: output=3f875c1eef82e32f input=85cb4a5589627144]*/
 {
     Py_ssize_t n;
     int async_err = 0;



More information about the Python-checkins mailing list