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 self
->zst
.next_in
= NULL
;
305 self
->zst
.avail_in
= 0;
306 err
= deflateInit2(&self
->zst
, level
, method
, wbits
, memLevel
, strategy
);
309 self
->is_initialised
= 1;
310 return (PyObject
*)self
;
313 PyErr_SetString(PyExc_MemoryError
,
314 "Can't allocate memory for compression object");
316 case(Z_STREAM_ERROR
):
318 PyErr_SetString(PyExc_ValueError
, "Invalid initialization option");
321 zlib_error(self
->zst
, err
, "while creating compression object");
328 PyZlib_decompressobj(PyObject
*selfptr
, PyObject
*args
)
330 int wbits
=DEF_WBITS
, err
;
332 if (!PyArg_ParseTuple(args
, "|i:decompressobj", &wbits
))
335 self
= newcompobject(&Decomptype
);
338 self
->zst
.zalloc
= (alloc_func
)NULL
;
339 self
->zst
.zfree
= (free_func
)Z_NULL
;
340 self
->zst
.next_in
= NULL
;
341 self
->zst
.avail_in
= 0;
342 err
= inflateInit2(&self
->zst
, wbits
);
345 self
->is_initialised
= 1;
346 return (PyObject
*)self
;
347 case(Z_STREAM_ERROR
):
349 PyErr_SetString(PyExc_ValueError
, "Invalid initialization option");
353 PyErr_SetString(PyExc_MemoryError
,
354 "Can't allocate memory for decompression object");
357 zlib_error(self
->zst
, err
, "while creating decompression object");
364 Comp_dealloc(compobject
*self
)
366 if (self
->is_initialised
)
367 deflateEnd(&self
->zst
);
368 Py_XDECREF(self
->unused_data
);
369 Py_XDECREF(self
->unconsumed_tail
);
374 Decomp_dealloc(compobject
*self
)
376 if (self
->is_initialised
)
377 inflateEnd(&self
->zst
);
378 Py_XDECREF(self
->unused_data
);
379 Py_XDECREF(self
->unconsumed_tail
);
383 PyDoc_STRVAR(comp_compress__doc__
,
384 "compress(data) -- Return a string containing data compressed.\n"
386 "After calling this function, some of the input data may still\n"
387 "be stored in internal buffers for later processing.\n"
388 "Call the flush() method to clear these buffers.");
392 PyZlib_objcompress(compobject
*self
, PyObject
*args
)
394 int err
, inplen
, length
= DEFAULTALLOC
;
397 unsigned long start_total_out
;
399 if (!PyArg_ParseTuple(args
, "s#:compress", &input
, &inplen
))
402 if (!(RetVal
= PyString_FromStringAndSize(NULL
, length
)))
407 start_total_out
= self
->zst
.total_out
;
408 self
->zst
.avail_in
= inplen
;
409 self
->zst
.next_in
= input
;
410 self
->zst
.avail_out
= length
;
411 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
);
413 Py_BEGIN_ALLOW_THREADS
414 err
= deflate(&(self
->zst
), Z_NO_FLUSH
);
417 /* while Z_OK and the output buffer is full, there might be more output,
418 so extend the output buffer and try again */
419 while (err
== Z_OK
&& self
->zst
.avail_out
== 0) {
420 if (_PyString_Resize(&RetVal
, length
<< 1) < 0)
422 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
) \
424 self
->zst
.avail_out
= length
;
425 length
= length
<< 1;
427 Py_BEGIN_ALLOW_THREADS
428 err
= deflate(&(self
->zst
), Z_NO_FLUSH
);
431 /* We will only get Z_BUF_ERROR if the output buffer was full but
432 there wasn't more output when we tried again, so it is not an error
436 if (err
!= Z_OK
&& err
!= Z_BUF_ERROR
) {
437 zlib_error(self
->zst
, err
, "while compressing");
442 _PyString_Resize(&RetVal
, self
->zst
.total_out
- start_total_out
);
449 PyDoc_STRVAR(decomp_decompress__doc__
,
450 "decompress(data, max_length) -- Return a string containing the decompressed\n"
451 "version of the data.\n"
453 "After calling this function, some of the input data may still be stored in\n"
454 "internal buffers for later processing.\n"
455 "Call the flush() method to clear these buffers.\n"
456 "If the max_length parameter is specified then the return value will be\n"
457 "no longer than max_length. Unconsumed input data will be stored in\n"
458 "the unconsumed_tail attribute.");
461 PyZlib_objdecompress(compobject
*self
, PyObject
*args
)
463 int err
, inplen
, old_length
, length
= DEFAULTALLOC
;
467 unsigned long start_total_out
;
469 if (!PyArg_ParseTuple(args
, "s#|i:decompress", &input
,
470 &inplen
, &max_length
))
472 if (max_length
< 0) {
473 PyErr_SetString(PyExc_ValueError
,
474 "max_length must be greater than zero");
478 /* limit amount of data allocated to max_length */
479 if (max_length
&& length
> max_length
)
481 if (!(RetVal
= PyString_FromStringAndSize(NULL
, length
)))
486 start_total_out
= self
->zst
.total_out
;
487 self
->zst
.avail_in
= inplen
;
488 self
->zst
.next_in
= input
;
489 self
->zst
.avail_out
= length
;
490 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
);
492 Py_BEGIN_ALLOW_THREADS
493 err
= inflate(&(self
->zst
), Z_SYNC_FLUSH
);
496 /* While Z_OK and the output buffer is full, there might be more output.
497 So extend the output buffer and try again.
499 while (err
== Z_OK
&& self
->zst
.avail_out
== 0) {
500 /* If max_length set, don't continue decompressing if we've already
503 if (max_length
&& length
>= max_length
)
508 length
= length
<< 1;
509 if (max_length
&& length
> max_length
)
512 if (_PyString_Resize(&RetVal
, length
) < 0)
514 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
) \
516 self
->zst
.avail_out
= length
- old_length
;
518 Py_BEGIN_ALLOW_THREADS
519 err
= inflate(&(self
->zst
), Z_SYNC_FLUSH
);
523 /* Not all of the compressed data could be accommodated in the output buffer
524 of specified size. Return the unconsumed tail in an attribute.*/
526 Py_DECREF(self
->unconsumed_tail
);
527 self
->unconsumed_tail
= PyString_FromStringAndSize((char *)self
->zst
.next_in
,
529 if(!self
->unconsumed_tail
) {
536 /* The end of the compressed data has been reached, so set the
537 unused_data attribute to a string containing the remainder of the
538 data in the string. Note that this is also a logical place to call
539 inflateEnd, but the old behaviour of only calling it on flush() is
542 if (err
== Z_STREAM_END
) {
543 Py_XDECREF(self
->unused_data
); /* Free original empty string */
544 self
->unused_data
= PyString_FromStringAndSize(
545 (char *)self
->zst
.next_in
, self
->zst
.avail_in
);
546 if (self
->unused_data
== NULL
) {
550 /* We will only get Z_BUF_ERROR if the output buffer was full
551 but there wasn't more output when we tried again, so it is
552 not an error condition.
554 } else if (err
!= Z_OK
&& err
!= Z_BUF_ERROR
) {
555 zlib_error(self
->zst
, err
, "while decompressing");
561 _PyString_Resize(&RetVal
, self
->zst
.total_out
- start_total_out
);
569 PyDoc_STRVAR(comp_flush__doc__
,
570 "flush( [mode] ) -- Return a string containing any remaining compressed data.\n"
572 "mode can be one of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH; the\n"
573 "default value used when mode is not specified is Z_FINISH.\n"
574 "If mode == Z_FINISH, the compressor object can no longer be used after\n"
575 "calling the flush() method. Otherwise, more data can still be compressed.");
578 PyZlib_flush(compobject
*self
, PyObject
*args
)
580 int err
, length
= DEFAULTALLOC
;
582 int flushmode
= Z_FINISH
;
583 unsigned long start_total_out
;
585 if (!PyArg_ParseTuple(args
, "|i:flush", &flushmode
))
588 /* Flushing with Z_NO_FLUSH is a no-op, so there's no point in
589 doing any work at all; just return an empty string. */
590 if (flushmode
== Z_NO_FLUSH
) {
591 return PyString_FromStringAndSize(NULL
, 0);
594 if (!(RetVal
= PyString_FromStringAndSize(NULL
, length
)))
599 start_total_out
= self
->zst
.total_out
;
600 self
->zst
.avail_in
= 0;
601 self
->zst
.avail_out
= length
;
602 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
);
604 Py_BEGIN_ALLOW_THREADS
605 err
= deflate(&(self
->zst
), flushmode
);
608 /* while Z_OK and the output buffer is full, there might be more output,
609 so extend the output buffer and try again */
610 while (err
== Z_OK
&& self
->zst
.avail_out
== 0) {
611 if (_PyString_Resize(&RetVal
, length
<< 1) < 0)
613 self
->zst
.next_out
= (unsigned char *)PyString_AS_STRING(RetVal
) \
615 self
->zst
.avail_out
= length
;
616 length
= length
<< 1;
618 Py_BEGIN_ALLOW_THREADS
619 err
= deflate(&(self
->zst
), flushmode
);
623 /* If flushmode is Z_FINISH, we also have to call deflateEnd() to free
624 various data structures. Note we should only get Z_STREAM_END when
625 flushmode is Z_FINISH, but checking both for safety*/
626 if (err
== Z_STREAM_END
&& flushmode
== Z_FINISH
) {
627 err
= deflateEnd(&(self
->zst
));
629 zlib_error(self
->zst
, err
, "from deflateEnd()");
635 self
->is_initialised
= 0;
637 /* We will only get Z_BUF_ERROR if the output buffer was full
638 but there wasn't more output when we tried again, so it is
639 not an error condition.
641 } else if (err
!=Z_OK
&& err
!=Z_BUF_ERROR
) {
642 zlib_error(self
->zst
, err
, "while flushing");
648 _PyString_Resize(&RetVal
, self
->zst
.total_out
- start_total_out
);
656 PyDoc_STRVAR(decomp_flush__doc__
,
657 "flush() -- Return a string containing any remaining decompressed data.\n"
659 "The decompressor object can no longer be used after this call.");
662 PyZlib_unflush(compobject
*self
, PyObject
*args
)
664 int err
, length
= DEFAULTALLOC
;
665 PyObject
* retval
= NULL
;
666 unsigned long start_total_out
;
668 if (!PyArg_ParseTuple(args
, "|i:flush", &length
))
670 if (!(retval
= PyString_FromStringAndSize(NULL
, length
)))
676 start_total_out
= self
->zst
.total_out
;
677 self
->zst
.avail_out
= length
;
678 self
->zst
.next_out
= (Byte
*)PyString_AS_STRING(retval
);
680 Py_BEGIN_ALLOW_THREADS
681 err
= inflate(&(self
->zst
), Z_FINISH
);
684 /* while Z_OK and the output buffer is full, there might be more output,
685 so extend the output buffer and try again */
686 while ((err
== Z_OK
|| err
== Z_BUF_ERROR
) && self
->zst
.avail_out
== 0) {
687 if (_PyString_Resize(&retval
, length
<< 1) < 0)
689 self
->zst
.next_out
= (Byte
*)PyString_AS_STRING(retval
) + length
;
690 self
->zst
.avail_out
= length
;
691 length
= length
<< 1;
693 Py_BEGIN_ALLOW_THREADS
694 err
= inflate(&(self
->zst
), Z_FINISH
);
698 /* If flushmode is Z_FINISH, we also have to call deflateEnd() to free
699 various data structures. Note we should only get Z_STREAM_END when
700 flushmode is Z_FINISH */
701 if (err
== Z_STREAM_END
) {
702 err
= inflateEnd(&(self
->zst
));
703 self
->is_initialised
= 0;
705 zlib_error(self
->zst
, err
, "from inflateEnd()");
711 _PyString_Resize(&retval
, self
->zst
.total_out
- start_total_out
);
720 static PyMethodDef comp_methods
[] =
722 {"compress", (binaryfunc
)PyZlib_objcompress
, METH_VARARGS
,
723 comp_compress__doc__
},
724 {"flush", (binaryfunc
)PyZlib_flush
, METH_VARARGS
,
729 static PyMethodDef Decomp_methods
[] =
731 {"decompress", (binaryfunc
)PyZlib_objdecompress
, METH_VARARGS
,
732 decomp_decompress__doc__
},
733 {"flush", (binaryfunc
)PyZlib_unflush
, METH_VARARGS
,
734 decomp_flush__doc__
},
739 Comp_getattr(compobject
*self
, char *name
)
741 /* No ENTER/LEAVE_ZLIB is necessary because this fn doesn't touch
744 return Py_FindMethod(comp_methods
, (PyObject
*)self
, name
);
748 Decomp_getattr(compobject
*self
, char *name
)
754 if (strcmp(name
, "unused_data") == 0) {
755 Py_INCREF(self
->unused_data
);
756 retval
= self
->unused_data
;
757 } else if (strcmp(name
, "unconsumed_tail") == 0) {
758 Py_INCREF(self
->unconsumed_tail
);
759 retval
= self
->unconsumed_tail
;
761 retval
= Py_FindMethod(Decomp_methods
, (PyObject
*)self
, name
);
768 PyDoc_STRVAR(adler32__doc__
,
769 "adler32(string[, start]) -- Compute an Adler-32 checksum of string.\n"
771 "An optional starting value can be specified. The returned checksum is\n"
775 PyZlib_adler32(PyObject
*self
, PyObject
*args
)
777 uLong adler32val
= adler32(0L, Z_NULL
, 0);
781 if (!PyArg_ParseTuple(args
, "s#|k:adler32", &buf
, &len
, &adler32val
))
783 adler32val
= adler32(adler32val
, buf
, len
);
784 return PyInt_FromLong(adler32val
);
787 PyDoc_STRVAR(crc32__doc__
,
788 "crc32(string[, start]) -- Compute a CRC-32 checksum of string.\n"
790 "An optional starting value can be specified. The returned checksum is\n"
794 PyZlib_crc32(PyObject
*self
, PyObject
*args
)
796 uLong crc32val
= crc32(0L, Z_NULL
, 0);
799 if (!PyArg_ParseTuple(args
, "s#|k:crc32", &buf
, &len
, &crc32val
))
801 crc32val
= crc32(crc32val
, buf
, len
);
802 return PyInt_FromLong(crc32val
);
806 static PyMethodDef zlib_methods
[] =
808 {"adler32", (PyCFunction
)PyZlib_adler32
, METH_VARARGS
,
810 {"compress", (PyCFunction
)PyZlib_compress
, METH_VARARGS
,
812 {"compressobj", (PyCFunction
)PyZlib_compressobj
, METH_VARARGS
,
814 {"crc32", (PyCFunction
)PyZlib_crc32
, METH_VARARGS
,
816 {"decompress", (PyCFunction
)PyZlib_decompress
, METH_VARARGS
,
818 {"decompressobj", (PyCFunction
)PyZlib_decompressobj
, METH_VARARGS
,
819 decompressobj__doc__
},
823 static PyTypeObject Comptype
= {
824 PyObject_HEAD_INIT(0)
829 (destructor
)Comp_dealloc
, /*tp_dealloc*/
831 (getattrfunc
)Comp_getattr
, /*tp_getattr*/
836 0, /*tp_as_sequence*/
840 static PyTypeObject Decomptype
= {
841 PyObject_HEAD_INIT(0)
846 (destructor
)Decomp_dealloc
, /*tp_dealloc*/
848 (getattrfunc
)Decomp_getattr
, /*tp_getattr*/
853 0, /*tp_as_sequence*/
857 PyDoc_STRVAR(zlib_module_documentation
,
858 "The functions in this module allow compression and decompression using the\n"
859 "zlib library, which is based on GNU zip.\n"
861 "adler32(string[, start]) -- Compute an Adler-32 checksum.\n"
862 "compress(string[, level]) -- Compress string, with compression level in 1-9.\n"
863 "compressobj([level]) -- Return a compressor object.\n"
864 "crc32(string[, start]) -- Compute a CRC-32 checksum.\n"
865 "decompress(string,[wbits],[bufsize]) -- Decompresses a compressed string.\n"
866 "decompressobj([wbits]) -- Return a decompressor object.\n"
868 "'wbits' is window buffer size.\n"
869 "Compressor objects support compress() and flush() methods; decompressor\n"
870 "objects support decompress() and flush().");
876 Comptype
.ob_type
= &PyType_Type
;
877 Decomptype
.ob_type
= &PyType_Type
;
878 m
= Py_InitModule4("zlib", zlib_methods
,
879 zlib_module_documentation
,
880 (PyObject
*)NULL
,PYTHON_API_VERSION
);
882 ZlibError
= PyErr_NewException("zlib.error", NULL
, NULL
);
883 if (ZlibError
!= NULL
) {
884 Py_INCREF(ZlibError
);
885 PyModule_AddObject(m
, "error", ZlibError
);
887 PyModule_AddIntConstant(m
, "MAX_WBITS", MAX_WBITS
);
888 PyModule_AddIntConstant(m
, "DEFLATED", DEFLATED
);
889 PyModule_AddIntConstant(m
, "DEF_MEM_LEVEL", DEF_MEM_LEVEL
);
890 PyModule_AddIntConstant(m
, "Z_BEST_SPEED", Z_BEST_SPEED
);
891 PyModule_AddIntConstant(m
, "Z_BEST_COMPRESSION", Z_BEST_COMPRESSION
);
892 PyModule_AddIntConstant(m
, "Z_DEFAULT_COMPRESSION", Z_DEFAULT_COMPRESSION
);
893 PyModule_AddIntConstant(m
, "Z_FILTERED", Z_FILTERED
);
894 PyModule_AddIntConstant(m
, "Z_HUFFMAN_ONLY", Z_HUFFMAN_ONLY
);
895 PyModule_AddIntConstant(m
, "Z_DEFAULT_STRATEGY", Z_DEFAULT_STRATEGY
);
897 PyModule_AddIntConstant(m
, "Z_FINISH", Z_FINISH
);
898 PyModule_AddIntConstant(m
, "Z_NO_FLUSH", Z_NO_FLUSH
);
899 PyModule_AddIntConstant(m
, "Z_SYNC_FLUSH", Z_SYNC_FLUSH
);
900 PyModule_AddIntConstant(m
, "Z_FULL_FLUSH", Z_FULL_FLUSH
);
902 ver
= PyString_FromString(ZLIB_VERSION
);
904 PyModule_AddObject(m
, "ZLIB_VERSION", ver
);
906 PyModule_AddStringConstant(m
, "__version__", "1.0");
909 zlib_lock
= PyThread_allocate_lock();
910 #endif /* WITH_THREAD */