Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the pydebug with trace refs and count_allocs for python > 3.7
Browse files Browse the repository at this point in the history
cecini committed Dec 23, 2020
1 parent 5170412 commit b77ba36
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b77ba36

Please sign in to comment.