Come to think of it, changing comparison logic unexpectedly is a bad idea.
This commit is contained in:
parent
e959c770e2
commit
71a5a43e33
|
@ -542,10 +542,6 @@ impl PartialEq for Device {
|
||||||
//
|
//
|
||||||
// In this code section we're trying to use the GetId method for the device comparison, cf.
|
// In this code section we're trying to use the GetId method for the device comparison, cf.
|
||||||
// https://docs.microsoft.com/en-us/windows/desktop/api/mmdeviceapi/nf-mmdeviceapi-immdevice-getid
|
// https://docs.microsoft.com/en-us/windows/desktop/api/mmdeviceapi/nf-mmdeviceapi-immdevice-getid
|
||||||
//
|
|
||||||
// If `GetId` mysteriously fails then we fall back to pointer comparison
|
|
||||||
// (we could panic, treating the `GetId` failure as something unexpected,
|
|
||||||
// but I simply don't know how reliable the `GetId` on Windows is).
|
|
||||||
unsafe {
|
unsafe {
|
||||||
struct IdRAII (LPWSTR);
|
struct IdRAII (LPWSTR);
|
||||||
/// RAII for device IDs.
|
/// RAII for device IDs.
|
||||||
|
@ -556,25 +552,24 @@ impl PartialEq for Device {
|
||||||
}
|
}
|
||||||
let mut id1: LPWSTR = ptr::null_mut();
|
let mut id1: LPWSTR = ptr::null_mut();
|
||||||
let rc1 = (*self.device).GetId(&mut id1);
|
let rc1 = (*self.device).GetId(&mut id1);
|
||||||
if rc1 == winerror::S_OK {
|
// GetId only fails with E_OUTOFMEMORY and if it does, we're probably dead already.
|
||||||
let id1 = IdRAII(id1);
|
// Plus it won't do to change the device comparison logic unexpectedly.
|
||||||
let mut id2: LPWSTR = ptr::null_mut();
|
if rc1 != winerror::S_OK {panic! ("cpal: GetId failure: {}", rc1)}
|
||||||
let rc2 = (*other.device).GetId(&mut id2);
|
let id1 = IdRAII(id1);
|
||||||
if rc2 == winerror::S_OK {
|
let mut id2: LPWSTR = ptr::null_mut();
|
||||||
let id2 = IdRAII(id2);
|
let rc2 = (*other.device).GetId(&mut id2);
|
||||||
// 16-bit null-terminated comparison.
|
if rc2 != winerror::S_OK {panic! ("cpal: GetId failure: {}", rc1)}
|
||||||
let mut offset = 0;
|
let id2 = IdRAII(id2);
|
||||||
loop {
|
// 16-bit null-terminated comparison.
|
||||||
let w1: WCHAR = *id1.0.offset(offset);
|
let mut offset = 0;
|
||||||
let w2: WCHAR = *id2.0.offset(offset);
|
loop {
|
||||||
if w1 == 0 && w2 == 0 {return true}
|
let w1: WCHAR = *id1.0.offset(offset);
|
||||||
if w1 != w2 {return false}
|
let w2: WCHAR = *id2.0.offset(offset);
|
||||||
offset += 1;
|
if w1 == 0 && w2 == 0 {return true}
|
||||||
}
|
if w1 != w2 {return false}
|
||||||
}
|
offset += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.device == other.device
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue