1 /* zlibmodule.c -- gzip-compatible data compression */
2 /* See http://www.gzip.org/zlib/ */
4 /* Windows users: read Python's PCbuild\readme.txt */
13 /* #defs ripped off from _tkinter.c, even though the situation here is much
14 simpler, because we don't have to worry about waiting for Tcl
15 events! And, since zlib itself is threadsafe, we don't need to worry
16 about re-entering zlib functions.
20 Since ENTER_ZLIB and LEAVE_ZLIB only need to be called on functions
21 that modify the components of preexisting de/compress objects, it
22 could prove to be a performance gain on multiprocessor machines if
23 there was an de/compress object-specific lock. However, for the
24 moment the ENTER_ZLIB and LEAVE_ZLIB calls are global for ALL
28 static PyThread_type_lock zlib_lock
= NULL
; /* initialized on module load */
31 Py_BEGIN_ALLOW_THREADS \
32 PyThread_acquire_lock(zlib_lock, 1); \
36 PyThread_release_lock(zlib_lock);
45 /* The following parameters are copied from zutil.h, version 0.95 */
47 #if MAX_MEM_LEVEL >= 8
48 # define DEF_MEM_LEVEL 8
50 # define DEF_MEM_LEVEL MAX_MEM_LEVEL
52 #define DEF_WBITS MAX_WBITS
54 /* The output buffer will be increased in chunks of DEFAULTALLOC bytes. */
55 #define DEFAULTALLOC (16*1024)
56 #define PyInit_zlib initzlib
58 staticforward PyTypeObject Comptype
;
59 staticforward PyTypeObject Decomptype
;
61 static PyObject
*ZlibError
;
67 PyObject
*unused_data
;
68 PyObject
*unconsumed_tail
;
73 zlib_error(z_stream zst
, int err
, char *msg
)
75 if (zst
.msg
== Z_NULL
)
76 PyErr_Format(ZlibError
, "Error %d %s", err
, msg
);
78 PyErr_Format(ZlibError
, "Error %d %s: %.200s", err
, msg
, zst
.msg
);
81 static char compressobj__doc__
[] =
82 "compressobj([level]) -- Return a compressor object.\n"
84 "Optional arg level is the compression level, in 1-9.";
86 static char decompressobj__doc__
[] =
87 "decompressobj([wbits]) -- Return a decompressor object.\n"
89 "Optional arg wbits is the window buffer size.";
92 newcompobject(PyTypeObject
*type
)
95 self
= PyObject_New(compobject
, type
);
98 self
->is_initialised
= 0;
99 self
->unused_data
= PyString_FromString("");
100 if (self
->unused_data
== NULL
) {
104 self
->unconsumed_tail
= PyString_FromString("");
105 if (self
->unconsumed_tail
== NULL
) {
112 static char compress__doc__
[] =
113 "compress(string[, level]) -- Returned compressed string.\n"
115 "Optional arg level is the compression level, in 1-9.";
118 PyZlib_compress(PyObject
*self
, PyObject
*args
)
120 PyObject
*ReturnVal
= NULL
;
121 Byte
*input
, *output
;
122 int length
, level
=Z_DEFAULT_COMPRESSION
, err
;
125 /* require Python string object, optional 'level' arg */
126 if (!PyArg_ParseTuple(args
, "s#|i:compress", &input
, &length
, &level
))
129 zst
.avail_out
= length
+ length
/1000 + 12 + 1;
131 output
= (Byte
*)malloc(zst
.avail_out
);
132 if (output
== NULL
) {
133 PyErr_SetString(PyExc_MemoryError
,
134 "Can't allocate memory to compress data");
138 /* Past the point of no return. From here on out, we need to make sure
139 we clean up mallocs & INCREFs. */
141 zst
.zalloc
= (alloc_func
)NULL
;
142 zst
.zfree
= (free_func
)Z_NULL
;
143 zst
.next_out
= (Byte
*)output
;
144 zst
.next_in
= (Byte
*)input
;
145 zst
.avail_in
= length
;
146 err
= deflateInit(&zst
, level
);
152 PyErr_SetString(PyExc_MemoryError
,
153 "Out of memory while compressing data");
155 case(Z_STREAM_ERROR
):
156 PyErr_SetString(ZlibError
,
157 "Bad compression level");
161 zlib_error(zst
, err
, "while compressing data");
165 Py_BEGIN_ALLOW_THREADS
;
166 err
= deflate(&zst
, Z_FINISH
);
167 Py_END_ALLOW_THREADS
;
169 if (err
!= Z_STREAM_END
) {
170 zlib_error(zst
, err
, "while compressing data");
175 err
=deflateEnd(&zst
);
177 ReturnVal
= PyString_FromStringAndSize((char *)output
,
180 zlib_error(zst
, err
, "while finishing compression");
188 static char decompress__doc__
[] =
189 "decompress(string[, wbits[, bufsize]]) -- Return decompressed string.\n"
191 "Optional arg wbits is the window buffer size. Optional arg bufsize is\n"
192 "the initial output buffer size.";
195 PyZlib_decompress(PyObject
*self
, PyObject
*args
)
197 PyObject
*result_str
;
200 int wsize
=DEF_WBITS
, r_strlen
=DEFAULTALLOC
;
203 if (!PyArg_ParseTuple(args
, "s#|ii:decompress",
204 &input
, &length
, &wsize
, &r_strlen
))
210 zst
.avail_in
= length
;
211 zst
.avail_out
= r_strlen
;
213 if (!(result_str
= PyString_FromStringAndSize(NULL
, r_strlen
)))
216 zst
.zalloc
= (alloc_func
)NULL
;
217 zst
.zfree
= (free_func
)Z_NULL
;
218 zst
.next_out
= (Byte
*)PyString_AS_STRING(result_str
);
219 zst
.next_in
= (Byte
*)input
;
220 err
= inflateInit2(&zst
, wsize
);
226 PyErr_SetString(PyExc_MemoryError
,
227 "Out of memory while decompressing data");
231 zlib_error(zst
, err
, "while preparing to decompress data");
236 Py_BEGIN_ALLOW_THREADS
237 err
=inflate(&zst
, Z_FINISH
);
245 * If there is at least 1 byte of room according to zst.avail_out
246 * and we get this error, assume that it means zlib cannot
247 * process the inflate call() due to an error in the data.
249 if (zst
.avail_out
> 0) {
250 PyErr_Format(ZlibError
, "Error %i while decompressing data",
257 /* need more memory */
258 if (_PyString_Resize(&result_str
, r_strlen
<< 1) == -1) {
263 zst
.next_out
= (unsigned char *)PyString_AS_STRING(result_str
) \
265 zst
.avail_out
= r_strlen
;
266 r_strlen
= r_strlen
<< 1;
270 zlib_error(zst
, err
, "while decompressing data");
273 } while (err
!= Z_STREAM_END
);
275 err
= inflateEnd(&zst
);
277 zlib_error(zst
, err
, "while finishing data decompression");
281 _PyString_Resize(&result_str
, zst
.total_out
);
285 Py_XDECREF(result_str
);
290 PyZlib_compressobj(PyObject
*selfptr
, PyObject
*args
)
293 int level
=Z_DEFAULT_COMPRESSION
, method
=DEFLATED
;
294 int wbits
=MAX_WBITS
, memLevel
=DEF_MEM_LEVEL
, strategy
=0, err
;
296 if (!PyArg_ParseTuple(args
, "|iiiii:compressobj", &level
, &method
, &wbits
,
297 &memLevel
, &strategy
))
300 self
= newcompobject(&Comptype
);
303 self
->zst
.zalloc
= (alloc_func
)NULL
;
304 self
->zst
.zfree
= (free_func
)Z_NULL
;
305 err
= deflateInit2(&self
->zst
, level
, method
, wbits
, memLevel
, strategy
);
308 self
->is_initialised
= 1;
309 return (PyObject
*)self
;
312 PyErr_SetString(PyExc_MemoryError
,
313 "Can't allocate memory for compression object");
315 case(Z_STREAM_ERROR
):
317 PyErr_SetString(PyExc_ValueError
, "Invalid initialization option");
320 zlib_error(self
->zst
, err
, "while creating compression object");
327 PyZlib_decompressobj(PyObject
*selfptr
, PyObject
*args
)
329 int wbits
=DEF_WBITS
, err
;
331 if (!PyArg_ParseTuple(args
, "|i:decompressobj", &wbits
))
334 self
= newcompobject(&Decomptype
);
337 self
->zst
.zalloc
= (alloc_func
)NULL
;
338 self
->zst
.zfree
= (free_func
)Z_NULL
;
339 err
= inflateInit2(&self
->zst
, wbits
);
342 self
->is_initialised
= 1;
343 return (PyObject
*)self
;
344 case(Z_STREAM_ERROR
):
346 PyErr_SetString(PyExc_ValueError
, "Invalid initialization option");
350 PyErr_SetString(PyExc_MemoryError
,
351 "Can't allocate memory for decompression object");
354 zlib_error(self
->zst
, err
, "while creating decompression object");
361 Comp_dealloc(compobject
*self
)
363 if (self
->is_initialised
)
364 deflateEnd(&self
->zst
);
365 Py_XDECREF(self
->unused_data
);
366 Py_XDECREF(self
->unconsumed_tail
);
371 Decomp_dealloc(compobject
*self
)
373 if (self
->is_initialised
)
374 inflateEnd(&self
->zst
);
375 Py_XDECREF(self
->unused_data
);
376 Py_XDECREF(self
->unconsumed_tail
);
380 static char comp_compress__doc__
[] =
381 "compress(data) -- Return a string containing data compressed.\n"
383 "After calling this function, some of the input data may still\n"
384 "be stored in internal buffers for later processing.\n"
385 "Call the flush() method to clear these buffers.";
389 PyZlib_objcompress(compobject
*self
, PyObject
*args
)
391 int err
, inplen
, length
= DEFAULTALLOC
;
394 unsigned long start_total_out
;
396 if (!PyArg_ParseTuple(args
, "s#:compress", &input
, &inplen
))
399 if (!(RetVal
= PyString_FromStringAndSize(NULL
, length
)))
404 start_total_out
= self
->zst
.total_out
;
405 self
->zst
.avail_in
= inplen
;
406 self
->zst
.next_in
= input
;
407 self
->zst
.avail_out
= length
;
408 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
);
410 Py_BEGIN_ALLOW_THREADS
411 err
= deflate(&(self
->zst
), Z_NO_FLUSH
);
414 /* while Z_OK and the output buffer is full, there might be more output,
415 so extend the output buffer and try again */
416 while (err
== Z_OK
&& self
->zst
.avail_out
== 0) {
417 if (_PyString_Resize(&RetVal
, length
<< 1) == -1) {
421 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
) \
423 self
->zst
.avail_out
= length
;
424 length
= length
<< 1;
426 Py_BEGIN_ALLOW_THREADS
427 err
= deflate(&(self
->zst
), Z_NO_FLUSH
);
430 /* We will only get Z_BUF_ERROR if the output buffer was full but
431 there wasn't more output when we tried again, so it is not an error
435 if (err
!= Z_OK
&& err
!= Z_BUF_ERROR
) {
436 zlib_error(self
->zst
, err
, "while compressing");
441 if (_PyString_Resize(&RetVal
,
442 self
->zst
.total_out
- start_total_out
) < 0)
450 static char decomp_decompress__doc__
[] =
451 "decompress(data, max_length) -- Return a string containing the decompressed\n"
452 "version of the data.\n"
454 "After calling this function, some of the input data may still be stored in\n"
455 "internal buffers for later processing.\n"
456 "Call the flush() method to clear these buffers.\n"
457 "If the max_length parameter is specified then the return value will be\n"
458 "no longer than max_length. Unconsumed input data will be stored in\n"
459 "the unconsumed_tail attribute.";
462 PyZlib_objdecompress(compobject
*self
, PyObject
*args
)
464 int err
, inplen
, old_length
, length
= DEFAULTALLOC
;
468 unsigned long start_total_out
;
470 if (!PyArg_ParseTuple(args
, "s#|i:decompress", &input
,
471 &inplen
, &max_length
))
473 if (max_length
< 0) {
474 PyErr_SetString(PyExc_ValueError
,
475 "max_length must be greater than zero");
479 /* limit amount of data allocated to max_length */
480 if (max_length
&& length
> max_length
)
482 if (!(RetVal
= PyString_FromStringAndSize(NULL
, length
)))
487 start_total_out
= self
->zst
.total_out
;
488 self
->zst
.avail_in
= inplen
;
489 self
->zst
.next_in
= input
;
490 self
->zst
.avail_out
= length
;
491 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
);
493 Py_BEGIN_ALLOW_THREADS
494 err
= inflate(&(self
->zst
), Z_SYNC_FLUSH
);
497 /* While Z_OK and the output buffer is full, there might be more output.
498 So extend the output buffer and try again.
500 while (err
== Z_OK
&& self
->zst
.avail_out
== 0) {
501 /* If max_length set, don't continue decompressing if we've already
504 if (max_length
&& length
>= max_length
)
509 length
= length
<< 1;
510 if (max_length
&& length
> max_length
)
513 if (_PyString_Resize(&RetVal
, length
) == -1) {
517 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
) \
519 self
->zst
.avail_out
= length
- old_length
;
521 Py_BEGIN_ALLOW_THREADS
522 err
= inflate(&(self
->zst
), Z_SYNC_FLUSH
);
526 /* Not all of the compressed data could be accomodated in the output buffer
527 of specified size. Return the unconsumed tail in an attribute.*/
529 Py_DECREF(self
->unconsumed_tail
);
530 self
->unconsumed_tail
= PyString_FromStringAndSize((char *)self
->zst
.next_in
,
532 if(!self
->unconsumed_tail
) {
539 /* The end of the compressed data has been reached, so set the
540 unused_data attribute to a string containing the remainder of the
541 data in the string. Note that this is also a logical place to call
542 inflateEnd, but the old behaviour of only calling it on flush() is
545 if (err
== Z_STREAM_END
) {
546 Py_XDECREF(self
->unused_data
); /* Free original empty string */
547 self
->unused_data
= PyString_FromStringAndSize(
548 (char *)self
->zst
.next_in
, self
->zst
.avail_in
);
549 if (self
->unused_data
== NULL
) {
553 /* We will only get Z_BUF_ERROR if the output buffer was full
554 but there wasn't more output when we tried again, so it is
555 not an error condition.
557 } else if (err
!= Z_OK
&& err
!= Z_BUF_ERROR
) {
558 zlib_error(self
->zst
, err
, "while decompressing");
564 if (_PyString_Resize(&RetVal
, self
->zst
.total_out
- start_total_out
) < 0)
573 static char comp_flush__doc__
[] =
574 "flush( [mode] ) -- Return a string containing any remaining compressed data.\n"
576 "mode can be one of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH; the\n"
577 "default value used when mode is not specified is Z_FINISH.\n"
578 "If mode == Z_FINISH, the compressor object can no longer be used after\n"
579 "calling the flush() method. Otherwise, more data can still be compressed.\n";
582 PyZlib_flush(compobject
*self
, PyObject
*args
)
584 int err
, length
= DEFAULTALLOC
;
586 int flushmode
= Z_FINISH
;
587 unsigned long start_total_out
;
589 if (!PyArg_ParseTuple(args
, "|i:flush", &flushmode
))
592 /* Flushing with Z_NO_FLUSH is a no-op, so there's no point in
593 doing any work at all; just return an empty string. */
594 if (flushmode
== Z_NO_FLUSH
) {
595 return PyString_FromStringAndSize(NULL
, 0);
598 if (!(RetVal
= PyString_FromStringAndSize(NULL
, length
)))
603 start_total_out
= self
->zst
.total_out
;
604 self
->zst
.avail_in
= 0;
605 self
->zst
.avail_out
= length
;
606 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
);
608 Py_BEGIN_ALLOW_THREADS
609 err
= deflate(&(self
->zst
), flushmode
);
612 /* while Z_OK and the output buffer is full, there might be more output,
613 so extend the output buffer and try again */
614 while (err
== Z_OK
&& self
->zst
.avail_out
== 0) {
615 if (_PyString_Resize(&RetVal
, length
<< 1) == -1) {
619 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
) \
621 self
->zst
.avail_out
= length
;
622 length
= length
<< 1;
624 Py_BEGIN_ALLOW_THREADS
625 err
= deflate(&(self
->zst
), flushmode
);
629 /* If flushmode is Z_FINISH, we also have to call deflateEnd() to free
630 various data structures. Note we should only get Z_STREAM_END when
631 flushmode is Z_FINISH, but checking both for safety*/
632 if (err
== Z_STREAM_END
&& flushmode
== Z_FINISH
) {
633 err
= deflateEnd(&(self
->zst
));
635 zlib_error(self
->zst
, err
, "from deflateEnd()");
641 self
->is_initialised
= 0;
643 /* We will only get Z_BUF_ERROR if the output buffer was full
644 but there wasn't more output when we tried again, so it is
645 not an error condition.
647 } else if (err
!=Z_OK
&& err
!=Z_BUF_ERROR
) {
648 zlib_error(self
->zst
, err
, "while flushing");
653 if (_PyString_Resize(&RetVal
, self
->zst
.total_out
- start_total_out
) < 0)
662 static char decomp_flush__doc__
[] =
663 "flush() -- Return a string containing any remaining decompressed data.\n"
665 "The decompressor object can no longer be used after this call.";
668 PyZlib_unflush(compobject
*self
, PyObject
*args
)
669 /*decompressor flush is a no-op because all pending data would have been
670 flushed by the decompress method. However, this routine previously called
671 inflateEnd, causing any further decompress or flush calls to raise
672 exceptions. This behaviour has been preserved.*/
675 PyObject
* retval
= NULL
;
677 if (!PyArg_ParseTuple(args
, ""))
682 err
= inflateEnd(&(self
->zst
));
684 zlib_error(self
->zst
, err
, "from inflateEnd()");
686 self
->is_initialised
= 0;
687 retval
= PyString_FromStringAndSize(NULL
, 0);
695 static PyMethodDef comp_methods
[] =
697 {"compress", (binaryfunc
)PyZlib_objcompress
, METH_VARARGS
,
698 comp_compress__doc__
},
699 {"flush", (binaryfunc
)PyZlib_flush
, METH_VARARGS
,
704 static PyMethodDef Decomp_methods
[] =
706 {"decompress", (binaryfunc
)PyZlib_objdecompress
, METH_VARARGS
,
707 decomp_decompress__doc__
},
708 {"flush", (binaryfunc
)PyZlib_unflush
, METH_VARARGS
,
709 decomp_flush__doc__
},
714 Comp_getattr(compobject
*self
, char *name
)
716 /* No ENTER/LEAVE_ZLIB is necessary because this fn doesn't touch
719 return Py_FindMethod(comp_methods
, (PyObject
*)self
, name
);
723 Decomp_getattr(compobject
*self
, char *name
)
729 if (strcmp(name
, "unused_data") == 0) {
730 Py_INCREF(self
->unused_data
);
731 retval
= self
->unused_data
;
732 } else if (strcmp(name
, "unconsumed_tail") == 0) {
733 Py_INCREF(self
->unconsumed_tail
);
734 retval
= self
->unconsumed_tail
;
736 retval
= Py_FindMethod(Decomp_methods
, (PyObject
*)self
, name
);
743 static char adler32__doc__
[] =
744 "adler32(string[, start]) -- Compute an Adler-32 checksum of string.\n"
746 "An optional starting value can be specified. The returned checksum is\n"
750 PyZlib_adler32(PyObject
*self
, PyObject
*args
)
752 uLong adler32val
= adler32(0L, Z_NULL
, 0);
756 if (!PyArg_ParseTuple(args
, "s#|l:adler32", &buf
, &len
, &adler32val
))
758 adler32val
= adler32(adler32val
, buf
, len
);
759 return PyInt_FromLong(adler32val
);
762 static char crc32__doc__
[] =
763 "crc32(string[, start]) -- Compute a CRC-32 checksum of string.\n"
765 "An optional starting value can be specified. The returned checksum is\n"
769 PyZlib_crc32(PyObject
*self
, PyObject
*args
)
771 uLong crc32val
= crc32(0L, Z_NULL
, 0);
774 if (!PyArg_ParseTuple(args
, "s#|l:crc32", &buf
, &len
, &crc32val
))
776 crc32val
= crc32(crc32val
, buf
, len
);
777 return PyInt_FromLong(crc32val
);
781 static PyMethodDef zlib_methods
[] =
783 {"adler32", (PyCFunction
)PyZlib_adler32
, METH_VARARGS
,
785 {"compress", (PyCFunction
)PyZlib_compress
, METH_VARARGS
,
787 {"compressobj", (PyCFunction
)PyZlib_compressobj
, METH_VARARGS
,
789 {"crc32", (PyCFunction
)PyZlib_crc32
, METH_VARARGS
,
791 {"decompress", (PyCFunction
)PyZlib_decompress
, METH_VARARGS
,
793 {"decompressobj", (PyCFunction
)PyZlib_decompressobj
, METH_VARARGS
,
794 decompressobj__doc__
},
798 statichere PyTypeObject Comptype
= {
799 PyObject_HEAD_INIT(0)
804 (destructor
)Comp_dealloc
, /*tp_dealloc*/
806 (getattrfunc
)Comp_getattr
, /*tp_getattr*/
811 0, /*tp_as_sequence*/
815 statichere PyTypeObject Decomptype
= {
816 PyObject_HEAD_INIT(0)
821 (destructor
)Decomp_dealloc
, /*tp_dealloc*/
823 (getattrfunc
)Decomp_getattr
, /*tp_getattr*/
828 0, /*tp_as_sequence*/
832 static char zlib_module_documentation
[]=
833 "The functions in this module allow compression and decompression using the\n"
834 "zlib library, which is based on GNU zip.\n"
836 "adler32(string[, start]) -- Compute an Adler-32 checksum.\n"
837 "compress(string[, level]) -- Compress string, with compression level in 1-9.\n"
838 "compressobj([level]) -- Return a compressor object.\n"
839 "crc32(string[, start]) -- Compute a CRC-32 checksum.\n"
840 "decompress(string,[wbits],[bufsize]) -- Decompresses a compressed string.\n"
841 "decompressobj([wbits]) -- Return a decompressor object.\n"
843 "'wbits' is window buffer size.\n"
844 "Compressor objects support compress() and flush() methods; decompressor\n"
845 "objects support decompress() and flush().";
850 PyObject
*m
, *d
, *ver
;
851 Comptype
.ob_type
= &PyType_Type
;
852 Decomptype
.ob_type
= &PyType_Type
;
853 m
= Py_InitModule4("zlib", zlib_methods
,
854 zlib_module_documentation
,
855 (PyObject
*)NULL
,PYTHON_API_VERSION
);
856 d
= PyModule_GetDict(m
);
857 ZlibError
= PyErr_NewException("zlib.error", NULL
, NULL
);
858 if (ZlibError
!= NULL
)
859 PyDict_SetItemString(d
, "error", ZlibError
);
861 PyModule_AddIntConstant(m
, "MAX_WBITS", MAX_WBITS
);
862 PyModule_AddIntConstant(m
, "DEFLATED", DEFLATED
);
863 PyModule_AddIntConstant(m
, "DEF_MEM_LEVEL", DEF_MEM_LEVEL
);
864 PyModule_AddIntConstant(m
, "Z_BEST_SPEED", Z_BEST_SPEED
);
865 PyModule_AddIntConstant(m
, "Z_BEST_COMPRESSION", Z_BEST_COMPRESSION
);
866 PyModule_AddIntConstant(m
, "Z_DEFAULT_COMPRESSION", Z_DEFAULT_COMPRESSION
);
867 PyModule_AddIntConstant(m
, "Z_FILTERED", Z_FILTERED
);
868 PyModule_AddIntConstant(m
, "Z_HUFFMAN_ONLY", Z_HUFFMAN_ONLY
);
869 PyModule_AddIntConstant(m
, "Z_DEFAULT_STRATEGY", Z_DEFAULT_STRATEGY
);
871 PyModule_AddIntConstant(m
, "Z_FINISH", Z_FINISH
);
872 PyModule_AddIntConstant(m
, "Z_NO_FLUSH", Z_NO_FLUSH
);
873 PyModule_AddIntConstant(m
, "Z_SYNC_FLUSH", Z_SYNC_FLUSH
);
874 PyModule_AddIntConstant(m
, "Z_FULL_FLUSH", Z_FULL_FLUSH
);
876 ver
= PyString_FromString(ZLIB_VERSION
);
878 PyDict_SetItemString(d
, "ZLIB_VERSION", ver
);
883 zlib_lock
= PyThread_allocate_lock();
884 #endif // WITH_THREAD