Skip to content

Commit e9151b4

Browse files
Deprecate and remove Py_TRACE_REFS support (#5824)
* Deprecate and remove `Py_TRACE_REFS` support (unsupported from Python 3.13). * Add news fragment for `Py_TRACE_REFS` deprecation and removal. * Update pyo3-build-config/src/impl_.rs Co-authored-by: David Hewitt <mail@davidhewitt.dev> * Remove final traces of `Py_TRACE_REFS` support. --------- Co-authored-by: David Hewitt <mail@davidhewitt.dev>
1 parent f519845 commit e9151b4

File tree

4 files changed

+4
-37
lines changed

4 files changed

+4
-37
lines changed

newsfragments/5824.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate and remove `Py_TRACE_REFS` support (unsupported from Python 3.13).

pyo3-build-config/src/impl_.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,7 @@ pub fn cross_compiling_from_cargo_env() -> Result<Option<CrossCompileConfig>> {
11471147
pub enum BuildFlag {
11481148
Py_DEBUG,
11491149
Py_REF_DEBUG,
1150+
#[deprecated(since = "0.29.0", note = "no longer supported by PyO3")]
11501151
Py_TRACE_REFS,
11511152
Py_GIL_DISABLED,
11521153
COUNT_ALLOCS,
@@ -1168,7 +1169,6 @@ impl FromStr for BuildFlag {
11681169
match s {
11691170
"Py_DEBUG" => Ok(BuildFlag::Py_DEBUG),
11701171
"Py_REF_DEBUG" => Ok(BuildFlag::Py_REF_DEBUG),
1171-
"Py_TRACE_REFS" => Ok(BuildFlag::Py_TRACE_REFS),
11721172
"Py_GIL_DISABLED" => Ok(BuildFlag::Py_GIL_DISABLED),
11731173
"COUNT_ALLOCS" => Ok(BuildFlag::COUNT_ALLOCS),
11741174
other => Ok(BuildFlag::Other(other.to_owned())),
@@ -1194,10 +1194,9 @@ impl FromStr for BuildFlag {
11941194
pub struct BuildFlags(pub HashSet<BuildFlag>);
11951195

11961196
impl BuildFlags {
1197-
const ALL: [BuildFlag; 5] = [
1197+
const ALL: [BuildFlag; 4] = [
11981198
BuildFlag::Py_DEBUG,
11991199
BuildFlag::Py_REF_DEBUG,
1200-
BuildFlag::Py_TRACE_REFS,
12011200
BuildFlag::Py_GIL_DISABLED,
12021201
BuildFlag::COUNT_ALLOCS,
12031202
];

pyo3-ffi/src/modsupport.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub const PYTHON_API_VERSION: i32 = 1013;
8383
pub const PYTHON_ABI_VERSION: i32 = 3;
8484

8585
extern "C" {
86-
#[cfg(not(py_sys_config = "Py_TRACE_REFS"))]
86+
8787
#[cfg_attr(PyPy, link_name = "PyPyModule_Create2")]
8888
pub fn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject;
8989
}
@@ -101,39 +101,14 @@ pub unsafe fn PyModule_Create(module: *mut PyModuleDef) -> *mut PyObject {
101101
}
102102

103103
extern "C" {
104-
#[cfg(py_sys_config = "Py_TRACE_REFS")]
105-
fn PyModule_Create2TraceRefs(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject;
106104

107-
#[cfg(not(py_sys_config = "Py_TRACE_REFS"))]
108105
#[cfg_attr(PyPy, link_name = "PyPyModule_FromDefAndSpec2")]
109106
pub fn PyModule_FromDefAndSpec2(
110107
def: *mut PyModuleDef,
111108
spec: *mut PyObject,
112109
module_api_version: c_int,
113110
) -> *mut PyObject;
114111

115-
#[cfg(py_sys_config = "Py_TRACE_REFS")]
116-
fn PyModule_FromDefAndSpec2TraceRefs(
117-
def: *mut PyModuleDef,
118-
spec: *mut PyObject,
119-
module_api_version: c_int,
120-
) -> *mut PyObject;
121-
}
122-
123-
#[cfg(py_sys_config = "Py_TRACE_REFS")]
124-
#[inline]
125-
pub unsafe fn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject {
126-
PyModule_Create2TraceRefs(module, apiver)
127-
}
128-
129-
#[cfg(py_sys_config = "Py_TRACE_REFS")]
130-
#[inline]
131-
pub unsafe fn PyModule_FromDefAndSpec2(
132-
def: *mut PyModuleDef,
133-
spec: *mut PyObject,
134-
module_api_version: c_int,
135-
) -> *mut PyObject {
136-
PyModule_FromDefAndSpec2TraceRefs(def, spec, module_api_version)
137112
}
138113

139114
#[inline]

pyo3-ffi/src/object.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ const _PyObject_MIN_ALIGNMENT: usize = 4;
9696
#[cfg_attr(all(Py_3_15, Py_GIL_DISABLED), repr(C, align(4)))]
9797
#[derive(Debug)]
9898
pub struct PyObject {
99-
#[cfg(py_sys_config = "Py_TRACE_REFS")]
100-
pub _ob_next: *mut PyObject,
101-
#[cfg(py_sys_config = "Py_TRACE_REFS")]
102-
pub _ob_prev: *mut PyObject,
10399
#[cfg(Py_GIL_DISABLED)]
104100
pub ob_tid: libc::uintptr_t,
105101
#[cfg(all(Py_GIL_DISABLED, not(Py_3_14)))]
@@ -128,10 +124,6 @@ const _: () = assert!(std::mem::align_of::<PyObject>() >= _PyObject_MIN_ALIGNMEN
128124
reason = "contains atomic refcount on free-threaded builds"
129125
)]
130126
pub const PyObject_HEAD_INIT: PyObject = PyObject {
131-
#[cfg(py_sys_config = "Py_TRACE_REFS")]
132-
_ob_next: std::ptr::null_mut(),
133-
#[cfg(py_sys_config = "Py_TRACE_REFS")]
134-
_ob_prev: std::ptr::null_mut(),
135127
#[cfg(Py_GIL_DISABLED)]
136128
ob_tid: 0,
137129
#[cfg(all(Py_GIL_DISABLED, Py_3_15))]

0 commit comments

Comments
 (0)