Skip to content

feat: api port#3

Merged
dmadisetti merged 18 commits into
mainfrom
dm/port-from-reference
May 19, 2026
Merged

feat: api port#3
dmadisetti merged 18 commits into
mainfrom
dm/port-from-reference

Conversation

@dmadisetti
Copy link
Copy Markdown
Collaborator

Adds:

  • adler32
  • crc32
  • compress
  • decompress
  • compressobj + Compress.{compress,flush}
  • decompressobj + Decompress methods, attrs, zdict

dmadisetti added 18 commits May 18, 2026 17:26
THIRD_PARTY.md credits farhaanaliii/zlib-rs-python as the upstream
the bindings adapt from, with the 16 deviations we correct vs CPython's
spec at 5775aa8e. tests/test_adler32.py vendors ChecksumTestCase
adler32-only methods (lines 85-93) verbatim with provenance comments.
VersionTestCase, ExceptionTestCase, TestModule, and the rest of
CompressObjectTestCase / DecompressObjectTestCase missing from the
earlier slices — 16 in-scope tests + test_wbits as xfail. Adjusts
error mapping (compress/level → zlib.error, compressobj/wbits →
ValueError), makes Decompress.decompress's max_length keyword-OK,
and adds __version__ deprecation warning per CPython 3.16 spec.
Thin wrappers over zlib-rs 0.6.3's public combine helpers; i64→u64
cast mirrors C zlib's z_off_t. Vendor CPython's ChecksumCombineMixin
+ CRC32CombineTestCase + Adler32CombineTestCase verbatim.

Also bump abi3 floor to py311 and refresh the cargo-vendor FOD hash
(both were already in the working tree).
All callers replaced with real implementations in earlier commits.
Underscore-private decompressor stdlib gzip / streaming readers depend
on. Parallel state machine to Decompress: internal input buffer (no
unconsumed_tail), max_length < 0 sentinel for unlimited, EOFError on
any decompress() after eof. Reuses the NeedDict-on-demand zdict pattern
from Decompress. Same gzip-streaming restriction as decompressobj —
documented as deviation 17.

Vendor ZlibDecompressorTest from cpython@5775aa8e; skip 4G/refleak
tests that need CPython's bigmem/refcount harnesses.
decompress() bufsize was usize, so sys.maxsize+1 parsed fine then
panicked in Vec::resize. Switch to isize with an explicit negative
guard; isize overflow at parse time raises OverflowError, matching
CPython's "int too large" message.

Vendor test_overflow and test_disallow_instantiation (cpython_only
gate dropped — check_disallow_instantiation inlined as
assertRaises(TypeError)).
11 bigmem-gated tests from CPython's Lib/test/test_zlib.py
(ChecksumBigBufferTestCase, CompressTestCase, CompressObjectTestCase)
preserved verbatim and grouped in test_bigmem.py. All skipped because
they depend on CPython's test.support.bigmemtest decorator — re-enable
by wiring that in.

This closes the audit: every CPython test_zlib.py method is now either
vendored, vendored-as-xfail (engine divergences), or vendored-as-skip
(bigmem/refcount harness).
GitHub's windows-latest runner ships only x64 pythons in
hostedtoolcache, so maturin --find-interpreter --target i686 skips all
of them and the build fails with "Could not find any interpreters".
setup-python@v6 with architecture: x86 plants an interpreter but
maturin-action doesn't pick it up. Comment out until we figure out how
to provision a 32-bit interpreter the action will find.
Adapted only by rebinding zlib_rs → zlib_py. Methodology, sizes,
levels, and iteration counts are upstream's.

Sample run on aarch64-darwin: decompress 4-6x faster than CPython,
adler32 ~10x, streaming compress 4-5x. crc32 ~3x slower for >=64KB
because CPython uses Intel CRC32 intrinsics that zlib-rs doesn't hit
on this target. Compression ratios match stdlib byte-for-byte at L9
and diverge at L1/L6 (already documented as ByteParityWithStdlib xfails).
@dmadisetti dmadisetti merged commit f6b6540 into main May 19, 2026
17 checks passed
@dmadisetti dmadisetti deleted the dm/port-from-reference branch May 27, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant