Skip to content

Commit 65c043f

Browse files
committed
capi: advertise the abi3t suffix only once the loader is registered
Advertising it unconditionally made the extension tests of test_importlib run, and fail, on builds without the C API. Assisted-by: Claude Code:claude-sonnet-5-5
1 parent 15a3b62 commit 65c043f

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

‎crates/capi/src/extension.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ type ExecSlot = unsafe extern "C" fn(*mut PyObject) -> c_int;
1515
static PENDING_EXEC: Mutex<Vec<(usize, Vec<ExecSlot>)>> = Mutex::new(Vec::new());
1616

1717
/// Make `_imp.create_dynamic` able to load extension modules built for the stable ABI.
18+
///
19+
/// importlib reads the extension suffixes while the interpreter is built, so code that
20+
/// builds the interpreter itself must call this before `Interpreter::builder`.
1821
pub fn register_extension_loader() {
1922
rustpython_vm::stdlib::set_extension_module_loader(
2023
load_extension_module,

‎crates/vm/src/stdlib/_imp.rs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,13 @@ mod _imp {
252252

253253
#[pyfunction]
254254
fn extension_suffixes(vm: &VirtualMachine) -> Vec<PyObjectRef> {
255-
// importlib reads this while the interpreter is built, possibly before the C API
256-
// loader is registered, so the suffix is advertised whenever loading is possible.
257-
// `create_dynamic` reports an error if no loader was registered by then.
258-
let suffixes: &[&str] = if !cfg!(all(feature = "host_env", any(unix, windows))) {
259-
&[]
260-
} else if cfg!(windows) {
255+
// Only abi3t extensions can be loaded, and only once a C API loader is registered.
256+
// importlib reads this while the interpreter is built, so the loader has to be
257+
// registered before that.
258+
if super::EXTENSION_MODULE_LOADER.get().is_none() {
259+
return Vec::new();
260+
}
261+
let suffixes: &[&str] = if cfg!(windows) {
261262
&[".abi3t.pyd"]
262263
} else {
263264
&[".abi3t.so"]

0 commit comments

Comments
 (0)