Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 1 | /* zlibmodule.c -- gzip-compatible data compression */ |
Guido van Rossum | 821a5e4 | 1998-05-08 14:56:29 +0000 | [diff] [blame] | 2 | /* See http://www.cdrom.com/pub/infozip/zlib/ */ |
| 3 | /* See http://www.winimage.com/zLibDll for Windows */ |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 4 | |
Guido van Rossum | 97b5457 | 1997-06-03 22:21:47 +0000 | [diff] [blame] | 5 | #include "Python.h" |
| 6 | #include "zlib.h" |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 7 | |
| 8 | /* The following parameters are copied from zutil.h, version 0.95 */ |
| 9 | #define DEFLATED 8 |
| 10 | #if MAX_MEM_LEVEL >= 8 |
| 11 | # define DEF_MEM_LEVEL 8 |
| 12 | #else |
| 13 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL |
| 14 | #endif |
| 15 | #define DEF_WBITS MAX_WBITS |
| 16 | |
Guido van Rossum | b729a1d | 1999-04-07 20:23:17 +0000 | [diff] [blame] | 17 | /* The output buffer will be increased in chunks of DEFAULTALLOC bytes. */ |
| 18 | #define DEFAULTALLOC (16*1024) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 19 | #define PyInit_zlib initzlib |
| 20 | |
| 21 | staticforward PyTypeObject Comptype; |
| 22 | staticforward PyTypeObject Decomptype; |
| 23 | |
| 24 | static PyObject *ZlibError; |
| 25 | |
| 26 | typedef struct |
| 27 | { |
| 28 | PyObject_HEAD |
| 29 | z_stream zst; |
Andrew M. Kuchling | b95227d | 1999-03-25 21:21:08 +0000 | [diff] [blame] | 30 | PyObject *unused_data; |
Andrew M. Kuchling | 1c7aaa2 | 1999-01-29 21:49:34 +0000 | [diff] [blame] | 31 | int is_initialised; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 32 | } compobject; |
| 33 | |
Guido van Rossum | 3c54030 | 1997-06-03 22:21:03 +0000 | [diff] [blame] | 34 | static char compressobj__doc__[] = |
| 35 | "compressobj() -- Return a compressor object.\n" |
| 36 | "compressobj(level) -- Return a compressor object, using the given compression level.\n" |
| 37 | ; |
| 38 | |
| 39 | static char decompressobj__doc__[] = |
| 40 | "decompressobj() -- Return a decompressor object.\n" |
| 41 | "decompressobj(wbits) -- Return a decompressor object, setting the window buffer size to wbits.\n" |
| 42 | ; |
| 43 | |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 44 | static compobject * |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 45 | newcompobject(PyTypeObject *type) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 46 | { |
| 47 | compobject *self; |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 48 | self = PyObject_New(compobject, type); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 49 | if (self == NULL) |
| 50 | return NULL; |
Andrew M. Kuchling | 1c7aaa2 | 1999-01-29 21:49:34 +0000 | [diff] [blame] | 51 | self->is_initialised = 0; |
Andrew M. Kuchling | b95227d | 1999-03-25 21:21:08 +0000 | [diff] [blame] | 52 | self->unused_data = PyString_FromString(""); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 53 | return self; |
| 54 | } |
| 55 | |
Guido van Rossum | 3c54030 | 1997-06-03 22:21:03 +0000 | [diff] [blame] | 56 | static char compress__doc__[] = |
| 57 | "compress(string) -- Compress string using the default compression level, " |
| 58 | "returning a string containing compressed data.\n" |
| 59 | "compress(string, level) -- Compress string, using the chosen compression " |
| 60 | "level (from 1 to 9). Return a string containing the compressed data.\n" |
| 61 | ; |
| 62 | |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 63 | static PyObject * |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 64 | PyZlib_compress(PyObject *self, PyObject *args) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 65 | { |
| 66 | PyObject *ReturnVal; |
| 67 | Byte *input, *output; |
| 68 | int length, level=Z_DEFAULT_COMPRESSION, err; |
| 69 | z_stream zst; |
| 70 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 71 | if (!PyArg_ParseTuple(args, "s#|i:compress", &input, &length, &level)) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 72 | return NULL; |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 73 | zst.avail_out = length + length/1000 + 12 + 1; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 74 | output=(Byte*)malloc(zst.avail_out); |
| 75 | if (output==NULL) |
| 76 | { |
| 77 | PyErr_SetString(PyExc_MemoryError, |
| 78 | "Can't allocate memory to compress data"); |
| 79 | return NULL; |
| 80 | } |
Jeremy Hylton | a37e244 | 1998-12-18 22:13:11 +0000 | [diff] [blame] | 81 | |
Jeremy Hylton | 5bc4abe | 1998-12-21 17:15:00 +0000 | [diff] [blame] | 82 | zst.zalloc=(alloc_func)NULL; |
Guido van Rossum | 97b5457 | 1997-06-03 22:21:47 +0000 | [diff] [blame] | 83 | zst.zfree=(free_func)Z_NULL; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 84 | zst.next_out=(Byte *)output; |
| 85 | zst.next_in =(Byte *)input; |
| 86 | zst.avail_in=length; |
| 87 | err=deflateInit(&zst, level); |
| 88 | switch(err) |
| 89 | { |
| 90 | case(Z_OK): |
| 91 | break; |
| 92 | case(Z_MEM_ERROR): |
| 93 | PyErr_SetString(PyExc_MemoryError, |
| 94 | "Out of memory while compressing data"); |
| 95 | free(output); |
| 96 | return NULL; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 97 | case(Z_STREAM_ERROR): |
| 98 | PyErr_SetString(ZlibError, |
| 99 | "Bad compression level"); |
| 100 | free(output); |
| 101 | return NULL; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 102 | default: |
| 103 | { |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 104 | if (zst.msg == Z_NULL) |
| 105 | PyErr_Format(ZlibError, "Error %i while compressing data", |
| 106 | err); |
| 107 | else |
| 108 | PyErr_Format(ZlibError, "Error %i while compressing data: %.200s", |
| 109 | err, zst.msg); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 110 | deflateEnd(&zst); |
| 111 | free(output); |
| 112 | return NULL; |
| 113 | } |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | err=deflate(&zst, Z_FINISH); |
| 117 | switch(err) |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 118 | { |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 119 | case(Z_STREAM_END): |
| 120 | break; |
| 121 | /* Are there other errors to be trapped here? */ |
| 122 | default: |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 123 | { |
| 124 | if (zst.msg == Z_NULL) |
| 125 | PyErr_Format(ZlibError, "Error %i while compressing data", |
| 126 | err); |
| 127 | else |
| 128 | PyErr_Format(ZlibError, "Error %i while compressing data: %.200s", |
| 129 | err, zst.msg); |
| 130 | deflateEnd(&zst); |
| 131 | free(output); |
| 132 | return NULL; |
| 133 | } |
| 134 | } |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 135 | err=deflateEnd(&zst); |
| 136 | if (err!=Z_OK) |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 137 | { |
| 138 | if (zst.msg == Z_NULL) |
| 139 | PyErr_Format(ZlibError, "Error %i while finishing compression", |
| 140 | err); |
| 141 | else |
| 142 | PyErr_Format(ZlibError, |
| 143 | "Error %i while finishing compression: %.200s", |
| 144 | err, zst.msg); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 145 | free(output); |
| 146 | return NULL; |
| 147 | } |
Guido van Rossum | 97b5457 | 1997-06-03 22:21:47 +0000 | [diff] [blame] | 148 | ReturnVal=PyString_FromStringAndSize((char *)output, zst.total_out); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 149 | free(output); |
| 150 | return ReturnVal; |
| 151 | } |
| 152 | |
Guido van Rossum | 3c54030 | 1997-06-03 22:21:03 +0000 | [diff] [blame] | 153 | static char decompress__doc__[] = |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 154 | "decompress(string) -- Decompress the data in string, returning a string containing the decompressed data.\n" |
| 155 | "decompress(string, wbits) -- Decompress the data in string with a window buffer size of wbits.\n" |
| 156 | "decompress(string, wbits, bufsize) -- Decompress the data in string with a window buffer size of wbits and an initial output buffer size of bufsize.\n" |
Guido van Rossum | 3c54030 | 1997-06-03 22:21:03 +0000 | [diff] [blame] | 157 | ; |
| 158 | |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 159 | static PyObject * |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 160 | PyZlib_decompress(PyObject *self, PyObject *args) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 161 | { |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 162 | PyObject *result_str; |
| 163 | Byte *input; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 164 | int length, err; |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 165 | int wsize=DEF_WBITS, r_strlen=DEFAULTALLOC; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 166 | z_stream zst; |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 167 | if (!PyArg_ParseTuple(args, "s#|ii:decompress", &input, &length, &wsize, &r_strlen)) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 168 | return NULL; |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 169 | |
| 170 | if (r_strlen <= 0) |
| 171 | r_strlen = 1; |
Jeremy Hylton | a37e244 | 1998-12-18 22:13:11 +0000 | [diff] [blame] | 172 | |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 173 | zst.avail_in=length; |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 174 | zst.avail_out=r_strlen; |
| 175 | if (!(result_str = PyString_FromStringAndSize(NULL, r_strlen))) |
| 176 | { |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 177 | PyErr_SetString(PyExc_MemoryError, |
| 178 | "Can't allocate memory to decompress data"); |
| 179 | return NULL; |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 180 | } |
Guido van Rossum | 97b5457 | 1997-06-03 22:21:47 +0000 | [diff] [blame] | 181 | zst.zalloc=(alloc_func)NULL; |
| 182 | zst.zfree=(free_func)Z_NULL; |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 183 | zst.next_out=(Byte *)PyString_AsString(result_str); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 184 | zst.next_in =(Byte *)input; |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 185 | err=inflateInit2(&zst, wsize); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 186 | switch(err) |
| 187 | { |
| 188 | case(Z_OK): |
| 189 | break; |
| 190 | case(Z_MEM_ERROR): |
| 191 | PyErr_SetString(PyExc_MemoryError, |
| 192 | "Out of memory while decompressing data"); |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 193 | Py_DECREF(result_str); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 194 | return NULL; |
| 195 | default: |
| 196 | { |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 197 | if (zst.msg == Z_NULL) |
| 198 | PyErr_Format(ZlibError, "Error %i preparing to decompress data", |
| 199 | err); |
| 200 | else |
| 201 | PyErr_Format(ZlibError, |
| 202 | "Error %i while preparing to decompress data: %.200s", |
| 203 | err, zst.msg); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 204 | inflateEnd(&zst); |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 205 | Py_DECREF(result_str); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 206 | return NULL; |
| 207 | } |
| 208 | } |
| 209 | do |
| 210 | { |
| 211 | err=inflate(&zst, Z_FINISH); |
| 212 | switch(err) |
| 213 | { |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 214 | case(Z_STREAM_END): |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 215 | break; |
Guido van Rossum | 115f517 | 1998-04-23 20:22:11 +0000 | [diff] [blame] | 216 | case(Z_BUF_ERROR): |
Andrew M. Kuchling | d923831 | 2000-10-09 14:18:10 +0000 | [diff] [blame] | 217 | /* |
| 218 | * If there is at least 1 byte of room according to zst.avail_out |
| 219 | * and we get this error, assume that it means zlib cannot |
| 220 | * process the inflate call() due to an error in the data. |
| 221 | */ |
| 222 | if (zst.avail_out > 0) |
| 223 | { |
| 224 | PyErr_Format(ZlibError, "Error %i while decompressing data", |
| 225 | err); |
| 226 | inflateEnd(&zst); |
| 227 | Py_DECREF(result_str); |
| 228 | return NULL; |
| 229 | } |
| 230 | /* fall through */ |
| 231 | case(Z_OK): |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 232 | /* need more memory */ |
| 233 | if (_PyString_Resize(&result_str, r_strlen << 1) == -1) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 234 | { |
| 235 | PyErr_SetString(PyExc_MemoryError, |
| 236 | "Out of memory while decompressing data"); |
| 237 | inflateEnd(&zst); |
| 238 | return NULL; |
| 239 | } |
Guido van Rossum | ed2554a | 1997-08-18 15:31:24 +0000 | [diff] [blame] | 240 | zst.next_out = (unsigned char *)PyString_AsString(result_str) + r_strlen; |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 241 | zst.avail_out=r_strlen; |
| 242 | r_strlen = r_strlen << 1; |
| 243 | break; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 244 | default: |
| 245 | { |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 246 | if (zst.msg == Z_NULL) |
| 247 | PyErr_Format(ZlibError, "Error %i while decompressing data", |
| 248 | err); |
| 249 | else |
| 250 | PyErr_Format(ZlibError, |
| 251 | "Error %i while decompressing data: %.200s", |
| 252 | err, zst.msg); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 253 | inflateEnd(&zst); |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 254 | Py_DECREF(result_str); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 255 | return NULL; |
| 256 | } |
| 257 | } |
| 258 | } while(err!=Z_STREAM_END); |
| 259 | |
| 260 | err=inflateEnd(&zst); |
| 261 | if (err!=Z_OK) |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 262 | { |
| 263 | if (zst.msg == Z_NULL) |
| 264 | PyErr_Format(ZlibError, |
| 265 | "Error %i while finishing data decompression", |
| 266 | err); |
| 267 | else |
| 268 | PyErr_Format(ZlibError, |
| 269 | "Error %i while finishing data decompression: %.200s", |
| 270 | err, zst.msg); |
| 271 | Py_DECREF(result_str); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 272 | return NULL; |
| 273 | } |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 274 | _PyString_Resize(&result_str, zst.total_out); |
| 275 | return result_str; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | static PyObject * |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 279 | PyZlib_compressobj(PyObject *selfptr, PyObject *args) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 280 | { |
| 281 | compobject *self; |
| 282 | int level=Z_DEFAULT_COMPRESSION, method=DEFLATED; |
| 283 | int wbits=MAX_WBITS, memLevel=DEF_MEM_LEVEL, strategy=0, err; |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 284 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 285 | if (!PyArg_ParseTuple(args, "|iiiii:compressobj", &level, &method, &wbits, |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 286 | &memLevel, &strategy)) |
| 287 | return NULL; |
| 288 | |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 289 | self = newcompobject(&Comptype); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 290 | if (self==NULL) return(NULL); |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 291 | self->zst.zalloc = (alloc_func)NULL; |
| 292 | self->zst.zfree = (free_func)Z_NULL; |
| 293 | err = deflateInit2(&self->zst, level, method, wbits, memLevel, strategy); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 294 | switch(err) |
| 295 | { |
| 296 | case (Z_OK): |
Andrew M. Kuchling | 1c7aaa2 | 1999-01-29 21:49:34 +0000 | [diff] [blame] | 297 | self->is_initialised = 1; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 298 | return (PyObject*)self; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 299 | case (Z_MEM_ERROR): |
Andrew M. Kuchling | 1c7aaa2 | 1999-01-29 21:49:34 +0000 | [diff] [blame] | 300 | Py_DECREF(self); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 301 | PyErr_SetString(PyExc_MemoryError, |
| 302 | "Can't allocate memory for compression object"); |
| 303 | return NULL; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 304 | case(Z_STREAM_ERROR): |
Andrew M. Kuchling | 1c7aaa2 | 1999-01-29 21:49:34 +0000 | [diff] [blame] | 305 | Py_DECREF(self); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 306 | PyErr_SetString(PyExc_ValueError, |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 307 | "Invalid initialization option"); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 308 | return NULL; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 309 | default: |
| 310 | { |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 311 | if (self->zst.msg == Z_NULL) |
| 312 | PyErr_Format(ZlibError, |
| 313 | "Error %i while creating compression object", |
| 314 | err); |
| 315 | else |
| 316 | PyErr_Format(ZlibError, |
| 317 | "Error %i while creating compression object: %.200s", |
| 318 | err, self->zst.msg); |
Andrew M. Kuchling | 1c7aaa2 | 1999-01-29 21:49:34 +0000 | [diff] [blame] | 319 | Py_DECREF(self); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 320 | return NULL; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | static PyObject * |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 326 | PyZlib_decompressobj(PyObject *selfptr, PyObject *args) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 327 | { |
| 328 | int wbits=DEF_WBITS, err; |
| 329 | compobject *self; |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 330 | if (!PyArg_ParseTuple(args, "|i:decompressobj", &wbits)) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 331 | { |
| 332 | return NULL; |
| 333 | } |
| 334 | self=newcompobject(&Decomptype); |
| 335 | if (self==NULL) return(NULL); |
Guido van Rossum | 97b5457 | 1997-06-03 22:21:47 +0000 | [diff] [blame] | 336 | self->zst.zalloc=(alloc_func)NULL; |
| 337 | self->zst.zfree=(free_func)Z_NULL; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 338 | err=inflateInit2(&self->zst, wbits); |
| 339 | switch(err) |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 340 | { |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 341 | case (Z_OK): |
Andrew M. Kuchling | 1c7aaa2 | 1999-01-29 21:49:34 +0000 | [diff] [blame] | 342 | self->is_initialised = 1; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 343 | return (PyObject*)self; |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 344 | case(Z_STREAM_ERROR): |
Andrew M. Kuchling | 1c7aaa2 | 1999-01-29 21:49:34 +0000 | [diff] [blame] | 345 | Py_DECREF(self); |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 346 | PyErr_SetString(PyExc_ValueError, |
| 347 | "Invalid initialization option"); |
| 348 | return NULL; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 349 | case (Z_MEM_ERROR): |
Andrew M. Kuchling | 1c7aaa2 | 1999-01-29 21:49:34 +0000 | [diff] [blame] | 350 | Py_DECREF(self); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 351 | PyErr_SetString(PyExc_MemoryError, |
| 352 | "Can't allocate memory for decompression object"); |
| 353 | return NULL; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 354 | default: |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 355 | { |
| 356 | if (self->zst.msg == Z_NULL) |
| 357 | PyErr_Format(ZlibError, |
| 358 | "Error %i while creating decompression object", |
| 359 | err); |
| 360 | else |
| 361 | PyErr_Format(ZlibError, |
| 362 | "Error %i while creating decompression object: %.200s", |
| 363 | err, self->zst.msg); |
Andrew M. Kuchling | 1c7aaa2 | 1999-01-29 21:49:34 +0000 | [diff] [blame] | 364 | Py_DECREF(self); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 365 | return NULL; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 366 | } |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 367 | } |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | static void |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 371 | Comp_dealloc(compobject *self) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 372 | { |
Andrew M. Kuchling | 1c7aaa2 | 1999-01-29 21:49:34 +0000 | [diff] [blame] | 373 | if (self->is_initialised) |
| 374 | deflateEnd(&self->zst); |
Andrew M. Kuchling | b95227d | 1999-03-25 21:21:08 +0000 | [diff] [blame] | 375 | Py_XDECREF(self->unused_data); |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 376 | PyObject_Del(self); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | static void |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 380 | Decomp_dealloc(compobject *self) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 381 | { |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 382 | inflateEnd(&self->zst); |
Andrew M. Kuchling | b95227d | 1999-03-25 21:21:08 +0000 | [diff] [blame] | 383 | Py_XDECREF(self->unused_data); |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 384 | PyObject_Del(self); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Guido van Rossum | 3c54030 | 1997-06-03 22:21:03 +0000 | [diff] [blame] | 387 | static char comp_compress__doc__[] = |
| 388 | "compress(data) -- Return a string containing a compressed version of the data.\n\n" |
| 389 | "After calling this function, some of the input data may still\n" |
| 390 | "be stored in internal buffers for later processing.\n" |
| 391 | "Call the flush() method to clear these buffers." |
| 392 | ; |
| 393 | |
| 394 | |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 395 | static PyObject * |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 396 | PyZlib_objcompress(compobject *self, PyObject *args) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 397 | { |
Jeremy Hylton | 644c17d | 1997-08-14 21:06:42 +0000 | [diff] [blame] | 398 | int err = Z_OK, inplen; |
| 399 | int length = DEFAULTALLOC; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 400 | PyObject *RetVal; |
| 401 | Byte *input; |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 402 | unsigned long start_total_out; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 403 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 404 | if (!PyArg_ParseTuple(args, "s#:compress", &input, &inplen)) |
Jeremy Hylton | 644c17d | 1997-08-14 21:06:42 +0000 | [diff] [blame] | 405 | return NULL; |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 406 | self->zst.avail_in = inplen; |
| 407 | self->zst.next_in = input; |
Jeremy Hylton | 644c17d | 1997-08-14 21:06:42 +0000 | [diff] [blame] | 408 | if (!(RetVal = PyString_FromStringAndSize(NULL, length))) { |
| 409 | PyErr_SetString(PyExc_MemoryError, |
| 410 | "Can't allocate memory to compress data"); |
| 411 | return NULL; |
| 412 | } |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 413 | start_total_out = self->zst.total_out; |
Guido van Rossum | ed2554a | 1997-08-18 15:31:24 +0000 | [diff] [blame] | 414 | self->zst.next_out = (unsigned char *)PyString_AsString(RetVal); |
Jeremy Hylton | 644c17d | 1997-08-14 21:06:42 +0000 | [diff] [blame] | 415 | self->zst.avail_out = length; |
| 416 | while (self->zst.avail_in != 0 && err == Z_OK) |
| 417 | { |
| 418 | err = deflate(&(self->zst), Z_NO_FLUSH); |
| 419 | if (self->zst.avail_out <= 0) { |
| 420 | if (_PyString_Resize(&RetVal, length << 1) == -1) { |
| 421 | PyErr_SetString(PyExc_MemoryError, |
| 422 | "Can't allocate memory to compress data"); |
| 423 | return NULL; |
| 424 | } |
Guido van Rossum | ed2554a | 1997-08-18 15:31:24 +0000 | [diff] [blame] | 425 | self->zst.next_out = (unsigned char *)PyString_AsString(RetVal) + length; |
Jeremy Hylton | 644c17d | 1997-08-14 21:06:42 +0000 | [diff] [blame] | 426 | self->zst.avail_out = length; |
| 427 | length = length << 1; |
| 428 | } |
| 429 | } |
| 430 | if (err != Z_OK) |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 431 | { |
| 432 | if (self->zst.msg == Z_NULL) |
| 433 | PyErr_Format(ZlibError, "Error %i while compressing", |
| 434 | err); |
| 435 | else |
| 436 | PyErr_Format(ZlibError, "Error %i while compressing: %.200s", |
| 437 | err, self->zst.msg); |
| 438 | Py_DECREF(RetVal); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 439 | return NULL; |
| 440 | } |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 441 | _PyString_Resize(&RetVal, self->zst.total_out - start_total_out); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 442 | return RetVal; |
| 443 | } |
| 444 | |
Guido van Rossum | 3c54030 | 1997-06-03 22:21:03 +0000 | [diff] [blame] | 445 | static char decomp_decompress__doc__[] = |
| 446 | "decompress(data) -- Return a string containing the decompressed version of the data.\n\n" |
| 447 | "After calling this function, some of the input data may still\n" |
| 448 | "be stored in internal buffers for later processing.\n" |
| 449 | "Call the flush() method to clear these buffers." |
| 450 | ; |
| 451 | |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 452 | static PyObject * |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 453 | PyZlib_objdecompress(compobject *self, PyObject *args) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 454 | { |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 455 | int length, err, inplen; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 456 | PyObject *RetVal; |
| 457 | Byte *input; |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 458 | unsigned long start_total_out; |
| 459 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 460 | if (!PyArg_ParseTuple(args, "s#:decompress", &input, &inplen)) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 461 | return NULL; |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 462 | start_total_out = self->zst.total_out; |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 463 | RetVal = PyString_FromStringAndSize(NULL, DEFAULTALLOC); |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 464 | self->zst.avail_in = inplen; |
| 465 | self->zst.next_in = input; |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 466 | self->zst.avail_out = length = DEFAULTALLOC; |
Guido van Rossum | ed2554a | 1997-08-18 15:31:24 +0000 | [diff] [blame] | 467 | self->zst.next_out = (unsigned char *)PyString_AsString(RetVal); |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 468 | err = Z_OK; |
Jeremy Hylton | a74ef66 | 1997-08-13 21:39:18 +0000 | [diff] [blame] | 469 | |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 470 | while (self->zst.avail_in != 0 && err == Z_OK) |
| 471 | { |
| 472 | err = inflate(&(self->zst), Z_NO_FLUSH); |
| 473 | if (err == Z_OK && self->zst.avail_out <= 0) |
| 474 | { |
| 475 | if (_PyString_Resize(&RetVal, length << 1) == -1) |
| 476 | { |
| 477 | PyErr_SetString(PyExc_MemoryError, |
| 478 | "Can't allocate memory to compress data"); |
| 479 | return NULL; |
| 480 | } |
Guido van Rossum | ed2554a | 1997-08-18 15:31:24 +0000 | [diff] [blame] | 481 | self->zst.next_out = (unsigned char *)PyString_AsString(RetVal) + length; |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 482 | self->zst.avail_out = length; |
| 483 | length = length << 1; |
| 484 | } |
| 485 | } |
| 486 | |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 487 | if (err != Z_OK && err != Z_STREAM_END) |
| 488 | { |
| 489 | if (self->zst.msg == Z_NULL) |
| 490 | PyErr_Format(ZlibError, "Error %i while decompressing", |
| 491 | err); |
| 492 | else |
| 493 | PyErr_Format(ZlibError, "Error %i while decompressing: %.200s", |
| 494 | err, self->zst.msg); |
| 495 | Py_DECREF(RetVal); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 496 | return NULL; |
| 497 | } |
Andrew M. Kuchling | b95227d | 1999-03-25 21:21:08 +0000 | [diff] [blame] | 498 | |
| 499 | if (err == Z_STREAM_END) |
| 500 | { |
| 501 | /* The end of the compressed data has been reached, so set |
| 502 | the unused_data attribute to a string containing the |
| 503 | remainder of the data in the string. */ |
| 504 | int pos = self->zst.next_in - input; /* Position in the string */ |
| 505 | Py_XDECREF(self->unused_data); /* Free the original, empty string */ |
| 506 | |
Guido van Rossum | aee9bb2 | 1999-04-12 14:35:48 +0000 | [diff] [blame] | 507 | self->unused_data = PyString_FromStringAndSize((char *)input+pos, |
| 508 | inplen-pos); |
Andrew M. Kuchling | b95227d | 1999-03-25 21:21:08 +0000 | [diff] [blame] | 509 | if (self->unused_data == NULL) return NULL; |
| 510 | } |
| 511 | |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 512 | _PyString_Resize(&RetVal, self->zst.total_out - start_total_out); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 513 | return RetVal; |
| 514 | } |
| 515 | |
Guido van Rossum | 3c54030 | 1997-06-03 22:21:03 +0000 | [diff] [blame] | 516 | static char comp_flush__doc__[] = |
Jeremy Hylton | a37e244 | 1998-12-18 22:13:11 +0000 | [diff] [blame] | 517 | "flush( [mode] ) -- Return a string containing any remaining compressed data.\n" |
| 518 | "mode can be one of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH; the \n" |
| 519 | "default value used when mode is not specified is Z_FINISH.\n" |
| 520 | "If mode == Z_FINISH, the compressor object can no longer be used after\n" |
| 521 | "calling the flush() method. Otherwise, more data can still be compressed.\n" |
Guido van Rossum | 3c54030 | 1997-06-03 22:21:03 +0000 | [diff] [blame] | 522 | ; |
| 523 | |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 524 | static PyObject * |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 525 | PyZlib_flush(compobject *self, PyObject *args) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 526 | { |
Jeremy Hylton | 644c17d | 1997-08-14 21:06:42 +0000 | [diff] [blame] | 527 | int length=DEFAULTALLOC, err = Z_OK; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 528 | PyObject *RetVal; |
Jeremy Hylton | a37e244 | 1998-12-18 22:13:11 +0000 | [diff] [blame] | 529 | int flushmode = Z_FINISH; |
| 530 | unsigned long start_total_out; |
| 531 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 532 | if (!PyArg_ParseTuple(args, "|i:flush", &flushmode)) |
Jeremy Hylton | 644c17d | 1997-08-14 21:06:42 +0000 | [diff] [blame] | 533 | return NULL; |
Jeremy Hylton | a37e244 | 1998-12-18 22:13:11 +0000 | [diff] [blame] | 534 | |
| 535 | /* Flushing with Z_NO_FLUSH is a no-op, so there's no point in |
| 536 | doing any work at all; just return an empty string. */ |
| 537 | if (flushmode == Z_NO_FLUSH) |
| 538 | { |
| 539 | return PyString_FromStringAndSize(NULL, 0); |
| 540 | } |
| 541 | |
Jeremy Hylton | 644c17d | 1997-08-14 21:06:42 +0000 | [diff] [blame] | 542 | self->zst.avail_in = 0; |
| 543 | self->zst.next_in = Z_NULL; |
| 544 | if (!(RetVal = PyString_FromStringAndSize(NULL, length))) { |
| 545 | PyErr_SetString(PyExc_MemoryError, |
| 546 | "Can't allocate memory to compress data"); |
| 547 | return NULL; |
| 548 | } |
Jeremy Hylton | a37e244 | 1998-12-18 22:13:11 +0000 | [diff] [blame] | 549 | start_total_out = self->zst.total_out; |
Guido van Rossum | ed2554a | 1997-08-18 15:31:24 +0000 | [diff] [blame] | 550 | self->zst.next_out = (unsigned char *)PyString_AsString(RetVal); |
Jeremy Hylton | 644c17d | 1997-08-14 21:06:42 +0000 | [diff] [blame] | 551 | self->zst.avail_out = length; |
Jeremy Hylton | a37e244 | 1998-12-18 22:13:11 +0000 | [diff] [blame] | 552 | |
| 553 | /* When flushing the zstream, there's no input data. |
| 554 | If zst.avail_out == 0, that means that more output space is |
| 555 | needed to complete the flush operation. */ |
Andrew M. Kuchling | 173156f | 1999-03-22 19:25:30 +0000 | [diff] [blame] | 556 | while (1) { |
| 557 | err = deflate(&(self->zst), flushmode); |
| 558 | |
| 559 | /* If the output is Z_OK, and there's still room in the output |
| 560 | buffer, then the flush is complete. */ |
| 561 | if ( (err == Z_OK) && self->zst.avail_out > 0) break; |
| 562 | |
| 563 | /* A nonzero return indicates some sort of error (but see |
| 564 | the comment for the error handler below) */ |
| 565 | if ( err != Z_OK ) break; |
| 566 | |
| 567 | /* There's no space left for output, so increase the buffer and loop |
| 568 | again */ |
| 569 | if (_PyString_Resize(&RetVal, length << 1) == -1) { |
| 570 | PyErr_SetString(PyExc_MemoryError, |
| 571 | "Can't allocate memory to compress data"); |
| 572 | return NULL; |
Jeremy Hylton | 644c17d | 1997-08-14 21:06:42 +0000 | [diff] [blame] | 573 | } |
Andrew M. Kuchling | 173156f | 1999-03-22 19:25:30 +0000 | [diff] [blame] | 574 | self->zst.next_out = (unsigned char *)PyString_AsString(RetVal) + length; |
| 575 | self->zst.avail_out = length; |
| 576 | length = length << 1; |
Jeremy Hylton | 6892aa3 | 1999-01-06 22:56:24 +0000 | [diff] [blame] | 577 | } |
Jeremy Hylton | a37e244 | 1998-12-18 22:13:11 +0000 | [diff] [blame] | 578 | |
Andrew M. Kuchling | 173156f | 1999-03-22 19:25:30 +0000 | [diff] [blame] | 579 | /* Raise an exception indicating an error. The condition for |
| 580 | detecting a error is kind of complicated; Z_OK indicates no |
| 581 | error, but if the flushmode is Z_FINISH, then Z_STREAM_END is |
| 582 | also not an error. */ |
| 583 | if (err!=Z_OK && !(flushmode == Z_FINISH && err == Z_STREAM_END) ) |
Jeremy Hylton | a37e244 | 1998-12-18 22:13:11 +0000 | [diff] [blame] | 584 | { |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 585 | if (self->zst.msg == Z_NULL) |
Jeremy Hylton | a37e244 | 1998-12-18 22:13:11 +0000 | [diff] [blame] | 586 | PyErr_Format(ZlibError, "Error %i while flushing", |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 587 | err); |
| 588 | else |
Jeremy Hylton | a37e244 | 1998-12-18 22:13:11 +0000 | [diff] [blame] | 589 | PyErr_Format(ZlibError, "Error %i while flushing: %.200s", |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 590 | err, self->zst.msg); |
| 591 | Py_DECREF(RetVal); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 592 | return NULL; |
Jeremy Hylton | 6892aa3 | 1999-01-06 22:56:24 +0000 | [diff] [blame] | 593 | } |
Andrew M. Kuchling | 173156f | 1999-03-22 19:25:30 +0000 | [diff] [blame] | 594 | |
| 595 | /* If flushmode is Z_FINISH, we also have to call deflateEnd() to |
| 596 | free various data structures */ |
| 597 | |
Jeremy Hylton | a37e244 | 1998-12-18 22:13:11 +0000 | [diff] [blame] | 598 | if (flushmode == Z_FINISH) { |
| 599 | err=deflateEnd(&(self->zst)); |
| 600 | if (err!=Z_OK) { |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 601 | if (self->zst.msg == Z_NULL) |
Jeremy Hylton | a37e244 | 1998-12-18 22:13:11 +0000 | [diff] [blame] | 602 | PyErr_Format(ZlibError, "Error %i from deflateEnd()", |
| 603 | err); |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 604 | else |
Jeremy Hylton | a37e244 | 1998-12-18 22:13:11 +0000 | [diff] [blame] | 605 | PyErr_Format(ZlibError, |
| 606 | "Error %i from deflateEnd(): %.200s", |
| 607 | err, self->zst.msg); |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 608 | Py_DECREF(RetVal); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 609 | return NULL; |
Jeremy Hylton | a37e244 | 1998-12-18 22:13:11 +0000 | [diff] [blame] | 610 | } |
Jeremy Hylton | 644c17d | 1997-08-14 21:06:42 +0000 | [diff] [blame] | 611 | } |
Jeremy Hylton | a37e244 | 1998-12-18 22:13:11 +0000 | [diff] [blame] | 612 | _PyString_Resize(&RetVal, self->zst.total_out - start_total_out); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 613 | return RetVal; |
| 614 | } |
| 615 | |
Guido van Rossum | 3c54030 | 1997-06-03 22:21:03 +0000 | [diff] [blame] | 616 | static char decomp_flush__doc__[] = |
| 617 | "flush() -- Return a string containing any remaining decompressed data. " |
| 618 | "The decompressor object can no longer be used after this call." |
| 619 | ; |
| 620 | |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 621 | static PyObject * |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 622 | PyZlib_unflush(compobject *self, PyObject *args) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 623 | { |
| 624 | int length=0, err; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 625 | PyObject *RetVal; |
| 626 | |
Andrew M. Kuchling | 14f5158 | 2000-08-03 02:04:05 +0000 | [diff] [blame] | 627 | if (!PyArg_ParseTuple(args, "")) |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 628 | return NULL; |
Jeremy Hylton | 644c17d | 1997-08-14 21:06:42 +0000 | [diff] [blame] | 629 | if (!(RetVal = PyString_FromStringAndSize(NULL, DEFAULTALLOC))) |
| 630 | { |
| 631 | PyErr_SetString(PyExc_MemoryError, |
| 632 | "Can't allocate memory to decompress data"); |
| 633 | return NULL; |
| 634 | } |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 635 | self->zst.avail_in=0; |
Guido van Rossum | ed2554a | 1997-08-18 15:31:24 +0000 | [diff] [blame] | 636 | self->zst.next_out = (unsigned char *)PyString_AsString(RetVal); |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 637 | length = self->zst.avail_out = DEFAULTALLOC; |
| 638 | |
Guido van Rossum | b729a1d | 1999-04-07 20:23:17 +0000 | [diff] [blame] | 639 | /* I suspect that Z_BUF_ERROR is the only error code we need to check for |
| 640 | in the following loop, but will leave the Z_OK in for now to avoid |
| 641 | destabilizing this function. --amk */ |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 642 | err = Z_OK; |
Guido van Rossum | b729a1d | 1999-04-07 20:23:17 +0000 | [diff] [blame] | 643 | while ( err == Z_OK ) |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 644 | { |
| 645 | err = inflate(&(self->zst), Z_FINISH); |
Guido van Rossum | b729a1d | 1999-04-07 20:23:17 +0000 | [diff] [blame] | 646 | if ( ( err == Z_OK || err == Z_BUF_ERROR ) && self->zst.avail_out == 0) |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 647 | { |
| 648 | if (_PyString_Resize(&RetVal, length << 1) == -1) |
| 649 | { |
| 650 | PyErr_SetString(PyExc_MemoryError, |
| 651 | "Can't allocate memory to decompress data"); |
| 652 | return NULL; |
| 653 | } |
Guido van Rossum | ed2554a | 1997-08-18 15:31:24 +0000 | [diff] [blame] | 654 | self->zst.next_out = (unsigned char *)PyString_AsString(RetVal) + length; |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 655 | self->zst.avail_out = length; |
| 656 | length = length << 1; |
Guido van Rossum | b729a1d | 1999-04-07 20:23:17 +0000 | [diff] [blame] | 657 | err = Z_OK; |
Jeremy Hylton | 41b9f00 | 1997-08-13 23:19:55 +0000 | [diff] [blame] | 658 | } |
| 659 | } |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 660 | if (err!=Z_STREAM_END) |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 661 | { |
| 662 | if (self->zst.msg == Z_NULL) |
| 663 | PyErr_Format(ZlibError, "Error %i while decompressing", |
| 664 | err); |
| 665 | else |
| 666 | PyErr_Format(ZlibError, "Error %i while decompressing: %.200s", |
| 667 | err, self->zst.msg); |
| 668 | Py_DECREF(RetVal); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 669 | return NULL; |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 670 | } |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 671 | err=inflateEnd(&(self->zst)); |
| 672 | if (err!=Z_OK) |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 673 | { |
| 674 | if (self->zst.msg == Z_NULL) |
| 675 | PyErr_Format(ZlibError, |
| 676 | "Error %i while flushing decompression object", |
| 677 | err); |
| 678 | else |
| 679 | PyErr_Format(ZlibError, |
| 680 | "Error %i while flushing decompression object: %.200s", |
| 681 | err, self->zst.msg); |
| 682 | Py_DECREF(RetVal); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 683 | return NULL; |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 684 | } |
Jeremy Hylton | 644c17d | 1997-08-14 21:06:42 +0000 | [diff] [blame] | 685 | _PyString_Resize(&RetVal, |
| 686 | (char *)self->zst.next_out - PyString_AsString(RetVal)); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 687 | return RetVal; |
| 688 | } |
| 689 | |
| 690 | static PyMethodDef comp_methods[] = |
| 691 | { |
Andrew M. Kuchling | 14f5158 | 2000-08-03 02:04:05 +0000 | [diff] [blame] | 692 | {"compress", (binaryfunc)PyZlib_objcompress, |
| 693 | METH_VARARGS, comp_compress__doc__}, |
| 694 | {"flush", (binaryfunc)PyZlib_flush, |
| 695 | METH_VARARGS, comp_flush__doc__}, |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 696 | {NULL, NULL} |
| 697 | }; |
| 698 | |
| 699 | static PyMethodDef Decomp_methods[] = |
| 700 | { |
Andrew M. Kuchling | 14f5158 | 2000-08-03 02:04:05 +0000 | [diff] [blame] | 701 | {"decompress", (binaryfunc)PyZlib_objdecompress, |
| 702 | METH_VARARGS, decomp_decompress__doc__}, |
| 703 | {"flush", (binaryfunc)PyZlib_unflush, |
| 704 | METH_VARARGS, decomp_flush__doc__}, |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 705 | {NULL, NULL} |
| 706 | }; |
| 707 | |
| 708 | static PyObject * |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 709 | Comp_getattr(compobject *self, char *name) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 710 | { |
| 711 | return Py_FindMethod(comp_methods, (PyObject *)self, name); |
| 712 | } |
| 713 | |
| 714 | static PyObject * |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 715 | Decomp_getattr(compobject *self, char *name) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 716 | { |
Andrew M. Kuchling | b95227d | 1999-03-25 21:21:08 +0000 | [diff] [blame] | 717 | if (strcmp(name, "unused_data") == 0) |
| 718 | { |
| 719 | Py_INCREF(self->unused_data); |
| 720 | return self->unused_data; |
| 721 | } |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 722 | return Py_FindMethod(Decomp_methods, (PyObject *)self, name); |
| 723 | } |
| 724 | |
Guido van Rossum | 3c54030 | 1997-06-03 22:21:03 +0000 | [diff] [blame] | 725 | static char adler32__doc__[] = |
| 726 | "adler32(string) -- Compute an Adler-32 checksum of string, using " |
| 727 | "a default starting value, and returning an integer value.\n" |
| 728 | "adler32(string, value) -- Compute an Adler-32 checksum of string, using " |
| 729 | "the starting value provided, and returning an integer value\n" |
| 730 | ; |
| 731 | |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 732 | static PyObject * |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 733 | PyZlib_adler32(PyObject *self, PyObject *args) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 734 | { |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 735 | uLong adler32val=adler32(0L, Z_NULL, 0); |
| 736 | Byte *buf; |
| 737 | int len; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 738 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 739 | if (!PyArg_ParseTuple(args, "s#|l:adler32", &buf, &len, &adler32val)) |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 740 | { |
| 741 | return NULL; |
| 742 | } |
| 743 | adler32val = adler32(adler32val, buf, len); |
| 744 | return PyInt_FromLong(adler32val); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 745 | } |
| 746 | |
Guido van Rossum | 3c54030 | 1997-06-03 22:21:03 +0000 | [diff] [blame] | 747 | static char crc32__doc__[] = |
| 748 | "crc32(string) -- Compute a CRC-32 checksum of string, using " |
| 749 | "a default starting value, and returning an integer value.\n" |
| 750 | "crc32(string, value) -- Compute a CRC-32 checksum of string, using " |
| 751 | "the starting value provided, and returning an integer value.\n" |
| 752 | ; |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 753 | |
| 754 | static PyObject * |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 755 | PyZlib_crc32(PyObject *self, PyObject *args) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 756 | { |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 757 | uLong crc32val=crc32(0L, Z_NULL, 0); |
| 758 | Byte *buf; |
| 759 | int len; |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 760 | if (!PyArg_ParseTuple(args, "s#|l:crc32", &buf, &len, &crc32val)) |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 761 | { |
| 762 | return NULL; |
| 763 | } |
| 764 | crc32val = crc32(crc32val, buf, len); |
| 765 | return PyInt_FromLong(crc32val); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | |
| 769 | static PyMethodDef zlib_methods[] = |
| 770 | { |
Andrew M. Kuchling | 14f5158 | 2000-08-03 02:04:05 +0000 | [diff] [blame] | 771 | {"adler32", (PyCFunction)PyZlib_adler32, |
| 772 | METH_VARARGS, adler32__doc__}, |
| 773 | {"compress", (PyCFunction)PyZlib_compress, |
| 774 | METH_VARARGS, compress__doc__}, |
| 775 | {"compressobj", (PyCFunction)PyZlib_compressobj, |
| 776 | METH_VARARGS, compressobj__doc__}, |
| 777 | {"crc32", (PyCFunction)PyZlib_crc32, |
| 778 | METH_VARARGS, crc32__doc__}, |
| 779 | {"decompress", (PyCFunction)PyZlib_decompress, |
| 780 | METH_VARARGS, decompress__doc__}, |
| 781 | {"decompressobj", (PyCFunction)PyZlib_decompressobj, |
| 782 | METH_VARARGS, decompressobj__doc__}, |
| 783 | {NULL, NULL} |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 784 | }; |
| 785 | |
| 786 | statichere PyTypeObject Comptype = { |
Guido van Rossum | 9ec0f8b | 1997-12-18 05:21:29 +0000 | [diff] [blame] | 787 | PyObject_HEAD_INIT(0) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 788 | 0, |
| 789 | "Compress", |
| 790 | sizeof(compobject), |
| 791 | 0, |
| 792 | (destructor)Comp_dealloc, /*tp_dealloc*/ |
| 793 | 0, /*tp_print*/ |
| 794 | (getattrfunc)Comp_getattr, /*tp_getattr*/ |
| 795 | 0, /*tp_setattr*/ |
| 796 | 0, /*tp_compare*/ |
| 797 | 0, /*tp_repr*/ |
| 798 | 0, /*tp_as_number*/ |
| 799 | 0, /*tp_as_sequence*/ |
| 800 | 0, /*tp_as_mapping*/ |
| 801 | }; |
| 802 | |
| 803 | statichere PyTypeObject Decomptype = { |
Guido van Rossum | 9ec0f8b | 1997-12-18 05:21:29 +0000 | [diff] [blame] | 804 | PyObject_HEAD_INIT(0) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 805 | 0, |
| 806 | "Decompress", |
| 807 | sizeof(compobject), |
| 808 | 0, |
| 809 | (destructor)Decomp_dealloc, /*tp_dealloc*/ |
| 810 | 0, /*tp_print*/ |
| 811 | (getattrfunc)Decomp_getattr, /*tp_getattr*/ |
| 812 | 0, /*tp_setattr*/ |
| 813 | 0, /*tp_compare*/ |
| 814 | 0, /*tp_repr*/ |
| 815 | 0, /*tp_as_number*/ |
| 816 | 0, /*tp_as_sequence*/ |
| 817 | 0, /*tp_as_mapping*/ |
| 818 | }; |
| 819 | |
| 820 | /* The following insint() routine was blatantly ripped off from |
| 821 | socketmodule.c */ |
| 822 | |
| 823 | /* Convenience routine to export an integer value. |
| 824 | For simplicity, errors (which are unlikely anyway) are ignored. */ |
| 825 | static void |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 826 | insint(PyObject *d, char *name, int value) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 827 | { |
| 828 | PyObject *v = PyInt_FromLong((long) value); |
| 829 | if (v == NULL) { |
| 830 | /* Don't bother reporting this error */ |
| 831 | PyErr_Clear(); |
| 832 | } |
| 833 | else { |
| 834 | PyDict_SetItemString(d, name, v); |
| 835 | Py_DECREF(v); |
| 836 | } |
| 837 | } |
| 838 | |
Guido van Rossum | 3c54030 | 1997-06-03 22:21:03 +0000 | [diff] [blame] | 839 | static char zlib_module_documentation[]= |
| 840 | "The functions in this module allow compression and decompression " |
| 841 | "using the zlib library, which is based on GNU zip. \n\n" |
| 842 | "adler32(string) -- Compute an Adler-32 checksum.\n" |
| 843 | "adler32(string, start) -- Compute an Adler-32 checksum using a given starting value.\n" |
| 844 | "compress(string) -- Compress a string.\n" |
| 845 | "compress(string, level) -- Compress a string with the given level of compression (1--9).\n" |
| 846 | "compressobj([level]) -- Return a compressor object.\n" |
| 847 | "crc32(string) -- Compute a CRC-32 checksum.\n" |
| 848 | "crc32(string, start) -- Compute a CRC-32 checksum using a given starting value.\n" |
Andrew M. Kuchling | 313a3e3 | 1999-12-20 22:13:38 +0000 | [diff] [blame] | 849 | "decompress(string,[wbits],[bufsize]) -- Decompresses a compressed string.\n" |
Guido van Rossum | 3c54030 | 1997-06-03 22:21:03 +0000 | [diff] [blame] | 850 | "decompressobj([wbits]) -- Return a decompressor object (wbits=window buffer size).\n\n" |
| 851 | "Compressor objects support compress() and flush() methods; decompressor \n" |
| 852 | "objects support decompress() and flush()." |
| 853 | ; |
| 854 | |
Guido van Rossum | 3886bb6 | 1998-12-04 18:50:17 +0000 | [diff] [blame] | 855 | DL_EXPORT(void) |
Thomas Wouters | f3f33dc | 2000-07-21 06:00:07 +0000 | [diff] [blame] | 856 | PyInit_zlib(void) |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 857 | { |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 858 | PyObject *m, *d, *ver; |
Guido van Rossum | 9ec0f8b | 1997-12-18 05:21:29 +0000 | [diff] [blame] | 859 | Comptype.ob_type = &PyType_Type; |
| 860 | Decomptype.ob_type = &PyType_Type; |
Guido van Rossum | 3c54030 | 1997-06-03 22:21:03 +0000 | [diff] [blame] | 861 | m = Py_InitModule4("zlib", zlib_methods, |
| 862 | zlib_module_documentation, |
| 863 | (PyObject*)NULL,PYTHON_API_VERSION); |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 864 | d = PyModule_GetDict(m); |
Guido van Rossum | 0cb96de | 1997-10-01 04:29:29 +0000 | [diff] [blame] | 865 | ZlibError = PyErr_NewException("zlib.error", NULL, NULL); |
Fred Drake | 8972dfd | 1999-12-22 16:13:54 +0000 | [diff] [blame] | 866 | if (ZlibError != NULL) |
| 867 | PyDict_SetItemString(d, "error", ZlibError); |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 868 | |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 869 | insint(d, "MAX_WBITS", MAX_WBITS); |
| 870 | insint(d, "DEFLATED", DEFLATED); |
| 871 | insint(d, "DEF_MEM_LEVEL", DEF_MEM_LEVEL); |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 872 | insint(d, "Z_BEST_SPEED", Z_BEST_SPEED); |
| 873 | insint(d, "Z_BEST_COMPRESSION", Z_BEST_COMPRESSION); |
| 874 | insint(d, "Z_DEFAULT_COMPRESSION", Z_DEFAULT_COMPRESSION); |
| 875 | insint(d, "Z_FILTERED", Z_FILTERED); |
| 876 | insint(d, "Z_HUFFMAN_ONLY", Z_HUFFMAN_ONLY); |
| 877 | insint(d, "Z_DEFAULT_STRATEGY", Z_DEFAULT_STRATEGY); |
Jeremy Hylton | a37e244 | 1998-12-18 22:13:11 +0000 | [diff] [blame] | 878 | |
| 879 | insint(d, "Z_FINISH", Z_FINISH); |
| 880 | insint(d, "Z_NO_FLUSH", Z_NO_FLUSH); |
| 881 | insint(d, "Z_SYNC_FLUSH", Z_SYNC_FLUSH); |
| 882 | insint(d, "Z_FULL_FLUSH", Z_FULL_FLUSH); |
| 883 | |
Jeremy Hylton | cb91404 | 1997-09-04 23:39:23 +0000 | [diff] [blame] | 884 | ver = PyString_FromString(ZLIB_VERSION); |
Fred Drake | 8972dfd | 1999-12-22 16:13:54 +0000 | [diff] [blame] | 885 | if (ver != NULL) { |
| 886 | PyDict_SetItemString(d, "ZLIB_VERSION", ver); |
| 887 | Py_DECREF(ver); |
| 888 | } |
Guido van Rossum | fb22156 | 1997-04-29 15:38:09 +0000 | [diff] [blame] | 889 | } |