File tree Expand file tree Collapse file tree 8 files changed +201
-99
lines changed Expand file tree Collapse file tree 8 files changed +201
-99
lines changed Original file line number Diff line number Diff line change @@ -37,12 +37,9 @@ automated tooling because:
3737 - it gives us best control about how to adapt C conventions to Rust, and
3838 - there are many Python interpreter versions we support in a single set of files.
3939
40- We aim to provide straight-forward Rust wrappers resembling the file structure of
41- [ ` cpython/Include ` ] ( https://github.com/python/cpython/tree/v3.9.2/Include ) .
40+ We aim to provide straight-forward Rust wrappers resembling the file structure of [ ` cpython/Include ` ] ( https://github.com/python/cpython/tree/3.13/Include ) .
4241
43- However, we still lack some APIs and are continuously updating the module to match
44- the file contents upstream in CPython.
45- The tracking issue is [ #1289 ] ( https://github.com/PyO3/pyo3/issues/1289 ) , and contribution is welcome.
42+ We are continuously updating the module to match the latest CPython version which PyO3 supports (i.e. as of time of writing Python 3.13). The tracking issue is [ #1289 ] ( https://github.com/PyO3/pyo3/issues/1289 ) , and contribution is welcome.
4643
4744In the [ ` pyo3-ffi ` ] crate, there is lots of conditional compilation such as ` #[cfg(Py_LIMITED_API)] ` ,
4845` #[cfg(Py_3_7)] ` , and ` #[cfg(PyPy)] ` .
Original file line number Diff line number Diff line change 11use crate :: object:: * ;
22use crate :: pyport:: Py_ssize_t ;
33use std:: os:: raw:: { c_char, c_int} ;
4- use std:: ptr;
5-
6- extern "C" {
7- #[ cfg( PyPy ) ]
8- #[ link_name = "PyPyObject_DelAttrString" ]
9- pub fn PyObject_DelAttrString ( o : * mut PyObject , attr_name : * const c_char ) -> c_int ;
10- }
114
125#[ inline]
13- #[ cfg( not( PyPy ) ) ]
6+ #[ cfg( all ( not( Py_3_13 ) , not ( PyPy ) ) ) ] // CPython exposed as a function in 3.13, in object.h
147pub unsafe fn PyObject_DelAttrString ( o : * mut PyObject , attr_name : * const c_char ) -> c_int {
15- PyObject_SetAttrString ( o, attr_name, ptr:: null_mut ( ) )
8+ PyObject_SetAttrString ( o, attr_name, std :: ptr:: null_mut ( ) )
169}
1710
1811#[ inline]
12+ #[ cfg( all( not( Py_3_13 ) , not( PyPy ) ) ) ] // CPython exposed as a function in 3.13, in object.h
1913pub unsafe fn PyObject_DelAttr ( o : * mut PyObject , attr_name : * mut PyObject ) -> c_int {
20- PyObject_SetAttr ( o, attr_name, ptr:: null_mut ( ) )
14+ PyObject_SetAttr ( o, attr_name, std :: ptr:: null_mut ( ) )
2115}
2216
2317extern "C" {
Original file line number Diff line number Diff line change @@ -4,12 +4,6 @@ use crate::object::*;
44use std:: os:: raw:: { c_int, c_long} ;
55use std:: ptr:: addr_of_mut;
66
7- #[ cfg_attr( windows, link( name = "pythonXY" ) ) ]
8- extern "C" {
9- #[ cfg_attr( PyPy , link_name = "PyPyBool_Type" ) ]
10- pub static mut PyBool_Type : PyTypeObject ;
11- }
12-
137#[ inline]
148pub unsafe fn PyBool_Check ( op : * mut PyObject ) -> c_int {
159 ( Py_TYPE ( op) == addr_of_mut ! ( PyBool_Type ) ) as c_int
Original file line number Diff line number Diff line change @@ -240,7 +240,10 @@ pub struct PyTypeObject {
240240 pub tp_getattro : Option < object:: getattrofunc > ,
241241 pub tp_setattro : Option < object:: setattrofunc > ,
242242 pub tp_as_buffer : * mut PyBufferProcs ,
243+ #[ cfg( not( Py_GIL_DISABLED ) ) ]
243244 pub tp_flags : c_ulong ,
245+ #[ cfg( Py_GIL_DISABLED ) ]
246+ pub tp_flags : crate :: impl_:: AtomicCULong ,
244247 pub tp_doc : * const c_char ,
245248 pub tp_traverse : Option < object:: traverseproc > ,
246249 pub tp_clear : Option < object:: inquiry > ,
Original file line number Diff line number Diff line change 1+ #[ cfg( Py_GIL_DISABLED ) ]
2+ mod atomic_c_ulong {
3+ pub ( crate ) struct GetAtomicCULong < const SIZE : usize > ( ) ;
4+
5+ pub ( crate ) trait AtomicCULongType {
6+ type Type ;
7+ }
8+ impl AtomicCULongType for GetAtomicCULong < 32 > {
9+ type Type = std:: sync:: atomic:: AtomicU32 ;
10+ }
11+ impl AtomicCULongType for GetAtomicCULong < 64 > {
12+ type Type = std:: sync:: atomic:: AtomicU64 ;
13+ }
14+
15+ pub ( crate ) type TYPE = GetAtomicCULong < { std:: mem:: size_of :: < std:: os:: raw:: c_ulong > ( ) } > ;
16+ }
17+
18+ /// Typedef for an atomic integer to match the platform-dependent c_ulong type.
19+ #[ cfg( Py_GIL_DISABLED ) ]
20+ pub ( crate ) type AtomicCULong = atomic_c_ulong:: TYPE ;
Original file line number Diff line number Diff line change @@ -292,6 +292,7 @@ pub const fn _cstr_from_utf8_with_nul_checked(s: &str) -> &CStr {
292292use std:: ffi:: CStr ;
293293
294294pub mod compat;
295+ mod impl_;
295296
296297pub use self :: abstract_:: * ;
297298pub use self :: bltinmodule:: * ;
Original file line number Diff line number Diff line change @@ -6,12 +6,6 @@ use std::ptr::addr_of_mut;
66
77opaque_struct ! ( PyLongObject ) ;
88
9- #[ cfg_attr( windows, link( name = "pythonXY" ) ) ]
10- extern "C" {
11- #[ cfg_attr( PyPy , link_name = "PyPyLong_Type" ) ]
12- pub static mut PyLong_Type : PyTypeObject ;
13- }
14-
159#[ inline]
1610pub unsafe fn PyLong_Check ( op : * mut PyObject ) -> c_int {
1711 PyType_FastSubclass ( Py_TYPE ( op) , Py_TPFLAGS_LONG_SUBCLASS )
You can’t perform that action at this time.
0 commit comments