Mercurial > cpython-lru_cache-weakref
annotate Modules/zlibmodule.c @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | d5ce7ff531bd |
| children |
| rev | line source |
|---|---|
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /* zlibmodule.c -- gzip-compatible data compression */ |
|
20327
54f05b9b1fc4
Update URL. Fixes bug #468118.
Martin v. Löwis <martin@v.loewis.de>
parents:
19810
diff
changeset
|
2 /* See http://www.gzip.org/zlib/ */ |
|
16368
c696a52c2621
Fix [ Bug #129293 ] zlib library used for binary win32 distribution can crash
Mark Hammond <mhammond@skippinet.com.au>
parents:
15098
diff
changeset
|
3 |
|
16369
c04ca6cba1e3
Docs for new Windows zlib build procedure.
Tim Peters <tim.peters@gmail.com>
parents:
16368
diff
changeset
|
4 /* Windows users: read Python's PCbuild\readme.txt */ |
|
16368
c696a52c2621
Fix [ Bug #129293 ] zlib library used for binary win32 distribution can crash
Mark Hammond <mhammond@skippinet.com.au>
parents:
15098
diff
changeset
|
5 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
5723
beee351f1f72
Small changes (casts etc.) by Jack, for Mac compilation.
Guido van Rossum <guido@python.org>
parents:
5722
diff
changeset
|
7 #include "Python.h" |
|
beee351f1f72
Small changes (casts etc.) by Jack, for Mac compilation.
Guido van Rossum <guido@python.org>
parents:
5722
diff
changeset
|
8 #include "zlib.h" |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
10 #ifdef WITH_THREAD |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
11 #include "pythread.h" |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
12 |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
13 /* #defs ripped off from _tkinter.c, even though the situation here is much |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
14 simpler, because we don't have to worry about waiting for Tcl |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
15 events! And, since zlib itself is threadsafe, we don't need to worry |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
16 about re-entering zlib functions. |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
17 |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
18 N.B. |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
19 |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
20 Since ENTER_ZLIB and LEAVE_ZLIB only need to be called on functions |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
21 that modify the components of preexisting de/compress objects, it |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
22 could prove to be a performance gain on multiprocessor machines if |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
23 there was an de/compress object-specific lock. However, for the |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
24 moment the ENTER_ZLIB and LEAVE_ZLIB calls are global for ALL |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
25 de/compress objects. |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
26 */ |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
27 |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
28 static PyThread_type_lock zlib_lock = NULL; /* initialized on module load */ |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
29 |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
30 #define ENTER_ZLIB \ |
|
20482
8f473179b073
Removed obsolete comments about confused string refcount tricks (Jeremy
Tim Peters <tim.peters@gmail.com>
parents:
20478
diff
changeset
|
31 Py_BEGIN_ALLOW_THREADS \ |
|
8f473179b073
Removed obsolete comments about confused string refcount tricks (Jeremy
Tim Peters <tim.peters@gmail.com>
parents:
20478
diff
changeset
|
32 PyThread_acquire_lock(zlib_lock, 1); \ |
|
8f473179b073
Removed obsolete comments about confused string refcount tricks (Jeremy
Tim Peters <tim.peters@gmail.com>
parents:
20478
diff
changeset
|
33 Py_END_ALLOW_THREADS |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
34 |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
35 #define LEAVE_ZLIB \ |
|
20482
8f473179b073
Removed obsolete comments about confused string refcount tricks (Jeremy
Tim Peters <tim.peters@gmail.com>
parents:
20478
diff
changeset
|
36 PyThread_release_lock(zlib_lock); |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
37 |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
38 #else |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
39 |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
40 #define ENTER_ZLIB |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
41 #define LEAVE_ZLIB |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
42 |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
43 #endif |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
44 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 /* The following parameters are copied from zutil.h, version 0.95 */ |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 #define DEFLATED 8 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 #if MAX_MEM_LEVEL >= 8 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 # define DEF_MEM_LEVEL 8 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 #else |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 # define DEF_MEM_LEVEL MAX_MEM_LEVEL |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 #endif |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 #define DEF_WBITS MAX_WBITS |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 |
|
10538
ccee3c28b7ef
Patch by Andrew Kuchling to unflush() (flush() for deflating).
Guido van Rossum <guido@python.org>
parents:
10467
diff
changeset
|
54 /* The output buffer will be increased in chunks of DEFAULTALLOC bytes. */ |
|
ccee3c28b7ef
Patch by Andrew Kuchling to unflush() (flush() for deflating).
Guido van Rossum <guido@python.org>
parents:
10467
diff
changeset
|
55 #define DEFAULTALLOC (16*1024) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 #define PyInit_zlib initzlib |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 staticforward PyTypeObject Comptype; |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 staticforward PyTypeObject Decomptype; |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 static PyObject *ZlibError; |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
63 typedef struct |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 { |
| 20469 | 65 PyObject_HEAD |
| 66 z_stream zst; | |
| 67 PyObject *unused_data; | |
| 68 PyObject *unconsumed_tail; | |
| 69 int is_initialised; | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 } compobject; |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 |
|
20474
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
72 static void |
|
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
73 zlib_error(z_stream zst, int err, char *msg) |
|
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
74 { |
|
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
75 if (zst.msg == Z_NULL) |
|
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
76 PyErr_Format(ZlibError, "Error %d %s", err, msg); |
|
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
77 else |
|
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
78 PyErr_Format(ZlibError, "Error %d %s: %.200s", err, msg, zst.msg); |
|
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
79 } |
|
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
80 |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
81 static char compressobj__doc__[] = |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
82 "compressobj([level]) -- Return a compressor object.\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
83 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
84 "Optional arg level is the compression level, in 1-9."; |
| 5722 | 85 |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
86 static char decompressobj__doc__[] = |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
87 "decompressobj([wbits]) -- Return a decompressor object.\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
88 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
89 "Optional arg wbits is the window buffer size."; |
| 5722 | 90 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 static compobject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
92 newcompobject(PyTypeObject *type) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 { |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
94 compobject *self; |
| 20469 | 95 self = PyObject_New(compobject, type); |
| 96 if (self == NULL) | |
| 97 return NULL; | |
| 98 self->is_initialised = 0; | |
| 99 self->unused_data = PyString_FromString(""); | |
| 100 if (self->unused_data == NULL) { | |
| 101 Py_DECREF(self); | |
| 102 return NULL; | |
| 103 } | |
| 104 self->unconsumed_tail = PyString_FromString(""); | |
| 105 if (self->unconsumed_tail == NULL) { | |
| 106 Py_DECREF(self); | |
| 107 return NULL; | |
| 108 } | |
| 109 return self; | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
112 static char compress__doc__[] = |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
113 "compress(string[, level]) -- Returned compressed string.\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
114 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
115 "Optional arg level is the compression level, in 1-9."; |
| 5722 | 116 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
118 PyZlib_compress(PyObject *self, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 { |
| 20469 | 120 PyObject *ReturnVal = NULL; |
| 121 Byte *input, *output; | |
| 122 int length, level=Z_DEFAULT_COMPRESSION, err; | |
| 123 z_stream zst; | |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
124 |
| 20469 | 125 /* require Python string object, optional 'level' arg */ |
|
20478
071cfee8d8eb
Undo needless INCREF chicanery introduced by SF patch #450702.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20477
diff
changeset
|
126 if (!PyArg_ParseTuple(args, "s#|i:compress", &input, &length, &level)) |
| 20469 | 127 return NULL; |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
128 |
| 20469 | 129 zst.avail_out = length + length/1000 + 12 + 1; |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
130 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
131 output = (Byte*)malloc(zst.avail_out); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
132 if (output == NULL) { |
| 20469 | 133 PyErr_SetString(PyExc_MemoryError, |
| 134 "Can't allocate memory to compress data"); | |
| 135 return NULL; | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 } |
| 9657 | 137 |
| 20469 | 138 /* Past the point of no return. From here on out, we need to make sure |
| 139 we clean up mallocs & INCREFs. */ | |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
140 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
141 zst.zalloc = (alloc_func)NULL; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
142 zst.zfree = (free_func)Z_NULL; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
143 zst.next_out = (Byte *)output; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
144 zst.next_in = (Byte *)input; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
145 zst.avail_in = length; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
146 err = deflateInit(&zst, level); |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
147 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
148 switch(err) { |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 case(Z_OK): |
| 20469 | 150 break; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 case(Z_MEM_ERROR): |
| 20469 | 152 PyErr_SetString(PyExc_MemoryError, |
| 153 "Out of memory while compressing data"); | |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
154 goto error; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 case(Z_STREAM_ERROR): |
| 20469 | 156 PyErr_SetString(ZlibError, |
| 157 "Bad compression level"); | |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
158 goto error; |
|
20474
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
159 default: |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 deflateEnd(&zst); |
|
20474
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
161 zlib_error(zst, err, "while compressing data"); |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
162 goto error; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 } |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
164 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
165 Py_BEGIN_ALLOW_THREADS; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
166 err = deflate(&zst, Z_FINISH); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
167 Py_END_ALLOW_THREADS; |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
168 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
169 if (err != Z_STREAM_END) { |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
170 zlib_error(zst, err, "while compressing data"); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
171 deflateEnd(&zst); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
172 goto error; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
173 } |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
174 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
175 err=deflateEnd(&zst); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
176 if (err == Z_OK) |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
177 ReturnVal = PyString_FromStringAndSize((char *)output, |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
178 zst.total_out); |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
179 else |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
180 zlib_error(zst, err, "while finishing compression"); |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
181 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
182 error: |
| 20469 | 183 free(output); |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
184 |
| 20469 | 185 return ReturnVal; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
187 |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
188 static char decompress__doc__[] = |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
189 "decompress(string[, wbits[, bufsize]]) -- Return decompressed string.\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
190 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
191 "Optional arg wbits is the window buffer size. Optional arg bufsize is\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
192 "the initial output buffer size."; |
| 5722 | 193 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
194 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
195 PyZlib_decompress(PyObject *self, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
196 { |
| 20469 | 197 PyObject *result_str; |
| 198 Byte *input; | |
| 199 int length, err; | |
| 200 int wsize=DEF_WBITS, r_strlen=DEFAULTALLOC; | |
| 201 z_stream zst; | |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
202 |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
203 if (!PyArg_ParseTuple(args, "s#|ii:decompress", |
|
20478
071cfee8d8eb
Undo needless INCREF chicanery introduced by SF patch #450702.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20477
diff
changeset
|
204 &input, &length, &wsize, &r_strlen)) |
| 20469 | 205 return NULL; |
| 6236 | 206 |
| 20469 | 207 if (r_strlen <= 0) |
| 208 r_strlen = 1; | |
| 9657 | 209 |
| 20469 | 210 zst.avail_in = length; |
| 211 zst.avail_out = r_strlen; | |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
212 |
|
20470
8964ef84c92f
Remove many calls to set MemoryError exceptions.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20469
diff
changeset
|
213 if (!(result_str = PyString_FromStringAndSize(NULL, r_strlen))) |
| 20469 | 214 return NULL; |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
215 |
| 20469 | 216 zst.zalloc = (alloc_func)NULL; |
| 217 zst.zfree = (free_func)Z_NULL; | |
|
20478
071cfee8d8eb
Undo needless INCREF chicanery introduced by SF patch #450702.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20477
diff
changeset
|
218 zst.next_out = (Byte *)PyString_AS_STRING(result_str); |
| 20469 | 219 zst.next_in = (Byte *)input; |
| 220 err = inflateInit2(&zst, wsize); | |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
221 |
| 20469 | 222 switch(err) { |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
223 case(Z_OK): |
| 20469 | 224 break; |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
225 case(Z_MEM_ERROR): |
| 20469 | 226 PyErr_SetString(PyExc_MemoryError, |
| 227 "Out of memory while decompressing data"); | |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
228 goto error; |
|
20474
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
229 default: |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
230 inflateEnd(&zst); |
|
20474
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
231 zlib_error(zst, err, "while preparing to decompress data"); |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
232 goto error; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
233 } |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
234 |
| 20469 | 235 do { |
| 236 Py_BEGIN_ALLOW_THREADS | |
| 237 err=inflate(&zst, Z_FINISH); | |
| 238 Py_END_ALLOW_THREADS | |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
239 |
| 20469 | 240 switch(err) { |
| 241 case(Z_STREAM_END): | |
| 6007 | 242 break; |
|
8128
fdba6397b729
Tiny patch for zlib 1.1.2
Guido van Rossum <guido@python.org>
parents:
6911
diff
changeset
|
243 case(Z_BUF_ERROR): |
|
15098
7de0808f1fe3
Patch #101810: check whether zst.avail_out is non-zero when getting
Andrew M. Kuchling <amk@amk.ca>
parents:
13816
diff
changeset
|
244 /* |
|
7de0808f1fe3
Patch #101810: check whether zst.avail_out is non-zero when getting
Andrew M. Kuchling <amk@amk.ca>
parents:
13816
diff
changeset
|
245 * If there is at least 1 byte of room according to zst.avail_out |
|
7de0808f1fe3
Patch #101810: check whether zst.avail_out is non-zero when getting
Andrew M. Kuchling <amk@amk.ca>
parents:
13816
diff
changeset
|
246 * and we get this error, assume that it means zlib cannot |
|
7de0808f1fe3
Patch #101810: check whether zst.avail_out is non-zero when getting
Andrew M. Kuchling <amk@amk.ca>
parents:
13816
diff
changeset
|
247 * process the inflate call() due to an error in the data. |
|
7de0808f1fe3
Patch #101810: check whether zst.avail_out is non-zero when getting
Andrew M. Kuchling <amk@amk.ca>
parents:
13816
diff
changeset
|
248 */ |
|
20474
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
249 if (zst.avail_out > 0) { |
| 20469 | 250 PyErr_Format(ZlibError, "Error %i while decompressing data", |
| 251 err); | |
| 252 inflateEnd(&zst); | |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
253 goto error; |
| 20469 | 254 } |
|
15098
7de0808f1fe3
Patch #101810: check whether zst.avail_out is non-zero when getting
Andrew M. Kuchling <amk@amk.ca>
parents:
13816
diff
changeset
|
255 /* fall through */ |
|
7de0808f1fe3
Patch #101810: check whether zst.avail_out is non-zero when getting
Andrew M. Kuchling <amk@amk.ca>
parents:
13816
diff
changeset
|
256 case(Z_OK): |
| 6007 | 257 /* need more memory */ |
| 20469 | 258 if (_PyString_Resize(&result_str, r_strlen << 1) == -1) { |
| 259 inflateEnd(&zst); | |
| 260 result_str = NULL; | |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
261 goto error; |
| 20469 | 262 } |
|
20478
071cfee8d8eb
Undo needless INCREF chicanery introduced by SF patch #450702.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20477
diff
changeset
|
263 zst.next_out = (unsigned char *)PyString_AS_STRING(result_str) \ |
| 20469 | 264 + r_strlen; |
| 265 zst.avail_out = r_strlen; | |
| 6007 | 266 r_strlen = r_strlen << 1; |
| 267 break; | |
|
20474
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
268 default: |
| 20469 | 269 inflateEnd(&zst); |
|
20474
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
270 zlib_error(zst, err, "while decompressing data"); |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
271 goto error; |
| 20469 | 272 } |
| 273 } while (err != Z_STREAM_END); | |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
274 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
275 err = inflateEnd(&zst); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
276 if (err != Z_OK) { |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
277 zlib_error(zst, err, "while finishing data decompression"); |
|
20478
071cfee8d8eb
Undo needless INCREF chicanery introduced by SF patch #450702.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20477
diff
changeset
|
278 goto error; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
279 } |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
280 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
281 _PyString_Resize(&result_str, zst.total_out); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
282 return result_str; |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
283 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
284 error: |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
285 Py_XDECREF(result_str); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
286 return NULL; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
287 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
288 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
289 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
290 PyZlib_compressobj(PyObject *selfptr, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
291 { |
| 20475 | 292 compobject *self; |
| 293 int level=Z_DEFAULT_COMPRESSION, method=DEFLATED; | |
| 294 int wbits=MAX_WBITS, memLevel=DEF_MEM_LEVEL, strategy=0, err; | |
| 6007 | 295 |
| 20475 | 296 if (!PyArg_ParseTuple(args, "|iiiii:compressobj", &level, &method, &wbits, |
| 297 &memLevel, &strategy)) | |
| 298 return NULL; | |
| 6007 | 299 |
| 20475 | 300 self = newcompobject(&Comptype); |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
301 if (self==NULL) |
| 20475 | 302 return(NULL); |
| 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); | |
| 306 switch(err) { | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
307 case (Z_OK): |
| 20475 | 308 self->is_initialised = 1; |
| 309 return (PyObject*)self; | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
310 case (Z_MEM_ERROR): |
| 20475 | 311 Py_DECREF(self); |
| 312 PyErr_SetString(PyExc_MemoryError, | |
| 313 "Can't allocate memory for compression object"); | |
| 314 return NULL; | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
315 case(Z_STREAM_ERROR): |
| 20475 | 316 Py_DECREF(self); |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
317 PyErr_SetString(PyExc_ValueError, "Invalid initialization option"); |
| 20475 | 318 return NULL; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
319 default: |
|
20474
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
320 zlib_error(self->zst, err, "while creating compression object"); |
|
10028
167adf31786d
Added missing DECREF's in the error branches when creating a compressor or
Andrew M. Kuchling <amk@amk.ca>
parents:
9995
diff
changeset
|
321 Py_DECREF(self); |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 return NULL; |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
323 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
324 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
325 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
326 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
327 PyZlib_decompressobj(PyObject *selfptr, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
328 { |
| 20475 | 329 int wbits=DEF_WBITS, err; |
| 330 compobject *self; | |
| 331 if (!PyArg_ParseTuple(args, "|i:decompressobj", &wbits)) | |
| 332 return NULL; | |
| 333 | |
| 334 self = newcompobject(&Decomptype); | |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
335 if (self == NULL) |
| 20475 | 336 return(NULL); |
| 337 self->zst.zalloc = (alloc_func)NULL; | |
| 338 self->zst.zfree = (free_func)Z_NULL; | |
| 339 err = inflateInit2(&self->zst, wbits); | |
| 340 switch(err) { | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
341 case (Z_OK): |
| 20475 | 342 self->is_initialised = 1; |
| 343 return (PyObject*)self; | |
| 6236 | 344 case(Z_STREAM_ERROR): |
| 20475 | 345 Py_DECREF(self); |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
346 PyErr_SetString(PyExc_ValueError, "Invalid initialization option"); |
| 20475 | 347 return NULL; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
348 case (Z_MEM_ERROR): |
| 20475 | 349 Py_DECREF(self); |
| 350 PyErr_SetString(PyExc_MemoryError, | |
| 351 "Can't allocate memory for decompression object"); | |
| 352 return NULL; | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
353 default: |
|
20474
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
354 zlib_error(self->zst, err, "while creating decompression object"); |
|
10028
167adf31786d
Added missing DECREF's in the error branches when creating a compressor or
Andrew M. Kuchling <amk@amk.ca>
parents:
9995
diff
changeset
|
355 Py_DECREF(self); |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
356 return NULL; |
| 20475 | 357 } |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
358 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
359 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
360 static void |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
361 Comp_dealloc(compobject *self) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
362 { |
|
10028
167adf31786d
Added missing DECREF's in the error branches when creating a compressor or
Andrew M. Kuchling <amk@amk.ca>
parents:
9995
diff
changeset
|
363 if (self->is_initialised) |
| 20475 | 364 deflateEnd(&self->zst); |
|
10467
255abab3c574
Add an .unused_data attribute to decompressor objects. If .unused_data
Andrew M. Kuchling <amk@amk.ca>
parents:
10440
diff
changeset
|
365 Py_XDECREF(self->unused_data); |
|
20466
60e12f83d2d2
[ #403753 ] zlib decompress; uncontrollable memory usage
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20327
diff
changeset
|
366 Py_XDECREF(self->unconsumed_tail); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12255
diff
changeset
|
367 PyObject_Del(self); |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
368 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
369 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
370 static void |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
371 Decomp_dealloc(compobject *self) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
372 { |
|
16718
01c2470eeb2e
Patch #103373 from Donovan Baarda: This patch:
Andrew M. Kuchling <amk@amk.ca>
parents:
16369
diff
changeset
|
373 if (self->is_initialised) |
| 20475 | 374 inflateEnd(&self->zst); |
|
10467
255abab3c574
Add an .unused_data attribute to decompressor objects. If .unused_data
Andrew M. Kuchling <amk@amk.ca>
parents:
10440
diff
changeset
|
375 Py_XDECREF(self->unused_data); |
|
20466
60e12f83d2d2
[ #403753 ] zlib decompress; uncontrollable memory usage
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20327
diff
changeset
|
376 Py_XDECREF(self->unconsumed_tail); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12255
diff
changeset
|
377 PyObject_Del(self); |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
378 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
379 |
| 5722 | 380 static char comp_compress__doc__[] = |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
381 "compress(data) -- Return a string containing data compressed.\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
382 "\n" |
| 5722 | 383 "After calling this function, some of the input data may still\n" |
| 384 "be stored in internal buffers for later processing.\n" | |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
385 "Call the flush() method to clear these buffers."; |
| 5722 | 386 |
| 387 | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
388 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
389 PyZlib_objcompress(compobject *self, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
390 { |
| 20469 | 391 int err, inplen, length = DEFAULTALLOC; |
| 392 PyObject *RetVal; | |
| 393 Byte *input; | |
| 394 unsigned long start_total_out; | |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
395 |
|
20478
071cfee8d8eb
Undo needless INCREF chicanery introduced by SF patch #450702.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20477
diff
changeset
|
396 if (!PyArg_ParseTuple(args, "s#:compress", &input, &inplen)) |
| 20469 | 397 return NULL; |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
398 |
|
20470
8964ef84c92f
Remove many calls to set MemoryError exceptions.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20469
diff
changeset
|
399 if (!(RetVal = PyString_FromStringAndSize(NULL, length))) |
| 20469 | 400 return NULL; |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
401 |
| 20469 | 402 ENTER_ZLIB |
| 403 | |
| 404 start_total_out = self->zst.total_out; | |
| 405 self->zst.avail_in = inplen; | |
| 406 self->zst.next_in = input; | |
|
16718
01c2470eeb2e
Patch #103373 from Donovan Baarda: This patch:
Andrew M. Kuchling <amk@amk.ca>
parents:
16369
diff
changeset
|
407 self->zst.avail_out = length; |
|
20478
071cfee8d8eb
Undo needless INCREF chicanery introduced by SF patch #450702.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20477
diff
changeset
|
408 self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal); |
| 20469 | 409 |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
410 Py_BEGIN_ALLOW_THREADS |
|
16718
01c2470eeb2e
Patch #103373 from Donovan Baarda: This patch:
Andrew M. Kuchling <amk@amk.ca>
parents:
16369
diff
changeset
|
411 err = deflate(&(self->zst), Z_NO_FLUSH); |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
412 Py_END_ALLOW_THREADS |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
413 |
| 20469 | 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) { | |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
417 if (_PyString_Resize(&RetVal, length << 1) == -1) { |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
418 RetVal = NULL; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
419 goto error; |
| 20469 | 420 } |
|
20478
071cfee8d8eb
Undo needless INCREF chicanery introduced by SF patch #450702.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20477
diff
changeset
|
421 self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \ |
| 20469 | 422 + length; |
| 423 self->zst.avail_out = length; | |
| 424 length = length << 1; | |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
425 |
| 20469 | 426 Py_BEGIN_ALLOW_THREADS |
| 427 err = deflate(&(self->zst), Z_NO_FLUSH); | |
| 428 Py_END_ALLOW_THREADS | |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
429 } |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
430 /* We will only get Z_BUF_ERROR if the output buffer was full but |
| 20469 | 431 there wasn't more output when we tried again, so it is not an error |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
432 condition. |
|
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
433 */ |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
434 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
435 if (err != Z_OK && err != Z_BUF_ERROR) { |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
436 zlib_error(self->zst, err, "while compressing"); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
437 Py_DECREF(RetVal); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
438 RetVal = NULL; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
439 goto error; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
440 } |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
441 if (_PyString_Resize(&RetVal, |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
442 self->zst.total_out - start_total_out) < 0) |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
443 RetVal = NULL; |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
444 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
445 error: |
| 20469 | 446 LEAVE_ZLIB |
| 447 return RetVal; | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
448 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
449 |
| 5722 | 450 static char decomp_decompress__doc__[] = |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
451 "decompress(data, max_length) -- Return a string containing the decompressed\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
452 "version of the data.\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
453 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
454 "After calling this function, some of the input data may still be stored in\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
455 "internal buffers for later processing.\n" |
|
20466
60e12f83d2d2
[ #403753 ] zlib decompress; uncontrollable memory usage
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20327
diff
changeset
|
456 "Call the flush() method to clear these buffers.\n" |
|
60e12f83d2d2
[ #403753 ] zlib decompress; uncontrollable memory usage
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20327
diff
changeset
|
457 "If the max_length parameter is specified then the return value will be\n" |
|
60e12f83d2d2
[ #403753 ] zlib decompress; uncontrollable memory usage
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20327
diff
changeset
|
458 "no longer than max_length. Unconsumed input data will be stored in\n" |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
459 "the unconsumed_tail attribute."; |
| 5722 | 460 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
461 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
462 PyZlib_objdecompress(compobject *self, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
463 { |
| 20469 | 464 int err, inplen, old_length, length = DEFAULTALLOC; |
| 465 int max_length = 0; | |
| 466 PyObject *RetVal; | |
| 467 Byte *input; | |
| 468 unsigned long start_total_out; | |
|
20466
60e12f83d2d2
[ #403753 ] zlib decompress; uncontrollable memory usage
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20327
diff
changeset
|
469 |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
470 if (!PyArg_ParseTuple(args, "s#|i:decompress", &input, |
|
20478
071cfee8d8eb
Undo needless INCREF chicanery introduced by SF patch #450702.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20477
diff
changeset
|
471 &inplen, &max_length)) |
| 20469 | 472 return NULL; |
| 473 if (max_length < 0) { | |
| 474 PyErr_SetString(PyExc_ValueError, | |
| 475 "max_length must be greater than zero"); | |
| 476 return NULL; | |
| 477 } | |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
478 |
| 20469 | 479 /* limit amount of data allocated to max_length */ |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
480 if (max_length && length > max_length) |
| 20469 | 481 length = max_length; |
|
20470
8964ef84c92f
Remove many calls to set MemoryError exceptions.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20469
diff
changeset
|
482 if (!(RetVal = PyString_FromStringAndSize(NULL, length))) |
| 20469 | 483 return NULL; |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
484 |
| 20469 | 485 ENTER_ZLIB |
| 486 | |
| 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; | |
|
20478
071cfee8d8eb
Undo needless INCREF chicanery introduced by SF patch #450702.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20477
diff
changeset
|
491 self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal); |
|
20466
60e12f83d2d2
[ #403753 ] zlib decompress; uncontrollable memory usage
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20327
diff
changeset
|
492 |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
493 Py_BEGIN_ALLOW_THREADS |
|
16718
01c2470eeb2e
Patch #103373 from Donovan Baarda: This patch:
Andrew M. Kuchling <amk@amk.ca>
parents:
16369
diff
changeset
|
494 err = inflate(&(self->zst), Z_SYNC_FLUSH); |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
495 Py_END_ALLOW_THREADS |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
496 |
| 20469 | 497 /* While Z_OK and the output buffer is full, there might be more output. |
| 498 So extend the output buffer and try again. | |
| 499 */ | |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
500 while (err == Z_OK && self->zst.avail_out == 0) { |
| 20469 | 501 /* If max_length set, don't continue decompressing if we've already |
| 502 reached the limit. | |
| 503 */ | |
| 504 if (max_length && length >= max_length) | |
| 505 break; | |
| 506 | |
| 507 /* otherwise, ... */ | |
| 508 old_length = length; | |
| 509 length = length << 1; | |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
510 if (max_length && length > max_length) |
| 20469 | 511 length = max_length; |
|
20466
60e12f83d2d2
[ #403753 ] zlib decompress; uncontrollable memory usage
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20327
diff
changeset
|
512 |
| 20469 | 513 if (_PyString_Resize(&RetVal, length) == -1) { |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
514 RetVal = NULL; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
515 goto error; |
| 20469 | 516 } |
|
20478
071cfee8d8eb
Undo needless INCREF chicanery introduced by SF patch #450702.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20477
diff
changeset
|
517 self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \ |
| 20469 | 518 + old_length; |
| 519 self->zst.avail_out = length - old_length; | |
| 520 | |
| 521 Py_BEGIN_ALLOW_THREADS | |
| 522 err = inflate(&(self->zst), Z_SYNC_FLUSH); | |
| 523 Py_END_ALLOW_THREADS | |
| 524 } | |
| 525 | |
| 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.*/ | |
| 528 if(max_length) { | |
| 529 Py_DECREF(self->unconsumed_tail); | |
| 20644 | 530 self->unconsumed_tail = PyString_FromStringAndSize((char *)self->zst.next_in, |
| 20469 | 531 self->zst.avail_in); |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
532 if(!self->unconsumed_tail) { |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
533 Py_DECREF(RetVal); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
534 RetVal = NULL; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
535 goto error; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
536 } |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
537 } |
| 20469 | 538 |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
539 /* The end of the compressed data has been reached, so set the |
|
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
540 unused_data attribute to a string containing the remainder of the |
|
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
541 data in the string. Note that this is also a logical place to call |
| 20469 | 542 inflateEnd, but the old behaviour of only calling it on flush() is |
| 543 preserved. | |
| 544 */ | |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
545 if (err == Z_STREAM_END) { |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
546 Py_XDECREF(self->unused_data); /* Free original empty string */ |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
547 self->unused_data = PyString_FromStringAndSize( |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
548 (char *)self->zst.next_in, self->zst.avail_in); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
549 if (self->unused_data == NULL) { |
| 20469 | 550 Py_DECREF(RetVal); |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
551 goto error; |
| 20469 | 552 } |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
553 /* We will only get Z_BUF_ERROR if the output buffer was full |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
554 but there wasn't more output when we tried again, so it is |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
555 not an error condition. |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
556 */ |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
557 } else if (err != Z_OK && err != Z_BUF_ERROR) { |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
558 zlib_error(self->zst, err, "while decompressing"); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
559 Py_DECREF(RetVal); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
560 RetVal = NULL; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
561 goto error; |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
562 } |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
563 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
564 if (_PyString_Resize(&RetVal, self->zst.total_out - start_total_out) < 0) |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
565 RetVal = NULL; |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
566 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
567 error: |
| 20469 | 568 LEAVE_ZLIB |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
569 |
| 20469 | 570 return RetVal; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
571 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
572 |
| 5722 | 573 static char comp_flush__doc__[] = |
| 9657 | 574 "flush( [mode] ) -- Return a string containing any remaining compressed data.\n" |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
575 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
576 "mode can be one of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH; the\n" |
| 9657 | 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" | |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
579 "calling the flush() method. Otherwise, more data can still be compressed.\n"; |
| 5722 | 580 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
581 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
582 PyZlib_flush(compobject *self, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
583 { |
| 20469 | 584 int err, length = DEFAULTALLOC; |
| 585 PyObject *RetVal; | |
| 586 int flushmode = Z_FINISH; | |
| 587 unsigned long start_total_out; | |
| 9657 | 588 |
| 20469 | 589 if (!PyArg_ParseTuple(args, "|i:flush", &flushmode)) |
| 590 return NULL; | |
| 9657 | 591 |
| 20469 | 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); | |
| 596 } | |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
597 |
|
20470
8964ef84c92f
Remove many calls to set MemoryError exceptions.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20469
diff
changeset
|
598 if (!(RetVal = PyString_FromStringAndSize(NULL, length))) |
| 20469 | 599 return NULL; |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
600 |
| 20469 | 601 ENTER_ZLIB |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
602 |
| 20469 | 603 start_total_out = self->zst.total_out; |
| 604 self->zst.avail_in = 0; | |
|
16718
01c2470eeb2e
Patch #103373 from Donovan Baarda: This patch:
Andrew M. Kuchling <amk@amk.ca>
parents:
16369
diff
changeset
|
605 self->zst.avail_out = length; |
|
20478
071cfee8d8eb
Undo needless INCREF chicanery introduced by SF patch #450702.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20477
diff
changeset
|
606 self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal); |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
607 |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
608 Py_BEGIN_ALLOW_THREADS |
|
16718
01c2470eeb2e
Patch #103373 from Donovan Baarda: This patch:
Andrew M. Kuchling <amk@amk.ca>
parents:
16369
diff
changeset
|
609 err = deflate(&(self->zst), flushmode); |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
610 Py_END_ALLOW_THREADS |
| 20469 | 611 |
| 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) { | |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
616 RetVal = NULL; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
617 goto error; |
| 20469 | 618 } |
|
20478
071cfee8d8eb
Undo needless INCREF chicanery introduced by SF patch #450702.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20477
diff
changeset
|
619 self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \ |
| 20469 | 620 + length; |
| 621 self->zst.avail_out = length; | |
| 622 length = length << 1; | |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
623 |
| 20469 | 624 Py_BEGIN_ALLOW_THREADS |
| 625 err = deflate(&(self->zst), flushmode); | |
| 626 Py_END_ALLOW_THREADS | |
| 627 } | |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
628 |
| 20469 | 629 /* If flushmode is Z_FINISH, we also have to call deflateEnd() to free |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
630 various data structures. Note we should only get Z_STREAM_END when |
| 20469 | 631 flushmode is Z_FINISH, but checking both for safety*/ |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
632 if (err == Z_STREAM_END && flushmode == Z_FINISH) { |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
633 err = deflateEnd(&(self->zst)); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
634 if (err != Z_OK) { |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
635 zlib_error(self->zst, err, "from deflateEnd()"); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
636 Py_DECREF(RetVal); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
637 RetVal = NULL; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
638 goto error; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
639 } |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
640 else |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
641 self->is_initialised = 0; |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
642 |
|
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
643 /* We will only get Z_BUF_ERROR if the output buffer was full |
|
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
644 but there wasn't more output when we tried again, so it is |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
645 not an error condition. |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
646 */ |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
647 } else if (err!=Z_OK && err!=Z_BUF_ERROR) { |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
648 zlib_error(self->zst, err, "while flushing"); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
649 Py_DECREF(RetVal); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
650 RetVal = NULL; |
|
23171
d5ce7ff531bd
[backport bug fix from the trunk]
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21313
diff
changeset
|
651 goto error; |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
652 } |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
653 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
654 if (_PyString_Resize(&RetVal, self->zst.total_out - start_total_out) < 0) |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
655 RetVal = NULL; |
| 20469 | 656 |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
657 error: |
|
20483
5d678356c894
Removed more comments that didn't make much sense.
Tim Peters <tim.peters@gmail.com>
parents:
20482
diff
changeset
|
658 LEAVE_ZLIB |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
659 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
660 return RetVal; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
661 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
662 |
| 5722 | 663 static char decomp_flush__doc__[] = |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
664 "flush() -- Return a string containing any remaining decompressed data.\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
665 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
666 "The decompressor object can no longer be used after this call."; |
| 5722 | 667 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
668 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
669 PyZlib_unflush(compobject *self, PyObject *args) |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
670 /*decompressor flush is a no-op because all pending data would have been |
|
16718
01c2470eeb2e
Patch #103373 from Donovan Baarda: This patch:
Andrew M. Kuchling <amk@amk.ca>
parents:
16369
diff
changeset
|
671 flushed by the decompress method. However, this routine previously called |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
672 inflateEnd, causing any further decompress or flush calls to raise |
|
16718
01c2470eeb2e
Patch #103373 from Donovan Baarda: This patch:
Andrew M. Kuchling <amk@amk.ca>
parents:
16369
diff
changeset
|
673 exceptions. This behaviour has been preserved.*/ |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
674 { |
| 20469 | 675 int err; |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
676 PyObject * retval = NULL; |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
677 |
| 20469 | 678 if (!PyArg_ParseTuple(args, "")) |
| 679 return NULL; | |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
680 |
| 20469 | 681 ENTER_ZLIB |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
682 |
| 20469 | 683 err = inflateEnd(&(self->zst)); |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
684 if (err != Z_OK) |
|
20474
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
685 zlib_error(self->zst, err, "from inflateEnd()"); |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
686 else { |
| 20469 | 687 self->is_initialised = 0; |
| 688 retval = PyString_FromStringAndSize(NULL, 0); | |
| 689 } | |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
690 |
| 20469 | 691 LEAVE_ZLIB |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
692 |
| 20469 | 693 return retval; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
694 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
695 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
696 static PyMethodDef comp_methods[] = |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
697 { |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
698 {"compress", (binaryfunc)PyZlib_objcompress, METH_VARARGS, |
| 20469 | 699 comp_compress__doc__}, |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
700 {"flush", (binaryfunc)PyZlib_flush, METH_VARARGS, |
| 20469 | 701 comp_flush__doc__}, |
| 702 {NULL, NULL} | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
703 }; |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
704 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
705 static PyMethodDef Decomp_methods[] = |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
706 { |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
707 {"decompress", (binaryfunc)PyZlib_objdecompress, METH_VARARGS, |
| 20469 | 708 decomp_decompress__doc__}, |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
709 {"flush", (binaryfunc)PyZlib_unflush, METH_VARARGS, |
| 20469 | 710 decomp_flush__doc__}, |
| 711 {NULL, NULL} | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
712 }; |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
713 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
714 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
715 Comp_getattr(compobject *self, char *name) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
716 { |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
717 /* No ENTER/LEAVE_ZLIB is necessary because this fn doesn't touch |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
718 internal data. */ |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
719 |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
720 return Py_FindMethod(comp_methods, (PyObject *)self, name); |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
721 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
722 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
723 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
724 Decomp_getattr(compobject *self, char *name) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
725 { |
| 20469 | 726 PyObject * retval; |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
727 |
| 20469 | 728 ENTER_ZLIB |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
729 |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
730 if (strcmp(name, "unused_data") == 0) { |
| 20469 | 731 Py_INCREF(self->unused_data); |
| 732 retval = self->unused_data; | |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
733 } else if (strcmp(name, "unconsumed_tail") == 0) { |
| 20469 | 734 Py_INCREF(self->unconsumed_tail); |
| 735 retval = self->unconsumed_tail; | |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
736 } else |
| 20469 | 737 retval = Py_FindMethod(Decomp_methods, (PyObject *)self, name); |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
738 |
| 20469 | 739 LEAVE_ZLIB |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
740 |
| 20469 | 741 return retval; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
742 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
743 |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
744 static char adler32__doc__[] = |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
745 "adler32(string[, start]) -- Compute an Adler-32 checksum of string.\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
746 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
747 "An optional starting value can be specified. The returned checksum is\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
748 "an integer."; |
| 5722 | 749 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
750 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
751 PyZlib_adler32(PyObject *self, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
752 { |
| 20469 | 753 uLong adler32val = adler32(0L, Z_NULL, 0); |
| 6236 | 754 Byte *buf; |
| 755 int len; | |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
756 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11619
diff
changeset
|
757 if (!PyArg_ParseTuple(args, "s#|l:adler32", &buf, &len, &adler32val)) |
| 6236 | 758 return NULL; |
| 759 adler32val = adler32(adler32val, buf, len); | |
| 760 return PyInt_FromLong(adler32val); | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
761 } |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
762 |
|
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
763 static char crc32__doc__[] = |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
764 "crc32(string[, start]) -- Compute a CRC-32 checksum of string.\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
765 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
766 "An optional starting value can be specified. The returned checksum is\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
767 "an integer."; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
768 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
769 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
770 PyZlib_crc32(PyObject *self, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
771 { |
| 20469 | 772 uLong crc32val = crc32(0L, Z_NULL, 0); |
| 6236 | 773 Byte *buf; |
| 774 int len; | |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11619
diff
changeset
|
775 if (!PyArg_ParseTuple(args, "s#|l:crc32", &buf, &len, &crc32val)) |
| 6236 | 776 return NULL; |
| 777 crc32val = crc32(crc32val, buf, len); | |
| 778 return PyInt_FromLong(crc32val); | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
779 } |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
780 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
781 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
782 static PyMethodDef zlib_methods[] = |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
783 { |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
784 {"adler32", (PyCFunction)PyZlib_adler32, METH_VARARGS, |
| 20469 | 785 adler32__doc__}, |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
786 {"compress", (PyCFunction)PyZlib_compress, METH_VARARGS, |
| 20469 | 787 compress__doc__}, |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
788 {"compressobj", (PyCFunction)PyZlib_compressobj, METH_VARARGS, |
| 20469 | 789 compressobj__doc__}, |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
790 {"crc32", (PyCFunction)PyZlib_crc32, METH_VARARGS, |
|
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
791 crc32__doc__}, |
|
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
792 {"decompress", (PyCFunction)PyZlib_decompress, METH_VARARGS, |
| 20469 | 793 decompress__doc__}, |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
794 {"decompressobj", (PyCFunction)PyZlib_decompressobj, METH_VARARGS, |
| 20469 | 795 decompressobj__doc__}, |
| 796 {NULL, NULL} | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
797 }; |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
798 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
799 statichere PyTypeObject Comptype = { |
| 20469 | 800 PyObject_HEAD_INIT(0) |
| 801 0, | |
|
21313
91dd223829c6
Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents:
20644
diff
changeset
|
802 "zlib.Compress", |
| 20469 | 803 sizeof(compobject), |
| 804 0, | |
| 805 (destructor)Comp_dealloc, /*tp_dealloc*/ | |
| 806 0, /*tp_print*/ | |
| 807 (getattrfunc)Comp_getattr, /*tp_getattr*/ | |
| 808 0, /*tp_setattr*/ | |
| 809 0, /*tp_compare*/ | |
| 810 0, /*tp_repr*/ | |
| 811 0, /*tp_as_number*/ | |
| 812 0, /*tp_as_sequence*/ | |
| 813 0, /*tp_as_mapping*/ | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
814 }; |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
815 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
816 statichere PyTypeObject Decomptype = { |
| 20469 | 817 PyObject_HEAD_INIT(0) |
| 818 0, | |
|
21313
91dd223829c6
Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents:
20644
diff
changeset
|
819 "zlib.Decompress", |
| 20469 | 820 sizeof(compobject), |
| 821 0, | |
| 822 (destructor)Decomp_dealloc, /*tp_dealloc*/ | |
| 823 0, /*tp_print*/ | |
| 824 (getattrfunc)Decomp_getattr, /*tp_getattr*/ | |
| 825 0, /*tp_setattr*/ | |
| 826 0, /*tp_compare*/ | |
| 827 0, /*tp_repr*/ | |
| 828 0, /*tp_as_number*/ | |
| 829 0, /*tp_as_sequence*/ | |
| 830 0, /*tp_as_mapping*/ | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
831 }; |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
832 |
| 5722 | 833 static char zlib_module_documentation[]= |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
834 "The functions in this module allow compression and decompression using the\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
835 "zlib library, which is based on GNU zip.\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
836 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
837 "adler32(string[, start]) -- Compute an Adler-32 checksum.\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
838 "compress(string[, level]) -- Compress string, with compression level in 1-9.\n" |
| 5722 | 839 "compressobj([level]) -- Return a compressor object.\n" |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
840 "crc32(string[, start]) -- Compute a CRC-32 checksum.\n" |
|
11607
69216c11a1bd
Fix typo in docstring: wbites -> wbits
Andrew M. Kuchling <amk@amk.ca>
parents:
10571
diff
changeset
|
841 "decompress(string,[wbits],[bufsize]) -- Decompresses a compressed string.\n" |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
842 "decompressobj([wbits]) -- Return a decompressor object.\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
843 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
844 "'wbits' is window buffer size.\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
845 "Compressor objects support compress() and flush() methods; decompressor\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
846 "objects support decompress() and flush()."; |
| 5722 | 847 |
|
9588
38023a425e48
Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents:
8636
diff
changeset
|
848 DL_EXPORT(void) |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13496
diff
changeset
|
849 PyInit_zlib(void) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
850 { |
| 20469 | 851 PyObject *m, *d, *ver; |
| 852 Comptype.ob_type = &PyType_Type; | |
| 853 Decomptype.ob_type = &PyType_Type; | |
| 854 m = Py_InitModule4("zlib", zlib_methods, | |
| 855 zlib_module_documentation, | |
| 856 (PyObject*)NULL,PYTHON_API_VERSION); | |
| 857 d = PyModule_GetDict(m); | |
| 858 ZlibError = PyErr_NewException("zlib.error", NULL, NULL); | |
| 859 if (ZlibError != NULL) | |
| 860 PyDict_SetItemString(d, "error", ZlibError); | |
| 6236 | 861 |
| 20469 | 862 PyModule_AddIntConstant(m, "MAX_WBITS", MAX_WBITS); |
| 863 PyModule_AddIntConstant(m, "DEFLATED", DEFLATED); | |
| 864 PyModule_AddIntConstant(m, "DEF_MEM_LEVEL", DEF_MEM_LEVEL); | |
| 865 PyModule_AddIntConstant(m, "Z_BEST_SPEED", Z_BEST_SPEED); | |
| 866 PyModule_AddIntConstant(m, "Z_BEST_COMPRESSION", Z_BEST_COMPRESSION); | |
| 867 PyModule_AddIntConstant(m, "Z_DEFAULT_COMPRESSION", Z_DEFAULT_COMPRESSION); | |
| 868 PyModule_AddIntConstant(m, "Z_FILTERED", Z_FILTERED); | |
| 869 PyModule_AddIntConstant(m, "Z_HUFFMAN_ONLY", Z_HUFFMAN_ONLY); | |
| 870 PyModule_AddIntConstant(m, "Z_DEFAULT_STRATEGY", Z_DEFAULT_STRATEGY); | |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
871 |
| 20469 | 872 PyModule_AddIntConstant(m, "Z_FINISH", Z_FINISH); |
| 873 PyModule_AddIntConstant(m, "Z_NO_FLUSH", Z_NO_FLUSH); | |
| 874 PyModule_AddIntConstant(m, "Z_SYNC_FLUSH", Z_SYNC_FLUSH); | |
| 875 PyModule_AddIntConstant(m, "Z_FULL_FLUSH", Z_FULL_FLUSH); | |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
876 |
| 20469 | 877 ver = PyString_FromString(ZLIB_VERSION); |
| 878 if (ver != NULL) { | |
| 879 PyDict_SetItemString(d, "ZLIB_VERSION", ver); | |
| 880 Py_DECREF(ver); | |
| 881 } | |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
882 |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
883 #ifdef WITH_THREAD |
| 20469 | 884 zlib_lock = PyThread_allocate_lock(); |
|
19798
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
885 #endif // WITH_THREAD |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
886 } |
