зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1736459 - Handle null RawHandles in winapi-util. r=xpcom-reviewers,nika
This works around a regression in rust 1.56's libstd. Differential Revision: https://phabricator.services.mozilla.com/D129571
This commit is contained in:
Родитель
c7055c9450
Коммит
3e2e10708d
|
@ -5777,8 +5777,6 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
|||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
|
|
@ -110,3 +110,7 @@ path = "third_party/rust/mio"
|
|||
|
||||
[patch.crates-io.prost-derive]
|
||||
path = "third_party/rust/prost-derive"
|
||||
|
||||
# Patched to work around https://github.com/rust-lang/rust/issues/88576
|
||||
[patch.crates-io.winapi-util]
|
||||
path = "third_party/rust/winapi-util"
|
||||
|
|
|
@ -101,13 +101,16 @@ struct HandleRefInner(Option<File>);
|
|||
|
||||
impl Drop for HandleRefInner {
|
||||
fn drop(&mut self) {
|
||||
self.0.take().unwrap().into_raw_handle();
|
||||
self.0.take().map(|f| f.into_raw_handle());
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRawHandle for HandleRef {
|
||||
fn as_raw_handle(&self) -> RawHandle {
|
||||
self.as_file().as_raw_handle()
|
||||
match (self.0).0.as_ref() {
|
||||
Some(f) => f.as_raw_handle(),
|
||||
None => std::ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,17 +162,11 @@ impl HandleRef {
|
|||
/// is a valid handle. The caller must ensure this is true before invoking
|
||||
/// this constructor.
|
||||
pub unsafe fn from_raw_handle(handle: RawHandle) -> HandleRef {
|
||||
HandleRef(HandleRefInner(Some(File::from_raw_handle(handle))))
|
||||
}
|
||||
|
||||
/// Return this handle as a standard `File` reference.
|
||||
pub fn as_file(&self) -> &File {
|
||||
(self.0).0.as_ref().unwrap()
|
||||
}
|
||||
|
||||
/// Return this handle as a standard `File` mutable reference.
|
||||
pub fn as_file_mut(&mut self) -> &mut File {
|
||||
(self.0).0.as_mut().unwrap()
|
||||
HandleRef(HandleRefInner(if handle.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(File::from_raw_handle(handle))
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче