◐ Shell
clean mode source ↗

Add slice functions to c-api by bschoenmaeckers · Pull Request #8019 · RustPython/RustPython

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: fa12ac68-9c41-41b0-9a82-e5d80a83aeec

📥 Commits

Reviewing files that changed from the base of the PR and between 5947a89 and d984640.

📒 Files selected for processing (3)
  • crates/capi/src/lib.rs
  • crates/capi/src/sliceobject.rs
  • crates/vm/src/sliceable.rs
✅ Files skipped from review due to trivial changes (1)
  • crates/capi/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/capi/src/sliceobject.rs
  • crates/vm/src/sliceable.rs

📝 Walkthrough

Walkthrough

Adds a new sliceobject capi module and three FFI functions—PySlice_New, PySlice_Unpack, PySlice_AdjustIndices—plus const accessors on SaturatedSlice; includes disabled PyO3 unit tests for slice index behavior.

Changes

Slice FFI Implementation

Layer / File(s) Summary
SaturatedSlice public API
crates/vm/src/sliceable.rs
SaturatedSlice gains a const from_parts() constructor and const start(), stop(), step() getters marked #[must_use], enabling construction and inspection of slice components without direct field access.
PySlice FFI functions and tests
crates/capi/src/sliceobject.rs
Adds three FFI entrypoints: PySlice_New (build PySlice from nullable PyObject* inputs), PySlice_Unpack (downcast and write saturated start/stop/step to isize* outputs), and PySlice_AdjustIndices (saturate and adjust indices for a given length, handling negative step specially). Contains PyO3-based unit tests currently gated by #[cfg(false)].
Module export
crates/capi/src/lib.rs
Declares and publicly exports the sliceobject module in the capi crate.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • youknowone
  • ShaharNaveh

Poem

🐰
I nibbled at indices, tuned every part,
From null to None, I stitched slice art.
Const bits in order, adjusted with care,
C callers and VM now dance in the air.
Hop—FFI slices land safely, fair.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add slice functions to c-api' clearly and concisely describes the main change: adding three FFI functions (PySlice_New, PySlice_Unpack, PySlice_AdjustIndices) to the C API surface.
Docstring Coverage ✅ Passed Docstring coverage is 90.91% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.