Skip to content

Add slice functions to c-api#8019

Merged
youknowone merged 1 commit into
RustPython:mainfrom
bschoenmaeckers:c-api-slice
Jun 3, 2026
Merged

Add slice functions to c-api#8019
youknowone merged 1 commit into
RustPython:mainfrom
bschoenmaeckers:c-api-slice

Conversation

@bschoenmaeckers
Copy link
Copy Markdown
Contributor

@bschoenmaeckers bschoenmaeckers commented Jun 2, 2026

Summary by CodeRabbit

  • New Features
    • Public API expanded to include slice object handling, exposing creation, unpacking, and index-adjustment entrypoints for external callers.
    • Added a const constructor and const accessors for saturated slice values to inspect slice parameters reliably.
    • Slice-related utilities now available for integration and interoperability with external components.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 2, 2026

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.

Copy link
Copy Markdown
Contributor

@ShaharNaveh ShaharNaveh left a comment

Choose a reason for hiding this comment

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

The capi looks clean 🚀

@youknowone youknowone merged commit ad88d5a into RustPython:main Jun 3, 2026
26 checks passed
@bschoenmaeckers bschoenmaeckers deleted the c-api-slice branch June 3, 2026 09:38
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.

3 participants