◐ Shell
reader mode source ↗
Skip to content

Add more list functions to the c-api#8045

Merged
youknowone merged 1 commit into
RustPython:mainfrom
bschoenmaeckers:c-api-more-list
Jun 10, 2026
Merged

Add more list functions to the c-api#8045
youknowone merged 1 commit into
RustPython:mainfrom
bschoenmaeckers:c-api-more-list

Conversation

@bschoenmaeckers

@bschoenmaeckers bschoenmaeckers commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Expanded list manipulation capabilities with four new C-API functions enabling list-to-tuple conversion, slice retrieval, slice modification, and list sorting.
  • Tests

    • Reorganized and enhanced test suite for list operations.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR extends RustPython's CPython compatibility layer by adding four new list C-API functions: PyList_AsTuple, PyList_GetSlice, PyList_SetSlice, and PyList_Sort. The implementation uses RustPython's VM internals and includes updates to test coverage and test naming conventions.

Changes

List C-API Extensions

Layer / File(s) Summary
New list C-API functions with imports
crates/capi/src/listobject.rs
Updated imports add AsObject and slice utilities (SaturatedSlice, slice traits). Four new extern "C" FFI functions dispatch through the RustPython VM to implement list-to-tuple conversion, slice retrieval with saturated bounds, slice modification/deletion (including null-pointer deletion), and list sorting via the sort method.
Test coverage and refactoring
crates/capi/src/listobject.rs
Existing test functions renamed by removing the test_ prefix. Test module extended with comprehensive coverage for tuple conversion, slice get/set operations, list reversal, and sorting assertions under #[cfg(false)].

Sequence Diagram(s)

No sequence diagram generated. This PR introduces FFI function implementations within a single module without multi-component sequential flows that would benefit from visualization.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • RustPython/RustPython#7944: Adds foundational PyList_New, PyList_SetItem, PyList_Append, PyList_Insert, and PyList_Reverse C-API functions to the same listobject.rs module, sharing the VM dispatch pattern used by this PR's new functions.
  • RustPython/RustPython#8019: Introduces PySlice_* C-API support and SaturatedSlice utilities that the new PyList_GetSlice and PyList_SetSlice functions depend upon.
  • RustPython/RustPython#7907: Adds tuple C-API support in tupleobject.rs that aligns with this PR's new PyList_AsTuple conversion function.

Suggested reviewers

  • ShaharNaveh
  • youknowone

Poem

🐰 List magic unfolds, four new spells are cast,
Slice, sort, tuple—a feast unsurpassed!
RustPython's embrace grows ever more wide,
C-API friends hop along for the ride! 🐇✨

🚥 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 clearly and concisely summarizes the main change: adding new list-related functions to the C-API, which aligns directly with the changeset introducing PyList_AsTuple, PyList_GetSlice, PyList_SetSlice, and PyList_Sort.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hide comment

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/capi/src/listobject.rs`:
- Around line 160-164: PyList_Sort currently downcasts to PyList and uses
vm.call_method(list.as_object(), "sort", ()) which performs normal Python-level
dispatch and can run overridden user code; change it to invoke the builtin list
sort implementation directly (not via instance dispatch). Specifically, replace
vm.call_method(...) in PyList_Sort with a direct call to the internal list
sorting routine (the in-place sorter for PyList) or call the "sort" function
bound to the exact built-in list type rather than the instance (e.g., resolve
the attribute on vm.ctx.types.list_type and invoke that bound function with the
list as self, or call PyList's internal sort method such as the library's
sort_inplace routine), ensuring no instance-level __dict__/subclass override can
run. Use the symbols PyList_Sort, PyList, and avoid vm.call_method to implement
this change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 5c374d9b-913d-4252-8864-62b444550774

📥 Commits

Reviewing files that changed from the base of the PR and between 51c97b9 and 073cd03.

📒 Files selected for processing (1)
  • crates/capi/src/listobject.rs

Hide details View details @youknowone youknowone merged commit 19ca508 into RustPython:main Jun 10, 2026
26 checks passed
@bschoenmaeckers bschoenmaeckers deleted the c-api-more-list branch June 10, 2026 07: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.

2 participants