Skip to content

Commit

Permalink
Fix the pydebug with trace refs and count_allocs for python > 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
cecini committed Dec 22, 2020
1 parent 5170412 commit 4654243
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,26 @@ 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> {
if let Some("1") = config_map.get("Py_DEBUG").as_ref().map(|s| s.as_str()) {
fn fix_config_map(
mut config_map: HashMap<String, String>,
interpreter_config: &InterpreterConfig,
) -> HashMap<String, String> {
assert_eq!(interpreter_config.version.major, 3);
// defining the Py_DEBUG macro no longer implies the Py_TRACE_REFS macro by py38
if interpreter_config.version.minor.unwrap_or(0) >= 8 {
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());
}
} else 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());
}

// py3.9 remove the COUNT_ALLOCS related code
// if interpreter_config.version.minor.unwrap_or(0) <= 8 {
// // find CFLAGS to whether contains the COUNT_ALLOCS then set
// // config_map.insert("COUNT_ALLOCS".to_owned(), "1".to_owned());
// }
config_map
}

Expand Down Expand Up @@ -414,7 +427,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(
Expand Down Expand Up @@ -446,7 +459,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(
Expand Down Expand Up @@ -501,7 +514,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>> {
Expand Down Expand Up @@ -529,7 +542,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 {
Expand Down Expand Up @@ -889,6 +902,7 @@ fn main() -> Result<()> {
find_interpreter_and_get_config()?
};

config_map = fix_config_map(config_map, &interpreter_config);
let flags = configure(&interpreter_config)?;

// These flags need to be enabled manually for PyPy, because it does not expose
Expand Down

0 comments on commit 4654243

Please sign in to comment.