Add more object functions to c-api#8042
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds multiple C-API object/type helpers (type module-name, optional/generic attr access, rich compare, callable/dir, generic dict get/set, weakref clearing) and makes VM object dict utilities and a weakref-clear method public and re-exported. ChangesC-API Object Introspection and Manipulation Functions
Sequence Diagram(s)sequenceDiagram
participant CCaller
participant CApiLayer
participant VMBuiltins
participant VMCore
CCaller->>CApiLayer: PyObject_GetOptionalAttr(obj, name, out)
CApiLayer->>VMCore: generic_getattr / has_attr
VMCore-->>CApiLayer: attribute pointer / NULL
CCaller->>CApiLayer: PyObject_GenericSetDict(obj, value, ctx)
CApiLayer->>VMBuiltins: object_generic_set_dict(obj, value, vm)
VMBuiltins-->>CApiLayer: status (0/1)
CCaller->>CApiLayer: PyObject_ClearWeakRefs(obj)
CApiLayer->>VMCore: PyObject::clear_weak_refs()
VMCore-->>CApiLayer: cleared
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/object.rs`:
- Around line 273-279: PyObject_Dir currently dereferences obj unconditionally;
add a fast-path at the start of PyObject_Dir to check if obj.is_null() and
immediately return std::ptr::null_mut() (matching CPython semantics of returning
NULL without setting an exception) before calling with_vm or dereferencing; keep
the existing with_vm(... unsafe { &*obj }.to_owned().dir(vm).map(|list|
list.into_ref(&vm.ctx)) logic for the non-null path so behavior of to_owned(),
dir(), and into_ref() is unchanged.
- Around line 302-311: The function PyObject_GenericSetDict currently
unconditionally dereferences value causing UB when the descriptor protocol
passes NULL to signal deletion; change the code to check value with
NonNull::new(value) and map to PySetterValue::Delete when NULL (or
PySetterValue::Assign(non_null.to_owned()) when non-null) before calling
object_generic_set_dict so deletion flows through correctly and avoids
dereferencing a NULL pointer.
🪄 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: a7337516-4056-43f8-814e-250e06407d98
📒 Files selected for processing (4)
crates/capi/src/object.rscrates/vm/src/builtins/mod.rscrates/vm/src/builtins/object.rscrates/vm/src/object/core.rs
df865b4 to
0597510
Compare
Summary by CodeRabbit