Skip to content

Commit

Permalink
Merge pull request #12 from pycompression/release_0.2.0
Browse files Browse the repository at this point in the history
Release 0.2.0
  • Loading branch information
rhpvorderman authored Mar 21, 2023
2 parents d870bef + 11d65b6 commit fedd078
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 51 deletions.
6 changes: 6 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
version: 2
formats: [] # Do not build epub and pdf

# This adds mambaforge for the installation
build:
os: "ubuntu-20.04"
tools:
python: "mambaforge-4.10"

python:
install:
- method: pip
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Changelog
.. This document is user facing. Please word the changes in such a way
.. that users understand how the changes affect the new version.
version 0.2.0
-----------------
+ Update embedded zlib-ng version to 2.0.7
+ Escape GIL for adler32 and crc32 functions.

version 0.1.0
-----------------
+ Build wheels for all three major operating systems.
Expand Down
7 changes: 1 addition & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,8 @@ Differences with zlib and gzip modules

.. differences start
+ Compression level 1 zlib_ng has a much worse compression rate than that in
+ Compression level 1 zlib_ng has a worse compression rate than that in
zlib. For other compression levels zlib_ng compresses better.
+ Compression level 1 does not apply requested ``wbits`` correctly. For example
compressing with ``zlib_ng.compress(data, level=1, wbits=-9)`` results in
data that cannot be decompressed with ``zlib_ng.decompress(data, wbits=-9)``
as this will throw an error mentioning invalid window sizes. This is a
bug in the included zlib-ng 2.0.6.
+ ``gzip_ng.open`` returns a class ``GzipNGFile`` instead of ``GzipFile``. Since
there are differences between the compressed ratios between levels, a
difference in naming was chosen to reflect this.
Expand Down
3 changes: 2 additions & 1 deletion docs/conda-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ channels:
- conda-forge
- defaults
dependencies:
- zlib-ng
- zlib-ng >=2.0.7
- python >=3.7
- sphinx
- setuptools
- pip
- pip:
- sphinx-rtd-theme
- sphinx-argparse
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def build_zlib_ng():

setup(
name="zlib-ng",
version="0.1.0",
version="0.2.0",
description="Drop-in replacement for zlib and gzip modules using zlib-ng",
author="Leiden University Medical Center",
author_email="r.h.p.vorderman@lumc.nl", # A placeholder for now
Expand Down
2 changes: 1 addition & 1 deletion src/zlib_ng/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# This file is part of python-zlib-ng which is distributed under the
# PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2.

__version__ = "0.1.0"
__version__ = "0.2.0"
2 changes: 1 addition & 1 deletion src/zlib_ng/zlib-ng
Submodule zlib-ng updated 76 files
+48 −14 .github/workflows/analyze.yml
+225 −169 .github/workflows/cmake.yml
+41 −0 .github/workflows/codeql.yml
+23 −38 .github/workflows/configure.yml
+0 −23 .github/workflows/fuzz.yml
+22 −17 .github/workflows/libpng.yml
+38 −18 .github/workflows/nmake.yml
+54 −34 .github/workflows/pigz.yml
+33 −26 .github/workflows/pkgcheck.yml
+13 −10 .github/workflows/release.yml
+66 −33 CMakeLists.txt
+21 −22 Makefile.in
+11 −3 PORTING.md
+3 −2 README.md
+3 −0 arch/arm/armfeature.c
+3 −8 arch/arm/chunkset_neon.c
+10 −24 arch/arm/crc32_acle.c
+8 −2 arch/s390/dfltcc_deflate.c
+103 −73 arch/s390/dfltcc_detail.h
+5 −3 arch/s390/dfltcc_inflate.c
+2 −0 arch/s390/self-hosted-builder/actions-runner.Dockerfile
+9 −8 arch/x86/chunkset_avx.c
+9 −8 arch/x86/chunkset_sse.c
+6 −42 chunkset.c
+4 −1 chunkset_tpl.h
+1 −1 cmake/detect-arch.c
+4 −4 cmake/detect-sanitizer.cmake
+14 −4 cmake/run-and-compare.cmake
+1 −1 cmake/test-compress.cmake
+3 −5 cmake/toolchain-aarch64.cmake
+9 −4 cmake/toolchain-arm.cmake
+25 −0 cmake/toolchain-armhf.cmake
+25 −6 cmake/toolchain-mingw-i686.cmake
+24 −6 cmake/toolchain-mingw-x86_64.cmake
+6 −6 cmake/toolchain-powerpc.cmake
+6 −6 cmake/toolchain-powerpc64.cmake
+6 −6 cmake/toolchain-powerpc64le.cmake
+5 −5 cmake/toolchain-s390x.cmake
+5 −5 cmake/toolchain-sparc64.cmake
+2 −0 compress.c
+45 −32 configure
+14 −8 deflate.c
+29 −49 deflate.h
+4 −0 fallback_builtins.h
+1 −10 gzguts.h
+0 −18 gzlib.c
+3 −5 gzread.c
+1 −1 gzwrite.c
+8 −6 infback.c
+13 −4 inflate.c
+1 −1 inftrees.c
+1 −0 test/CVE-2018-25032/default.txt
+1 −0 test/CVE-2018-25032/fixed.txt
+9 −2 test/Makefile.in
+2 −1 test/README.md
+12 −12 test/abicheck.sh
+1 −1 test/example.c
+39 −0 test/gh1235.c
+5 −0 test/infcover.c
+66 −19 test/minideflate.c
+15 −6 test/minigzip.c
+9 −1 test/pigz/CMakeLists.txt
+1 −1 test/pkgcheck.sh
+1 −1 tools/maketrees.c
+2 −2 trees.c
+0 −4 win32/zlib-ng1.rc
+0 −4 win32/zlib1.rc
+11 −0 zbuild.h
+0 −1 zconf-ng.h.in
+6 −2 zconf.h.in
+5 −3 zlib-ng.h
+0 −1 zlib-ng.map
+8 −5 zlib.h
+0 −1 zlib.map
+1 −1 zutil.c
+3 −1 zutil_p.h
42 changes: 30 additions & 12 deletions src/zlib_ng/zlib_ngmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include "stdbool.h"
#include "stdint.h"

#if defined(ZLIBNG_VERNUM) && ZLIBNG_VERNUM < 0x02060
#error "At least zlib-ng version 2.0.6 is required"
#if defined(ZLIBNG_VERNUM) && ZLIBNG_VERNUM < 0x02070
#error "At least zlib-ng version 2.0.7 is required"
#endif

#define ENTER_ZLIB(obj) do { \
Expand Down Expand Up @@ -1466,12 +1466,21 @@ zlib_adler32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)

Py_ssize_t len = data.len ;
uint8_t *buf = data.buf;
while ((size_t)len > UINT32_MAX) {
value = zng_adler32(value, buf, UINT32_MAX);
buf += (size_t) UINT32_MAX;
len -= (size_t) UINT32_MAX;

/* Do not drop GIL for small values as it increases overhead */
if (len > 1024 * 5) {
Py_BEGIN_ALLOW_THREADS
while ((size_t)len > UINT32_MAX) {
value = zng_adler32(value, buf, UINT32_MAX);
buf += (size_t) UINT32_MAX;
len -= (size_t) UINT32_MAX;
}
value = zng_adler32(value, buf, (uint32_t)len);
Py_END_ALLOW_THREADS
} else {
value = zng_adler32(value, buf, (uint32_t)len);
}
value = zng_adler32(value, buf, (uint32_t)len);

return_value = PyLong_FromUnsignedLong(value & 0xffffffffU);
PyBuffer_Release(&data);
return return_value;
Expand Down Expand Up @@ -1519,12 +1528,21 @@ zlib_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)

Py_ssize_t len = data.len ;
uint8_t *buf = data.buf;
while ((size_t)len > UINT32_MAX) {
value = zng_crc32(value, buf, UINT32_MAX);
buf += (size_t) UINT32_MAX;
len -= (size_t) UINT32_MAX;

/* Do not drop GIL for small values as it increases overhead */
if (len > 1024 * 5) {
Py_BEGIN_ALLOW_THREADS
while ((size_t)len > UINT32_MAX) {
value = zng_crc32(value, buf, UINT32_MAX);
buf += (size_t) UINT32_MAX;
len -= (size_t) UINT32_MAX;
}
value = zng_crc32(value, buf, (uint32_t)len);
Py_END_ALLOW_THREADS
} else {
value = zng_crc32(value, buf, (uint32_t)len);
}
value = zng_crc32(value, buf, (uint32_t)len);

return_value = PyLong_FromUnsignedLong(value & 0xffffffffU);
PyBuffer_Release(&data);
return return_value;
Expand Down
28 changes: 3 additions & 25 deletions tests/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,7 @@ def test_adler32(data_size, value):
def test_compress(data_size, level, wbits):
data = DATA[:data_size]
compressed = zlib_ng.compress(data, level=level, wbits=wbits)
try:
decompressed = zlib.decompress(compressed, wbits)
except zlib.error:
# Known bug in zlib-ng 2.0.6. Wbits is not correctly applied for level 1.
if (zlib_ng.ZLIBNG_VERSION == "2.0.6" and
level == 1 and
wbits & 0b1111 < 13):
pytest.xfail()
decompressed = zlib.decompress(compressed, wbits)
assert decompressed == data


Expand Down Expand Up @@ -118,15 +111,7 @@ def test_decompress_wbits(data_size, level, wbits, memLevel, strategy):
def test_decompress_zlib_ng(data_size, level, wbits):
data = DATA[:data_size]
compressed = zlib_ng.compress(data, level=level, wbits=wbits)
try:
decompressed = zlib_ng.decompress(compressed, wbits=wbits)
except zlib_ng.error:
# Known bug in zlib-ng 2.0.6. Wbits is not correctly applied for level 1.
if (zlib_ng.ZLIBNG_VERSION == "2.0.6" and
level == 1 and
wbits & 0b1111 < 13):
pytest.xfail()
assert decompressed == data
decompressed = zlib_ng.decompress(compressed, wbits=wbits)
assert decompressed == data


Expand All @@ -139,14 +124,7 @@ def test_compress_compressobj(data_size, level, wbits, memLevel, strategy):
memLevel=memLevel,
strategy=strategy)
compressed = compressobj.compress(data) + compressobj.flush()
try:
decompressed = zlib.decompress(compressed, wbits=wbits)
except zlib.error:
# Known bug in zlib-ng 2.0.6. Wbits is not correctly applied for level 1.
if (zlib_ng.ZLIBNG_VERSION == "2.0.6" and
level == 1 and
wbits & 0b1111 < 13):
pytest.xfail()
decompressed = zlib.decompress(compressed, wbits=wbits)
assert data == decompressed


Expand Down
4 changes: 0 additions & 4 deletions tests/test_zlib_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,10 +835,6 @@ def test_large_unconsumed_tail(self, size):
finally:
comp = uncomp = data = None

# TODO: zlib-ng does not handle wbits for the zlib header correctly.
# TODO: latest zlib-ng works correctly. Should be fixed when new release
# TODO: of zlib-ng comes.
@unittest.expectedFailure
def test_wbits(self):
# wbits=0 only supported since zlib v1.2.3.5
# Register "1.2.3" as "1.2.3.0"
Expand Down

0 comments on commit fedd078

Please sign in to comment.