@@ -2,9 +2,10 @@ use crate::get_main_interpreter;
22use crate :: pyerrors:: init_exception_statics;
33use crate :: pystate:: ensure_thread_has_vm_attached;
44use core:: ffi:: { c_char, c_int} ;
5- use rustpython_vm:: version:: get_version ;
5+ use rustpython_vm:: version:: { MAJOR , MICRO , MINOR , VERSION_HEX } ;
66use rustpython_vm:: vm:: thread:: ThreadedVirtualMachine ;
77use rustpython_vm:: { Context , Interpreter } ;
8+ use std:: ffi:: c_ulong;
89use std:: sync:: { LazyLock , Mutex } ;
910
1011pub ( 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) ]
2125pub 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) ]
5862pub 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