GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add object protocol methods to c-api by bschoenmaeckers · Pull Request #7882 · RustPython/RustPython

Conversation

@bschoenmaeckers

@bschoenmaeckers bschoenmaeckers commented May 16, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

Review Change Stack

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@coderabbitai

coderabbitai Bot commented May 16, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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
  • X
  • Mastodon
  • Reddit
  • LinkedIn

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

coderabbitai[bot]
coderabbitai Bot reviewed May 16, 2026
View reviewed changes

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
Comment thread crates/capi/src/abstract_.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bschoenmaeckers
bschoenmaeckers force-pushed the c-api-abstract branch from 6a28e4e to 8cc3821 Compare May 16, 2026 11:24
youknowone
youknowone approved these changes May 16, 2026
View reviewed changes
@bschoenmaeckers
Add object protocol methods to c-api
4357f78
@bschoenmaeckers
bschoenmaeckers force-pushed the c-api-abstract branch from 8cc3821 to 4357f78 Compare May 16, 2026 18:29
@youknowone
youknowone merged commit 3a56f37 into RustPython:main May 17, 2026
26 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bschoenmaeckers
bschoenmaeckers deleted the c-api-abstract branch May 17, 2026 11:34
@coderabbitai coderabbitai Bot mentioned this pull request May 20, 2026
Add call functions to c-api #7937
Merged
This was referenced Jun 1, 2026
Update PyO3 to 0.29 & enable c-api tests #8000
Merged
Add mapping c-api functions #8003
Merged
Add number protocol functions to c-api #8005
Merged
This was referenced Jun 25, 2026
Add allocator functions to c-api #8168
Merged
Add more abstract functions to c-api #8202
Merged
youknowone pushed a commit that referenced this pull request Sep 16, 2026
@bschoenmaeckers
Add object protocol methods to c-api (#7882)
5dfa67b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments
@youknowone youknowone youknowone approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

2 participants

@bschoenmaeckers @youknowone
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.