Commit b729a1d0 authored by Guido van Rossum's avatar Guido van Rossum

Patch by Andrew Kuchling to unflush() (flush() for deflating).

Without this, if inflate() returned Z_BUF_ERROR asking for more output
space, we would report the error; now, we increase the buffer size and
try again, just as for Z_OK.
parent 052364b2
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
#endif #endif
#define DEF_WBITS MAX_WBITS #define DEF_WBITS MAX_WBITS
/* The output buffer will be increased in chunks of ADDCHUNK bytes. */ /* The output buffer will be increased in chunks of DEFAULTALLOC bytes. */
#define DEFAULTALLOC 16*1024 #define DEFAULTALLOC (16*1024)
#define PyInit_zlib initzlib #define PyInit_zlib initzlib
staticforward PyTypeObject Comptype; staticforward PyTypeObject Comptype;
...@@ -643,11 +643,14 @@ PyZlib_unflush(self, args) ...@@ -643,11 +643,14 @@ PyZlib_unflush(self, args)
self->zst.next_out = (unsigned char *)PyString_AsString(RetVal); self->zst.next_out = (unsigned char *)PyString_AsString(RetVal);
length = self->zst.avail_out = DEFAULTALLOC; length = self->zst.avail_out = DEFAULTALLOC;
/* I suspect that Z_BUF_ERROR is the only error code we need to check for
in the following loop, but will leave the Z_OK in for now to avoid
destabilizing this function. --amk */
err = Z_OK; err = Z_OK;
while (err == Z_OK) while ( err == Z_OK )
{ {
err = inflate(&(self->zst), Z_FINISH); err = inflate(&(self->zst), Z_FINISH);
if (err == Z_OK && self->zst.avail_out == 0) if ( ( err == Z_OK || err == Z_BUF_ERROR ) && self->zst.avail_out == 0)
{ {
if (_PyString_Resize(&RetVal, length << 1) == -1) if (_PyString_Resize(&RetVal, length << 1) == -1)
{ {
...@@ -658,6 +661,7 @@ PyZlib_unflush(self, args) ...@@ -658,6 +661,7 @@ PyZlib_unflush(self, args)
self->zst.next_out = (unsigned char *)PyString_AsString(RetVal) + length; self->zst.next_out = (unsigned char *)PyString_AsString(RetVal) + length;
self->zst.avail_out = length; self->zst.avail_out = length;
length = length << 1; length = length << 1;
err = Z_OK;
} }
} }
if (err!=Z_STREAM_END) if (err!=Z_STREAM_END)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment