Skip to content

Add: Translate into caller-owned buffers - #353

Merged
ashvardanian merged 1 commit into
ashvardanian:main-devfrom
ternaus:codex/python-translate-out
Oct 18, 2026
Merged

ashvardanian merged 1 commit into
ashvardanian:main-devfrom
ternaus:codex/python-translate-out

Conversation

@ternaus

@ternaus ternaus commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Add keyword-only translate(..., out=buffer) to reuse writable, contiguous byte buffers. Accept sufficient capacity, return the supplied object, and leave the unused tail untouched. Exact aliasing is supported; partial overlap and combining out with inplace=True are rejected.

Extend the existing translation tests in test/string.py, including source views invalidated by output-export callbacks.

Validation: 10,512 core Python tests passed with debug allocation enabled; 161 optional tests skipped. Markdown, Python, and C formatting checks pass.

Fixes #352. Part of #302.

@ternaus
ternaus force-pushed the codex/python-translate-out branch from 998ad13 to 090509b Compare October 15, 2026 23:29
@ternaus ternaus changed the title Feat: Translate into caller-owned writable buffers Feature: Translate into caller-owned writable buffers Oct 15, 2026
@ternaus
ternaus marked this pull request as ready for review October 17, 2026 04:51
Copilot AI balanced review requested due to automatic review settings October 17, 2026 04:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

A source-lifetime defect and unresolved hosted-suite memory corruption require correction and human investigation.

1 open issue
What changed in this PR

Adds caller-owned writable outputs to byte translation, avoiding an intermediate immutable allocation.

Changes:

  • Adds keyword-only out with length and overlap validation.
  • Rejects invalid keywords before mutation and delays source binding.
  • Documents the API and adds buffer/error regression tests.
File Description
test/​memory.py Tests writable outputs, aliasing, and error handling.
python/​stringzilla/​memory.c Implements output buffers and safer argument handling.
python/​README.md Documents output requirements and usage.

Review effort: Balanced

Comment thread python/stringzilla/memory.c Resolved
@ashvardanian
ashvardanian force-pushed the codex/python-translate-out branch 2 times, most recently from 43e1d2d to 3fbb441 Compare October 18, 2026 21:27
@ashvardanian
ashvardanian changed the base branch from main to main-dev October 18, 2026 21:27
Write into writable caller buffers, preserving unused capacity and returning the supplied object.
@ashvardanian ashvardanian changed the title Feature: Translate into caller-owned writable buffers Add: Translate into caller-owned buffers Oct 18, 2026
@ashvardanian
ashvardanian force-pushed the codex/python-translate-out branch from 3fbb441 to 53a7c84 Compare October 18, 2026 21:48
@ashvardanian
ashvardanian merged commit e1d7b8c into ashvardanian:main-dev Oct 18, 2026
19 of 21 checks passed
sub4biz pushed a commit to sub4biz/StringZilla that referenced this pull request Nov 14, 2026
The 5.x line released v5.2.0 through v5.3.2 after 6.0 branched at
v5.1.2, and its public main ends at d0c8dea. Its fixes now hold on
6.0's code:

- Reverse searches with large limits no longer overflow (1b9b0a5, ashvardanian#347)
- Empty needles match in default string views (faf71d7, ashvardanian#346)
- `rpartition` puts the text last when the separator is missing
  (b128ed3, ashvardanian#356)
- `translate` writes into a reusable `out` buffer (e1d7b8c, ashvardanian#353)
- Byte argsort walks windows on a heap stack instead of recursing, so
  long shared prefixes no longer exhaust the call stack, and Haswell and
  NEON accept empty inputs (7deae1e, ashvardanian#344; 12d5f81)
- 2-4 byte needles search backward with SWAR (e94052b, ashvardanian#342)
- RISC-V GCM kernels dispatch only where Zvkg is present (2f78f25)
- Pyodide wheels and RISC-V wheel images (96c88fd, ashvardanian#343), and Python
  CI runs under the debug allocator (339f47a)

Already on 6.0's code: forward searches past the end (31e7c8c, ashvardanian#348)
and big-endian VSX byte sets (fcf768b, ashvardanian#360), both via 8f298ac, and
the test package's exclusion from wheels (fa427ac, ashvardanian#338). The CUDA
wheel, StringZillas scratch and tape-length fixes target code 6.0
replaced.

Unknown keyword arguments now raise `TypeError` in `split`, `splitlines`,
the strips, `decode`, the `String` constructor, `shuffled` and `sample`,
where `else if (PyErr_Format(...))` never returned and surfaced as
`SystemError`; porting `translate(out=)` exposed it.

Also folded: dead includes dropped from four tests.

Co-Authored-By: Guillaume de Rouville <[email protected]>
Co-Authored-By: Shai <[email protected]>
Co-Authored-By: Vladimir Iglovikov <[email protected]>
Co-Authored-By: Vladimir Babin <[email protected]>
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.

Bug: translate returns SystemError for unexpected or duplicate keywords

3 participants