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 static PyTypeObject Comptype
;
59 static 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 PyDoc_STRVAR(compressobj__doc__
,
82 "compressobj([level]) -- Return a compressor object.\n"
84 "Optional arg level is the compression level, in 1-9.");
86 PyDoc_STRVAR(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 PyDoc_STRVAR(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 PyDoc_STRVAR(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) < 0) {
262 zst
.next_out
= (unsigned char *)PyString_AS_STRING(result_str
) \
264 zst
.avail_out
= r_strlen
;
265 r_strlen
= r_strlen
<< 1;
269 zlib_error(zst
, err
, "while decompressing data");
272 } while (err
!= Z_STREAM_END
);
274 err
= inflateEnd(&zst
);
276 zlib_error(zst
, err
, "while finishing data decompression");
280 _PyString_Resize(&result_str
, zst
.total_out
);
284 Py_XDECREF(result_str
);
289 PyZlib_compressobj(PyObject
*selfptr
, PyObject
*args
)
292 int level
=Z_DEFAULT_COMPRESSION
, method
=DEFLATED
;
293 int wbits
=MAX_WBITS
, memLevel
=DEF_MEM_LEVEL
, strategy
=0, err
;
295 if (!PyArg_ParseTuple(args
, "|iiiii:compressobj", &level
, &method
, &wbits
,
296 &memLevel
, &strategy
))
299 self
= newcompobject(&Comptype
);
302 self
->zst
.zalloc
= (alloc_func
)NULL
;
303 self
->zst
.zfree
= (free_func
)Z_NULL
;
304 err
= deflateInit2(&self
->zst
, level
, method
, wbits
, memLevel
, strategy
);
307 self
->is_initialised
= 1;
308 return (PyObject
*)self
;
311 PyErr_SetString(PyExc_MemoryError
,
312 "Can't allocate memory for compression object");
314 case(Z_STREAM_ERROR
):
316 PyErr_SetString(PyExc_ValueError
, "Invalid initialization option");
319 zlib_error(self
->zst
, err
, "while creating compression object");
326 PyZlib_decompressobj(PyObject
*selfptr
, PyObject
*args
)
328 int wbits
=DEF_WBITS
, err
;
330 if (!PyArg_ParseTuple(args
, "|i:decompressobj", &wbits
))
333 self
= newcompobject(&Decomptype
);
336 self
->zst
.zalloc
= (alloc_func
)NULL
;
337 self
->zst
.zfree
= (free_func
)Z_NULL
;
338 err
= inflateInit2(&self
->zst
, wbits
);
341 self
->is_initialised
= 1;
342 return (PyObject
*)self
;
343 case(Z_STREAM_ERROR
):
345 PyErr_SetString(PyExc_ValueError
, "Invalid initialization option");
349 PyErr_SetString(PyExc_MemoryError
,
350 "Can't allocate memory for decompression object");
353 zlib_error(self
->zst
, err
, "while creating decompression object");
360 Comp_dealloc(compobject
*self
)
362 if (self
->is_initialised
)
363 deflateEnd(&self
->zst
);
364 Py_XDECREF(self
->unused_data
);
365 Py_XDECREF(self
->unconsumed_tail
);
370 Decomp_dealloc(compobject
*self
)
372 if (self
->is_initialised
)
373 inflateEnd(&self
->zst
);
374 Py_XDECREF(self
->unused_data
);
375 Py_XDECREF(self
->unconsumed_tail
);
379 PyDoc_STRVAR(comp_compress__doc__
,
380 "compress(data) -- Return a string containing data compressed.\n"
382 "After calling this function, some of the input data may still\n"
383 "be stored in internal buffers for later processing.\n"
384 "Call the flush() method to clear these buffers.");
388 PyZlib_objcompress(compobject
*self
, PyObject
*args
)
390 int err
, inplen
, length
= DEFAULTALLOC
;
393 unsigned long start_total_out
;
395 if (!PyArg_ParseTuple(args
, "s#:compress", &input
, &inplen
))
398 if (!(RetVal
= PyString_FromStringAndSize(NULL
, length
)))
403 start_total_out
= self
->zst
.total_out
;
404 self
->zst
.avail_in
= inplen
;
405 self
->zst
.next_in
= input
;
406 self
->zst
.avail_out
= length
;
407 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
);
409 Py_BEGIN_ALLOW_THREADS
410 err
= deflate(&(self
->zst
), Z_NO_FLUSH
);
413 /* while Z_OK and the output buffer is full, there might be more output,
414 so extend the output buffer and try again */
415 while (err
== Z_OK
&& self
->zst
.avail_out
== 0) {
416 if (_PyString_Resize(&RetVal
, length
<< 1) < 0)
418 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
) \
420 self
->zst
.avail_out
= length
;
421 length
= length
<< 1;
423 Py_BEGIN_ALLOW_THREADS
424 err
= deflate(&(self
->zst
), Z_NO_FLUSH
);
427 /* We will only get Z_BUF_ERROR if the output buffer was full but
428 there wasn't more output when we tried again, so it is not an error
432 if (err
!= Z_OK
&& err
!= Z_BUF_ERROR
) {
433 zlib_error(self
->zst
, err
, "while compressing");
438 _PyString_Resize(&RetVal
, self
->zst
.total_out
- start_total_out
);
445 PyDoc_STRVAR(decomp_decompress__doc__
,
446 "decompress(data, max_length) -- Return a string containing the decompressed\n"
447 "version of the data.\n"
449 "After calling this function, some of the input data may still be stored in\n"
450 "internal buffers for later processing.\n"
451 "Call the flush() method to clear these buffers.\n"
452 "If the max_length parameter is specified then the return value will be\n"
453 "no longer than max_length. Unconsumed input data will be stored in\n"
454 "the unconsumed_tail attribute.");
457 PyZlib_objdecompress(compobject
*self
, PyObject
*args
)
459 int err
, inplen
, old_length
, length
= DEFAULTALLOC
;
463 unsigned long start_total_out
;
465 if (!PyArg_ParseTuple(args
, "s#|i:decompress", &input
,
466 &inplen
, &max_length
))
468 if (max_length
< 0) {
469 PyErr_SetString(PyExc_ValueError
,
470 "max_length must be greater than zero");
474 /* limit amount of data allocated to max_length */
475 if (max_length
&& length
> max_length
)
477 if (!(RetVal
= PyString_FromStringAndSize(NULL
, length
)))
482 start_total_out
= self
->zst
.total_out
;
483 self
->zst
.avail_in
= inplen
;
484 self
->zst
.next_in
= input
;
485 self
->zst
.avail_out
= length
;
486 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
);
488 Py_BEGIN_ALLOW_THREADS
489 err
= inflate(&(self
->zst
), Z_SYNC_FLUSH
);
492 /* While Z_OK and the output buffer is full, there might be more output.
493 So extend the output buffer and try again.
495 while (err
== Z_OK
&& self
->zst
.avail_out
== 0) {
496 /* If max_length set, don't continue decompressing if we've already
499 if (max_length
&& length
>= max_length
)
504 length
= length
<< 1;
505 if (max_length
&& length
> max_length
)
508 if (_PyString_Resize(&RetVal
, length
) < 0)
510 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
) \
512 self
->zst
.avail_out
= length
- old_length
;
514 Py_BEGIN_ALLOW_THREADS
515 err
= inflate(&(self
->zst
), Z_SYNC_FLUSH
);
519 /* Not all of the compressed data could be accomodated in the output buffer
520 of specified size. Return the unconsumed tail in an attribute.*/
522 Py_DECREF(self
->unconsumed_tail
);
523 self
->unconsumed_tail
= PyString_FromStringAndSize((char *)self
->zst
.next_in
,
525 if(!self
->unconsumed_tail
) {
532 /* The end of the compressed data has been reached, so set the
533 unused_data attribute to a string containing the remainder of the
534 data in the string. Note that this is also a logical place to call
535 inflateEnd, but the old behaviour of only calling it on flush() is
538 if (err
== Z_STREAM_END
) {
539 Py_XDECREF(self
->unused_data
); /* Free original empty string */
540 self
->unused_data
= PyString_FromStringAndSize(
541 (char *)self
->zst
.next_in
, self
->zst
.avail_in
);
542 if (self
->unused_data
== NULL
) {
546 /* We will only get Z_BUF_ERROR if the output buffer was full
547 but there wasn't more output when we tried again, so it is
548 not an error condition.
550 } else if (err
!= Z_OK
&& err
!= Z_BUF_ERROR
) {
551 zlib_error(self
->zst
, err
, "while decompressing");
557 _PyString_Resize(&RetVal
, self
->zst
.total_out
- start_total_out
);
565 PyDoc_STRVAR(comp_flush__doc__
,
566 "flush( [mode] ) -- Return a string containing any remaining compressed data.\n"
568 "mode can be one of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH; the\n"
569 "default value used when mode is not specified is Z_FINISH.\n"
570 "If mode == Z_FINISH, the compressor object can no longer be used after\n"
571 "calling the flush() method. Otherwise, more data can still be compressed.");
574 PyZlib_flush(compobject
*self
, PyObject
*args
)
576 int err
, length
= DEFAULTALLOC
;
578 int flushmode
= Z_FINISH
;
579 unsigned long start_total_out
;
581 if (!PyArg_ParseTuple(args
, "|i:flush", &flushmode
))
584 /* Flushing with Z_NO_FLUSH is a no-op, so there's no point in
585 doing any work at all; just return an empty string. */
586 if (flushmode
== Z_NO_FLUSH
) {
587 return PyString_FromStringAndSize(NULL
, 0);
590 if (!(RetVal
= PyString_FromStringAndSize(NULL
, length
)))
595 start_total_out
= self
->zst
.total_out
;
596 self
->zst
.avail_in
= 0;
597 self
->zst
.avail_out
= length
;
598 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
);
600 Py_BEGIN_ALLOW_THREADS
601 err
= deflate(&(self
->zst
), flushmode
);
604 /* while Z_OK and the output buffer is full, there might be more output,
605 so extend the output buffer and try again */
606 while (err
== Z_OK
&& self
->zst
.avail_out
== 0) {
607 if (_PyString_Resize(&RetVal
, length
<< 1) < 0)
609 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
) \
611 self
->zst
.avail_out
= length
;
612 length
= length
<< 1;
614 Py_BEGIN_ALLOW_THREADS
615 err
= deflate(&(self
->zst
), flushmode
);
619 /* If flushmode is Z_FINISH, we also have to call deflateEnd() to free
620 various data structures. Note we should only get Z_STREAM_END when
621 flushmode is Z_FINISH, but checking both for safety*/
622 if (err
== Z_STREAM_END
&& flushmode
== Z_FINISH
) {
623 err
= deflateEnd(&(self
->zst
));
625 zlib_error(self
->zst
, err
, "from deflateEnd()");
631 self
->is_initialised
= 0;
633 /* We will only get Z_BUF_ERROR if the output buffer was full
634 but there wasn't more output when we tried again, so it is
635 not an error condition.
637 } else if (err
!=Z_OK
&& err
!=Z_BUF_ERROR
) {
638 zlib_error(self
->zst
, err
, "while flushing");
644 _PyString_Resize(&RetVal
, self
->zst
.total_out
- start_total_out
);
652 PyDoc_STRVAR(decomp_flush__doc__
,
653 "flush() -- Return a string containing any remaining decompressed data.\n"
655 "The decompressor object can no longer be used after this call.");
658 PyZlib_unflush(compobject
*self
, PyObject
*args
)
659 /*decompressor flush is a no-op because all pending data would have been
660 flushed by the decompress method. However, this routine previously called
661 inflateEnd, causing any further decompress or flush calls to raise
662 exceptions. This behaviour has been preserved.*/
665 PyObject
* retval
= NULL
;
667 if (!PyArg_ParseTuple(args
, ""))
672 err
= inflateEnd(&(self
->zst
));
674 zlib_error(self
->zst
, err
, "from inflateEnd()");
676 self
->is_initialised
= 0;
677 retval
= PyString_FromStringAndSize(NULL
, 0);
685 static PyMethodDef comp_methods
[] =
687 {"compress", (binaryfunc
)PyZlib_objcompress
, METH_VARARGS
,
688 comp_compress__doc__
},
689 {"flush", (binaryfunc
)PyZlib_flush
, METH_VARARGS
,
694 static PyMethodDef Decomp_methods
[] =
696 {"decompress", (binaryfunc
)PyZlib_objdecompress
, METH_VARARGS
,
697 decomp_decompress__doc__
},
698 {"flush", (binaryfunc
)PyZlib_unflush
, METH_VARARGS
,
699 decomp_flush__doc__
},
704 Comp_getattr(compobject
*self
, char *name
)
706 /* No ENTER/LEAVE_ZLIB is necessary because this fn doesn't touch
709 return Py_FindMethod(comp_methods
, (PyObject
*)self
, name
);
713 Decomp_getattr(compobject
*self
, char *name
)
719 if (strcmp(name
, "unused_data") == 0) {
720 Py_INCREF(self
->unused_data
);
721 retval
= self
->unused_data
;
722 } else if (strcmp(name
, "unconsumed_tail") == 0) {
723 Py_INCREF(self
->unconsumed_tail
);
724 retval
= self
->unconsumed_tail
;
726 retval
= Py_FindMethod(Decomp_methods
, (PyObject
*)self
, name
);
733 PyDoc_STRVAR(adler32__doc__
,
734 "adler32(string[, start]) -- Compute an Adler-32 checksum of string.\n"
736 "An optional starting value can be specified. The returned checksum is\n"
740 PyZlib_adler32(PyObject
*self
, PyObject
*args
)
742 uLong adler32val
= adler32(0L, Z_NULL
, 0);
746 if (!PyArg_ParseTuple(args
, "s#|l:adler32", &buf
, &len
, &adler32val
))
748 adler32val
= adler32(adler32val
, buf
, len
);
749 return PyInt_FromLong(adler32val
);
752 PyDoc_STRVAR(crc32__doc__
,
753 "crc32(string[, start]) -- Compute a CRC-32 checksum of string.\n"
755 "An optional starting value can be specified. The returned checksum is\n"
759 PyZlib_crc32(PyObject
*self
, PyObject
*args
)
761 uLong crc32val
= crc32(0L, Z_NULL
, 0);
764 if (!PyArg_ParseTuple(args
, "s#|l:crc32", &buf
, &len
, &crc32val
))
766 crc32val
= crc32(crc32val
, buf
, len
);
767 return PyInt_FromLong(crc32val
);
771 static PyMethodDef zlib_methods
[] =
773 {"adler32", (PyCFunction
)PyZlib_adler32
, METH_VARARGS
,
775 {"compress", (PyCFunction
)PyZlib_compress
, METH_VARARGS
,
777 {"compressobj", (PyCFunction
)PyZlib_compressobj
, METH_VARARGS
,
779 {"crc32", (PyCFunction
)PyZlib_crc32
, METH_VARARGS
,
781 {"decompress", (PyCFunction
)PyZlib_decompress
, METH_VARARGS
,
783 {"decompressobj", (PyCFunction
)PyZlib_decompressobj
, METH_VARARGS
,
784 decompressobj__doc__
},
788 static PyTypeObject Comptype
= {
789 PyObject_HEAD_INIT(0)
794 (destructor
)Comp_dealloc
, /*tp_dealloc*/
796 (getattrfunc
)Comp_getattr
, /*tp_getattr*/
801 0, /*tp_as_sequence*/
805 static PyTypeObject Decomptype
= {
806 PyObject_HEAD_INIT(0)
811 (destructor
)Decomp_dealloc
, /*tp_dealloc*/
813 (getattrfunc
)Decomp_getattr
, /*tp_getattr*/
818 0, /*tp_as_sequence*/
822 PyDoc_STRVAR(zlib_module_documentation
,
823 "The functions in this module allow compression and decompression using the\n"
824 "zlib library, which is based on GNU zip.\n"
826 "adler32(string[, start]) -- Compute an Adler-32 checksum.\n"
827 "compress(string[, level]) -- Compress string, with compression level in 1-9.\n"
828 "compressobj([level]) -- Return a compressor object.\n"
829 "crc32(string[, start]) -- Compute a CRC-32 checksum.\n"
830 "decompress(string,[wbits],[bufsize]) -- Decompresses a compressed string.\n"
831 "decompressobj([wbits]) -- Return a decompressor object.\n"
833 "'wbits' is window buffer size.\n"
834 "Compressor objects support compress() and flush() methods; decompressor\n"
835 "objects support decompress() and flush().");
841 Comptype
.ob_type
= &PyType_Type
;
842 Decomptype
.ob_type
= &PyType_Type
;
843 m
= Py_InitModule4("zlib", zlib_methods
,
844 zlib_module_documentation
,
845 (PyObject
*)NULL
,PYTHON_API_VERSION
);
847 ZlibError
= PyErr_NewException("zlib.error", NULL
, NULL
);
848 if (ZlibError
!= NULL
) {
849 Py_INCREF(ZlibError
);
850 PyModule_AddObject(m
, "error", ZlibError
);
852 PyModule_AddIntConstant(m
, "MAX_WBITS", MAX_WBITS
);
853 PyModule_AddIntConstant(m
, "DEFLATED", DEFLATED
);
854 PyModule_AddIntConstant(m
, "DEF_MEM_LEVEL", DEF_MEM_LEVEL
);
855 PyModule_AddIntConstant(m
, "Z_BEST_SPEED", Z_BEST_SPEED
);
856 PyModule_AddIntConstant(m
, "Z_BEST_COMPRESSION", Z_BEST_COMPRESSION
);
857 PyModule_AddIntConstant(m
, "Z_DEFAULT_COMPRESSION", Z_DEFAULT_COMPRESSION
);
858 PyModule_AddIntConstant(m
, "Z_FILTERED", Z_FILTERED
);
859 PyModule_AddIntConstant(m
, "Z_HUFFMAN_ONLY", Z_HUFFMAN_ONLY
);
860 PyModule_AddIntConstant(m
, "Z_DEFAULT_STRATEGY", Z_DEFAULT_STRATEGY
);
862 PyModule_AddIntConstant(m
, "Z_FINISH", Z_FINISH
);
863 PyModule_AddIntConstant(m
, "Z_NO_FLUSH", Z_NO_FLUSH
);
864 PyModule_AddIntConstant(m
, "Z_SYNC_FLUSH", Z_SYNC_FLUSH
);
865 PyModule_AddIntConstant(m
, "Z_FULL_FLUSH", Z_FULL_FLUSH
);
867 ver
= PyString_FromString(ZLIB_VERSION
);
869 PyModule_AddObject(m
, "ZLIB_VERSION", ver
);
872 zlib_lock
= PyThread_allocate_lock();
873 #endif /* WITH_THREAD */