GeezerVison is showing github.com — Add object protocol methods to c-api by bschoenmaeckers · Pull Request #7882 · RustPython/RustPython
Conversation
bschoenmaeckers
commented
May 16, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary by CodeRabbit
- New Features
- Extended the C API surface with new object operations for getting, setting, and deleting items, and added subclass/instance checks—improving compatibility with C extensions and interoperability with code relying on these fundamental object behaviors.
- Exposed the new API group at crate/module level so it’s available to C consumers.

Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
May 16, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
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: 9a2da496-c73c-4ba0-b221-9349fd1a1841
📥 Commits
Reviewing files that changed from the base of the PR and between 8cc3821 and 4357f78.
📒 Files selected for processing (2)
crates/capi/src/abstract_.rs
crates/capi/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- crates/capi/src/abstract_.rs
📝 Walkthrough
Walkthrough
A new FFI module adds five C-ABI extern functions that wrap PyObject operations (GetItem, SetItem, DelItem, IsSubclass, IsInstance), converting raw *mut PyObject pointers to Rust references and executing the underlying methods inside with_vm.
Changes
PyObject FFI Wrappers
| Layer / File(s) |
Summary |
Module declaration and imports crates/capi/src/lib.rs, crates/capi/src/abstract_.rs |
Module abstract_ is declared in the crate root. Imports for PyObject, with_vm, and c_int are established in the new module. |
Item access FFI wrappers crates/capi/src/abstract_.rs |
PyObject_GetItem, PyObject_SetItem, and PyObject_DelItem expose subscript-like operations as C-ABI wrappers, converting raw pointers and forwarding to underlying PyObject methods within a VM context. |
Type checking FFI wrappers crates/capi/src/abstract_.rs |
PyObject_IsSubclass and PyObject_IsInstance expose type relationship checks as C-ABI wrappers, dereferencing raw class/instance pointers and forwarding to the corresponding PyObject methods. |
sequenceDiagram
participant Caller
participant PyObject_FFI
participant VM
participant PyObject
Caller->>PyObject_FFI: PyObject_GetItem(obj, key)
PyObject_FFI->>VM: with_vm(call get_item on obj)
VM->>PyObject: get_item(key)
PyObject-->>VM: result PyObject*
VM-->>PyObject_FFI: returned pointer
PyObject_FFI-->>Caller: result pointer
Loading
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
🐰 I hopped through FFI and found,
Pointers wrapped and calls unbound.
Get and Set beneath the VM moon,
Delete and check — a quick buffoon.
Rust carrots, C-ABI tune.
🚥 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 accurately describes the main change: adding FFI functions for object protocol methods (get_item, set_item, del_item, is_subclass, is_instance) to the c-api module. |
| 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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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/abstract_.rs`:
- Around line 5-11: The exported FFI function(s) like PyObject_GetItem (and the
other four exported functions in this module) currently have safe fn signatures
but dereference raw pointers (unsafe { &*obj }), so change their signatures to
pub unsafe extern "C" fn ... to reflect the required caller-safety contract;
update all five exported functions' declarations (keeping extern "C" and return
types) to be unsafe, and ensure any internal unsafe blocks remain as needed so
the functions properly express that callers must provide valid, non-null,
aligned pointers.
🪄 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: 29e4e1e8-0de0-495c-b69c-06e5355b891e
📥 Commits
Reviewing files that changed from the base of the PR and between 0871bc8 and 6a28e4e.
📒 Files selected for processing (2)
crates/capi/src/abstract_.rs
crates/capi/src/lib.rs
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Jun 1, 2026
This was referenced Jun 25, 2026
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|