Skip to content

Commit f08c4e7

Browse files
Fix Py_GetVersion
1 parent 50e17f1 commit f08c4e7

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

crates/capi/src/pylifecycle.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use crate::get_main_interpreter;
22
use crate::pyerrors::init_exception_statics;
33
use crate::pystate::ensure_thread_has_vm_attached;
44
use core::ffi::{c_char, c_int};
5-
use rustpython_vm::version::get_version;
5+
use rustpython_vm::version::{MAJOR, MICRO, MINOR, VERSION_HEX};
66
use rustpython_vm::vm::thread::ThreadedVirtualMachine;
77
use rustpython_vm::{Context, Interpreter};
8+
use std::ffi::c_ulong;
89
use std::sync::{LazyLock, Mutex};
910

1011
pub(crate) static MAIN_INTERP: Mutex<Option<Interpreter>> = Mutex::new(None);
@@ -17,6 +18,9 @@ pub(crate) fn request_vm_from_interpreter() -> ThreadedVirtualMachine {
1718
.enter(|vm| vm.new_thread())
1819
}
1920

21+
#[unsafe(no_mangle)]
22+
pub static Py_Version: c_ulong = VERSION_HEX as c_ulong;
23+
2024
#[unsafe(no_mangle)]
2125
pub extern "C" fn Py_IsInitialized() -> c_int {
2226
get_main_interpreter().is_some() as c_int
@@ -56,7 +60,7 @@ pub extern "C" fn Py_IsFinalizing() -> c_int {
5660

5761
#[unsafe(no_mangle)]
5862
pub extern "C" fn Py_GetVersion() -> *const c_char {
59-
static VERSION: LazyLock<String> = LazyLock::new(get_version);
63+
static VERSION: LazyLock<String> = LazyLock::new(|| format!("{MAJOR}.{MINOR}.{MICRO}"));
6064
VERSION.as_str().as_ptr() as *const c_char
6165
}
6266

@@ -70,5 +74,7 @@ mod tests {
7074
let version = py.version_info();
7175
assert!(version >= (3, 14));
7276
});
77+
78+
assert!(unsafe { pyo3::ffi::Py_Version } >= 0x030d0000);
7379
}
7480
}

0 commit comments

Comments
 (0)