Fix the pydebug with trace refs and count_allocs for python > 3.7

This commit is contained in:
cecini 2020-12-20 19:07:29 +00:00 committed by David Hewitt
parent 4498b77c2c
commit c780aa931d
2 changed files with 17 additions and 8 deletions

View File

@ -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)

View File

@ -230,13 +230,17 @@ fn parse_header_defines(header_path: impl AsRef<Path>) -> Result<HashMap<String,
Ok(definitions)
}
fn fix_config_map(mut config_map: HashMap<String, String>) -> HashMap<String, String> {
fn fix_config_map(
mut config_map: HashMap<String, String>,
version_minor: Option<u8>,
) -> HashMap<String, String> {
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<HashMap<String, String>> {
memo
});
Ok(fix_config_map(all_vars))
Ok(all_vars)
}
fn get_config_vars_windows(_: &Path) -> Result<HashMap<String, String>> {
@ -529,7 +533,7 @@ fn get_config_vars_windows(_: &Path) -> Result<HashMap<String, String>> {
// 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