diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-01-03 03:38:38 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-01-03 03:38:38 +0100 |
commit | 79d172aa6fd74928f50bce6afab86026c8a9896e (patch) | |
tree | 37bc089d1e0855ebe304b7f77d3af833a45381cd /Modules/_io | |
parent | 4460d8cf8f09cc7ac186388086c08eefa7900cce (diff) | |
parent | ddb0902d81cd45f66e8e8976cb426d33b3650f8d (diff) | |
download | cpython-79d172aa6fd74928f50bce6afab86026c8a9896e.tar.gz |
(Merge 3.3) Issue #16367: Fix FileIO.readall() on Windows for files larger than 2 GB.
Diffstat (limited to 'Modules/_io')
-rw-r--r-- | Modules/_io/bufferedio.c | 5 | ||||
-rw-r--r-- | Modules/_io/fileio.c | 7 | ||||
-rw-r--r-- | Modules/_io/textio.c | 18 |
3 files changed, 12 insertions, 18 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index b077f34fff..ea32a5e173 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -519,6 +519,11 @@ buffered_close(buffered *self, PyObject *args) res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_close, NULL); + if (self->buffer) { + PyMem_Free(self->buffer); + self->buffer = NULL; + } + if (exc != NULL) { if (res != NULL) { Py_CLEAR(res); diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index ca25209305..34425b7ae0 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -391,12 +391,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds) fd_is_own = 1; if (self->fd < 0) { -#ifdef MS_WINDOWS - if (widename != NULL) - PyErr_SetFromErrnoWithFilenameObject(PyExc_IOError, nameobj); - else -#endif - PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); + PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, nameobj); goto error; } } diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 83437d6add..4fc0caa84e 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -747,7 +747,7 @@ utf16_encode(textio *self, PyObject *text) { if (!self->encoding_start_of_stream) { /* Skip the BOM and use native byte ordering */ -#if defined(WORDS_BIGENDIAN) +#if PY_BIG_ENDIAN return utf16be_encode(self, text); #else return utf16le_encode(self, text); @@ -776,7 +776,7 @@ utf32_encode(textio *self, PyObject *text) { if (!self->encoding_start_of_stream) { /* Skip the BOM and use native byte ordering */ -#if defined(WORDS_BIGENDIAN) +#if PY_BIG_ENDIAN return utf32be_encode(self, text); #else return utf32le_encode(self, text); @@ -1913,10 +1913,7 @@ typedef struct { #define COOKIE_BUF_LEN (sizeof(Py_off_t) + 3 * sizeof(int) + sizeof(char)) -#if defined(WORDS_BIGENDIAN) - -# define IS_LITTLE_ENDIAN 0 - +#if PY_BIG_ENDIAN /* We want the least significant byte of start_pos to also be the least significant byte of the cookie, which means that in big-endian mode we must copy the fields in reverse order. */ @@ -1928,9 +1925,6 @@ typedef struct { # define OFF_NEED_EOF 0 #else - -# define IS_LITTLE_ENDIAN 1 - /* Little-endian mode: the least significant byte of start_pos will naturally end up the least significant byte of the cookie. */ @@ -1951,7 +1945,7 @@ textiowrapper_parse_cookie(cookie_type *cookie, PyObject *cookieObj) return -1; if (_PyLong_AsByteArray(cookieLong, buffer, sizeof(buffer), - IS_LITTLE_ENDIAN, 0) < 0) { + PY_LITTLE_ENDIAN, 0) < 0) { Py_DECREF(cookieLong); return -1; } @@ -1977,9 +1971,9 @@ textiowrapper_build_cookie(cookie_type *cookie) memcpy(buffer + OFF_CHARS_TO_SKIP, &cookie->chars_to_skip, sizeof(cookie->chars_to_skip)); memcpy(buffer + OFF_NEED_EOF, &cookie->need_eof, sizeof(cookie->need_eof)); - return _PyLong_FromByteArray(buffer, sizeof(buffer), IS_LITTLE_ENDIAN, 0); + return _PyLong_FromByteArray(buffer, sizeof(buffer), + PY_LITTLE_ENDIAN, 0); } -#undef IS_LITTLE_ENDIAN static int _textiowrapper_decoder_setstate(textio *self, cookie_type *cookie) |