diff options
author | Christian Heimes <christian@cheimes.de> | 2008-03-24 02:19:29 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2008-03-24 02:19:29 (GMT) |
commit | 1dc54009391974ecc6d18f202be05a230a92ca60 (patch) | |
tree | cf31772659cedd334f0fef4a05586ea78bbec8ae /Modules | |
parent | f8bba8e843451ac479633fe641345ade21149c44 (diff) | |
download | cpython-1dc54009391974ecc6d18f202be05a230a92ca60.zip cpython-1dc54009391974ecc6d18f202be05a230a92ca60.tar.gz cpython-1dc54009391974ecc6d18f202be05a230a92ca60.tar.bz2 |
Merged revisions 61820-61823 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61820 | gregory.p.smith | 2008-03-23 23:14:38 +0100 (Sun, 23 Mar 2008) | 2 lines
replace calls to get the initial values with the raw constants.
........
r61821 | gregory.p.smith | 2008-03-24 00:43:02 +0100 (Mon, 24 Mar 2008) | 2 lines
A bugfix for r61813, it would fail if the data size was >=2**32.
........
r61822 | gregory.p.smith | 2008-03-24 00:45:12 +0100 (Mon, 24 Mar 2008) | 2 lines
prevent a warning from the struct module when data size >= 2**32.
........
r61823 | gregory.p.smith | 2008-03-24 01:08:01 +0100 (Mon, 24 Mar 2008) | 4 lines
Have the binascii module use zlib's optimized crc32() function when available
to reduce our code size (1k data table and tiny bit of code). It falls back
to its own without zlib.
........
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/binascii.c | 18 | ||||
-rw-r--r-- | Modules/zlibmodule.c | 4 |
2 files changed, 20 insertions, 2 deletions
diff --git a/Modules/binascii.c b/Modules/binascii.c index e09255c..034dc01 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -56,6 +56,9 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" +#ifdef USE_ZLIB_CRC32 +#include "zlib.h" +#endif static PyObject *Error; static PyObject *Incomplete; @@ -776,6 +779,20 @@ binascii_crc_hqx(PyObject *self, PyObject *args) PyDoc_STRVAR(doc_crc32, "(data, oldcrc = 0) -> newcrc. Compute CRC-32 incrementally"); +#ifdef USE_ZLIB_CRC32 +/* This was taken from zlibmodule.c PyZlib_crc32 (but is PY_SSIZE_T_CLEAN) */ +static PyObject * +binascii_crc32(PyObject *self, PyObject *args) +{ + uLong crc32val = 0; /* crc32(0L, Z_NULL, 0) */ + Byte *buf; + int len; + if (!PyArg_ParseTuple(args, "s#|I:crc32", &buf, &len, &crc32val)) + return NULL; + crc32val = crc32(crc32val, buf, len); + return PyLong_FromUnsignedLong(crc32val & 0xffffffffU); +} +#else /* USE_ZLIB_CRC32 */ /* Crc - 32 BIT ANSI X3.66 CRC checksum files Also known as: ISO 3307 **********************************************************************| @@ -914,6 +931,7 @@ binascii_crc32(PyObject *self, PyObject *args) result = (crc ^ 0xFFFFFFFF); return PyLong_FromUnsignedLong(result & 0xffffffff); } +#endif /* USE_ZLIB_CRC32 */ static PyObject * diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index 3426ccf..cecb9cf 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -915,7 +915,7 @@ PyDoc_STRVAR(adler32__doc__, static PyObject * PyZlib_adler32(PyObject *self, PyObject *args) { - unsigned int adler32val = adler32(0L, Z_NULL, 0); + uLong adler32val = 1; /* adler32(0L, Z_NULL, 0) */ Byte *buf; int len; @@ -934,7 +934,7 @@ PyDoc_STRVAR(crc32__doc__, static PyObject * PyZlib_crc32(PyObject *self, PyObject *args) { - unsigned int crc32val = crc32(0L, Z_NULL, 0); + uLong crc32val = 0; /* crc32(0L, Z_NULL, 0) */ Byte *buf; int len; if (!PyArg_ParseTuple(args, "s#|I:crc32", &buf, &len, &crc32val)) |