Avoid closing invalid handles#119029
Conversation
|
r? @thomcc (rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
ed08061 to
599b092
Compare
|
I'm going to be away for a few months, so I'm rerolling my PRs so that folks don't have to wait for me. Sorry/thanks. r? libs |
joboet
left a comment
There was a problem hiding this comment.
That's a very good catch! Though I think this could be written a bit simpler without ManuallyDrop.
| #[stable(feature = "io_safety", since = "1.63.0")] | ||
| #[derive(Debug)] | ||
| pub struct HandleOrNull(OwnedHandle); | ||
| pub struct HandleOrNull(ManuallyDrop<OwnedHandle>); |
There was a problem hiding this comment.
I'd simply use RawHandle here, so that we don't have to do the ManuallyDrop::take dance below.
There was a problem hiding this comment.
Done. Since it's not possible to move out the inner field with a custom Drop implementation, I was looking for a decent way to implement TryFrom. However, I can just forget the struct altogether.
| #[stable(feature = "io_safety", since = "1.63.0")] | ||
| impl TryFrom<HandleOrNull> for OwnedHandle { | ||
| type Error = NullHandleError; | ||
| macro_rules! impl_handle_or { |
There was a problem hiding this comment.
Especially when combined with the suggestion above, I don't think that a macro is really necessary here.
There was a problem hiding this comment.
I would likely still use a macro due to the shared code between the implementations, but I don't have strong opinions if the preference is to avoid macros here.
599b092 to
24556e0
Compare
|
@rustbot ready |
|
Thanks! @bors r+ rollup |
| } | ||
| } | ||
|
|
||
| #[stable(feature = "handle_or_drop", since = "1.75.0")] |
There was a problem hiding this comment.
From where that 1.75? And next one.
There was a problem hiding this comment.
Hm, you're right. And this doesn't need a new feature as the fact it needs dropping isn't itself new.
|
@bors r- |
24556e0 to
f3b5b08
Compare
|
Updated and rebased on the latest master diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs
index 5566f525ea4..30a809daa21 100644
--- a/library/std/src/os/windows/io/handle.rs
+++ b/library/std/src/os/windows/io/handle.rs
@@ -173,7 +173,7 @@ fn try_from(handle_or_null: HandleOrNull) -> Result<Self, NullHandleError> {
}
}
-#[stable(feature = "handle_or_drop", since = "1.75.0")]
+#[stable(feature = "io_safety", since = "1.63.0")]
impl Drop for HandleOrNull {
#[inline]
fn drop(&mut self) {
@@ -251,7 +251,7 @@ fn try_from(handle_or_invalid: HandleOrInvalid) -> Result<Self, InvalidHandleErr
}
}
-#[stable(feature = "handle_or_drop", since = "1.75.0")]
+#[stable(feature = "io_safety", since = "1.63.0")]
impl Drop for HandleOrInvalid {
#[inline]
fn drop(&mut self) {@rustbot ready |
This comment has been minimized.
This comment has been minimized.
f3b5b08 to
a82587c
Compare
|
Thanks! @bors r+ rollup |
…s, r=ChrisDenton Avoid closing invalid handles Documentation for [`HandleOrInvalid`] has this note: > If holds a handle other than `INVALID_HANDLE_VALUE`, it will close the handle on drop. Documentation for [`HandleOrNull`] has this note: > If this holds a non-null handle, it will close the handle on drop. Currently, both will call `CloseHandle` on their invalid handles as a result of using `OwnedHandle` internally, contradicting the above paragraphs. This PR adds destructors that match the documentation. `@rustbot` label A-io O-windows T-libs [`HandleOrInvalid`]: https://doc.rust-lang.org/std/os/windows/io/struct.HandleOrInvalid.html [`HandleOrNull`]: https://doc.rust-lang.org/std/os/windows/io/struct.HandleOrNull.html
…s, r=ChrisDenton Avoid closing invalid handles Documentation for [`HandleOrInvalid`] has this note: > If holds a handle other than `INVALID_HANDLE_VALUE`, it will close the handle on drop. Documentation for [`HandleOrNull`] has this note: > If this holds a non-null handle, it will close the handle on drop. Currently, both will call `CloseHandle` on their invalid handles as a result of using `OwnedHandle` internally, contradicting the above paragraphs. This PR adds destructors that match the documentation. ``@rustbot`` label A-io O-windows T-libs [`HandleOrInvalid`]: https://doc.rust-lang.org/std/os/windows/io/struct.HandleOrInvalid.html [`HandleOrNull`]: https://doc.rust-lang.org/std/os/windows/io/struct.HandleOrNull.html
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#119029 (Avoid closing invalid handles) - rust-lang#122238 (Document some builtin impls in the next solver) - rust-lang#122247 (rustdoc-search: depth limit `T<U>` -> `U` unboxing) - rust-lang#122287 (add test ensuring simd codegen checks don't run when a static assertion failed) - rust-lang#122368 (chore: remove repetitive words) - rust-lang#122397 (Various cleanups around the const eval query providers) - rust-lang#122406 (Fix WF for `AsyncFnKindHelper` in new trait solver) - rust-lang#122477 (Change some attribute to only_local) - rust-lang#122482 (Ungate the `UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES` lint) - rust-lang#122490 (Update build instructions for OpenHarmony) Failed merges: - rust-lang#122471 (preserve span when evaluating mir::ConstOperand) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#119029 - dylni:avoid-closing-invalid-handles, r=ChrisDenton Avoid closing invalid handles Documentation for [`HandleOrInvalid`] has this note: > If holds a handle other than `INVALID_HANDLE_VALUE`, it will close the handle on drop. Documentation for [`HandleOrNull`] has this note: > If this holds a non-null handle, it will close the handle on drop. Currently, both will call `CloseHandle` on their invalid handles as a result of using `OwnedHandle` internally, contradicting the above paragraphs. This PR adds destructors that match the documentation. ```@rustbot``` label A-io O-windows T-libs [`HandleOrInvalid`]: https://doc.rust-lang.org/std/os/windows/io/struct.HandleOrInvalid.html [`HandleOrNull`]: https://doc.rust-lang.org/std/os/windows/io/struct.HandleOrNull.html
Documentation for
HandleOrInvalidhas this note:Documentation for
HandleOrNullhas this note:Currently, both will call
CloseHandleon their invalid handles as a result of usingOwnedHandleinternally, contradicting the above paragraphs. This PR adds destructors that match the documentation.@rustbot label A-io O-windows T-libs