Allow creating PyCapsule objects#7595
Conversation
📝 WalkthroughWalkthroughModified the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/vm/src/builtins/capsule.rs`:
- Around line 28-35: The constructor Capsule::new currently accepts a raw ptr
and stores it without validation; update it to reject NULL pointers by
validating ptr before constructing—either change the signature to return
Result<Self, ErrorType> (e.g., Result<Capsule, InvalidPointerError>) and return
an Err when ptr.is_null(), or perform a defensive check and panic with a clear
message; ensure the check happens before setting self.ptr and mention
PyCapsule_New and PyCapsule_IsValid semantics in the error or panic so callers
know NULL is not allowed, and keep the destructor handling unchanged.
🪄 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: 89365b54-c937-4160-99bf-fe663f7677a7
📒 Files selected for processing (2)
crates/vm/src/builtins/capsule.rscrates/vm/src/vm/context.rs
Sorry, something went wrong.
ShaharNaveh
left a comment
There was a problem hiding this comment.
welcome to the project:)
can you please share some information about this change? what is it trying to achieve?
Sorry, something went wrong.
I needed this while experimenting with a capi at #7562. But this might be useful for other usecases as well. |
Sorry, something went wrong.
youknowone
left a comment
There was a problem hiding this comment.
Looks good, Thank you!
Sorry, something went wrong.
7544628
into
RustPython:main
Apr 14, 2026
Allow creation of
PyCapsuleobjects. The destructor is aCfunction for easy interop with other languages.Summary by CodeRabbit
Release Notes