Skip to content

Commit fedd078

Browse files
authored
Merge pull request #12 from pycompression/release_0.2.0
Release 0.2.0
2 parents d870bef + 11d65b6 commit fedd078

10 files changed

+50
-51
lines changed

.readthedocs.yml

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
version: 2
22
formats: [] # Do not build epub and pdf
33

4+
# This adds mambaforge for the installation
5+
build:
6+
os: "ubuntu-20.04"
7+
tools:
8+
python: "mambaforge-4.10"
9+
410
python:
511
install:
612
- method: pip

CHANGELOG.rst

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ Changelog
77
.. This document is user facing. Please word the changes in such a way
88
.. that users understand how the changes affect the new version.
99
10+
version 0.2.0
11+
-----------------
12+
+ Update embedded zlib-ng version to 2.0.7
13+
+ Escape GIL for adler32 and crc32 functions.
14+
1015
version 0.1.0
1116
-----------------
1217
+ Build wheels for all three major operating systems.

README.rst

+1-6
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,8 @@ Differences with zlib and gzip modules
120120

121121
.. differences start
122122
123-
+ Compression level 1 zlib_ng has a much worse compression rate than that in
123+
+ Compression level 1 zlib_ng has a worse compression rate than that in
124124
zlib. For other compression levels zlib_ng compresses better.
125-
+ Compression level 1 does not apply requested ``wbits`` correctly. For example
126-
compressing with ``zlib_ng.compress(data, level=1, wbits=-9)`` results in
127-
data that cannot be decompressed with ``zlib_ng.decompress(data, wbits=-9)``
128-
as this will throw an error mentioning invalid window sizes. This is a
129-
bug in the included zlib-ng 2.0.6.
130125
+ ``gzip_ng.open`` returns a class ``GzipNGFile`` instead of ``GzipFile``. Since
131126
there are differences between the compressed ratios between levels, a
132127
difference in naming was chosen to reflect this.

docs/conda-environment.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ channels:
33
- conda-forge
44
- defaults
55
dependencies:
6-
- zlib-ng
6+
- zlib-ng >=2.0.7
77
- python >=3.7
88
- sphinx
99
- setuptools
10+
- pip
1011
- pip:
1112
- sphinx-rtd-theme
1213
- sphinx-argparse

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def build_zlib_ng():
121121

122122
setup(
123123
name="zlib-ng",
124-
version="0.1.0",
124+
version="0.2.0",
125125
description="Drop-in replacement for zlib and gzip modules using zlib-ng",
126126
author="Leiden University Medical Center",
127127
author_email="[email protected]", # A placeholder for now

src/zlib_ng/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# This file is part of python-zlib-ng which is distributed under the
66
# PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2.
77

8-
__version__ = "0.1.0"
8+
__version__ = "0.2.0"

src/zlib_ng/zlib-ng

Submodule zlib-ng updated 76 files

src/zlib_ng/zlib_ngmodule.c

+30-12
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include "stdbool.h"
1010
#include "stdint.h"
1111

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

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

14671467
Py_ssize_t len = data.len ;
14681468
uint8_t *buf = data.buf;
1469-
while ((size_t)len > UINT32_MAX) {
1470-
value = zng_adler32(value, buf, UINT32_MAX);
1471-
buf += (size_t) UINT32_MAX;
1472-
len -= (size_t) UINT32_MAX;
1469+
1470+
/* Do not drop GIL for small values as it increases overhead */
1471+
if (len > 1024 * 5) {
1472+
Py_BEGIN_ALLOW_THREADS
1473+
while ((size_t)len > UINT32_MAX) {
1474+
value = zng_adler32(value, buf, UINT32_MAX);
1475+
buf += (size_t) UINT32_MAX;
1476+
len -= (size_t) UINT32_MAX;
1477+
}
1478+
value = zng_adler32(value, buf, (uint32_t)len);
1479+
Py_END_ALLOW_THREADS
1480+
} else {
1481+
value = zng_adler32(value, buf, (uint32_t)len);
14731482
}
1474-
value = zng_adler32(value, buf, (uint32_t)len);
1483+
14751484
return_value = PyLong_FromUnsignedLong(value & 0xffffffffU);
14761485
PyBuffer_Release(&data);
14771486
return return_value;
@@ -1519,12 +1528,21 @@ zlib_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
15191528

15201529
Py_ssize_t len = data.len ;
15211530
uint8_t *buf = data.buf;
1522-
while ((size_t)len > UINT32_MAX) {
1523-
value = zng_crc32(value, buf, UINT32_MAX);
1524-
buf += (size_t) UINT32_MAX;
1525-
len -= (size_t) UINT32_MAX;
1531+
1532+
/* Do not drop GIL for small values as it increases overhead */
1533+
if (len > 1024 * 5) {
1534+
Py_BEGIN_ALLOW_THREADS
1535+
while ((size_t)len > UINT32_MAX) {
1536+
value = zng_crc32(value, buf, UINT32_MAX);
1537+
buf += (size_t) UINT32_MAX;
1538+
len -= (size_t) UINT32_MAX;
1539+
}
1540+
value = zng_crc32(value, buf, (uint32_t)len);
1541+
Py_END_ALLOW_THREADS
1542+
} else {
1543+
value = zng_crc32(value, buf, (uint32_t)len);
15261544
}
1527-
value = zng_crc32(value, buf, (uint32_t)len);
1545+
15281546
return_value = PyLong_FromUnsignedLong(value & 0xffffffffU);
15291547
PyBuffer_Release(&data);
15301548
return return_value;

tests/test_compat.py

+3-25
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,7 @@ def test_adler32(data_size, value):
8282
def test_compress(data_size, level, wbits):
8383
data = DATA[:data_size]
8484
compressed = zlib_ng.compress(data, level=level, wbits=wbits)
85-
try:
86-
decompressed = zlib.decompress(compressed, wbits)
87-
except zlib.error:
88-
# Known bug in zlib-ng 2.0.6. Wbits is not correctly applied for level 1.
89-
if (zlib_ng.ZLIBNG_VERSION == "2.0.6" and
90-
level == 1 and
91-
wbits & 0b1111 < 13):
92-
pytest.xfail()
85+
decompressed = zlib.decompress(compressed, wbits)
9386
assert decompressed == data
9487

9588

@@ -118,15 +111,7 @@ def test_decompress_wbits(data_size, level, wbits, memLevel, strategy):
118111
def test_decompress_zlib_ng(data_size, level, wbits):
119112
data = DATA[:data_size]
120113
compressed = zlib_ng.compress(data, level=level, wbits=wbits)
121-
try:
122-
decompressed = zlib_ng.decompress(compressed, wbits=wbits)
123-
except zlib_ng.error:
124-
# Known bug in zlib-ng 2.0.6. Wbits is not correctly applied for level 1.
125-
if (zlib_ng.ZLIBNG_VERSION == "2.0.6" and
126-
level == 1 and
127-
wbits & 0b1111 < 13):
128-
pytest.xfail()
129-
assert decompressed == data
114+
decompressed = zlib_ng.decompress(compressed, wbits=wbits)
130115
assert decompressed == data
131116

132117

@@ -139,14 +124,7 @@ def test_compress_compressobj(data_size, level, wbits, memLevel, strategy):
139124
memLevel=memLevel,
140125
strategy=strategy)
141126
compressed = compressobj.compress(data) + compressobj.flush()
142-
try:
143-
decompressed = zlib.decompress(compressed, wbits=wbits)
144-
except zlib.error:
145-
# Known bug in zlib-ng 2.0.6. Wbits is not correctly applied for level 1.
146-
if (zlib_ng.ZLIBNG_VERSION == "2.0.6" and
147-
level == 1 and
148-
wbits & 0b1111 < 13):
149-
pytest.xfail()
127+
decompressed = zlib.decompress(compressed, wbits=wbits)
150128
assert data == decompressed
151129

152130

tests/test_zlib_compliance.py

-4
Original file line numberDiff line numberDiff line change
@@ -835,10 +835,6 @@ def test_large_unconsumed_tail(self, size):
835835
finally:
836836
comp = uncomp = data = None
837837

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

0 commit comments

Comments
 (0)