Come to think of it, changing comparison logic unexpectedly is a bad idea.

This commit is contained in:
Artem 2018-07-14 16:22:56 +02:00
parent e959c770e2
commit 71a5a43e33
1 changed files with 16 additions and 21 deletions

View File

@ -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.
// 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 {
struct IdRAII (LPWSTR);
/// RAII for device IDs.
@ -556,11 +552,13 @@ impl PartialEq for Device {
}
let mut id1: LPWSTR = ptr::null_mut();
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.
// Plus it won't do to change the device comparison logic unexpectedly.
if rc1 != winerror::S_OK {panic! ("cpal: GetId failure: {}", rc1)}
let id1 = IdRAII(id1);
let mut id2: LPWSTR = ptr::null_mut();
let rc2 = (*other.device).GetId(&mut id2);
if rc2 == winerror::S_OK {
if rc2 != winerror::S_OK {panic! ("cpal: GetId failure: {}", rc1)}
let id2 = IdRAII(id2);
// 16-bit null-terminated comparison.
let mut offset = 0;
@ -573,9 +571,6 @@ impl PartialEq for Device {
}
}
}
}
self.device == other.device
}
}
impl Eq for Device {