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 21, 2020
1 parent 5170412 commit 1660fe7
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,29 @@ 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>,
interpreter_config: &InterpreterConfig,
) -> HashMap<String, String> {
if interpreter_config.version.major == 3 && interpreter_config.version.minor.unwrap_or(0) > 7 {
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());
}
if let Some("1") = config_map.get("Py_TRACE_REFS").as_ref().map(|s| s.as_str()) {
config_map.insert("Py_TRACE_REFS".to_owned(), "1".to_owned());
}
// find CFLAGS to whether contains COUNT_ALLOCS then set it as 1
// if interpreter_config.version.minor.unwrap_or(0) < 9 {
// }
return config_map;
}

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());
// 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 +430,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 +462,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 +517,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 +545,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 +905,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 1660fe7

Please sign in to comment.