Add import support to c-api by bschoenmaeckers · Pull Request #7881 · RustPython/RustPython · GitHub
Skip to content

Add import support to c-api#7881

Merged
youknowone merged 1 commit into
RustPython:mainfrom
bschoenmaeckers:c-api-import
May 16, 2026
Merged

Add import support to c-api#7881
youknowone merged 1 commit into
RustPython:mainfrom
bschoenmaeckers:c-api-import

Conversation

@bschoenmaeckers

@bschoenmaeckers bschoenmaeckers commented May 16, 2026

Copy link
Copy Markdown
Contributor

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

  • New Features
    • Added Python module import functionality to the C API, allowing import operations through the external C interface.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0871bc8 and c5008bb.

📒 Files selected for processing (2)
  • crates/capi/src/import.rs
  • crates/capi/src/lib.rs

Comment thread crates/capi/src/import.rs

@ShaharNaveh ShaharNaveh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall lgtm:)

Comment thread crates/capi/src/import.rs

@ShaharNaveh ShaharNaveh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just read the PR description...

@youknowone youknowone merged commit a364f86 into RustPython:main May 16, 2026
25 checks passed
@bschoenmaeckers bschoenmaeckers deleted the c-api-import branch May 16, 2026 18:29
@coderabbitai coderabbitai Bot mentioned this pull request Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants