From c780aa931ddd9c961f47f51f36149f7dfbc6ddc8 Mon Sep 17 00:00:00 2001 From: cecini Date: Sun, 20 Dec 2020 19:07:29 +0000 Subject: [PATCH] Fix the pydebug with trace refs and count_allocs for python > 3.7 --- CHANGELOG.md | 4 ++++ build.rs | 21 +++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca9c4abe..1cd12d0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ PyO3 versions, please see the [migration guide](https://pyo3.rs/master/migration The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [Unreleased] +### Fixed +- Stop including `Py_TRACE_REFS` config setting automatically if `Py_DEBUG` is set on Python 3.8 and up. [#1334](https://github.com/PyO3/pyo3/pull/1334) + ## [0.13.0] - 2020-12-22 ### Packaging - Drop support for Python 3.5 (as it is now end-of-life). [#1250](https://github.com/PyO3/pyo3/pull/1250) diff --git a/build.rs b/build.rs index 03ea00f6..8659c687 100644 --- a/build.rs +++ b/build.rs @@ -230,13 +230,17 @@ fn parse_header_defines(header_path: impl AsRef) -> Result) -> HashMap { +fn fix_config_map( + mut config_map: HashMap, + version_minor: Option, +) -> HashMap { if let Some("1") = config_map.get("Py_DEBUG").as_ref().map(|s| s.as_str()) { config_map.insert("Py_REF_DEBUG".to_owned(), "1".to_owned()); - config_map.insert("Py_TRACE_REFS".to_owned(), "1".to_owned()); - config_map.insert("COUNT_ALLOCS".to_owned(), "1".to_owned()); + if version_minor.map_or(false, |minor| minor <= 7) { + // Py_DEBUG only implies Py_TRACE_REFS until Python 3.7 + config_map.insert("Py_TRACE_REFS".to_owned(), "1".to_owned()); + } } - config_map } @@ -414,7 +418,7 @@ fn load_cross_compile_from_sysconfigdata( calcsize_pointer, }; - Ok((interpreter_config, fix_config_map(config_map))) + Ok((interpreter_config, config_map)) } fn load_cross_compile_from_headers( @@ -446,7 +450,7 @@ fn load_cross_compile_from_headers( calcsize_pointer: None, }; - Ok((interpreter_config, fix_config_map(config_map))) + Ok((interpreter_config, config_map)) } fn load_cross_compile_info( @@ -501,7 +505,7 @@ fn get_config_vars(python_path: &Path) -> Result> { memo }); - Ok(fix_config_map(all_vars)) + Ok(all_vars) } fn get_config_vars_windows(_: &Path) -> Result> { @@ -529,7 +533,7 @@ fn get_config_vars_windows(_: &Path) -> Result> { // map.insert("Py_REF_DEBUG", "1"); // map.insert("Py_TRACE_REFS", "1"); // map.insert("COUNT_ALLOCS", 1"); - Ok(fix_config_map(map)) + Ok(map) } fn is_value(key: &str) -> bool { @@ -889,6 +893,7 @@ fn main() -> Result<()> { find_interpreter_and_get_config()? }; + config_map = fix_config_map(config_map, interpreter_config.version.minor); let flags = configure(&interpreter_config)?; // These flags need to be enabled manually for PyPy, because it does not expose