Skip to content

Commit a76ce14

Browse files
committed
fix detection of freethreaded interpreter
1 parent 4c88e9a commit a76ce14

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

pyo3-build-config/src/impl_.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,27 +1040,31 @@ impl FromStr for BuildFlag {
10401040
pub struct BuildFlags(pub HashSet<BuildFlag>);
10411041

10421042
impl BuildFlags {
1043-
const ALL: [BuildFlag; 4] = [
1044-
BuildFlag::Py_DEBUG,
1045-
BuildFlag::Py_REF_DEBUG,
1046-
BuildFlag::Py_TRACE_REFS,
1047-
BuildFlag::COUNT_ALLOCS,
1048-
];
1043+
fn iter_all() -> impl Iterator<Item = BuildFlag> {
1044+
[
1045+
BuildFlag::Py_DEBUG,
1046+
BuildFlag::Py_REF_DEBUG,
1047+
BuildFlag::Py_TRACE_REFS,
1048+
BuildFlag::COUNT_ALLOCS,
1049+
// done this way for the 0.22 branch because adding Py_GIL_DISABLED as
1050+
// an enum member is a breaking change
1051+
BuildFlag::Other("Py_GIL_DISABLED".to_string()),
1052+
]
1053+
.into_iter()
1054+
}
10491055

10501056
pub fn new() -> Self {
10511057
BuildFlags(HashSet::new())
10521058
}
10531059

10541060
fn from_sysconfigdata(config_map: &Sysconfigdata) -> Self {
10551061
Self(
1056-
BuildFlags::ALL
1057-
.iter()
1062+
BuildFlags::iter_all()
10581063
.filter(|flag| {
10591064
config_map
10601065
.get_value(flag.to_string())
10611066
.map_or(false, |value| value == "1")
10621067
})
1063-
.cloned()
10641068
.collect(),
10651069
)
10661070
.fixup()
@@ -1079,20 +1083,19 @@ impl BuildFlags {
10791083
let mut script = String::from("import sysconfig\n");
10801084
script.push_str("config = sysconfig.get_config_vars()\n");
10811085

1082-
for k in &BuildFlags::ALL {
1086+
for k in BuildFlags::iter_all() {
10831087
use std::fmt::Write;
10841088
writeln!(&mut script, "print(config.get('{}', '0'))", k).unwrap();
10851089
}
10861090

10871091
let stdout = run_python_script(interpreter.as_ref(), &script)?;
10881092
let split_stdout: Vec<&str> = stdout.trim_end().lines().collect();
10891093
ensure!(
1090-
split_stdout.len() == BuildFlags::ALL.len(),
1094+
split_stdout.len() == BuildFlags::iter_all().count(),
10911095
"Python stdout len didn't return expected number of lines: {}",
10921096
split_stdout.len()
10931097
);
1094-
let flags = BuildFlags::ALL
1095-
.iter()
1098+
let flags = BuildFlags::iter_all()
10961099
.zip(split_stdout)
10971100
.filter(|(_, flag_value)| *flag_value == "1")
10981101
.map(|(flag, _)| flag.clone())
@@ -1980,7 +1983,7 @@ mod tests {
19801983
HashSet::new()
19811984
);
19821985

1983-
for flag in &BuildFlags::ALL {
1986+
for flag in BuildFlags::iter_all() {
19841987
sysconfigdata.insert(flag.to_string(), "0".into());
19851988
}
19861989

@@ -1990,7 +1993,7 @@ mod tests {
19901993
);
19911994

19921995
let mut expected_flags = HashSet::new();
1993-
for flag in &BuildFlags::ALL {
1996+
for flag in BuildFlags::iter_all() {
19941997
sysconfigdata.insert(flag.to_string(), "1".into());
19951998
expected_flags.insert(flag.clone());
19961999
}

0 commit comments

Comments
 (0)