[Python-checkins] cpython (merge 3.3 -> default): (Merge 3.3) Issue #16367: Fix FileIO.readall() on Windows for files larger than

victor.stinner python-checkins at python.org
Thu Jan 3 03:42:57 CET 2013


http://hg.python.org/cpython/rev/d81d4b3059e4
changeset: 81268:d81d4b3059e4
parent: 81265:49eb2488145d
parent: 81267:5f96e4619ceb
user: Victor Stinner <victor.stinner at gmail.com>
date: Thu Jan 03 03:38:38 2013 +0100
summary:
 (Merge 3.3) Issue #16367: Fix FileIO.readall() on Windows for files larger than 2 GB.
files:
 Misc/NEWS | 2 ++
 Modules/_io/fileio.c | 13 +++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@
 Core and Builtins
 -----------------
 
+- Issue #16367: Fix FileIO.readall() on Windows for files larger than 2 GB.
+
 - Issue #16761: Calling int() with base argument only now raises TypeError.
 
 - Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -602,7 +602,7 @@
 #endif
 PyObject *result;
 Py_ssize_t total = 0;
- int n;
+ Py_ssize_t n;
 size_t newsize;
 
 if (self->fd < 0)
@@ -651,9 +651,18 @@
 }
 Py_BEGIN_ALLOW_THREADS
 errno = 0;
+ n = newsize - total;
+#if defined(MS_WIN64) || defined(MS_WINDOWS)
+ if (n > INT_MAX)
+ n = INT_MAX;
 n = read(self->fd,
 PyBytes_AS_STRING(result) + total,
- newsize - total);
+ (int)n);
+#else
+ n = read(self->fd,
+ PyBytes_AS_STRING(result) + total,
+ n);
+#endif
 Py_END_ALLOW_THREADS
 if (n == 0)
 break;
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /