Skip to content

Commit 93beb66

Browse files
authored
Merge branch 'microsoft:master' into patch-1
2 parents 8bea710 + 139ca3c commit 93beb66

File tree

9 files changed

+60
-57
lines changed

9 files changed

+60
-57
lines changed

crates/libs/bindgen/src/rust/handles.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,34 @@ pub fn gen_win_handle(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
3030
let ident = to_ident(name);
3131
let underlying_type = def.underlying_type();
3232
let signature = writer.type_default_name(&underlying_type);
33-
let is_invalid = if underlying_type.is_pointer() {
33+
let invalid = metadata::type_def_invalid_values(def);
34+
35+
let is_invalid = if underlying_type.is_pointer() && (invalid.is_empty() || invalid == [0]) {
3436
quote! {
3537
impl #ident {
3638
pub fn is_invalid(&self) -> bool {
3739
self.0.is_null()
3840
}
3941
}
4042
}
43+
} else if invalid.is_empty() {
44+
quote! {}
4145
} else {
42-
let invalid = metadata::type_def_invalid_values(def);
46+
let invalid = invalid.iter().map(|value| {
47+
let literal = Literal::i64_unsuffixed(*value);
4348

44-
if !invalid.is_empty() {
45-
let invalid = invalid.iter().map(|value| {
46-
let literal = Literal::i64_unsuffixed(*value);
47-
48-
if *value < 0 && underlying_type.is_unsigned() {
49-
quote! { self.0 == #literal as _ }
50-
} else {
51-
quote! { self.0 == #literal }
52-
}
53-
});
54-
quote! {
55-
impl #ident {
56-
pub fn is_invalid(&self) -> bool {
57-
#(#invalid)||*
58-
}
49+
if underlying_type.is_pointer() || (*value < 0 && underlying_type.is_unsigned()) {
50+
quote! { self.0 == #literal as _ }
51+
} else {
52+
quote! { self.0 == #literal }
53+
}
54+
});
55+
quote! {
56+
impl #ident {
57+
pub fn is_invalid(&self) -> bool {
58+
#(#invalid)||*
5959
}
6060
}
61-
} else {
62-
quote! {}
6361
}
6462
};
6563

crates/libs/bindgen/src/rust/structs.rs

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,40 @@ fn gen_struct_with_name(
4343
quote! { #[repr(C)] }
4444
};
4545

46-
let fields = def.fields().map(|f| {
47-
let name = to_ident(f.name());
48-
let ty = f.ty(Some(def));
49-
50-
if f.flags().contains(metadata::FieldAttributes::Literal) {
51-
quote! {}
52-
} else if !writer.sys
53-
&& flags.contains(metadata::TypeAttributes::ExplicitLayout)
54-
&& !metadata::field_is_copyable(f, def)
55-
{
56-
let ty = writer.type_default_name(&ty);
57-
quote! { pub #name: core::mem::ManuallyDrop<#ty>, }
58-
} else if !writer.sys
59-
&& !flags.contains(metadata::TypeAttributes::WindowsRuntime)
60-
&& !metadata::field_is_blittable(f, def)
61-
{
62-
if let metadata::Type::Win32Array(ty, len) = ty {
46+
let fields = if def.fields().next().is_none() {
47+
quote! { (pub u8); }
48+
} else {
49+
let fields = def.fields().map(|f| {
50+
let name = to_ident(f.name());
51+
let ty = f.ty(Some(def));
52+
53+
if f.flags().contains(metadata::FieldAttributes::Literal) {
54+
quote! {}
55+
} else if !writer.sys
56+
&& flags.contains(metadata::TypeAttributes::ExplicitLayout)
57+
&& !metadata::field_is_copyable(f, def)
58+
{
6359
let ty = writer.type_default_name(&ty);
64-
quote! { pub #name: [core::mem::ManuallyDrop<#ty>; #len], }
60+
quote! { pub #name: core::mem::ManuallyDrop<#ty>, }
61+
} else if !writer.sys
62+
&& !flags.contains(metadata::TypeAttributes::WindowsRuntime)
63+
&& !metadata::field_is_blittable(f, def)
64+
{
65+
if let metadata::Type::Win32Array(ty, len) = ty {
66+
let ty = writer.type_default_name(&ty);
67+
quote! { pub #name: [core::mem::ManuallyDrop<#ty>; #len], }
68+
} else {
69+
let ty = writer.type_default_name(&ty);
70+
quote! { pub #name: core::mem::ManuallyDrop<#ty>, }
71+
}
6572
} else {
6673
let ty = writer.type_default_name(&ty);
67-
quote! { pub #name: core::mem::ManuallyDrop<#ty>, }
74+
quote! { pub #name: #ty, }
6875
}
69-
} else {
70-
let ty = writer.type_default_name(&ty);
71-
quote! { pub #name: #ty, }
72-
}
73-
});
76+
});
77+
78+
quote! { {#(#fields)*} }
79+
};
7480

7581
let struct_or_union = if flags.contains(metadata::TypeAttributes::ExplicitLayout) {
7682
quote! { union }
@@ -85,7 +91,7 @@ fn gen_struct_with_name(
8591
#repr
8692
#features
8793
#derive
88-
pub #struct_or_union #name {#(#fields)*}
94+
pub #struct_or_union #name #fields
8995
};
9096

9197
tokens.combine(&gen_struct_constants(writer, def, &name, &cfg));

crates/libs/core/src/imp/waiter.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use super::*;
22

33
#[doc(hidden)]
4-
pub struct Waiter(isize);
5-
pub struct WaiterSignaler(isize);
4+
pub struct Waiter(HANDLE);
5+
pub struct WaiterSignaler(HANDLE);
6+
7+
unsafe impl Send for WaiterSignaler {}
68

79
impl Waiter {
810
pub fn new() -> crate::Result<(Waiter, WaiterSignaler)> {

crates/libs/windows/src/Windows/Win32/Foundation/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10688,7 +10688,7 @@ impl windows_core::TypeKind for HANDLE_PTR {
1068810688
pub struct HGLOBAL(pub *mut core::ffi::c_void);
1068910689
impl HGLOBAL {
1069010690
pub fn is_invalid(&self) -> bool {
10691-
self.0.is_null()
10691+
self.0 == -1 as _ || self.0 == 0 as _
1069210692
}
1069310693
}
1069410694
impl windows_core::Free for HGLOBAL {
@@ -10740,7 +10740,7 @@ impl From<HINSTANCE> for HMODULE {
1074010740
pub struct HLOCAL(pub *mut core::ffi::c_void);
1074110741
impl HLOCAL {
1074210742
pub fn is_invalid(&self) -> bool {
10743-
self.0.is_null()
10743+
self.0 == -1 as _ || self.0 == 0 as _
1074410744
}
1074510745
}
1074610746
impl windows_core::Free for HLOCAL {

crates/libs/windows/src/Windows/Win32/Security/Cryptography/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14306,7 +14306,7 @@ impl windows_core::TypeKind for HCERTCHAINENGINE {
1430614306
pub struct HCERTSTORE(pub *mut core::ffi::c_void);
1430714307
impl HCERTSTORE {
1430814308
pub fn is_invalid(&self) -> bool {
14309-
self.0.is_null()
14309+
self.0 == -1 as _ || self.0 == 0 as _
1431014310
}
1431114311
}
1431214312
impl Default for HCERTSTORE {
@@ -14322,7 +14322,7 @@ impl windows_core::TypeKind for HCERTSTORE {
1432214322
pub struct HCERTSTOREPROV(pub *mut core::ffi::c_void);
1432314323
impl HCERTSTOREPROV {
1432414324
pub fn is_invalid(&self) -> bool {
14325-
self.0.is_null()
14325+
self.0 == -1 as _ || self.0 == 0 as _
1432614326
}
1432714327
}
1432814328
impl Default for HCERTSTOREPROV {

crates/libs/windows/src/Windows/Win32/Security/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2671,7 +2671,7 @@ impl Default for PRIVILEGE_SET {
26712671
pub struct PSECURITY_DESCRIPTOR(pub *mut core::ffi::c_void);
26722672
impl PSECURITY_DESCRIPTOR {
26732673
pub fn is_invalid(&self) -> bool {
2674-
self.0.is_null()
2674+
self.0 == -1 as _ || self.0 == 0 as _
26752675
}
26762676
}
26772677
impl Default for PSECURITY_DESCRIPTOR {

crates/libs/windows/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8227,7 +8227,7 @@ impl From<HCURSOR> for HICON {
82278227
pub struct HDEVNOTIFY(pub *mut core::ffi::c_void);
82288228
impl HDEVNOTIFY {
82298229
pub fn is_invalid(&self) -> bool {
8230-
self.0.is_null()
8230+
self.0 == -1 as _ || self.0 == 0 as _
82318231
}
82328232
}
82338233
impl windows_core::Free for HDEVNOTIFY {

crates/libs/windows/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs
99
#![doc(html_no_source)]
1010
#![allow(non_snake_case, clashing_extern_declarations, non_upper_case_globals, non_camel_case_types, missing_docs, clippy::all)]
1111
#![cfg_attr(not(feature = "docs"), doc(hidden))]
12-
// TODO: https://github.com/microsoft/windows-rs/issues/3096
13-
#![allow(dead_code)]
12+
// TODO: workaround for https://github.com/rust-lang/rust/issues/126169
13+
#![allow(unused)]
1414

1515
#[allow(unused_extern_crates)]
1616
extern crate self as windows;

crates/tests/lib/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,3 @@ features = [
3232

3333
[dependencies.windows-targets]
3434
path = "../../libs/targets"
35-
36-
[dependencies.mio]
37-
version = "0.8.6"

0 commit comments

Comments
 (0)