Mercurial > cpython-lru_cache-weakref
annotate Modules/zlibmodule.c @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | f6c4c178da56 |
| 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 \ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
31 Py_BEGIN_ALLOW_THREADS \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
32 PyThread_acquire_lock(zlib_lock, 1); \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
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 \ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
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 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
58 static PyTypeObject Comptype; |
|
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
59 static PyTypeObject Decomptype; |
|
5352
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 { |
|
72110
ba5000307b5d
Issue #12839: Fix crash in zlib module due to version mismatch.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
70102
diff
changeset
|
75 const char *zmsg = Z_NULL; |
|
ba5000307b5d
Issue #12839: Fix crash in zlib module due to version mismatch.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
70102
diff
changeset
|
76 /* In case of a version mismatch, zst.msg won't be initialized. |
|
ba5000307b5d
Issue #12839: Fix crash in zlib module due to version mismatch.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
70102
diff
changeset
|
77 Check for this case first, before looking at zst.msg. */ |
|
ba5000307b5d
Issue #12839: Fix crash in zlib module due to version mismatch.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
70102
diff
changeset
|
78 if (err == Z_VERSION_ERROR) |
|
ba5000307b5d
Issue #12839: Fix crash in zlib module due to version mismatch.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
70102
diff
changeset
|
79 zmsg = "library version mismatch"; |
|
ba5000307b5d
Issue #12839: Fix crash in zlib module due to version mismatch.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
70102
diff
changeset
|
80 if (zmsg == Z_NULL) |
|
ba5000307b5d
Issue #12839: Fix crash in zlib module due to version mismatch.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
70102
diff
changeset
|
81 zmsg = zst.msg; |
|
61521
3a8ca67ae431
Issue #8681: Make the zlib module's error messages more informative when
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
82 if (zmsg == Z_NULL) { |
|
3a8ca67ae431
Issue #8681: Make the zlib module's error messages more informative when
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
83 switch (err) { |
|
3a8ca67ae431
Issue #8681: Make the zlib module's error messages more informative when
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
84 case Z_BUF_ERROR: |
|
3a8ca67ae431
Issue #8681: Make the zlib module's error messages more informative when
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
85 zmsg = "incomplete or truncated stream"; |
|
3a8ca67ae431
Issue #8681: Make the zlib module's error messages more informative when
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
86 break; |
|
3a8ca67ae431
Issue #8681: Make the zlib module's error messages more informative when
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
87 case Z_STREAM_ERROR: |
|
3a8ca67ae431
Issue #8681: Make the zlib module's error messages more informative when
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
88 zmsg = "inconsistent stream state"; |
|
3a8ca67ae431
Issue #8681: Make the zlib module's error messages more informative when
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
89 break; |
|
3a8ca67ae431
Issue #8681: Make the zlib module's error messages more informative when
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
90 case Z_DATA_ERROR: |
|
3a8ca67ae431
Issue #8681: Make the zlib module's error messages more informative when
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
91 zmsg = "invalid input data"; |
|
3a8ca67ae431
Issue #8681: Make the zlib module's error messages more informative when
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
92 break; |
|
3a8ca67ae431
Issue #8681: Make the zlib module's error messages more informative when
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
93 } |
|
3a8ca67ae431
Issue #8681: Make the zlib module's error messages more informative when
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
94 } |
|
3a8ca67ae431
Issue #8681: Make the zlib module's error messages more informative when
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
95 if (zmsg == Z_NULL) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
96 PyErr_Format(ZlibError, "Error %d %s", err, msg); |
|
20474
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
97 else |
|
61521
3a8ca67ae431
Issue #8681: Make the zlib module's error messages more informative when
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
98 PyErr_Format(ZlibError, "Error %d %s: %.200s", err, msg, zmsg); |
|
20474
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
99 } |
|
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
100 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
101 PyDoc_STRVAR(compressobj__doc__, |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
102 "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
|
103 "\n" |
|
80385
f6c4c178da56
Issue #15677: Also fix docstrings in zlib module.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80357
diff
changeset
|
104 "Optional arg level is the compression level, in 0-9."); |
| 5722 | 105 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
106 PyDoc_STRVAR(decompressobj__doc__, |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
107 "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
|
108 "\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
109 "Optional arg wbits is the window buffer size."); |
| 5722 | 110 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 static compobject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
112 newcompobject(PyTypeObject *type) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 { |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
114 compobject *self; |
| 20469 | 115 self = PyObject_New(compobject, type); |
| 116 if (self == NULL) | |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
117 return NULL; |
| 20469 | 118 self->is_initialised = 0; |
| 119 self->unused_data = PyString_FromString(""); | |
| 120 if (self->unused_data == NULL) { | |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
121 Py_DECREF(self); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
122 return NULL; |
| 20469 | 123 } |
| 124 self->unconsumed_tail = PyString_FromString(""); | |
| 125 if (self->unconsumed_tail == NULL) { | |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
126 Py_DECREF(self); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
127 return NULL; |
| 20469 | 128 } |
| 129 return self; | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
132 PyDoc_STRVAR(compress__doc__, |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
133 "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
|
134 "\n" |
|
80385
f6c4c178da56
Issue #15677: Also fix docstrings in zlib module.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80357
diff
changeset
|
135 "Optional arg level is the compression level, in 0-9."); |
| 5722 | 136 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
138 PyZlib_compress(PyObject *self, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 { |
| 20469 | 140 PyObject *ReturnVal = NULL; |
| 141 Byte *input, *output; | |
| 142 int length, level=Z_DEFAULT_COMPRESSION, err; | |
| 143 z_stream zst; | |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
144 |
| 20469 | 145 /* 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
|
146 if (!PyArg_ParseTuple(args, "s#|i:compress", &input, &length, &level)) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
147 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
|
148 |
| 20469 | 149 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
|
150 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
151 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
|
152 if (output == NULL) { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
153 PyErr_SetString(PyExc_MemoryError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
154 "Can't allocate memory to compress data"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
155 return NULL; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
156 } |
| 9657 | 157 |
| 20469 | 158 /* Past the point of no return. From here on out, we need to make sure |
| 159 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
|
160 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
161 zst.zalloc = (alloc_func)NULL; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
162 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
|
163 zst.next_out = (Byte *)output; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
164 zst.next_in = (Byte *)input; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
165 zst.avail_in = length; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
166 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
|
167 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
168 switch(err) { |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
169 case(Z_OK): |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
170 break; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
171 case(Z_MEM_ERROR): |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
172 PyErr_SetString(PyExc_MemoryError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
173 "Out of memory while compressing data"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
174 goto error; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
175 case(Z_STREAM_ERROR): |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
176 PyErr_SetString(ZlibError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
177 "Bad compression level"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
178 goto error; |
|
20474
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
179 default: |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 deflateEnd(&zst); |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
181 zlib_error(zst, err, "while compressing data"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
182 goto error; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
183 } |
|
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 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
185 Py_BEGIN_ALLOW_THREADS; |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
186 err = deflate(&zst, Z_FINISH); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
187 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
|
188 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
189 if (err != Z_STREAM_END) { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
190 zlib_error(zst, err, "while compressing data"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
191 deflateEnd(&zst); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
192 goto error; |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
193 } |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
194 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
195 err=deflateEnd(&zst); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
196 if (err == Z_OK) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
197 ReturnVal = PyString_FromStringAndSize((char *)output, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
198 zst.total_out); |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
199 else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
200 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
|
201 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
202 error: |
| 20469 | 203 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
|
204 |
| 20469 | 205 return ReturnVal; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
208 PyDoc_STRVAR(decompress__doc__, |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
209 "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
|
210 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
211 "Optional arg wbits is the window buffer size. Optional arg bufsize is\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
212 "the initial output buffer size."); |
| 5722 | 213 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
215 PyZlib_decompress(PyObject *self, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 { |
| 20469 | 217 PyObject *result_str; |
| 218 Byte *input; | |
| 219 int length, err; | |
|
43936
38b1deb4e4eb
Fixed #1372: zlibmodule.c: int overflow in PyZlib_decompress
Christian Heimes <christian@cheimes.de>
parents:
38771
diff
changeset
|
220 int wsize=DEF_WBITS; |
|
38b1deb4e4eb
Fixed #1372: zlibmodule.c: int overflow in PyZlib_decompress
Christian Heimes <christian@cheimes.de>
parents:
38771
diff
changeset
|
221 Py_ssize_t r_strlen=DEFAULTALLOC; |
| 20469 | 222 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
|
223 |
|
43936
38b1deb4e4eb
Fixed #1372: zlibmodule.c: int overflow in PyZlib_decompress
Christian Heimes <christian@cheimes.de>
parents:
38771
diff
changeset
|
224 if (!PyArg_ParseTuple(args, "s#|in:decompress", |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
225 &input, &length, &wsize, &r_strlen)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
226 return NULL; |
| 6236 | 227 |
| 20469 | 228 if (r_strlen <= 0) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
229 r_strlen = 1; |
| 9657 | 230 |
| 20469 | 231 zst.avail_in = length; |
| 232 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
|
233 |
|
20470
8964ef84c92f
Remove many calls to set MemoryError exceptions.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20469
diff
changeset
|
234 if (!(result_str = PyString_FromStringAndSize(NULL, r_strlen))) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
235 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
|
236 |
| 20469 | 237 zst.zalloc = (alloc_func)NULL; |
| 238 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
|
239 zst.next_out = (Byte *)PyString_AS_STRING(result_str); |
| 20469 | 240 zst.next_in = (Byte *)input; |
| 241 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
|
242 |
| 20469 | 243 switch(err) { |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
244 case(Z_OK): |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
245 break; |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
246 case(Z_MEM_ERROR): |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
247 PyErr_SetString(PyExc_MemoryError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
248 "Out of memory while decompressing data"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
249 goto error; |
|
20474
a5a30ba2899f
Add zlib_error() helper.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20470
diff
changeset
|
250 default: |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
251 inflateEnd(&zst); |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
252 zlib_error(zst, err, "while preparing to decompress data"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
253 goto error; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
254 } |
|
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
|
255 |
| 20469 | 256 do { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
257 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
258 err=inflate(&zst, Z_FINISH); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
259 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
|
260 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
261 switch(err) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
262 case(Z_STREAM_END): |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
263 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
264 case(Z_BUF_ERROR): |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
265 /* |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
266 * If there is at least 1 byte of room according to zst.avail_out |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
267 * and we get this error, assume that it means zlib cannot |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
268 * process the inflate call() due to an error in the data. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
269 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
270 if (zst.avail_out > 0) { |
|
61521
3a8ca67ae431
Issue #8681: Make the zlib module's error messages more informative when
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
271 zlib_error(zst, err, "while decompressing data"); |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
272 inflateEnd(&zst); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
273 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
274 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
275 /* fall through */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
276 case(Z_OK): |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
277 /* need more memory */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
278 if (_PyString_Resize(&result_str, r_strlen << 1) < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
279 inflateEnd(&zst); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
280 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
281 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
282 zst.next_out = (unsigned char *)PyString_AS_STRING(result_str) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
283 + r_strlen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
284 zst.avail_out = r_strlen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
285 r_strlen = r_strlen << 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
286 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
287 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
288 inflateEnd(&zst); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
289 zlib_error(zst, err, "while decompressing data"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
290 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
291 } |
| 20469 | 292 } 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
|
293 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
294 err = inflateEnd(&zst); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
295 if (err != Z_OK) { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
296 zlib_error(zst, err, "while finishing data decompression"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
297 goto error; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
298 } |
|
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
|
299 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
300 _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
|
301 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
|
302 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
303 error: |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
304 Py_XDECREF(result_str); |
|
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
305 return NULL; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
306 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
307 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
308 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
309 PyZlib_compressobj(PyObject *selfptr, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
310 { |
| 20475 | 311 compobject *self; |
| 312 int level=Z_DEFAULT_COMPRESSION, method=DEFLATED; | |
| 313 int wbits=MAX_WBITS, memLevel=DEF_MEM_LEVEL, strategy=0, err; | |
| 6007 | 314 |
| 20475 | 315 if (!PyArg_ParseTuple(args, "|iiiii:compressobj", &level, &method, &wbits, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
316 &memLevel, &strategy)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
317 return NULL; |
| 6007 | 318 |
| 20475 | 319 self = newcompobject(&Comptype); |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
320 if (self==NULL) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
321 return(NULL); |
| 20475 | 322 self->zst.zalloc = (alloc_func)NULL; |
| 323 self->zst.zfree = (free_func)Z_NULL; | |
|
34264
b2ecda4dd70f
[Bug #1083110] calling .flush() on decompress objects causes a segfault due to an uninitialized pointer: fixes the problem and adds a test case
Andrew M. Kuchling <amk@amk.ca>
parents:
27653
diff
changeset
|
324 self->zst.next_in = NULL; |
|
b2ecda4dd70f
[Bug #1083110] calling .flush() on decompress objects causes a segfault due to an uninitialized pointer: fixes the problem and adds a test case
Andrew M. Kuchling <amk@amk.ca>
parents:
27653
diff
changeset
|
325 self->zst.avail_in = 0; |
| 20475 | 326 err = deflateInit2(&self->zst, level, method, wbits, memLevel, strategy); |
| 327 switch(err) { | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
328 case (Z_OK): |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
329 self->is_initialised = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
330 return (PyObject*)self; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
331 case (Z_MEM_ERROR): |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
332 Py_DECREF(self); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
333 PyErr_SetString(PyExc_MemoryError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
334 "Can't allocate memory for compression object"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
335 return NULL; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
336 case(Z_STREAM_ERROR): |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
337 Py_DECREF(self); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
338 PyErr_SetString(PyExc_ValueError, "Invalid initialization option"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
339 return NULL; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
340 default: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
341 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
|
342 Py_DECREF(self); |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
343 return NULL; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
344 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
345 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
346 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
347 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
348 PyZlib_decompressobj(PyObject *selfptr, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
349 { |
| 20475 | 350 int wbits=DEF_WBITS, err; |
| 351 compobject *self; | |
| 352 if (!PyArg_ParseTuple(args, "|i:decompressobj", &wbits)) | |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
353 return NULL; |
| 20475 | 354 |
| 355 self = newcompobject(&Decomptype); | |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
356 if (self == NULL) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
357 return(NULL); |
| 20475 | 358 self->zst.zalloc = (alloc_func)NULL; |
| 359 self->zst.zfree = (free_func)Z_NULL; | |
|
34264
b2ecda4dd70f
[Bug #1083110] calling .flush() on decompress objects causes a segfault due to an uninitialized pointer: fixes the problem and adds a test case
Andrew M. Kuchling <amk@amk.ca>
parents:
27653
diff
changeset
|
360 self->zst.next_in = NULL; |
|
b2ecda4dd70f
[Bug #1083110] calling .flush() on decompress objects causes a segfault due to an uninitialized pointer: fixes the problem and adds a test case
Andrew M. Kuchling <amk@amk.ca>
parents:
27653
diff
changeset
|
361 self->zst.avail_in = 0; |
| 20475 | 362 err = inflateInit2(&self->zst, wbits); |
| 363 switch(err) { | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
364 case (Z_OK): |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
365 self->is_initialised = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
366 return (PyObject*)self; |
| 6236 | 367 case(Z_STREAM_ERROR): |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
368 Py_DECREF(self); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
369 PyErr_SetString(PyExc_ValueError, "Invalid initialization option"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
370 return NULL; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
371 case (Z_MEM_ERROR): |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
372 Py_DECREF(self); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
373 PyErr_SetString(PyExc_MemoryError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
374 "Can't allocate memory for decompression object"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
375 return NULL; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
376 default: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
377 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
|
378 Py_DECREF(self); |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
379 return NULL; |
| 20475 | 380 } |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
381 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
382 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
383 static void |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
384 Comp_dealloc(compobject *self) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
385 { |
|
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
|
386 if (self->is_initialised) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
387 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
|
388 Py_XDECREF(self->unused_data); |
|
20466
60e12f83d2d2
[ #403753 ] zlib decompress; uncontrollable memory usage
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20327
diff
changeset
|
389 Py_XDECREF(self->unconsumed_tail); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12255
diff
changeset
|
390 PyObject_Del(self); |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
391 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
392 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
393 static void |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
394 Decomp_dealloc(compobject *self) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
395 { |
|
16718
01c2470eeb2e
Patch #103373 from Donovan Baarda: This patch:
Andrew M. Kuchling <amk@amk.ca>
parents:
16369
diff
changeset
|
396 if (self->is_initialised) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
397 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
|
398 Py_XDECREF(self->unused_data); |
|
20466
60e12f83d2d2
[ #403753 ] zlib decompress; uncontrollable memory usage
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20327
diff
changeset
|
399 Py_XDECREF(self->unconsumed_tail); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12255
diff
changeset
|
400 PyObject_Del(self); |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
401 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
402 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
403 PyDoc_STRVAR(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
|
404 "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
|
405 "\n" |
| 5722 | 406 "After calling this function, some of the input data may still\n" |
| 407 "be stored in internal buffers for later processing.\n" | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
408 "Call the flush() method to clear these buffers."); |
| 5722 | 409 |
| 410 | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
411 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
412 PyZlib_objcompress(compobject *self, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
413 { |
|
61368
b602676cadcd
Issue #8571: Fix an internal error when compressing or decompressing a
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
414 int err, inplen; |
|
b602676cadcd
Issue #8571: Fix an internal error when compressing or decompressing a
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
415 Py_ssize_t length = DEFAULTALLOC; |
| 20469 | 416 PyObject *RetVal; |
| 417 Byte *input; | |
| 418 unsigned long start_total_out; | |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
419 |
|
20478
071cfee8d8eb
Undo needless INCREF chicanery introduced by SF patch #450702.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20477
diff
changeset
|
420 if (!PyArg_ParseTuple(args, "s#:compress", &input, &inplen)) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
421 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
|
422 |
|
20470
8964ef84c92f
Remove many calls to set MemoryError exceptions.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20469
diff
changeset
|
423 if (!(RetVal = PyString_FromStringAndSize(NULL, length))) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
424 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
|
425 |
| 20469 | 426 ENTER_ZLIB |
| 427 | |
| 428 start_total_out = self->zst.total_out; | |
| 429 self->zst.avail_in = inplen; | |
| 430 self->zst.next_in = input; | |
|
16718
01c2470eeb2e
Patch #103373 from Donovan Baarda: This patch:
Andrew M. Kuchling <amk@amk.ca>
parents:
16369
diff
changeset
|
431 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
|
432 self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal); |
| 20469 | 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 Py_BEGIN_ALLOW_THREADS |
|
16718
01c2470eeb2e
Patch #103373 from Donovan Baarda: This patch:
Andrew M. Kuchling <amk@amk.ca>
parents:
16369
diff
changeset
|
435 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
|
436 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
|
437 |
| 20469 | 438 /* while Z_OK and the output buffer is full, there might be more output, |
| 439 so extend the output buffer and try again */ | |
| 440 while (err == Z_OK && self->zst.avail_out == 0) { | |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
441 if (_PyString_Resize(&RetVal, length << 1) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
442 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
443 self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
444 + length; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
445 self->zst.avail_out = length; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
446 length = length << 1; |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
447 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
448 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
449 err = deflate(&(self->zst), Z_NO_FLUSH); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
450 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
|
451 } |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
452 /* We will only get Z_BUF_ERROR if the output buffer was full but |
| 20469 | 453 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
|
454 condition. |
|
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
455 */ |
|
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
|
456 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
457 if (err != Z_OK && err != Z_BUF_ERROR) { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
458 zlib_error(self->zst, err, "while compressing"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
459 Py_DECREF(RetVal); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
460 RetVal = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
461 goto error; |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
462 } |
|
23295
6fa76b4e59fe
Repair widespread misuse of _PyString_Resize. Since it's clear people
Tim Peters <tim.peters@gmail.com>
parents:
23169
diff
changeset
|
463 _PyString_Resize(&RetVal, self->zst.total_out - start_total_out); |
|
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
|
464 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
465 error: |
| 20469 | 466 LEAVE_ZLIB |
| 467 return RetVal; | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
468 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
469 |
|
80349
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
470 /* Helper for objdecompress() and unflush(). Saves any unconsumed input data in |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
471 self->unused_data or self->unconsumed_tail, as appropriate. */ |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
472 static int |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
473 save_unconsumed_input(compobject *self, int err) |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
474 { |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
475 if (err == Z_STREAM_END) { |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
476 /* The end of the compressed data has been reached. Store the leftover |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
477 input data in self->unused_data. */ |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
478 if (self->zst.avail_in > 0) { |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
479 Py_ssize_t old_size = PyString_GET_SIZE(self->unused_data); |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
480 Py_ssize_t new_size; |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
481 PyObject *new_data; |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
482 if (self->zst.avail_in > PY_SSIZE_T_MAX - old_size) { |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
483 PyErr_NoMemory(); |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
484 return -1; |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
485 } |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
486 new_size = old_size + self->zst.avail_in; |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
487 new_data = PyString_FromStringAndSize(NULL, new_size); |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
488 if (new_data == NULL) |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
489 return -1; |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
490 Py_MEMCPY(PyString_AS_STRING(new_data), |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
491 PyString_AS_STRING(self->unused_data), old_size); |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
492 Py_MEMCPY(PyString_AS_STRING(new_data) + old_size, |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
493 self->zst.next_in, self->zst.avail_in); |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
494 Py_DECREF(self->unused_data); |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
495 self->unused_data = new_data; |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
496 self->zst.avail_in = 0; |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
497 } |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
498 } |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
499 if (self->zst.avail_in > 0 || PyString_GET_SIZE(self->unconsumed_tail)) { |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
500 /* This code handles two distinct cases: |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
501 1. Output limit was reached. Save leftover input in unconsumed_tail. |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
502 2. All input data was consumed. Clear unconsumed_tail. */ |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
503 PyObject *new_data = PyString_FromStringAndSize( |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
504 (char *)self->zst.next_in, self->zst.avail_in); |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
505 if (new_data == NULL) |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
506 return -1; |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
507 Py_DECREF(self->unconsumed_tail); |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
508 self->unconsumed_tail = new_data; |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
509 } |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
510 return 0; |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
511 } |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
512 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
513 PyDoc_STRVAR(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
|
514 "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
|
515 "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
|
516 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
517 "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
|
518 "internal buffers for later processing.\n" |
|
20466
60e12f83d2d2
[ #403753 ] zlib decompress; uncontrollable memory usage
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20327
diff
changeset
|
519 "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
|
520 "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
|
521 "no longer than max_length. Unconsumed input data will be stored in\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
522 "the unconsumed_tail attribute."); |
| 5722 | 523 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
524 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
525 PyZlib_objdecompress(compobject *self, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
526 { |
|
61368
b602676cadcd
Issue #8571: Fix an internal error when compressing or decompressing a
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
527 int err, inplen, max_length = 0; |
|
b602676cadcd
Issue #8571: Fix an internal error when compressing or decompressing a
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
528 Py_ssize_t old_length, length = DEFAULTALLOC; |
| 20469 | 529 PyObject *RetVal; |
| 530 Byte *input; | |
| 531 unsigned long start_total_out; | |
|
20466
60e12f83d2d2
[ #403753 ] zlib decompress; uncontrollable memory usage
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20327
diff
changeset
|
532 |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
533 if (!PyArg_ParseTuple(args, "s#|i:decompress", &input, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
534 &inplen, &max_length)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
535 return NULL; |
| 20469 | 536 if (max_length < 0) { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
537 PyErr_SetString(PyExc_ValueError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
538 "max_length must be greater than zero"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
539 return NULL; |
| 20469 | 540 } |
|
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
|
541 |
| 20469 | 542 /* limit amount of data allocated to max_length */ |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
543 if (max_length && length > max_length) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
544 length = max_length; |
|
20470
8964ef84c92f
Remove many calls to set MemoryError exceptions.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20469
diff
changeset
|
545 if (!(RetVal = PyString_FromStringAndSize(NULL, length))) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
546 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
|
547 |
| 20469 | 548 ENTER_ZLIB |
| 549 | |
| 550 start_total_out = self->zst.total_out; | |
| 551 self->zst.avail_in = inplen; | |
| 552 self->zst.next_in = input; | |
| 553 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
|
554 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
|
555 |
|
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
|
556 Py_BEGIN_ALLOW_THREADS |
|
16718
01c2470eeb2e
Patch #103373 from Donovan Baarda: This patch:
Andrew M. Kuchling <amk@amk.ca>
parents:
16369
diff
changeset
|
557 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
|
558 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
|
559 |
| 20469 | 560 /* While Z_OK and the output buffer is full, there might be more output. |
| 561 So extend the output buffer and try again. | |
| 562 */ | |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
563 while (err == Z_OK && self->zst.avail_out == 0) { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
564 /* If max_length set, don't continue decompressing if we've already |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
565 reached the limit. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
566 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
567 if (max_length && length >= max_length) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
568 break; |
| 20469 | 569 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
570 /* otherwise, ... */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
571 old_length = length; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
572 length = length << 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
573 if (max_length && length > max_length) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
574 length = max_length; |
|
20466
60e12f83d2d2
[ #403753 ] zlib decompress; uncontrollable memory usage
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20327
diff
changeset
|
575 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
576 if (_PyString_Resize(&RetVal, length) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
577 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
578 self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
579 + old_length; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
580 self->zst.avail_out = length - old_length; |
| 20469 | 581 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
582 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
583 err = inflate(&(self->zst), Z_SYNC_FLUSH); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
584 Py_END_ALLOW_THREADS |
| 20469 | 585 } |
| 586 | |
|
80349
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
587 if (save_unconsumed_input(self, err) < 0) { |
|
70102
24543f7a87ce
Issue #12050: zlib.decompressobj().decompress() now clears the unconsumed_tail
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
68255
diff
changeset
|
588 Py_DECREF(RetVal); |
|
24543f7a87ce
Issue #12050: zlib.decompressobj().decompress() now clears the unconsumed_tail
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
68255
diff
changeset
|
589 RetVal = NULL; |
|
24543f7a87ce
Issue #12050: zlib.decompressobj().decompress() now clears the unconsumed_tail
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
68255
diff
changeset
|
590 goto error; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
591 } |
| 20469 | 592 |
|
80349
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
593 /* This is the logical place to call inflateEnd, but the old behaviour of |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
594 only calling it on flush() is preserved. */ |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
595 |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
596 if (err != Z_STREAM_END && err != Z_OK && err != Z_BUF_ERROR) { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
597 /* We will only get Z_BUF_ERROR if the output buffer was full |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
598 but there wasn't more output when we tried again, so it is |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
599 not an error condition. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
600 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
601 zlib_error(self->zst, err, "while decompressing"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
602 Py_DECREF(RetVal); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
603 RetVal = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
604 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
|
605 } |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
606 |
|
23295
6fa76b4e59fe
Repair widespread misuse of _PyString_Resize. Since it's clear people
Tim Peters <tim.peters@gmail.com>
parents:
23169
diff
changeset
|
607 _PyString_Resize(&RetVal, self->zst.total_out - start_total_out); |
|
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
|
608 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
609 error: |
| 20469 | 610 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
|
611 |
| 20469 | 612 return RetVal; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
613 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
614 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
615 PyDoc_STRVAR(comp_flush__doc__, |
| 9657 | 616 "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
|
617 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
618 "mode can be one of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH; the\n" |
| 9657 | 619 "default value used when mode is not specified is Z_FINISH.\n" |
| 620 "If mode == Z_FINISH, the compressor object can no longer be used after\n" | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
621 "calling the flush() method. Otherwise, more data can still be compressed."); |
| 5722 | 622 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
623 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
624 PyZlib_flush(compobject *self, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
625 { |
| 20469 | 626 int err, length = DEFAULTALLOC; |
| 627 PyObject *RetVal; | |
| 628 int flushmode = Z_FINISH; | |
| 629 unsigned long start_total_out; | |
| 9657 | 630 |
| 20469 | 631 if (!PyArg_ParseTuple(args, "|i:flush", &flushmode)) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
632 return NULL; |
| 9657 | 633 |
| 20469 | 634 /* Flushing with Z_NO_FLUSH is a no-op, so there's no point in |
| 635 doing any work at all; just return an empty string. */ | |
| 636 if (flushmode == Z_NO_FLUSH) { | |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
637 return PyString_FromStringAndSize(NULL, 0); |
| 20469 | 638 } |
|
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
|
639 |
|
20470
8964ef84c92f
Remove many calls to set MemoryError exceptions.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20469
diff
changeset
|
640 if (!(RetVal = PyString_FromStringAndSize(NULL, length))) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
641 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
|
642 |
| 20469 | 643 ENTER_ZLIB |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
644 |
| 20469 | 645 start_total_out = self->zst.total_out; |
| 646 self->zst.avail_in = 0; | |
|
16718
01c2470eeb2e
Patch #103373 from Donovan Baarda: This patch:
Andrew M. Kuchling <amk@amk.ca>
parents:
16369
diff
changeset
|
647 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
|
648 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
|
649 |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
650 Py_BEGIN_ALLOW_THREADS |
|
16718
01c2470eeb2e
Patch #103373 from Donovan Baarda: This patch:
Andrew M. Kuchling <amk@amk.ca>
parents:
16369
diff
changeset
|
651 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
|
652 Py_END_ALLOW_THREADS |
| 20469 | 653 |
| 654 /* while Z_OK and the output buffer is full, there might be more output, | |
| 655 so extend the output buffer and try again */ | |
| 656 while (err == Z_OK && self->zst.avail_out == 0) { | |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
657 if (_PyString_Resize(&RetVal, length << 1) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
658 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
659 self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
660 + length; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
661 self->zst.avail_out = length; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
662 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
|
663 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
664 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
665 err = deflate(&(self->zst), flushmode); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
666 Py_END_ALLOW_THREADS |
| 20469 | 667 } |
|
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
|
668 |
| 20469 | 669 /* 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
|
670 various data structures. Note we should only get Z_STREAM_END when |
| 20469 | 671 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
|
672 if (err == Z_STREAM_END && flushmode == Z_FINISH) { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
673 err = deflateEnd(&(self->zst)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
674 if (err != Z_OK) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
675 zlib_error(self->zst, err, "from deflateEnd()"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
676 Py_DECREF(RetVal); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
677 RetVal = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
678 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
679 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
680 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
681 self->is_initialised = 0; |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
682 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
683 /* We will only get Z_BUF_ERROR if the output buffer was full |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
684 but there wasn't more output when we tried again, so it is |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
685 not an error condition. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
686 */ |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
687 } else if (err!=Z_OK && err!=Z_BUF_ERROR) { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
688 zlib_error(self->zst, err, "while flushing"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
689 Py_DECREF(RetVal); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
690 RetVal = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
691 goto error; |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
692 } |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
693 |
|
23295
6fa76b4e59fe
Repair widespread misuse of _PyString_Resize. Since it's clear people
Tim Peters <tim.peters@gmail.com>
parents:
23169
diff
changeset
|
694 _PyString_Resize(&RetVal, self->zst.total_out - start_total_out); |
| 20469 | 695 |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
696 error: |
|
20483
5d678356c894
Removed more comments that didn't make much sense.
Tim Peters <tim.peters@gmail.com>
parents:
20482
diff
changeset
|
697 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
|
698 |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
699 return RetVal; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
700 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
701 |
|
38771
618d088d9668
Patch #1503046, Conditional compilation of zlib.(de)compressobj.copy
Neal Norwitz <nnorwitz@gmail.com>
parents:
38198
diff
changeset
|
702 #ifdef HAVE_ZLIB_COPY |
|
38190
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
703 PyDoc_STRVAR(comp_copy__doc__, |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
704 "copy() -- Return a copy of the compression object."); |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
705 |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
706 static PyObject * |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
707 PyZlib_copy(compobject *self) |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
708 { |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
709 compobject *retval = NULL; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
710 int err; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
711 |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
712 retval = newcompobject(&Comptype); |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
713 if (!retval) return NULL; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
714 |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
715 /* Copy the zstream state |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
716 * We use ENTER_ZLIB / LEAVE_ZLIB to make this thread-safe |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
717 */ |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
718 ENTER_ZLIB |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
719 err = deflateCopy(&retval->zst, &self->zst); |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
720 switch(err) { |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
721 case(Z_OK): |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
722 break; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
723 case(Z_STREAM_ERROR): |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
724 PyErr_SetString(PyExc_ValueError, "Inconsistent stream state"); |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
725 goto error; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
726 case(Z_MEM_ERROR): |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
727 PyErr_SetString(PyExc_MemoryError, |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
728 "Can't allocate memory for compression object"); |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
729 goto error; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
730 default: |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
731 zlib_error(self->zst, err, "while copying compression object"); |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
732 goto error; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
733 } |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
734 |
|
38198
30188c523bc5
PyZlib_copy(), PyZlib_uncopy(): Repair leaks on the normal-case path.
Tim Peters <tim.peters@gmail.com>
parents:
38190
diff
changeset
|
735 Py_INCREF(self->unused_data); |
|
30188c523bc5
PyZlib_copy(), PyZlib_uncopy(): Repair leaks on the normal-case path.
Tim Peters <tim.peters@gmail.com>
parents:
38190
diff
changeset
|
736 Py_INCREF(self->unconsumed_tail); |
|
30188c523bc5
PyZlib_copy(), PyZlib_uncopy(): Repair leaks on the normal-case path.
Tim Peters <tim.peters@gmail.com>
parents:
38190
diff
changeset
|
737 Py_XDECREF(retval->unused_data); |
|
30188c523bc5
PyZlib_copy(), PyZlib_uncopy(): Repair leaks on the normal-case path.
Tim Peters <tim.peters@gmail.com>
parents:
38190
diff
changeset
|
738 Py_XDECREF(retval->unconsumed_tail); |
|
38190
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
739 retval->unused_data = self->unused_data; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
740 retval->unconsumed_tail = self->unconsumed_tail; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
741 |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
742 /* Mark it as being initialized */ |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
743 retval->is_initialised = 1; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
744 |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
745 LEAVE_ZLIB |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
746 return (PyObject *)retval; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
747 |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
748 error: |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
749 LEAVE_ZLIB |
|
38198
30188c523bc5
PyZlib_copy(), PyZlib_uncopy(): Repair leaks on the normal-case path.
Tim Peters <tim.peters@gmail.com>
parents:
38190
diff
changeset
|
750 Py_XDECREF(retval); |
|
38190
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
751 return NULL; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
752 } |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
753 |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
754 PyDoc_STRVAR(decomp_copy__doc__, |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
755 "copy() -- Return a copy of the decompression object."); |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
756 |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
757 static PyObject * |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
758 PyZlib_uncopy(compobject *self) |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
759 { |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
760 compobject *retval = NULL; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
761 int err; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
762 |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
763 retval = newcompobject(&Decomptype); |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
764 if (!retval) return NULL; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
765 |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
766 /* Copy the zstream state |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
767 * We use ENTER_ZLIB / LEAVE_ZLIB to make this thread-safe |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
768 */ |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
769 ENTER_ZLIB |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
770 err = inflateCopy(&retval->zst, &self->zst); |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
771 switch(err) { |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
772 case(Z_OK): |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
773 break; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
774 case(Z_STREAM_ERROR): |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
775 PyErr_SetString(PyExc_ValueError, "Inconsistent stream state"); |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
776 goto error; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
777 case(Z_MEM_ERROR): |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
778 PyErr_SetString(PyExc_MemoryError, |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
779 "Can't allocate memory for decompression object"); |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
780 goto error; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
781 default: |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
782 zlib_error(self->zst, err, "while copying decompression object"); |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
783 goto error; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
784 } |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
785 |
|
38198
30188c523bc5
PyZlib_copy(), PyZlib_uncopy(): Repair leaks on the normal-case path.
Tim Peters <tim.peters@gmail.com>
parents:
38190
diff
changeset
|
786 Py_INCREF(self->unused_data); |
|
30188c523bc5
PyZlib_copy(), PyZlib_uncopy(): Repair leaks on the normal-case path.
Tim Peters <tim.peters@gmail.com>
parents:
38190
diff
changeset
|
787 Py_INCREF(self->unconsumed_tail); |
|
30188c523bc5
PyZlib_copy(), PyZlib_uncopy(): Repair leaks on the normal-case path.
Tim Peters <tim.peters@gmail.com>
parents:
38190
diff
changeset
|
788 Py_XDECREF(retval->unused_data); |
|
30188c523bc5
PyZlib_copy(), PyZlib_uncopy(): Repair leaks on the normal-case path.
Tim Peters <tim.peters@gmail.com>
parents:
38190
diff
changeset
|
789 Py_XDECREF(retval->unconsumed_tail); |
|
38190
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
790 retval->unused_data = self->unused_data; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
791 retval->unconsumed_tail = self->unconsumed_tail; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
792 |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
793 /* Mark it as being initialized */ |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
794 retval->is_initialised = 1; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
795 |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
796 LEAVE_ZLIB |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
797 return (PyObject *)retval; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
798 |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
799 error: |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
800 LEAVE_ZLIB |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
801 Py_XDECREF(retval); |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
802 return NULL; |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
803 } |
|
38771
618d088d9668
Patch #1503046, Conditional compilation of zlib.(de)compressobj.copy
Neal Norwitz <nnorwitz@gmail.com>
parents:
38198
diff
changeset
|
804 #endif |
|
38190
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
805 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
806 PyDoc_STRVAR(decomp_flush__doc__, |
|
37373
f64812b2b5c1
Patch #1459631: documnent zlib.Decompress.flush() length parameter.
Georg Brandl <georg@python.org>
parents:
36324
diff
changeset
|
807 "flush( [length] ) -- Return a string containing any remaining\n" |
|
f64812b2b5c1
Patch #1459631: documnent zlib.Decompress.flush() length parameter.
Georg Brandl <georg@python.org>
parents:
36324
diff
changeset
|
808 "decompressed data. length, if given, is the initial size of the\n" |
|
f64812b2b5c1
Patch #1459631: documnent zlib.Decompress.flush() length parameter.
Georg Brandl <georg@python.org>
parents:
36324
diff
changeset
|
809 "output buffer.\n" |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
810 "\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
811 "The decompressor object can no longer be used after this call."); |
| 5722 | 812 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
813 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
814 PyZlib_unflush(compobject *self, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
815 { |
|
27653
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
816 int err, length = DEFAULTALLOC; |
|
20477
c23989e22ffa
Simplify and fix error handling for most cases.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20475
diff
changeset
|
817 PyObject * retval = NULL; |
|
27653
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
818 unsigned long start_total_out; |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
819 |
|
27653
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
820 if (!PyArg_ParseTuple(args, "|i:flush", &length)) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
821 return NULL; |
|
46364
0498ebb6c41b
Merge r62235 from trunk.
Gregory P. Smith <greg@mad-scientist.com>
parents:
43936
diff
changeset
|
822 if (length <= 0) { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
823 PyErr_SetString(PyExc_ValueError, "length must be greater than zero"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
824 return NULL; |
|
46364
0498ebb6c41b
Merge r62235 from trunk.
Gregory P. Smith <greg@mad-scientist.com>
parents:
43936
diff
changeset
|
825 } |
|
27653
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
826 if (!(retval = PyString_FromStringAndSize(NULL, length))) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
827 return NULL; |
|
27653
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
828 |
|
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
|
829 |
| 20469 | 830 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
|
831 |
|
27653
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
832 start_total_out = self->zst.total_out; |
|
80357
be40a10d553a
Fix typo in backporting fix of issue #16411 to 2.7.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80353
diff
changeset
|
833 self->zst.avail_in = PyString_GET_SIZE(self->unconsumed_tail); |
|
be40a10d553a
Fix typo in backporting fix of issue #16411 to 2.7.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80353
diff
changeset
|
834 self->zst.next_in = (Byte *)PyString_AS_STRING(self->unconsumed_tail); |
|
27653
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
835 self->zst.avail_out = length; |
|
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
836 self->zst.next_out = (Byte *)PyString_AS_STRING(retval); |
|
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
837 |
|
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
838 Py_BEGIN_ALLOW_THREADS |
|
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
839 err = inflate(&(self->zst), Z_FINISH); |
|
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
840 Py_END_ALLOW_THREADS |
|
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
841 |
|
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
842 /* while Z_OK and the output buffer is full, there might be more output, |
|
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
843 so extend the output buffer and try again */ |
|
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
844 while ((err == Z_OK || err == Z_BUF_ERROR) && self->zst.avail_out == 0) { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
845 if (_PyString_Resize(&retval, length << 1) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
846 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
847 self->zst.next_out = (Byte *)PyString_AS_STRING(retval) + length; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
848 self->zst.avail_out = length; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
849 length = length << 1; |
|
27653
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
850 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
851 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
852 err = inflate(&(self->zst), Z_FINISH); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
853 Py_END_ALLOW_THREADS |
| 20469 | 854 } |
|
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
|
855 |
|
80349
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
856 if (save_unconsumed_input(self, err) < 0) { |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
857 Py_DECREF(retval); |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
858 retval = NULL; |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
859 goto error; |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
860 } |
|
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
861 |
|
27653
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
862 /* If flushmode is Z_FINISH, we also have to call deflateEnd() to free |
|
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
863 various data structures. Note we should only get Z_STREAM_END when |
|
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
864 flushmode is Z_FINISH */ |
|
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
865 if (err == Z_STREAM_END) { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
866 err = inflateEnd(&(self->zst)); |
|
27653
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
867 self->is_initialised = 0; |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
868 if (err != Z_OK) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
869 zlib_error(self->zst, err, "from inflateEnd()"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
870 Py_DECREF(retval); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
871 retval = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
872 goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
873 } |
|
27653
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
874 } |
|
80349
94256d7804b8
Issue #16350, part 2: Set unused_data (and unconsumed_tail) correctly in decompressobj().flush().
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80258
diff
changeset
|
875 |
|
27653
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
876 _PyString_Resize(&retval, self->zst.total_out - start_total_out); |
|
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
877 |
|
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
878 error: |
|
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
879 |
| 20469 | 880 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
|
881 |
| 20469 | 882 return retval; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
883 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
884 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
885 static PyMethodDef comp_methods[] = |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
886 { |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
887 {"compress", (binaryfunc)PyZlib_objcompress, METH_VARARGS, |
| 20469 | 888 comp_compress__doc__}, |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
889 {"flush", (binaryfunc)PyZlib_flush, METH_VARARGS, |
| 20469 | 890 comp_flush__doc__}, |
|
38771
618d088d9668
Patch #1503046, Conditional compilation of zlib.(de)compressobj.copy
Neal Norwitz <nnorwitz@gmail.com>
parents:
38198
diff
changeset
|
891 #ifdef HAVE_ZLIB_COPY |
|
38190
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
892 {"copy", (PyCFunction)PyZlib_copy, METH_NOARGS, |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
893 comp_copy__doc__}, |
|
38771
618d088d9668
Patch #1503046, Conditional compilation of zlib.(de)compressobj.copy
Neal Norwitz <nnorwitz@gmail.com>
parents:
38198
diff
changeset
|
894 #endif |
| 20469 | 895 {NULL, NULL} |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
896 }; |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
897 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
898 static PyMethodDef Decomp_methods[] = |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
899 { |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
900 {"decompress", (binaryfunc)PyZlib_objdecompress, METH_VARARGS, |
| 20469 | 901 decomp_decompress__doc__}, |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
902 {"flush", (binaryfunc)PyZlib_unflush, METH_VARARGS, |
| 20469 | 903 decomp_flush__doc__}, |
|
38771
618d088d9668
Patch #1503046, Conditional compilation of zlib.(de)compressobj.copy
Neal Norwitz <nnorwitz@gmail.com>
parents:
38198
diff
changeset
|
904 #ifdef HAVE_ZLIB_COPY |
|
38190
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
905 {"copy", (PyCFunction)PyZlib_uncopy, METH_NOARGS, |
|
d6d879af36d3
Patch #1435422: zlib's compress and decompress objects now have a
Georg Brandl <georg@python.org>
parents:
37373
diff
changeset
|
906 decomp_copy__doc__}, |
|
38771
618d088d9668
Patch #1503046, Conditional compilation of zlib.(de)compressobj.copy
Neal Norwitz <nnorwitz@gmail.com>
parents:
38198
diff
changeset
|
907 #endif |
| 20469 | 908 {NULL, NULL} |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
909 }; |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
910 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
911 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
912 Comp_getattr(compobject *self, char *name) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
913 { |
|
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
|
914 /* 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
|
915 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
|
916 |
|
091c01d07d98
Patch #450702: allow threads when calling into zlib, protect usage of
Martin v. Löwis <martin@v.loewis.de>
parents:
16735
diff
changeset
|
917 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
|
918 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
919 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
920 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
921 Decomp_getattr(compobject *self, char *name) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
922 { |
| 20469 | 923 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
|
924 |
| 20469 | 925 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
|
926 |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
927 if (strcmp(name, "unused_data") == 0) { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
928 Py_INCREF(self->unused_data); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
929 retval = self->unused_data; |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
930 } else if (strcmp(name, "unconsumed_tail") == 0) { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
931 Py_INCREF(self->unconsumed_tail); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
932 retval = self->unconsumed_tail; |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
933 } else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
934 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
|
935 |
| 20469 | 936 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
|
937 |
| 20469 | 938 return retval; |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
939 } |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
940 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
941 PyDoc_STRVAR(adler32__doc__, |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
942 "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
|
943 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
944 "An optional starting value can be specified. The returned checksum is\n" |
|
45798
710478a1977a
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
Gregory P. Smith <greg@mad-scientist.com>
parents:
44350
diff
changeset
|
945 "a signed integer."); |
| 5722 | 946 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
947 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
948 PyZlib_adler32(PyObject *self, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
949 { |
|
46070
4f9ca827a7d8
Use a 32-bit unsigned int here, a long is not needed.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46035
diff
changeset
|
950 unsigned int adler32val = 1; /* adler32(0L, Z_NULL, 0) */ |
| 6236 | 951 Byte *buf; |
|
46031
c1fc6e0a94b9
Revert r61779 - It undid correct code and caused test_zlib to fail on all
Gregory P. Smith <greg@mad-scientist.com>
parents:
46022
diff
changeset
|
952 int len, signed_val; |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
953 |
|
46070
4f9ca827a7d8
Use a 32-bit unsigned int here, a long is not needed.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46035
diff
changeset
|
954 if (!PyArg_ParseTuple(args, "s#|I:adler32", &buf, &len, &adler32val)) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
955 return NULL; |
|
45798
710478a1977a
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
Gregory P. Smith <greg@mad-scientist.com>
parents:
44350
diff
changeset
|
956 /* In Python 2.x we return a signed integer regardless of native platform |
|
710478a1977a
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
Gregory P. Smith <greg@mad-scientist.com>
parents:
44350
diff
changeset
|
957 * long size (the 32bit unsigned long is treated as 32-bit signed and sign |
|
710478a1977a
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
Gregory P. Smith <greg@mad-scientist.com>
parents:
44350
diff
changeset
|
958 * extended into a 64-bit long inside the integer object). 3.0 does the |
|
710478a1977a
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
Gregory P. Smith <greg@mad-scientist.com>
parents:
44350
diff
changeset
|
959 * right thing and returns unsigned. http://bugs.python.org/issue1202 */ |
|
710478a1977a
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
Gregory P. Smith <greg@mad-scientist.com>
parents:
44350
diff
changeset
|
960 signed_val = adler32(adler32val, buf, len); |
|
710478a1977a
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
Gregory P. Smith <greg@mad-scientist.com>
parents:
44350
diff
changeset
|
961 return PyInt_FromLong(signed_val); |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
962 } |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
963 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
964 PyDoc_STRVAR(crc32__doc__, |
|
20485
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
965 "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
|
966 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
967 "An optional starting value can be specified. The returned checksum is\n" |
|
45798
710478a1977a
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
Gregory P. Smith <greg@mad-scientist.com>
parents:
44350
diff
changeset
|
968 "a signed integer."); |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
969 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
970 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
12576
diff
changeset
|
971 PyZlib_crc32(PyObject *self, PyObject *args) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
972 { |
|
46070
4f9ca827a7d8
Use a 32-bit unsigned int here, a long is not needed.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46035
diff
changeset
|
973 unsigned int crc32val = 0; /* crc32(0L, Z_NULL, 0) */ |
| 6236 | 974 Byte *buf; |
|
46031
c1fc6e0a94b9
Revert r61779 - It undid correct code and caused test_zlib to fail on all
Gregory P. Smith <greg@mad-scientist.com>
parents:
46022
diff
changeset
|
975 int len, signed_val; |
|
45798
710478a1977a
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
Gregory P. Smith <greg@mad-scientist.com>
parents:
44350
diff
changeset
|
976 |
|
46070
4f9ca827a7d8
Use a 32-bit unsigned int here, a long is not needed.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46035
diff
changeset
|
977 if (!PyArg_ParseTuple(args, "s#|I:crc32", &buf, &len, &crc32val)) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
978 return NULL; |
|
45798
710478a1977a
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
Gregory P. Smith <greg@mad-scientist.com>
parents:
44350
diff
changeset
|
979 /* In Python 2.x we return a signed integer regardless of native platform |
|
710478a1977a
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
Gregory P. Smith <greg@mad-scientist.com>
parents:
44350
diff
changeset
|
980 * long size (the 32bit unsigned long is treated as 32-bit signed and sign |
|
710478a1977a
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
Gregory P. Smith <greg@mad-scientist.com>
parents:
44350
diff
changeset
|
981 * extended into a 64-bit long inside the integer object). 3.0 does the |
|
710478a1977a
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
Gregory P. Smith <greg@mad-scientist.com>
parents:
44350
diff
changeset
|
982 * right thing and returns unsigned. http://bugs.python.org/issue1202 */ |
|
710478a1977a
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
Gregory P. Smith <greg@mad-scientist.com>
parents:
44350
diff
changeset
|
983 signed_val = crc32(crc32val, buf, len); |
|
710478a1977a
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
Gregory P. Smith <greg@mad-scientist.com>
parents:
44350
diff
changeset
|
984 return PyInt_FromLong(signed_val); |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
985 } |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
986 |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
987 |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
988 static PyMethodDef zlib_methods[] = |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
989 { |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
990 {"adler32", (PyCFunction)PyZlib_adler32, METH_VARARGS, |
| 20469 | 991 adler32__doc__}, |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
992 {"compress", (PyCFunction)PyZlib_compress, METH_VARARGS, |
| 20469 | 993 compress__doc__}, |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
994 {"compressobj", (PyCFunction)PyZlib_compressobj, METH_VARARGS, |
| 20469 | 995 compressobj__doc__}, |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
996 {"crc32", (PyCFunction)PyZlib_crc32, METH_VARARGS, |
|
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
997 crc32__doc__}, |
|
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
998 {"decompress", (PyCFunction)PyZlib_decompress, METH_VARARGS, |
| 20469 | 999 decompress__doc__}, |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
1000 {"decompressobj", (PyCFunction)PyZlib_decompressobj, METH_VARARGS, |
| 20469 | 1001 decompressobj__doc__}, |
| 1002 {NULL, NULL} | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1003 }; |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1004 |
|
24283
c0a67a1cab09
Removed more stray instances of statichere, but left _sre.c alone.
Tim Peters <tim.peters@gmail.com>
parents:
24280
diff
changeset
|
1005 static PyTypeObject Comptype = { |
|
42333
6620a510e9a9
PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents:
38771
diff
changeset
|
1006 PyVarObject_HEAD_INIT(0, 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
|
1007 "zlib.Compress", |
| 20469 | 1008 sizeof(compobject), |
| 1009 0, | |
| 1010 (destructor)Comp_dealloc, /*tp_dealloc*/ | |
| 1011 0, /*tp_print*/ | |
| 1012 (getattrfunc)Comp_getattr, /*tp_getattr*/ | |
| 1013 0, /*tp_setattr*/ | |
| 1014 0, /*tp_compare*/ | |
| 1015 0, /*tp_repr*/ | |
| 1016 0, /*tp_as_number*/ | |
| 1017 0, /*tp_as_sequence*/ | |
| 1018 0, /*tp_as_mapping*/ | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1019 }; |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1020 |
|
24283
c0a67a1cab09
Removed more stray instances of statichere, but left _sre.c alone.
Tim Peters <tim.peters@gmail.com>
parents:
24280
diff
changeset
|
1021 static PyTypeObject Decomptype = { |
|
42333
6620a510e9a9
PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents:
38771
diff
changeset
|
1022 PyVarObject_HEAD_INIT(0, 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
|
1023 "zlib.Decompress", |
| 20469 | 1024 sizeof(compobject), |
| 1025 0, | |
| 1026 (destructor)Decomp_dealloc, /*tp_dealloc*/ | |
| 1027 0, /*tp_print*/ | |
| 1028 (getattrfunc)Decomp_getattr, /*tp_getattr*/ | |
| 1029 0, /*tp_setattr*/ | |
| 1030 0, /*tp_compare*/ | |
| 1031 0, /*tp_repr*/ | |
| 1032 0, /*tp_as_number*/ | |
| 1033 0, /*tp_as_sequence*/ | |
| 1034 0, /*tp_as_mapping*/ | |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1035 }; |
|
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1036 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
1037 PyDoc_STRVAR(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
|
1038 "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
|
1039 "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
|
1040 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
1041 "adler32(string[, start]) -- Compute an Adler-32 checksum.\n" |
|
80385
f6c4c178da56
Issue #15677: Also fix docstrings in zlib module.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
80357
diff
changeset
|
1042 "compress(string[, level]) -- Compress string, with compression level in 0-9.\n" |
| 5722 | 1043 "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
|
1044 "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
|
1045 "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
|
1046 "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
|
1047 "\n" |
|
4af8d24fa691
Simplify and regularize docstrings. Also reformat so that each docstring
Tim Peters <tim.peters@gmail.com>
parents:
20484
diff
changeset
|
1048 "'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
|
1049 "Compressor objects support compress() and flush() methods; decompressor\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23295
diff
changeset
|
1050 "objects support decompress() and flush()."); |
| 5722 | 1051 |
|
24363
979ff5d0ae07
Replace DL_IMPORT with PyMODINIT_FUNC and remove "/export:init..." link
Mark Hammond <mhammond@skippinet.com.au>
parents:
24283
diff
changeset
|
1052 PyMODINIT_FUNC |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13496
diff
changeset
|
1053 PyInit_zlib(void) |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1054 { |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22217
diff
changeset
|
1055 PyObject *m, *ver; |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
43937
diff
changeset
|
1056 Py_TYPE(&Comptype) = &PyType_Type; |
|
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
43937
diff
changeset
|
1057 Py_TYPE(&Decomptype) = &PyType_Type; |
| 20469 | 1058 m = Py_InitModule4("zlib", zlib_methods, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
1059 zlib_module_documentation, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
1060 (PyObject*)NULL,PYTHON_API_VERSION); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35914
diff
changeset
|
1061 if (m == NULL) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
1062 return; |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22217
diff
changeset
|
1063 |
| 20469 | 1064 ZlibError = PyErr_NewException("zlib.error", NULL, NULL); |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22217
diff
changeset
|
1065 if (ZlibError != NULL) { |
|
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22217
diff
changeset
|
1066 Py_INCREF(ZlibError); |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
1067 PyModule_AddObject(m, "error", ZlibError); |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22217
diff
changeset
|
1068 } |
| 20469 | 1069 PyModule_AddIntConstant(m, "MAX_WBITS", MAX_WBITS); |
| 1070 PyModule_AddIntConstant(m, "DEFLATED", DEFLATED); | |
| 1071 PyModule_AddIntConstant(m, "DEF_MEM_LEVEL", DEF_MEM_LEVEL); | |
| 1072 PyModule_AddIntConstant(m, "Z_BEST_SPEED", Z_BEST_SPEED); | |
| 1073 PyModule_AddIntConstant(m, "Z_BEST_COMPRESSION", Z_BEST_COMPRESSION); | |
| 1074 PyModule_AddIntConstant(m, "Z_DEFAULT_COMPRESSION", Z_DEFAULT_COMPRESSION); | |
| 1075 PyModule_AddIntConstant(m, "Z_FILTERED", Z_FILTERED); | |
| 1076 PyModule_AddIntConstant(m, "Z_HUFFMAN_ONLY", Z_HUFFMAN_ONLY); | |
| 1077 PyModule_AddIntConstant(m, "Z_DEFAULT_STRATEGY", Z_DEFAULT_STRATEGY); | |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
1078 |
| 20469 | 1079 PyModule_AddIntConstant(m, "Z_FINISH", Z_FINISH); |
| 1080 PyModule_AddIntConstant(m, "Z_NO_FLUSH", Z_NO_FLUSH); | |
| 1081 PyModule_AddIntConstant(m, "Z_SYNC_FLUSH", Z_SYNC_FLUSH); | |
| 1082 PyModule_AddIntConstant(m, "Z_FULL_FLUSH", Z_FULL_FLUSH); | |
|
20484
1a9494f9edb2
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
20483
diff
changeset
|
1083 |
| 20469 | 1084 ver = PyString_FromString(ZLIB_VERSION); |
|
22729
cdff3c7c1a76
Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents:
22217
diff
changeset
|
1085 if (ver != NULL) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61368
diff
changeset
|
1086 PyModule_AddObject(m, "ZLIB_VERSION", ver); |
|
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
|
1087 |
|
27653
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
1088 PyModule_AddStringConstant(m, "__version__", "1.0"); |
|
106a44a4b975
- Thanks to Scott David Daniels, a subtle bug in how the zlib
Guido van Rossum <guido@python.org>
parents:
24363
diff
changeset
|
1089 |
|
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
|
1090 #ifdef WITH_THREAD |
| 20469 | 1091 zlib_lock = PyThread_allocate_lock(); |
|
22217
da518fc78066
Changed C++ comment into standard comment.
Sjoerd Mullender <sjoerd@acm.org>
parents:
21313
diff
changeset
|
1092 #endif /* WITH_THREAD */ |
|
5352
d5757aad1a4f
Added Andrew Kuchling's zlib module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1093 } |
