Skip to content

Commit

Permalink
Merge branch 'microsoft:master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mati865 authored Jun 17, 2024
2 parents 8bea710 + 139ca3c commit 93beb66
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 57 deletions.
36 changes: 17 additions & 19 deletions crates/libs/bindgen/src/rust/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,34 @@ pub fn gen_win_handle(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
let ident = to_ident(name);
let underlying_type = def.underlying_type();
let signature = writer.type_default_name(&underlying_type);
let is_invalid = if underlying_type.is_pointer() {
let invalid = metadata::type_def_invalid_values(def);

let is_invalid = if underlying_type.is_pointer() && (invalid.is_empty() || invalid == [0]) {
quote! {
impl #ident {
pub fn is_invalid(&self) -> bool {
self.0.is_null()
}
}
}
} else if invalid.is_empty() {
quote! {}
} else {
let invalid = metadata::type_def_invalid_values(def);
let invalid = invalid.iter().map(|value| {
let literal = Literal::i64_unsuffixed(*value);

if !invalid.is_empty() {
let invalid = invalid.iter().map(|value| {
let literal = Literal::i64_unsuffixed(*value);

if *value < 0 && underlying_type.is_unsigned() {
quote! { self.0 == #literal as _ }
} else {
quote! { self.0 == #literal }
}
});
quote! {
impl #ident {
pub fn is_invalid(&self) -> bool {
#(#invalid)||*
}
if underlying_type.is_pointer() || (*value < 0 && underlying_type.is_unsigned()) {
quote! { self.0 == #literal as _ }
} else {
quote! { self.0 == #literal }
}
});
quote! {
impl #ident {
pub fn is_invalid(&self) -> bool {
#(#invalid)||*
}
}
} else {
quote! {}
}
};

Expand Down
56 changes: 31 additions & 25 deletions crates/libs/bindgen/src/rust/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,40 @@ fn gen_struct_with_name(
quote! { #[repr(C)] }
};

let fields = def.fields().map(|f| {
let name = to_ident(f.name());
let ty = f.ty(Some(def));

if f.flags().contains(metadata::FieldAttributes::Literal) {
quote! {}
} else if !writer.sys
&& flags.contains(metadata::TypeAttributes::ExplicitLayout)
&& !metadata::field_is_copyable(f, def)
{
let ty = writer.type_default_name(&ty);
quote! { pub #name: core::mem::ManuallyDrop<#ty>, }
} else if !writer.sys
&& !flags.contains(metadata::TypeAttributes::WindowsRuntime)
&& !metadata::field_is_blittable(f, def)
{
if let metadata::Type::Win32Array(ty, len) = ty {
let fields = if def.fields().next().is_none() {
quote! { (pub u8); }
} else {
let fields = def.fields().map(|f| {
let name = to_ident(f.name());
let ty = f.ty(Some(def));

if f.flags().contains(metadata::FieldAttributes::Literal) {
quote! {}
} else if !writer.sys
&& flags.contains(metadata::TypeAttributes::ExplicitLayout)
&& !metadata::field_is_copyable(f, def)
{
let ty = writer.type_default_name(&ty);
quote! { pub #name: [core::mem::ManuallyDrop<#ty>; #len], }
quote! { pub #name: core::mem::ManuallyDrop<#ty>, }
} else if !writer.sys
&& !flags.contains(metadata::TypeAttributes::WindowsRuntime)
&& !metadata::field_is_blittable(f, def)
{
if let metadata::Type::Win32Array(ty, len) = ty {
let ty = writer.type_default_name(&ty);
quote! { pub #name: [core::mem::ManuallyDrop<#ty>; #len], }
} else {
let ty = writer.type_default_name(&ty);
quote! { pub #name: core::mem::ManuallyDrop<#ty>, }
}
} else {
let ty = writer.type_default_name(&ty);
quote! { pub #name: core::mem::ManuallyDrop<#ty>, }
quote! { pub #name: #ty, }
}
} else {
let ty = writer.type_default_name(&ty);
quote! { pub #name: #ty, }
}
});
});

quote! { {#(#fields)*} }
};

let struct_or_union = if flags.contains(metadata::TypeAttributes::ExplicitLayout) {
quote! { union }
Expand All @@ -85,7 +91,7 @@ fn gen_struct_with_name(
#repr
#features
#derive
pub #struct_or_union #name {#(#fields)*}
pub #struct_or_union #name #fields
};

tokens.combine(&gen_struct_constants(writer, def, &name, &cfg));
Expand Down
6 changes: 4 additions & 2 deletions crates/libs/core/src/imp/waiter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use super::*;

#[doc(hidden)]
pub struct Waiter(isize);
pub struct WaiterSignaler(isize);
pub struct Waiter(HANDLE);
pub struct WaiterSignaler(HANDLE);

unsafe impl Send for WaiterSignaler {}

impl Waiter {
pub fn new() -> crate::Result<(Waiter, WaiterSignaler)> {
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/windows/src/Windows/Win32/Foundation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10688,7 +10688,7 @@ impl windows_core::TypeKind for HANDLE_PTR {
pub struct HGLOBAL(pub *mut core::ffi::c_void);
impl HGLOBAL {
pub fn is_invalid(&self) -> bool {
self.0.is_null()
self.0 == -1 as _ || self.0 == 0 as _
}
}
impl windows_core::Free for HGLOBAL {
Expand Down Expand Up @@ -10740,7 +10740,7 @@ impl From<HINSTANCE> for HMODULE {
pub struct HLOCAL(pub *mut core::ffi::c_void);
impl HLOCAL {
pub fn is_invalid(&self) -> bool {
self.0.is_null()
self.0 == -1 as _ || self.0 == 0 as _
}
}
impl windows_core::Free for HLOCAL {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14306,7 +14306,7 @@ impl windows_core::TypeKind for HCERTCHAINENGINE {
pub struct HCERTSTORE(pub *mut core::ffi::c_void);
impl HCERTSTORE {
pub fn is_invalid(&self) -> bool {
self.0.is_null()
self.0 == -1 as _ || self.0 == 0 as _
}
}
impl Default for HCERTSTORE {
Expand All @@ -14322,7 +14322,7 @@ impl windows_core::TypeKind for HCERTSTORE {
pub struct HCERTSTOREPROV(pub *mut core::ffi::c_void);
impl HCERTSTOREPROV {
pub fn is_invalid(&self) -> bool {
self.0.is_null()
self.0 == -1 as _ || self.0 == 0 as _
}
}
impl Default for HCERTSTOREPROV {
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/windows/src/Windows/Win32/Security/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2671,7 +2671,7 @@ impl Default for PRIVILEGE_SET {
pub struct PSECURITY_DESCRIPTOR(pub *mut core::ffi::c_void);
impl PSECURITY_DESCRIPTOR {
pub fn is_invalid(&self) -> bool {
self.0.is_null()
self.0 == -1 as _ || self.0 == 0 as _
}
}
impl Default for PSECURITY_DESCRIPTOR {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8227,7 +8227,7 @@ impl From<HCURSOR> for HICON {
pub struct HDEVNOTIFY(pub *mut core::ffi::c_void);
impl HDEVNOTIFY {
pub fn is_invalid(&self) -> bool {
self.0.is_null()
self.0 == -1 as _ || self.0 == 0 as _
}
}
impl windows_core::Free for HDEVNOTIFY {
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/windows/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs
#![doc(html_no_source)]
#![allow(non_snake_case, clashing_extern_declarations, non_upper_case_globals, non_camel_case_types, missing_docs, clippy::all)]
#![cfg_attr(not(feature = "docs"), doc(hidden))]
// TODO: https://github.com/microsoft/windows-rs/issues/3096
#![allow(dead_code)]
// TODO: workaround for https://github.com/rust-lang/rust/issues/126169
#![allow(unused)]

#[allow(unused_extern_crates)]
extern crate self as windows;
Expand Down
3 changes: 0 additions & 3 deletions crates/tests/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,3 @@ features = [

[dependencies.windows-targets]
path = "../../libs/targets"

[dependencies.mio]
version = "0.8.6"

0 comments on commit 93beb66

Please sign in to comment.