Add descriptor support to c-api - #8283
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds C ABI definitions and exported constructors for RustPython method, class-method, get/set, member, mapping-proxy, and wrapper descriptors, with validation, VM execution, callback handling, and exception translation. ChangesDescriptor FFI integration
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant C_API_Caller
participant DescriptorConstructor
participant RustPython_VM
participant Python_Descriptor
C_API_Caller->>DescriptorConstructor: call PyDescr_NewGetSet or PyDescr_NewMember
DescriptorConstructor->>RustPython_VM: execute construction through with_vm
RustPython_VM->>Python_Descriptor: construct descriptor with callbacks and metadata
Python_Descriptor-->>C_API_Caller: return PyObject or translated exception
C_API_Caller->>DescriptorConstructor: call PyWrapper_New
DescriptorConstructor->>RustPython_VM: call descriptor __get__ with obj and obj.class()
RustPython_VM-->>C_API_Caller: return bound object
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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/descrobject.rs`:
- Around line 82-184: In the descriptor construction flow around the four `match
(getset.get, getset.set)` arms, extract shared `wrap_native_getter` and
`wrap_native_setter` helpers and have every arm reuse them. Make the getter
wrapper convert a NULL native return into the raised exception or a
`SystemError` via `vm.take_raised_exception().unwrap_or_else(...)` instead of
panicking, while preserving the existing unreadable-attribute behavior for
missing getters and setters.
- Around line 48-68: Update PyDescr_NewClassMethod to construct the descriptor
with build_classmethod instead of build_method, while preserving its existing
type and method handling; leave PyDescr_NewMethod unchanged.
- Around line 70-184: Update PyDescr_NewGetSet to propagate getset.doc into
every descriptor constructor, preserving the C extension docstring for both
readable and setter-only descriptors. In all getter closures, replace the
NULL-return expect panic with a SystemError when no exception is set, while
continuing to propagate an already-raised exception.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 35e2d182-0118-411d-a8dc-2dfdcd287ec9
📒 Files selected for processing (2)
crates/capi/src/descrobject.rscrates/vm/src/builtins/mod.rs
1f5fb7f to
d09a824
Compare
d09a824 to
4b29795
Compare
3a604af to
f99a214
Compare
| use rustpython_vm::{Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine}; | ||
|
|
||
| #[repr(C)] | ||
| pub struct PyGetSetDef { |
There was a problem hiding this comment.
this is part of api... painful
There was a problem hiding this comment.
Yes it is...
Summary by CodeRabbit