Add import support to c-api#7881
Conversation
📝 WalkthroughWalkthroughIntroduces ChangesPyImport_Import C-ABI Export
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 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: 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/import.rs`:
- Around line 5-8: The FFI function PyImport_Import dereferences the incoming
pointer name without a null check, causing UB; before the unsafe block that does
(&*name).try_downcast_ref::<PyStr>(vm) add a guard if name.is_null() { return
std::ptr::null_mut(); } (or set an appropriate Python error on the VM and then
return std::ptr::null_mut()) so the function returns a null pointer on invalid
input; update the PyImport_Import implementation (the with_vm closure and the
place where try_downcast_ref and vm.import are called) to early-return when name
is null rather than dereferencing it.
🪄 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: 55deddf3-1835-45db-91d4-7de4cf550570
📒 Files selected for processing (2)
crates/capi/src/import.rscrates/capi/src/lib.rs
ShaharNaveh
left a comment
There was a problem hiding this comment.
Just read the PR description...
Add import support to the c-api. The test is currently disabled until we have enough api exposed to make it compile.
Summary by CodeRabbit