Skip to content

pypy support: fix incompatibilities and a severe cpyext memory leak, see #1755 - #9976

Draft
ThomasWaldmann wants to merge 1 commit into
borgbackup:masterfrom
ThomasWaldmann:try-pypy
Draft

pypy support: fix incompatibilities and a severe cpyext memory leak, see #1755#9976
ThomasWaldmann wants to merge 1 commit into
borgbackup:masterfrom
ThomasWaldmann:try-pypy

Conversation

@ThomasWaldmann

@ThomasWaldmann ThomasWaldmann commented Jul 30, 2026

Copy link
Copy Markdown
Member

Summary

With this PR (plus #9978), borg works on pypy3.11 (tested: 7.3.23 on macOS/arm64): the full test suite passes under pypy (2056 passed, 1 xfailed) and there are no regressions on CPython (full suite verified). Details and benchmark numbers in #1755 (comment).

Changes:

  • platformflags: add is_pypy.
  • platform/darwin: pypy's fcntl lacks F_FULLFSYNC → numeric fallback (51).
  • crypto/low_level: pypy's hmac.digest only accepts bytes → coerce memoryview/bytearray on pypy.
  • archive: pypy's os.link(follow_symlinks=False) raises EINVAL despite advertised support (pypy bug) → emulate the secure CVE-2026-62268 behaviour (plain link for regular targets, an equal symlink when the hardlink target is a symlink).
  • tests: sys.executable instead of hardcoded python3 in test_with_lock (robustness fix, helps any venv layout), tolerate the pure-python-msgpack warning, xfail test_unknown_property on pypy, relax the inode identity assertion for the emulated hardlinked-symlink restore.

The severe pypy memory leak found during this work (chunk data memoryviews never released) is split out into #9978, since that fix is useful independently of pypy.

Follow-up to the (closed) #1755.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.83%. Comparing base (3a864cd) to head (666ecd5).
⚠️ Report is 5 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/borg/archive.py 33.33% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9976      +/-   ##
==========================================
- Coverage   85.84%   85.83%   -0.02%     
==========================================
  Files          95       95              
  Lines       17056    17072      +16     
  Branches     2614     2616       +2     
==========================================
+ Hits        14642    14653      +11     
- Misses       1674     1679       +5     
  Partials      740      740              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@ThomasWaldmann

Copy link
Copy Markdown
Member Author

Guess most of these should be fixed in PyPy rather, so do not merge this yet.

With these changes, borg works on pypy3.11 (7.3.23) on macOS:
the full test suite passes (2 pypy-specific expectation tweaks, 1 xfail)
and it causes no changes/regressions on CPython.

- platformflags: add is_pypy
- platform/darwin: pypy's fcntl module does not expose F_FULLFSYNC,
  fall back to the numeric constant (51).
- crypto/low_level: pypy's hmac.digest only accepts bytes keys/data
  (no memoryview, no bytearray), coerce on pypy.
- archive: pypy's os.link advertises follow_symlinks support, but raises
  EINVAL when the parameter is used (pypy bug). Emulate the secure
  CVE-2026-62268 behaviour: plain os.link for regular files, an equal
  symlink when the hardlink target is a symlink (fail closed otherwise).
- tests: use sys.executable instead of "python3" in test_with_lock
  (robustness, not pypy-specific), ignore the pure-python msgpack
  warning on stderr, expect slow msgpack on pypy, xfail
  test_unknown_property (cdef class attr setting not blocked on pypy),
  relax inode identity assertion for the emulated hardlinked-symlink
  restore, reference darwin.F_FULLFSYNC instead of fcntl's.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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