Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crates/capi/src/import.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::{PyObject, pystate::with_vm};
use rustpython_vm::builtins::PyStr;

#[unsafe(no_mangle)]
pub unsafe extern "C" fn PyImport_Import(name: *mut PyObject) -> *mut PyObject {
with_vm(|vm| {
let name = unsafe { (&*name).try_downcast_ref::<PyStr>(vm)? };
vm.import(name, 0)
Comment thread
bschoenmaeckers marked this conversation as resolved.
})
}

#[cfg(false)]
Comment thread
bschoenmaeckers marked this conversation as resolved.
mod tests {
use pyo3::prelude::*;

#[test]
fn test_import() {
Python::attach(|py| {
let _module = py.import("sys").unwrap();
})
}
}
1 change: 1 addition & 0 deletions crates/capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::sync::MutexGuard;

extern crate alloc;

pub mod import;
pub mod object;
pub mod pyerrors;
pub mod pylifecycle;
Expand Down
Loading