Skip to content

Commit ddd6aa0

Browse files
authored
remove FFI definitions of private static variables (PyO3#5105)
* remove FFI definitions of private static variables * newsfragment * revert removal of `_PyWeakRef_RefType` for now
1 parent 936a1c6 commit ddd6aa0

File tree

8 files changed

+16
-21
lines changed

8 files changed

+16
-21
lines changed

newsfragments/5105.removed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove FFI definitions of private static variables: `_PyMethodWrapper_Type`, `_PyCoroWrapper_Type`, `_PyImport_FrozenBootstrap`, `_PyImport_FrozenStdlib`, `_PyImport_FrozenTest`, `_PyManagedBuffer_Type`, `_PySet_Dummy`, `_PyWeakref_ProxyType`, and `_PyWeakref_CallableProxyType`.

pyo3-ffi/src/cpython/descrobject.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ pub struct PyWrapperDescrObject {
6969
pub d_wrapped: *mut c_void,
7070
}
7171

72-
#[cfg_attr(windows, link(name = "pythonXY"))]
73-
extern "C" {
74-
pub static mut _PyMethodWrapper_Type: PyTypeObject;
75-
}
72+
// skipped _PyMethodWrapper_Type
7673

7774
// skipped non-limited PyDescr_NewWrapper
7875
// skipped non-limited PyDescr_IsData

pyo3-ffi/src/cpython/genobject.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ extern "C" {
6868
#[cfg_attr(windows, link(name = "pythonXY"))]
6969
extern "C" {
7070
pub static mut PyCoro_Type: PyTypeObject;
71-
pub static mut _PyCoroWrapper_Type: PyTypeObject;
7271
}
7372

73+
// skipped _PyCoroWrapper_Type
74+
7475
#[inline]
7576
pub unsafe fn PyCoro_CheckExact(op: *mut PyObject) -> c_int {
7677
PyObject_TypeCheck(op, addr_of_mut!(PyCoro_Type))

pyo3-ffi/src/cpython/import.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ pub struct _frozen {
6565
extern "C" {
6666
#[cfg(not(PyPy))]
6767
pub static mut PyImport_FrozenModules: *const _frozen;
68-
#[cfg(all(not(PyPy), Py_3_11))]
69-
pub static mut _PyImport_FrozenBootstrap: *const _frozen;
70-
#[cfg(all(not(PyPy), Py_3_11))]
71-
pub static mut _PyImport_FrozenStdlib: *const _frozen;
72-
#[cfg(all(not(PyPy), Py_3_11))]
73-
pub static mut _PyImport_FrozenTest: *const _frozen;
7468
}
69+
70+
// skipped _PyImport_FrozenBootstrap
71+
// skipped _PyImport_FrozenStdlib
72+
// skipped _PyImport_FrozenTest

pyo3-ffi/src/memoryobject.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ use crate::pyport::Py_ssize_t;
33
use std::os::raw::{c_char, c_int};
44
use std::ptr::addr_of_mut;
55

6+
// skipped _PyManagedBuffer_Type
7+
68
#[cfg_attr(windows, link(name = "pythonXY"))]
79
extern "C" {
8-
#[cfg(not(Py_LIMITED_API))]
9-
pub static mut _PyManagedBuffer_Type: PyTypeObject;
10-
1110
#[cfg_attr(PyPy, link_name = "PyPyMemoryView_Type")]
1211
pub static mut PyMemoryView_Type: PyTypeObject;
1312
}

pyo3-ffi/src/setobject.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ pub unsafe fn PySet_GET_SIZE(so: *mut PyObject) -> Py_ssize_t {
3939
(*so).used
4040
}
4141

42-
#[cfg(not(Py_LIMITED_API))]
43-
#[cfg_attr(windows, link(name = "pythonXY"))]
44-
extern "C" {
45-
pub static mut _PySet_Dummy: *mut PyObject;
46-
}
42+
// skipped _PySet_Dummy
4743

4844
extern "C" {
4945
#[cfg(not(Py_LIMITED_API))]

pyo3-ffi/src/weakrefobject.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ pub use crate::_PyWeakReference as PyWeakReference;
1111

1212
#[cfg_attr(windows, link(name = "pythonXY"))]
1313
extern "C" {
14+
// TODO: PyO3 is depending on this symbol in `reference.rs`, we should change this and
15+
// remove the export as this is a private symbol.
1416
pub static mut _PyWeakref_RefType: PyTypeObject;
15-
pub static mut _PyWeakref_ProxyType: PyTypeObject;
16-
pub static mut _PyWeakref_CallableProxyType: PyTypeObject;
17+
static mut _PyWeakref_ProxyType: PyTypeObject;
18+
static mut _PyWeakref_CallableProxyType: PyTypeObject;
1719

1820
#[cfg(PyPy)]
1921
#[link_name = "PyPyWeakref_CheckRef"]

src/types/weakref/reference.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pyobject_subclassable_native_type!(PyWeakrefReference, crate::ffi::PyWeakReferen
2222
pyobject_native_type!(
2323
PyWeakrefReference,
2424
ffi::PyWeakReference,
25+
// TODO: should not be depending on a private symbol here!
2526
pyobject_native_static_type_object!(ffi::_PyWeakref_RefType),
2627
#module=Some("weakref"),
2728
#checkfunction=ffi::PyWeakref_CheckRefExact

0 commit comments

Comments
 (0)