Skip to content

Commit ab4e756

Browse files
bmwiedemannindygreg
authored andcommitted
global: adapt to zstd 1.5.7
All our code changes required to support the upgrade from 1.5.6. this changed compression results, so we have to adapt tests
1 parent aede8bd commit ab4e756

8 files changed

Lines changed: 15 additions & 10 deletions

c-ext/backend_c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void zstd_module_init(PyObject *m) {
152152
PyObject *features = NULL;
153153
PyObject *feature = NULL;
154154
unsigned zstd_ver_no = ZSTD_versionNumber();
155-
unsigned our_hardcoded_version = 10506;
155+
unsigned our_hardcoded_version = 10507;
156156
if (ZSTD_VERSION_NUMBER != our_hardcoded_version ||
157157
zstd_ver_no != our_hardcoded_version) {
158158
PyErr_Format(

make_cffi.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def normalize_output(output):
179179
include_dirs=INCLUDE_DIRS,
180180
)
181181

182-
DEFINE = re.compile(b"^\\#define ([a-zA-Z0-9_]+) ")
182+
DEFINE = re.compile(rb"^#define\s+([a-zA-Z0-9_]+)\s+(\S+)")
183183

184184
sources = []
185185

@@ -204,9 +204,14 @@ def normalize_output(output):
204204
if m.group(1) in (b"ZSTD_LIB_VERSION", b"ZSTD_VERSION_STRING"):
205205
continue
206206

207+
# These defines create aliases from old (camelCase) type names
208+
# to the new PascalCase names, which breaks CFFI.
209+
if m.group(1).lower() == m.group(2).lower():
210+
continue
211+
207212
# The ... is magic syntax by the cdef parser to resolve the
208213
# value at compile time.
209-
sources.append(m.group(0) + b" ...")
214+
sources.append(b"#define " + m.group(1) + b" ...")
210215

211216
cdeflines = b"\n".join(sources).splitlines()
212217
cdeflines = [line for line in cdeflines if line.strip()]

tests/test_compressor_compress.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_compress_large(self):
5252

5353
cctx = zstd.ZstdCompressor(level=3, write_content_size=False)
5454
result = cctx.compress(b"".join(chunks))
55-
self.assertEqual(len(result), 999)
55+
self.assertEqual(len(result), 1029)
5656
self.assertEqual(result[0:4], b"\x28\xb5\x2f\xfd")
5757

5858
# This matches the test for read_to_iter() below.

tests/test_compressor_compressobj.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_compressobj_large(self):
3939
cobj = cctx.compressobj()
4040

4141
result = cobj.compress(b"".join(chunks)) + cobj.flush()
42-
self.assertEqual(len(result), 999)
42+
self.assertEqual(len(result), 1029)
4343
self.assertEqual(result[0:4], b"\x28\xb5\x2f\xfd")
4444

4545
params = zstd.get_frame_parameters(result)

tests/test_compressor_copy_stream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_large_data(self):
5050
r, w = cctx.copy_stream(source, dest)
5151

5252
self.assertEqual(r, 255 * 16384)
53-
self.assertEqual(w, 999)
53+
self.assertEqual(w, 1029)
5454

5555
params = zstd.get_frame_parameters(dest.getvalue())
5656
self.assertEqual(params.content_size, zstd.CONTENTSIZE_UNKNOWN)

tests/test_compressor_stream_writer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def test_dictionary(self):
301301
d = zstd.train_dictionary(8192, samples)
302302

303303
h = hashlib.sha1(d.as_bytes()).hexdigest()
304-
self.assertEqual(h, "a46d2f7a3bc3357c9d717d3dadf9a26fde23e93d")
304+
self.assertEqual(h, "f32ddfbe0878bbd428afc00b17810387c6752191")
305305

306306
buffer = io.BytesIO()
307307
cctx = zstd.ZstdCompressor(level=9, dict_data=d)

tests/test_module_attributes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class TestModuleAttributes(unittest.TestCase):
77
def test_version(self):
8-
self.assertEqual(zstd.ZSTD_VERSION, (1, 5, 6))
8+
self.assertEqual(zstd.ZSTD_VERSION, (1, 5, 7))
99

1010
self.assertEqual(zstd.__version__, "0.24.0.dev0")
1111

zstandard/backend_cffi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,7 +2573,7 @@ def get_frame_parameters(data):
25732573
:return:
25742574
:py:class:`FrameParameters`
25752575
"""
2576-
params = ffi.new("ZSTD_frameHeader *")
2576+
params = ffi.new("ZSTD_FrameHeader *")
25772577

25782578
data_buffer = ffi.from_buffer(data)
25792579
zresult = lib.ZSTD_getFrameHeader(params, data_buffer, len(data_buffer))
@@ -4288,7 +4288,7 @@ def decompress_content_dict_chain(self, frames):
42884288

42894289
# All chunks should be zstd frames and should have content size set.
42904290
chunk_buffer = ffi.from_buffer(chunk)
4291-
params = ffi.new("ZSTD_frameHeader *")
4291+
params = ffi.new("ZSTD_FrameHeader *")
42924292
zresult = lib.ZSTD_getFrameHeader(
42934293
params, chunk_buffer, len(chunk_buffer)
42944294
)

0 commit comments

Comments
 (0)