Changeset 388 for python/vendor/current/Modules/zlibmodule.c
- Timestamp:
- Mar 19, 2014, 11:11:30 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/vendor/current/Modules/zlibmodule.c
r2 r388 29 29 30 30 #define ENTER_ZLIB \ 31 32 33 31 Py_BEGIN_ALLOW_THREADS \ 32 PyThread_acquire_lock(zlib_lock, 1); \ 33 Py_END_ALLOW_THREADS 34 34 35 35 #define LEAVE_ZLIB \ 36 36 PyThread_release_lock(zlib_lock); 37 37 38 38 #else … … 73 73 zlib_error(z_stream zst, int err, char *msg) 74 74 { 75 if (zst.msg == Z_NULL) 76 PyErr_Format(ZlibError, "Error %d %s", err, msg); 75 const char *zmsg = Z_NULL; 76 /* In case of a version mismatch, zst.msg won't be initialized. 77 Check for this case first, before looking at zst.msg. */ 78 if (err == Z_VERSION_ERROR) 79 zmsg = "library version mismatch"; 80 if (zmsg == Z_NULL) 81 zmsg = zst.msg; 82 if (zmsg == Z_NULL) { 83 switch (err) { 84 case Z_BUF_ERROR: 85 zmsg = "incomplete or truncated stream"; 86 break; 87 case Z_STREAM_ERROR: 88 zmsg = "inconsistent stream state"; 89 break; 90 case Z_DATA_ERROR: 91 zmsg = "invalid input data"; 92 break; 93 } 94 } 95 if (zmsg == Z_NULL) 96 PyErr_Format(ZlibError, "Error %d %s", err, msg); 77 97 else 78 PyErr_Format(ZlibError, "Error %d %s: %.200s", err, msg, zst.msg);98 PyErr_Format(ZlibError, "Error %d %s: %.200s", err, msg, zmsg); 79 99 } 80 100 … … 82 102 "compressobj([level]) -- Return a compressor object.\n" 83 103 "\n" 84 "Optional arg level is the compression level, in 1-9.");104 "Optional arg level is the compression level, in 0-9."); 85 105 86 106 PyDoc_STRVAR(decompressobj__doc__, … … 95 115 self = PyObject_New(compobject, type); 96 116 if (self == NULL) 97 117 return NULL; 98 118 self->is_initialised = 0; 99 119 self->unused_data = PyString_FromString(""); 100 120 if (self->unused_data == NULL) { 101 102 121 Py_DECREF(self); 122 return NULL; 103 123 } 104 124 self->unconsumed_tail = PyString_FromString(""); 105 125 if (self->unconsumed_tail == NULL) { 106 107 126 Py_DECREF(self); 127 return NULL; 108 128 } 109 129 return self; … … 113 133 "compress(string[, level]) -- Returned compressed string.\n" 114 134 "\n" 115 "Optional arg level is the compression level, in 1-9.");135 "Optional arg level is the compression level, in 0-9."); 116 136 117 137 static PyObject * … … 125 145 /* require Python string object, optional 'level' arg */ 126 146 if (!PyArg_ParseTuple(args, "s#|i:compress", &input, &length, &level)) 127 147 return NULL; 128 148 129 149 zst.avail_out = length + length/1000 + 12 + 1; … … 131 151 output = (Byte*)malloc(zst.avail_out); 132 152 if (output == NULL) { 133 134 135 153 PyErr_SetString(PyExc_MemoryError, 154 "Can't allocate memory to compress data"); 155 return NULL; 136 156 } 137 157 … … 148 168 switch(err) { 149 169 case(Z_OK): 150 170 break; 151 171 case(Z_MEM_ERROR): 152 153 154 172 PyErr_SetString(PyExc_MemoryError, 173 "Out of memory while compressing data"); 174 goto error; 155 175 case(Z_STREAM_ERROR): 156 157 158 176 PyErr_SetString(ZlibError, 177 "Bad compression level"); 178 goto error; 159 179 default: 160 180 deflateEnd(&zst); 161 162 181 zlib_error(zst, err, "while compressing data"); 182 goto error; 163 183 } 164 184 … … 168 188 169 189 if (err != Z_STREAM_END) { 170 171 172 190 zlib_error(zst, err, "while compressing data"); 191 deflateEnd(&zst); 192 goto error; 173 193 } 174 194 175 195 err=deflateEnd(&zst); 176 196 if (err == Z_OK) 177 178 197 ReturnVal = PyString_FromStringAndSize((char *)output, 198 zst.total_out); 179 199 else 180 200 zlib_error(zst, err, "while finishing compression"); 181 201 182 202 error: … … 203 223 204 224 if (!PyArg_ParseTuple(args, "s#|in:decompress", 205 206 225 &input, &length, &wsize, &r_strlen)) 226 return NULL; 207 227 208 228 if (r_strlen <= 0) 209 229 r_strlen = 1; 210 230 211 231 zst.avail_in = length; … … 213 233 214 234 if (!(result_str = PyString_FromStringAndSize(NULL, r_strlen))) 215 235 return NULL; 216 236 217 237 zst.zalloc = (alloc_func)NULL; … … 223 243 switch(err) { 224 244 case(Z_OK): 225 245 break; 226 246 case(Z_MEM_ERROR): 227 228 229 247 PyErr_SetString(PyExc_MemoryError, 248 "Out of memory while decompressing data"); 249 goto error; 230 250 default: 231 251 inflateEnd(&zst); 232 233 252 zlib_error(zst, err, "while preparing to decompress data"); 253 goto error; 234 254 } 235 255 236 256 do { 237 Py_BEGIN_ALLOW_THREADS 238 err=inflate(&zst, Z_FINISH); 239 Py_END_ALLOW_THREADS 240 241 switch(err) { 242 case(Z_STREAM_END): 243 break; 244 case(Z_BUF_ERROR): 245 /* 246 * If there is at least 1 byte of room according to zst.avail_out 247 * and we get this error, assume that it means zlib cannot 248 * process the inflate call() due to an error in the data. 249 */ 250 if (zst.avail_out > 0) { 251 PyErr_Format(ZlibError, "Error %i while decompressing data", 252 err); 253 inflateEnd(&zst); 254 goto error; 255 } 256 /* fall through */ 257 case(Z_OK): 258 /* need more memory */ 259 if (_PyString_Resize(&result_str, r_strlen << 1) < 0) { 260 inflateEnd(&zst); 261 goto error; 262 } 263 zst.next_out = (unsigned char *)PyString_AS_STRING(result_str) \ 264 + r_strlen; 265 zst.avail_out = r_strlen; 266 r_strlen = r_strlen << 1; 267 break; 268 default: 269 inflateEnd(&zst); 270 zlib_error(zst, err, "while decompressing data"); 271 goto error; 272 } 257 Py_BEGIN_ALLOW_THREADS 258 err=inflate(&zst, Z_FINISH); 259 Py_END_ALLOW_THREADS 260 261 switch(err) { 262 case(Z_STREAM_END): 263 break; 264 case(Z_BUF_ERROR): 265 /* 266 * If there is at least 1 byte of room according to zst.avail_out 267 * and we get this error, assume that it means zlib cannot 268 * process the inflate call() due to an error in the data. 269 */ 270 if (zst.avail_out > 0) { 271 zlib_error(zst, err, "while decompressing data"); 272 inflateEnd(&zst); 273 goto error; 274 } 275 /* fall through */ 276 case(Z_OK): 277 /* need more memory */ 278 if (_PyString_Resize(&result_str, r_strlen << 1) < 0) { 279 inflateEnd(&zst); 280 goto error; 281 } 282 zst.next_out = (unsigned char *)PyString_AS_STRING(result_str) \ 283 + r_strlen; 284 zst.avail_out = r_strlen; 285 r_strlen = r_strlen << 1; 286 break; 287 default: 288 inflateEnd(&zst); 289 zlib_error(zst, err, "while decompressing data"); 290 goto error; 291 } 273 292 } while (err != Z_STREAM_END); 274 293 275 294 err = inflateEnd(&zst); 276 295 if (err != Z_OK) { 277 278 296 zlib_error(zst, err, "while finishing data decompression"); 297 goto error; 279 298 } 280 299 … … 295 314 296 315 if (!PyArg_ParseTuple(args, "|iiiii:compressobj", &level, &method, &wbits, 297 298 316 &memLevel, &strategy)) 317 return NULL; 299 318 300 319 self = newcompobject(&Comptype); 301 320 if (self==NULL) 302 321 return(NULL); 303 322 self->zst.zalloc = (alloc_func)NULL; 304 323 self->zst.zfree = (free_func)Z_NULL; … … 308 327 switch(err) { 309 328 case (Z_OK): 310 311 329 self->is_initialised = 1; 330 return (PyObject*)self; 312 331 case (Z_MEM_ERROR): 313 314 315 316 332 Py_DECREF(self); 333 PyErr_SetString(PyExc_MemoryError, 334 "Can't allocate memory for compression object"); 335 return NULL; 317 336 case(Z_STREAM_ERROR): 318 319 320 337 Py_DECREF(self); 338 PyErr_SetString(PyExc_ValueError, "Invalid initialization option"); 339 return NULL; 321 340 default: 322 341 zlib_error(self->zst, err, "while creating compression object"); 323 342 Py_DECREF(self); 324 343 return NULL; 325 344 } 326 345 } … … 332 351 compobject *self; 333 352 if (!PyArg_ParseTuple(args, "|i:decompressobj", &wbits)) 334 353 return NULL; 335 354 336 355 self = newcompobject(&Decomptype); 337 356 if (self == NULL) 338 357 return(NULL); 339 358 self->zst.zalloc = (alloc_func)NULL; 340 359 self->zst.zfree = (free_func)Z_NULL; … … 344 363 switch(err) { 345 364 case (Z_OK): 346 347 365 self->is_initialised = 1; 366 return (PyObject*)self; 348 367 case(Z_STREAM_ERROR): 349 350 351 368 Py_DECREF(self); 369 PyErr_SetString(PyExc_ValueError, "Invalid initialization option"); 370 return NULL; 352 371 case (Z_MEM_ERROR): 353 354 355 356 372 Py_DECREF(self); 373 PyErr_SetString(PyExc_MemoryError, 374 "Can't allocate memory for decompression object"); 375 return NULL; 357 376 default: 358 377 zlib_error(self->zst, err, "while creating decompression object"); 359 378 Py_DECREF(self); 360 379 return NULL; 361 380 } 362 381 } … … 366 385 { 367 386 if (self->is_initialised) 368 387 deflateEnd(&self->zst); 369 388 Py_XDECREF(self->unused_data); 370 389 Py_XDECREF(self->unconsumed_tail); … … 376 395 { 377 396 if (self->is_initialised) 378 397 inflateEnd(&self->zst); 379 398 Py_XDECREF(self->unused_data); 380 399 Py_XDECREF(self->unconsumed_tail); … … 393 412 PyZlib_objcompress(compobject *self, PyObject *args) 394 413 { 395 int err, inplen, length = DEFAULTALLOC; 414 int err, inplen; 415 Py_ssize_t length = DEFAULTALLOC; 396 416 PyObject *RetVal; 397 417 Byte *input; … … 399 419 400 420 if (!PyArg_ParseTuple(args, "s#:compress", &input, &inplen)) 401 421 return NULL; 402 422 403 423 if (!(RetVal = PyString_FromStringAndSize(NULL, length))) 404 424 return NULL; 405 425 406 426 ENTER_ZLIB … … 419 439 so extend the output buffer and try again */ 420 440 while (err == Z_OK && self->zst.avail_out == 0) { 421 422 423 424 425 426 427 428 429 430 441 if (_PyString_Resize(&RetVal, length << 1) < 0) 442 goto error; 443 self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \ 444 + length; 445 self->zst.avail_out = length; 446 length = length << 1; 447 448 Py_BEGIN_ALLOW_THREADS 449 err = deflate(&(self->zst), Z_NO_FLUSH); 450 Py_END_ALLOW_THREADS 431 451 } 432 452 /* We will only get Z_BUF_ERROR if the output buffer was full but … … 436 456 437 457 if (err != Z_OK && err != Z_BUF_ERROR) { 438 439 440 441 458 zlib_error(self->zst, err, "while compressing"); 459 Py_DECREF(RetVal); 460 RetVal = NULL; 461 goto error; 442 462 } 443 463 _PyString_Resize(&RetVal, self->zst.total_out - start_total_out); … … 446 466 LEAVE_ZLIB 447 467 return RetVal; 468 } 469 470 /* Helper for objdecompress() and unflush(). Saves any unconsumed input data in 471 self->unused_data or self->unconsumed_tail, as appropriate. */ 472 static int 473 save_unconsumed_input(compobject *self, int err) 474 { 475 if (err == Z_STREAM_END) { 476 /* The end of the compressed data has been reached. Store the leftover 477 input data in self->unused_data. */ 478 if (self->zst.avail_in > 0) { 479 Py_ssize_t old_size = PyString_GET_SIZE(self->unused_data); 480 Py_ssize_t new_size; 481 PyObject *new_data; 482 if (self->zst.avail_in > PY_SSIZE_T_MAX - old_size) { 483 PyErr_NoMemory(); 484 return -1; 485 } 486 new_size = old_size + self->zst.avail_in; 487 new_data = PyString_FromStringAndSize(NULL, new_size); 488 if (new_data == NULL) 489 return -1; 490 Py_MEMCPY(PyString_AS_STRING(new_data), 491 PyString_AS_STRING(self->unused_data), old_size); 492 Py_MEMCPY(PyString_AS_STRING(new_data) + old_size, 493 self->zst.next_in, self->zst.avail_in); 494 Py_DECREF(self->unused_data); 495 self->unused_data = new_data; 496 self->zst.avail_in = 0; 497 } 498 } 499 if (self->zst.avail_in > 0 || PyString_GET_SIZE(self->unconsumed_tail)) { 500 /* This code handles two distinct cases: 501 1. Output limit was reached. Save leftover input in unconsumed_tail. 502 2. All input data was consumed. Clear unconsumed_tail. */ 503 PyObject *new_data = PyString_FromStringAndSize( 504 (char *)self->zst.next_in, self->zst.avail_in); 505 if (new_data == NULL) 506 return -1; 507 Py_DECREF(self->unconsumed_tail); 508 self->unconsumed_tail = new_data; 509 } 510 return 0; 448 511 } 449 512 … … 462 525 PyZlib_objdecompress(compobject *self, PyObject *args) 463 526 { 464 int err, inplen, old_length, length = DEFAULTALLOC;465 int max_length = 0;527 int err, inplen, max_length = 0; 528 Py_ssize_t old_length, length = DEFAULTALLOC; 466 529 PyObject *RetVal; 467 530 Byte *input; … … 469 532 470 533 if (!PyArg_ParseTuple(args, "s#|i:decompress", &input, 471 472 534 &inplen, &max_length)) 535 return NULL; 473 536 if (max_length < 0) { 474 475 476 537 PyErr_SetString(PyExc_ValueError, 538 "max_length must be greater than zero"); 539 return NULL; 477 540 } 478 541 479 542 /* limit amount of data allocated to max_length */ 480 543 if (max_length && length > max_length) 481 544 length = max_length; 482 545 if (!(RetVal = PyString_FromStringAndSize(NULL, length))) 483 546 return NULL; 484 547 485 548 ENTER_ZLIB … … 499 562 */ 500 563 while (err == Z_OK && self->zst.avail_out == 0) { 501 /* If max_length set, don't continue decompressing if we've already 502 reached the limit. 503 */ 504 if (max_length && length >= max_length) 505 break; 506 507 /* otherwise, ... */ 508 old_length = length; 509 length = length << 1; 510 if (max_length && length > max_length) 511 length = max_length; 512 513 if (_PyString_Resize(&RetVal, length) < 0) 514 goto error; 515 self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \ 516 + old_length; 517 self->zst.avail_out = length - old_length; 518 519 Py_BEGIN_ALLOW_THREADS 520 err = inflate(&(self->zst), Z_SYNC_FLUSH); 521 Py_END_ALLOW_THREADS 522 } 523 524 /* Not all of the compressed data could be accommodated in the output buffer 525 of specified size. Return the unconsumed tail in an attribute.*/ 526 if(max_length) { 527 Py_DECREF(self->unconsumed_tail); 528 self->unconsumed_tail = PyString_FromStringAndSize((char *)self->zst.next_in, 529 self->zst.avail_in); 530 if(!self->unconsumed_tail) { 531 Py_DECREF(RetVal); 532 RetVal = NULL; 533 goto error; 534 } 535 } 536 537 /* The end of the compressed data has been reached, so set the 538 unused_data attribute to a string containing the remainder of the 539 data in the string. Note that this is also a logical place to call 540 inflateEnd, but the old behaviour of only calling it on flush() is 541 preserved. 542 */ 543 if (err == Z_STREAM_END) { 544 Py_XDECREF(self->unused_data); /* Free original empty string */ 545 self->unused_data = PyString_FromStringAndSize( 546 (char *)self->zst.next_in, self->zst.avail_in); 547 if (self->unused_data == NULL) { 548 Py_DECREF(RetVal); 549 goto error; 550 } 551 /* We will only get Z_BUF_ERROR if the output buffer was full 552 but there wasn't more output when we tried again, so it is 553 not an error condition. 554 */ 555 } else if (err != Z_OK && err != Z_BUF_ERROR) { 556 zlib_error(self->zst, err, "while decompressing"); 557 Py_DECREF(RetVal); 558 RetVal = NULL; 559 goto error; 564 /* If max_length set, don't continue decompressing if we've already 565 reached the limit. 566 */ 567 if (max_length && length >= max_length) 568 break; 569 570 /* otherwise, ... */ 571 old_length = length; 572 length = length << 1; 573 if (max_length && length > max_length) 574 length = max_length; 575 576 if (_PyString_Resize(&RetVal, length) < 0) 577 goto error; 578 self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \ 579 + old_length; 580 self->zst.avail_out = length - old_length; 581 582 Py_BEGIN_ALLOW_THREADS 583 err = inflate(&(self->zst), Z_SYNC_FLUSH); 584 Py_END_ALLOW_THREADS 585 } 586 587 if (save_unconsumed_input(self, err) < 0) { 588 Py_DECREF(RetVal); 589 RetVal = NULL; 590 goto error; 591 } 592 593 /* This is the logical place to call inflateEnd, but the old behaviour of 594 only calling it on flush() is preserved. */ 595 596 if (err != Z_STREAM_END && err != Z_OK && err != Z_BUF_ERROR) { 597 /* We will only get Z_BUF_ERROR if the output buffer was full 598 but there wasn't more output when we tried again, so it is 599 not an error condition. 600 */ 601 zlib_error(self->zst, err, "while decompressing"); 602 Py_DECREF(RetVal); 603 RetVal = NULL; 604 goto error; 560 605 } 561 606 … … 585 630 586 631 if (!PyArg_ParseTuple(args, "|i:flush", &flushmode)) 587 632 return NULL; 588 633 589 634 /* Flushing with Z_NO_FLUSH is a no-op, so there's no point in 590 635 doing any work at all; just return an empty string. */ 591 636 if (flushmode == Z_NO_FLUSH) { 592 637 return PyString_FromStringAndSize(NULL, 0); 593 638 } 594 639 595 640 if (!(RetVal = PyString_FromStringAndSize(NULL, length))) 596 641 return NULL; 597 642 598 643 ENTER_ZLIB … … 610 655 so extend the output buffer and try again */ 611 656 while (err == Z_OK && self->zst.avail_out == 0) { 612 613 614 615 616 617 618 619 620 621 657 if (_PyString_Resize(&RetVal, length << 1) < 0) 658 goto error; 659 self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \ 660 + length; 661 self->zst.avail_out = length; 662 length = length << 1; 663 664 Py_BEGIN_ALLOW_THREADS 665 err = deflate(&(self->zst), flushmode); 666 Py_END_ALLOW_THREADS 622 667 } 623 668 … … 626 671 flushmode is Z_FINISH, but checking both for safety*/ 627 672 if (err == Z_STREAM_END && flushmode == Z_FINISH) { 628 629 630 631 632 633 634 635 636 637 638 639 640 641 673 err = deflateEnd(&(self->zst)); 674 if (err != Z_OK) { 675 zlib_error(self->zst, err, "from deflateEnd()"); 676 Py_DECREF(RetVal); 677 RetVal = NULL; 678 goto error; 679 } 680 else 681 self->is_initialised = 0; 682 683 /* We will only get Z_BUF_ERROR if the output buffer was full 684 but there wasn't more output when we tried again, so it is 685 not an error condition. 686 */ 642 687 } else if (err!=Z_OK && err!=Z_BUF_ERROR) { 643 644 645 646 688 zlib_error(self->zst, err, "while flushing"); 689 Py_DECREF(RetVal); 690 RetVal = NULL; 691 goto error; 647 692 } 648 693 … … 774 819 775 820 if (!PyArg_ParseTuple(args, "|i:flush", &length)) 776 821 return NULL; 777 822 if (length <= 0) { 778 779 823 PyErr_SetString(PyExc_ValueError, "length must be greater than zero"); 824 return NULL; 780 825 } 781 826 if (!(retval = PyString_FromStringAndSize(NULL, length))) 782 827 return NULL; 783 828 784 829 … … 786 831 787 832 start_total_out = self->zst.total_out; 833 self->zst.avail_in = PyString_GET_SIZE(self->unconsumed_tail); 834 self->zst.next_in = (Byte *)PyString_AS_STRING(self->unconsumed_tail); 788 835 self->zst.avail_out = length; 789 836 self->zst.next_out = (Byte *)PyString_AS_STRING(retval); … … 796 843 so extend the output buffer and try again */ 797 844 while ((err == Z_OK || err == Z_BUF_ERROR) && self->zst.avail_out == 0) { 798 if (_PyString_Resize(&retval, length << 1) < 0) 799 goto error; 800 self->zst.next_out = (Byte *)PyString_AS_STRING(retval) + length; 801 self->zst.avail_out = length; 802 length = length << 1; 803 804 Py_BEGIN_ALLOW_THREADS 805 err = inflate(&(self->zst), Z_FINISH); 806 Py_END_ALLOW_THREADS 845 if (_PyString_Resize(&retval, length << 1) < 0) 846 goto error; 847 self->zst.next_out = (Byte *)PyString_AS_STRING(retval) + length; 848 self->zst.avail_out = length; 849 length = length << 1; 850 851 Py_BEGIN_ALLOW_THREADS 852 err = inflate(&(self->zst), Z_FINISH); 853 Py_END_ALLOW_THREADS 854 } 855 856 if (save_unconsumed_input(self, err) < 0) { 857 Py_DECREF(retval); 858 retval = NULL; 859 goto error; 807 860 } 808 861 … … 811 864 flushmode is Z_FINISH */ 812 865 if (err == Z_STREAM_END) { 813 866 err = inflateEnd(&(self->zst)); 814 867 self->is_initialised = 0; 815 if (err != Z_OK) { 816 zlib_error(self->zst, err, "from inflateEnd()"); 817 Py_DECREF(retval); 818 retval = NULL; 819 goto error; 820 } 821 } 868 if (err != Z_OK) { 869 zlib_error(self->zst, err, "from inflateEnd()"); 870 Py_DECREF(retval); 871 retval = NULL; 872 goto error; 873 } 874 } 875 822 876 _PyString_Resize(&retval, self->zst.total_out - start_total_out); 823 877 … … 872 926 873 927 if (strcmp(name, "unused_data") == 0) { 874 875 928 Py_INCREF(self->unused_data); 929 retval = self->unused_data; 876 930 } else if (strcmp(name, "unconsumed_tail") == 0) { 877 878 931 Py_INCREF(self->unconsumed_tail); 932 retval = self->unconsumed_tail; 879 933 } else 880 934 retval = Py_FindMethod(Decomp_methods, (PyObject *)self, name); 881 935 882 936 LEAVE_ZLIB … … 899 953 900 954 if (!PyArg_ParseTuple(args, "s#|I:adler32", &buf, &len, &adler32val)) 901 955 return NULL; 902 956 /* In Python 2.x we return a signed integer regardless of native platform 903 957 * long size (the 32bit unsigned long is treated as 32-bit signed and sign … … 922 976 923 977 if (!PyArg_ParseTuple(args, "s#|I:crc32", &buf, &len, &crc32val)) 924 978 return NULL; 925 979 /* In Python 2.x we return a signed integer regardless of native platform 926 980 * long size (the 32bit unsigned long is treated as 32-bit signed and sign … … 986 1040 "\n" 987 1041 "adler32(string[, start]) -- Compute an Adler-32 checksum.\n" 988 "compress(string[, level]) -- Compress string, with compression level in 1-9.\n"1042 "compress(string[, level]) -- Compress string, with compression level in 0-9.\n" 989 1043 "compressobj([level]) -- Return a compressor object.\n" 990 1044 "crc32(string[, start]) -- Compute a CRC-32 checksum.\n" … … 1003 1057 Py_TYPE(&Decomptype) = &PyType_Type; 1004 1058 m = Py_InitModule4("zlib", zlib_methods, 1005 1006 1059 zlib_module_documentation, 1060 (PyObject*)NULL,PYTHON_API_VERSION); 1007 1061 if (m == NULL) 1008 1062 return; 1009 1063 1010 1064 ZlibError = PyErr_NewException("zlib.error", NULL, NULL); 1011 1065 if (ZlibError != NULL) { 1012 1066 Py_INCREF(ZlibError); 1013 1067 PyModule_AddObject(m, "error", ZlibError); 1014 1068 } 1015 1069 PyModule_AddIntConstant(m, "MAX_WBITS", MAX_WBITS); … … 1030 1084 ver = PyString_FromString(ZLIB_VERSION); 1031 1085 if (ver != NULL) 1032 1086 PyModule_AddObject(m, "ZLIB_VERSION", ver); 1033 1087 1034 1088 PyModule_AddStringConstant(m, "__version__", "1.0");
Note:
See TracChangeset
for help on using the changeset viewer.