diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-08-01 20:13:11 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-08-01 20:13:11 (GMT) |
commit | 3970301e93ec3ab2e9a7a4c992d7056bea3ff9f6 (patch) | |
tree | 77a611a93c4da6dcc7b98308f339c6611ddb28b2 /Modules | |
parent | 30bfe764d739b916e9eb1807d07e3ee94e26fcbb (diff) | |
download | cpython-3970301e93ec3ab2e9a7a4c992d7056bea3ff9f6.zip cpython-3970301e93ec3ab2e9a7a4c992d7056bea3ff9f6.tar.gz cpython-3970301e93ec3ab2e9a7a4c992d7056bea3ff9f6.tar.bz2 |
Merged revisions 83440 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r83440 | antoine.pitrou | 2010-08-01 22:08:46 +0200 (dim., 01 août 2010) | 4 lines
Issue #8397: Raise an error when attempting to mix iteration and regular
reads on a BZ2File object, rather than returning incorrect results.
........
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/bz2module.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Modules/bz2module.c b/Modules/bz2module.c index 8e09766..0a367a7 100644 --- a/Modules/bz2module.c +++ b/Modules/bz2module.c @@ -144,6 +144,22 @@ typedef struct { /* ===================================================================== */ /* Utility functions. */ +/* Refuse regular I/O if there's data in the iteration-buffer. + * Mixing them would cause data to arrive out of order, as the read* + * methods don't use the iteration buffer. */ +static int +check_iterbuffered(BZ2FileObject *f) +{ + if (f->f_buf != NULL && + (f->f_bufend - f->f_bufptr) > 0 && + f->f_buf[0] != '\0') { + PyErr_SetString(PyExc_ValueError, + "Mixing iteration and read methods would lose data"); + return -1; + } + return 0; +} + static int Util_CatchBZ2Error(int bzerror) { @@ -527,6 +543,10 @@ BZ2File_read(BZ2FileObject *self, PyObject *args) goto cleanup; } + /* refuse to mix with f.next() */ + if (check_iterbuffered(self)) + goto cleanup; + if (bytesrequested < 0) buffersize = Util_NewBufferSize((size_t)0); else @@ -612,6 +632,10 @@ BZ2File_readline(BZ2FileObject *self, PyObject *args) goto cleanup; } + /* refuse to mix with f.next() */ + if (check_iterbuffered(self)) + goto cleanup; + if (sizehint == 0) ret = PyString_FromString(""); else @@ -669,6 +693,10 @@ BZ2File_readlines(BZ2FileObject *self, PyObject *args) goto cleanup; } + /* refuse to mix with f.next() */ + if (check_iterbuffered(self)) + goto cleanup; + if ((list = PyList_New(0)) == NULL) goto cleanup; |