Skip to content

Commit

Permalink
Fall back to old (broken) env arg behavior if CompareStringOrdinal
Browse files Browse the repository at this point in the history
…is not available

See rust-lang#85270 and rust-lang#87863
  • Loading branch information
seritools committed Nov 29, 2024
1 parent 3163c9c commit 9bc9106
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions library/std/src/sys/pal/windows/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,3 +636,19 @@ compat_fn_with_fallback! {
TRUE
}
}

#[cfg(target_vendor = "rust9x")]
compat_fn_with_fallback! {
pub static KERNEL32: &CStr = c"kernel32" => { load: false, unicows: false };
// >= Vista / Server 2008
// https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-comparestringordinal
pub fn CompareStringOrdinal(
lpstring1: PCWSTR,
cchcount1: i32,
lpstring2: PCWSTR,
cchcount2: i32,
bignorecase: BOOL,
) -> COMPARESTRING_RESULT {
unimplemented!()
}
}
16 changes: 16 additions & 0 deletions library/std/src/sys/pal/windows/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ impl EnvKey {
// [4] https://docs.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-comparestringordinal
impl Ord for EnvKey {
fn cmp(&self, other: &Self) -> cmp::Ordering {
#[cfg(target_vendor = "rust9x")]
{
if c::CompareStringOrdinal::available().is_none() {
return self.os_string.cmp(&other.os_string);
}
}

unsafe {
let result = c::CompareStringOrdinal(
self.utf16.as_ptr(),
Expand Down Expand Up @@ -120,6 +127,15 @@ impl PartialEq<str> for EnvKey {
// they are compared using a caseless string mapping.
impl From<OsString> for EnvKey {
fn from(k: OsString) -> Self {
#[cfg(target_vendor = "rust9x")]
{
if c::CompareStringOrdinal::available().is_none() {
let mut k = k;
k.make_ascii_uppercase();
return EnvKey { utf16: Vec::new(), os_string: k };
}
}

EnvKey { utf16: k.encode_wide().collect(), os_string: k }
}
}
Expand Down

0 comments on commit 9bc9106

Please sign in to comment.