From 970e566ca7317a2fa90d57de73aec7216995691f Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 3 Apr 2015 23:53:51 +0300 Subject: Issue #23501: Argumen Clinic now generates code into separate files by default. --- Modules/zlibmodule.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Modules/zlibmodule.c') diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index 0d2e188b43..768c4510d6 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -82,12 +82,11 @@ zlib_error(z_stream zst, int err, char *msg) } /*[clinic input] -output preset file module zlib class zlib.Compress "compobject *" "&Comptype" class zlib.Decompress "compobject *" "&Decomptype" [clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=bfd4c340573ba91d]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=093935115c3e3158]*/ static compobject * newcompobject(PyTypeObject *type) -- cgit v1.2.1 From 8f7e37ea29d7bdfadb98c3ef264862962e99748c Mon Sep 17 00:00:00 2001 From: Larry Hastings Date: Tue, 14 Apr 2015 18:07:59 -0400 Subject: Issue #23944: Argument Clinic now wraps long impl prototypes at column 78. --- Modules/zlibmodule.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'Modules/zlibmodule.c') diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index 768c4510d6..1997b40d18 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -280,8 +280,9 @@ Returns a bytes object containing the uncompressed data. [clinic start generated code]*/ static PyObject * -zlib_decompress_impl(PyModuleDef *module, Py_buffer *data, int wbits, unsigned int bufsize) -/*[clinic end generated code: output=9e5464e72df9cb5f input=0f4b9abb7103f50e]*/ +zlib_decompress_impl(PyModuleDef *module, Py_buffer *data, int wbits, + unsigned int bufsize) +/*[clinic end generated code: output=444d0987f3429574 input=0f4b9abb7103f50e]*/ { PyObject *result_str = NULL; Byte *input; @@ -410,8 +411,9 @@ Return a compressor object. [clinic start generated code]*/ static PyObject * -zlib_compressobj_impl(PyModuleDef *module, int level, int method, int wbits, int memLevel, int strategy, Py_buffer *zdict) -/*[clinic end generated code: output=89e5a6c1449caa9e input=b034847f8821f6af]*/ +zlib_compressobj_impl(PyModuleDef *module, int level, int method, int wbits, + int memLevel, int strategy, Py_buffer *zdict) +/*[clinic end generated code: output=2949bbb9a5723ccd input=b034847f8821f6af]*/ { compobject *self = NULL; int err; @@ -703,8 +705,9 @@ Call the flush() method to clear these buffers. [clinic start generated code]*/ static PyObject * -zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data, unsigned int max_length) -/*[clinic end generated code: output=755cccc9087bfe55 input=02cfc047377cec86]*/ +zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data, + unsigned int max_length) +/*[clinic end generated code: output=b82e2a2c19f5fe7b input=02cfc047377cec86]*/ { int err; unsigned int old_length, length = DEF_BUF_SIZE; -- cgit v1.2.1 From 6d214b29c483b2dc2940fcbdb497f309c6baecd7 Mon Sep 17 00:00:00 2001 From: Martin Panter Date: Fri, 20 Nov 2015 08:13:35 +0000 Subject: Issue #25626: Change zlib to accept Py_ssize_t and cap to UINT_MAX The underlying zlib library stores sizes in ?unsigned int?. The corresponding Python parameters are all sizes of buffers filled in by zlib, so it is okay to reduce higher values to the UINT_MAX internal cap. OverflowError is still raised for sizes that do not fit in Py_ssize_t. Sizes are now limited to Py_ssize_t rather than unsigned long, because Python byte strings cannot be larger than Py_ssize_t. Previously this could result in a SystemError on 32-bit platforms. This resolves a regression in the gzip module when reading more than UINT_MAX or LONG_MAX bytes in one call, introduced by revision 62723172412c. --- Modules/zlibmodule.c | 58 ++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'Modules/zlibmodule.c') diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index 1997b40d18..37307be39d 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -226,42 +226,42 @@ zlib_compress_impl(PyModuleDef *module, Py_buffer *bytes, int level) /*[python input] -class uint_converter(CConverter): +class capped_uint_converter(CConverter): type = 'unsigned int' - converter = 'uint_converter' + converter = 'capped_uint_converter' c_ignored_default = "0" [python start generated code]*/ -/*[python end generated code: output=da39a3ee5e6b4b0d input=22263855f7a3ebfd]*/ +/*[python end generated code: output=da39a3ee5e6b4b0d input=35521e4e733823c7]*/ static int -uint_converter(PyObject *obj, void *ptr) +capped_uint_converter(PyObject *obj, void *ptr) { - long val; - unsigned long uval; + PyObject *long_obj; + Py_ssize_t val; - val = PyLong_AsLong(obj); - if (val == -1 && PyErr_Occurred()) { - uval = PyLong_AsUnsignedLong(obj); - if (uval == (unsigned long)-1 && PyErr_Occurred()) - return 0; + long_obj = (PyObject *)_PyLong_FromNbInt(obj); + if (long_obj == NULL) { + return 0; } - else { - if (val < 0) { - PyErr_SetString(PyExc_ValueError, - "value must be positive"); - return 0; - } - uval = (unsigned long)val; + val = PyLong_AsSsize_t(long_obj); + Py_DECREF(long_obj); + if (val == -1 && PyErr_Occurred()) { + return 0; } - - if (uval > UINT_MAX) { - PyErr_SetString(PyExc_OverflowError, - "Python int too large for C unsigned int"); + if (val < 0) { + PyErr_SetString(PyExc_ValueError, + "value must be positive"); return 0; } - *(unsigned int *)ptr = Py_SAFE_DOWNCAST(uval, unsigned long, unsigned int); + if ((size_t)val > UINT_MAX) { + *(unsigned int *)ptr = UINT_MAX; + } + else { + *(unsigned int *)ptr = Py_SAFE_DOWNCAST(val, Py_ssize_t, + unsigned int); + } return 1; } @@ -272,7 +272,7 @@ zlib.decompress Compressed data. wbits: int(c_default="MAX_WBITS") = MAX_WBITS The window buffer size. - bufsize: uint(c_default="DEF_BUF_SIZE") = DEF_BUF_SIZE + bufsize: capped_uint(c_default="DEF_BUF_SIZE") = DEF_BUF_SIZE The initial output buffer size. / @@ -282,7 +282,7 @@ Returns a bytes object containing the uncompressed data. static PyObject * zlib_decompress_impl(PyModuleDef *module, Py_buffer *data, int wbits, unsigned int bufsize) -/*[clinic end generated code: output=444d0987f3429574 input=0f4b9abb7103f50e]*/ +/*[clinic end generated code: output=444d0987f3429574 input=da095118b3243b27]*/ { PyObject *result_str = NULL; Byte *input; @@ -691,7 +691,7 @@ zlib.Decompress.decompress data: Py_buffer The binary data to decompress. - max_length: uint = 0 + max_length: capped_uint = 0 The maximum allowable length of the decompressed data. Unconsumed input data will be stored in the unconsumed_tail attribute. @@ -707,7 +707,7 @@ Call the flush() method to clear these buffers. static PyObject * zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data, unsigned int max_length) -/*[clinic end generated code: output=b82e2a2c19f5fe7b input=02cfc047377cec86]*/ +/*[clinic end generated code: output=b82e2a2c19f5fe7b input=68b6508ab07c2cf0]*/ { int err; unsigned int old_length, length = DEF_BUF_SIZE; @@ -1048,7 +1048,7 @@ error: /*[clinic input] zlib.Decompress.flush - length: uint(c_default="DEF_BUF_SIZE") = zlib.DEF_BUF_SIZE + length: capped_uint(c_default="DEF_BUF_SIZE") = zlib.DEF_BUF_SIZE the initial size of the output buffer. / @@ -1057,7 +1057,7 @@ Return a bytes object containing any remaining decompressed data. static PyObject * zlib_Decompress_flush_impl(compobject *self, unsigned int length) -/*[clinic end generated code: output=db6fb753ab698e22 input=1580956505978993]*/ +/*[clinic end generated code: output=db6fb753ab698e22 input=1bb961eb21b62aa0]*/ { int err; unsigned int new_length; -- cgit v1.2.1 From 585a1eed45faea53f836b1db2ac211d7f14b44c8 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 24 Dec 2015 10:35:59 +0200 Subject: Issue #20440: Massive replacing unsafe attribute setting code with special macro Py_SETREF. --- Modules/zlibmodule.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'Modules/zlibmodule.c') diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index 37307be39d..a15fdb2a07 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -667,8 +667,7 @@ save_unconsumed_input(compobject *self, int err) PyBytes_AS_STRING(self->unused_data), old_size); Py_MEMCPY(PyBytes_AS_STRING(new_data) + old_size, self->zst.next_in, self->zst.avail_in); - Py_DECREF(self->unused_data); - self->unused_data = new_data; + Py_SETREF(self->unused_data, new_data); self->zst.avail_in = 0; } } @@ -680,8 +679,7 @@ save_unconsumed_input(compobject *self, int err) (char *)self->zst.next_in, self->zst.avail_in); if (new_data == NULL) return -1; - Py_DECREF(self->unconsumed_tail); - self->unconsumed_tail = new_data; + Py_SETREF(self->unconsumed_tail, new_data); } return 0; } -- cgit v1.2.1 From 5c633fc25fc6f9beee3ccb9ebc06633d1c9a1bc3 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 25 Dec 2015 20:01:53 +0200 Subject: Issue #25923: Added more const qualifiers to signatures of static and private functions. --- Modules/zlibmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Modules/zlibmodule.c') diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index a15fdb2a07..7d2f55ac30 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -53,7 +53,7 @@ typedef struct } compobject; static void -zlib_error(z_stream zst, int err, char *msg) +zlib_error(z_stream zst, int err, const char *msg) { const char *zmsg = Z_NULL; /* In case of a version mismatch, zst.msg won't be initialized. -- cgit v1.2.1 From 38f3c4611a7ed03dddc07fbd568b619af8b139a4 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 27 Dec 2015 15:41:34 +0200 Subject: Issue #20440: More use of Py_SETREF. This patch is manually crafted and contains changes that couldn't be handled automatically. --- Modules/zlibmodule.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'Modules/zlibmodule.c') diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index a15fdb2a07..d5a6e53ea5 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -961,14 +961,11 @@ zlib_Compress_copy_impl(compobject *self) goto error; } Py_INCREF(self->unused_data); + Py_SETREF(retval->unused_data, self->unused_data); Py_INCREF(self->unconsumed_tail); + Py_SETREF(retval->unconsumed_tail, self->unconsumed_tail); Py_XINCREF(self->zdict); - Py_XDECREF(retval->unused_data); - Py_XDECREF(retval->unconsumed_tail); - Py_XDECREF(retval->zdict); - retval->unused_data = self->unused_data; - retval->unconsumed_tail = self->unconsumed_tail; - retval->zdict = self->zdict; + Py_SETREF(retval->zdict, self->zdict); retval->eof = self->eof; /* Mark it as being initialized */ @@ -1020,14 +1017,11 @@ zlib_Decompress_copy_impl(compobject *self) } Py_INCREF(self->unused_data); + Py_SETREF(retval->unused_data, self->unused_data); Py_INCREF(self->unconsumed_tail); + Py_SETREF(retval->unconsumed_tail, self->unconsumed_tail); Py_XINCREF(self->zdict); - Py_XDECREF(retval->unused_data); - Py_XDECREF(retval->unconsumed_tail); - Py_XDECREF(retval->zdict); - retval->unused_data = self->unused_data; - retval->unconsumed_tail = self->unconsumed_tail; - retval->zdict = self->zdict; + Py_SETREF(retval->zdict, self->zdict); retval->eof = self->eof; /* Mark it as being initialized */ -- cgit v1.2.1 From 341946f1f841b074653b457740671987c5ba1e0e Mon Sep 17 00:00:00 2001 From: Martin Panter Date: Wed, 3 Feb 2016 07:06:33 +0000 Subject: Issue #26244: Clarify default zlib compression level in documentation Based on patch by Aviv Palivoda. --- Modules/zlibmodule.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Modules/zlibmodule.c') diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index d5a6e53ea5..11a34bbc62 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -390,8 +390,9 @@ zlib_decompress_impl(PyModuleDef *module, Py_buffer *data, int wbits, zlib.compressobj level: int(c_default="Z_DEFAULT_COMPRESSION") = Z_DEFAULT_COMPRESSION - The compression level (an integer in the range 0-9; default is 6). - Higher compression levels are slower, but produce smaller results. + The compression level (an integer in the range 0-9 or -1; default is + currently equivalent to 6). Higher compression levels are slower, + but produce smaller results. method: int(c_default="DEFLATED") = DEFLATED The compression algorithm. If given, this must be DEFLATED. wbits: int(c_default="MAX_WBITS") = MAX_WBITS @@ -413,7 +414,7 @@ Return a compressor object. static PyObject * zlib_compressobj_impl(PyModuleDef *module, int level, int method, int wbits, int memLevel, int strategy, Py_buffer *zdict) -/*[clinic end generated code: output=2949bbb9a5723ccd input=b034847f8821f6af]*/ +/*[clinic end generated code: output=2949bbb9a5723ccd input=de2ffab6e910cd8b]*/ { compobject *self = NULL; int err; -- cgit v1.2.1 From fce7cdddcc3c287e649b3d1f555e5ef38de38c8c Mon Sep 17 00:00:00 2001 From: Martin Panter Date: Wed, 10 Feb 2016 10:06:36 +0000 Subject: Issue #26243: zlib.compress() keyword argument support by Aviv Palivoda --- Modules/zlibmodule.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'Modules/zlibmodule.c') diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index 5cdab452b8..8ddc774097 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -137,18 +137,17 @@ PyZlib_Free(voidpf ctx, void *ptr) /*[clinic input] zlib.compress - bytes: Py_buffer + data: Py_buffer Binary data to be compressed. level: int(c_default="Z_DEFAULT_COMPRESSION") = Z_DEFAULT_COMPRESSION - Compression level, in 0-9. - / + Compression level, in 0-9 or -1. Returns a bytes object containing compressed data. [clinic start generated code]*/ static PyObject * -zlib_compress_impl(PyModuleDef *module, Py_buffer *bytes, int level) -/*[clinic end generated code: output=5d7dd4588788efd3 input=be3abe9934bda4b3]*/ +zlib_compress_impl(PyModuleDef *module, Py_buffer *data, int level) +/*[clinic end generated code: output=1b97589132b203b4 input=671c615a4b2267da]*/ { PyObject *ReturnVal = NULL; Byte *input, *output = NULL; @@ -156,13 +155,13 @@ zlib_compress_impl(PyModuleDef *module, Py_buffer *bytes, int level) int err; z_stream zst; - if ((size_t)bytes->len > UINT_MAX) { + if ((size_t)data->len > UINT_MAX) { PyErr_SetString(PyExc_OverflowError, "Size does not fit in an unsigned int"); goto error; } - input = bytes->buf; - length = (unsigned int)bytes->len; + input = data->buf; + length = (unsigned int)data->len; zst.avail_out = length + length/1000 + 12 + 1; @@ -1323,7 +1322,7 @@ PyDoc_STRVAR(zlib_module_documentation, "zlib library, which is based on GNU zip.\n" "\n" "adler32(string[, start]) -- Compute an Adler-32 checksum.\n" -"compress(string[, level]) -- Compress string, with compression level in 0-9.\n" +"compress(data[, level]) -- Compress data, with compression level 0-9 or -1.\n" "compressobj([level[, ...]]) -- Return a compressor object.\n" "crc32(string[, start]) -- Compute a CRC-32 checksum.\n" "decompress(string,[wbits],[bufsize]) -- Decompresses a compressed string.\n" -- cgit v1.2.1 From 14661bd9745f73207ac3b2823a2a19372b0f9422 Mon Sep 17 00:00:00 2001 From: Martin Panter Date: Wed, 10 Feb 2016 10:45:54 +0000 Subject: Issue 26243: Forgot to update zlib doc strings in Argument Clinic --- Modules/zlibmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Modules/zlibmodule.c') diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index 8ddc774097..db3d8c9e1e 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -147,7 +147,7 @@ Returns a bytes object containing compressed data. static PyObject * zlib_compress_impl(PyModuleDef *module, Py_buffer *data, int level) -/*[clinic end generated code: output=1b97589132b203b4 input=671c615a4b2267da]*/ +/*[clinic end generated code: output=1b97589132b203b4 input=abed30f4fa14e213]*/ { PyObject *ReturnVal = NULL; Byte *input, *output = NULL; -- cgit v1.2.1 From 4a078bdcc0f92d69fe95398c9036f1a28c44c230 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 25 Jun 2016 22:43:05 +0300 Subject: Issue #26243: Only the level argument to zlib.compress() is keyword argument now. The first argument is positional-only. --- Modules/zlibmodule.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Modules/zlibmodule.c') diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index ad6f28d7bc..3a459a58f4 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -143,6 +143,7 @@ zlib.compress data: Py_buffer Binary data to be compressed. + / level: int(c_default="Z_DEFAULT_COMPRESSION") = Z_DEFAULT_COMPRESSION Compression level, in 0-9 or -1. @@ -151,7 +152,7 @@ Returns a bytes object containing compressed data. static PyObject * zlib_compress_impl(PyModuleDef *module, Py_buffer *data, int level) -/*[clinic end generated code: output=1b97589132b203b4 input=abed30f4fa14e213]*/ +/*[clinic end generated code: output=1b97589132b203b4 input=638d54b6315dbed3]*/ { PyObject *ReturnVal = NULL; Byte *input, *output = NULL; -- cgit v1.2.1