Add basic dict function to c-api#7929
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 (2)
📝 WalkthroughWalkthroughAdds a new capi::dictobject module exposing C-API functions for dict creation, set/get, size, and iteration; exposes the module from capi::lib; and adds a PyDict::next_entry method and widens inner_setitem visibility to support iteration and C-API operations. ChangesDictionary C-API Surface
Sequence Diagram(s)sequenceDiagram
participant ComponentA
participant ComponentB
ComponentA->>ComponentB: observable interaction
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)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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
🧹 Nitpick comments (1)
crates/capi/src/dictobject.rs (1)
51-53: 💤 Low valueRemove redundant null assignment.
The result pointer is already set to null on line 41, making this assignment redundant.
♻️ Simplify by removing redundant assignment
} else { - unsafe { - *result = core::ptr::null_mut(); - } Ok(false) }🤖 Prompt for 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. In `@crates/capi/src/dictobject.rs` around lines 51 - 53, The assignment inside the unsafe block that sets *result = core::ptr::null_mut() is redundant because result is already initialized to null earlier; remove the unsafe block (or at least the single statement) that dereferences and writes to result to avoid the duplicate null assignment and unnecessary unsafe usage, referencing the variable name result and the unsafe block surrounding the assignment so you can locate and delete it safely.
🤖 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/dictobject.rs`:
- Around line 96-133: The test module in dictobject.rs is disabled via
#[cfg(false)] so tests like test_create_empty_dict, test_create_dict_with_items,
and test_dict_iter never run; either remove the #[cfg(false)] and adapt these
pyo3-based tests (Python::attach, PyDict, PyInt) to the project's testing
harness (e.g., convert them to use rustpython_vm::vm::thread APIs used in
pystate.rs), or if pyo3 usage is inappropriate delete the test module or add a
clear TODO comment explaining why they remain disabled and when/how they will be
enabled; update the tests to reference the project's VM entry points and types
or remove them to avoid misleading dead code.
---
Nitpick comments:
In `@crates/capi/src/dictobject.rs`:
- Around line 51-53: The assignment inside the unsafe block that sets *result =
core::ptr::null_mut() is redundant because result is already initialized to null
earlier; remove the unsafe block (or at least the single statement) that
dereferences and writes to result to avoid the duplicate null assignment and
unnecessary unsafe usage, referencing the variable name result and the unsafe
block surrounding the assignment so you can locate and delete it safely.
🪄 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: db25f9b1-5cfb-43e0-b57f-a7caaa293249
📒 Files selected for processing (2)
crates/capi/src/dictobject.rscrates/capi/src/lib.rs
|
@coderabbitai resume |
✅ Actions performedReviews resumed. |
da1777d to
d407549
Compare
There was a problem hiding this comment.
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/dictobject.rs`:
- Around line 26-30: The dict operations currently call the generic mapping
hooks via PyDict::set_item and get_item_opt inside with_vm (symbols: with_vm,
PyDict, set_item, get_item_opt), which can trigger subclass
__setitem__/__missing__; change these to call the dict-exact-storage helpers
that mirror CPython C-API semantics (PyDict_SetItem / PyDict_GetItemRef) on
rustpython_vm::builtins::PyDict so they bypass subclass hooks; locate the call
sites in dictobject.rs (the blocks that dereference dict/key/val and call
dict.set_item(...) and the analogous get_item_opt usages) and replace them with
the helper functions on PyDict that operate on underlying storage directly,
preserving error handling and VM context.
🪄 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: 36a3dc17-183f-4dcd-8d87-82e3e1d175ec
📒 Files selected for processing (3)
crates/capi/src/dictobject.rscrates/capi/src/lib.rscrates/vm/src/builtins/dict.rs
✅ Files skipped from review due to trivial changes (1)
- crates/capi/src/lib.rs
Summary by CodeRabbit