Skip to content

Commit

Permalink
Minor housekeeping (#2102)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Oct 18, 2022
1 parent cc2032e commit 3b9f912
Show file tree
Hide file tree
Showing 176 changed files with 3,294 additions and 3,179 deletions.
1 change: 0 additions & 1 deletion crates/libs/bindgen/src/classes.rs
Expand Up @@ -22,7 +22,6 @@ fn gen_class(gen: &Gen, def: TypeDef) -> TokenStream {

let name = to_ident(gen.reader.type_def_name(def));
let interfaces = gen.reader.type_interfaces(&Type::TypeDef((def, Vec::new())));
// TODO: faster if this were a Vec?
let mut methods = quote! {};
let mut method_names = MethodNames::new();

Expand Down
19 changes: 8 additions & 11 deletions crates/libs/bindgen/src/gen.rs
Expand Up @@ -157,10 +157,6 @@ impl<'a> Gen<'a> {
}
}
pub fn type_abi_name(&self, ty: &Type) -> TokenStream {
self.type_abi_name_imp(ty, false)
}
// TODO: this is only because we're trying to avoid the ManuallyDrop below - I don't think that matters so may want to scrap this once we have parity.
fn type_abi_name_imp(&self, ty: &Type, ptr: bool) -> TokenStream {
match ty {
Type::String => {
quote! { ::core::mem::ManuallyDrop<::windows::core::HSTRING> }
Expand All @@ -172,7 +168,7 @@ impl<'a> Gen<'a> {
quote! { *mut ::core::ffi::c_void }
}
Type::Win32Array((kind, len)) => {
let name = self.type_abi_name_imp(kind, ptr);
let name = self.type_abi_name(kind);
let len = Literal::usize_unsuffixed(*len);
quote! { [#name; #len] }
}
Expand All @@ -184,7 +180,7 @@ impl<'a> Gen<'a> {
TypeKind::Enum => self.type_def_name(*def, &[]),
TypeKind::Struct => {
let tokens = self.type_def_name(*def, &[]);
if self.reader.type_def_is_blittable(*def) || ptr {
if self.reader.type_def_is_blittable(*def) {
tokens
} else {
quote! { ::core::mem::ManuallyDrop<#tokens> }
Expand All @@ -194,16 +190,16 @@ impl<'a> Gen<'a> {
},
Type::MutPtr((kind, pointers)) => {
let pointers = gen_mut_ptrs(*pointers);
let kind = self.type_abi_name_imp(kind, true);
let kind = self.type_abi_name(kind);
quote! { #pointers #kind }
}
Type::ConstPtr((kind, pointers)) => {
let pointers = gen_const_ptrs(*pointers);
let kind = self.type_abi_name_imp(kind, true);
let kind = self.type_abi_name(kind);
quote! { #pointers #kind }
}
Type::WinrtArray(kind) => self.type_abi_name_imp(kind, ptr),
Type::WinrtArrayRef(kind) => self.type_abi_name_imp(kind, ptr),
Type::WinrtArray(kind) => self.type_abi_name(kind),
Type::WinrtArrayRef(kind) => self.type_abi_name(kind),
_ => self.type_name(ty),
}
}
Expand Down Expand Up @@ -847,7 +843,8 @@ impl<'a> Gen<'a> {
quote! { (this: *mut ::core::ffi::c_void, #udt_return_type #(#params)* #trailing_return_type) #return_type }
}
pub fn param_name(&self, param: Param) -> TokenStream {
// TODO: why do we need to_lowercase
// In Rust, function parameters cannot be named the same as structs. This avoids some collisions that occur in the win32 metadata.
// See Icmp6SendEcho2 for an example.
to_ident(&self.reader.param_name(param).to_lowercase())
}
pub fn return_sig(&self, signature: &Signature) -> TokenStream {
Expand Down
5 changes: 3 additions & 2 deletions crates/libs/bindgen/src/interfaces.rs
Expand Up @@ -30,7 +30,7 @@ fn gen_win_interface(gen: &Gen, def: TypeDef) -> TokenStream {
let cfg = gen.reader.type_def_cfg(def, &[]);
let doc = gen.cfg_doc(&cfg);
let features = gen.cfg_features(&cfg);
let interfaces = gen.reader.type_interfaces(&Type::TypeDef((def, generics.to_vec()))); // TODO: how to avoid copy?
let interfaces = gen.reader.type_interfaces(&Type::TypeDef((def, generics.to_vec())));
let vtables = gen.reader.type_def_vtables(def);
let has_unknown_base = matches!(vtables.first(), Some(Type::IUnknown));

Expand Down Expand Up @@ -68,7 +68,8 @@ fn gen_win_interface(gen: &Gen, def: TypeDef) -> TokenStream {

if !is_exclusive {
let mut methods = quote! {};
// TODO: why do we need to distinguish between public and virtual methods?
// We need to distinguish between public and virtual methods because some WinRT type hierarchies inherit colliding (overloaded)
// methods that must be distinguishable.
let method_names = &mut MethodNames::new();
let virtual_names = &mut MethodNames::new();

Expand Down
4 changes: 3 additions & 1 deletion crates/libs/metadata/src/reader/mod.rs
Expand Up @@ -869,7 +869,9 @@ impl<'a> Reader<'a> {
self.type_def_attributes(row).any(|attribute| self.attribute_name(attribute) == "ComposableAttribute")
}
pub fn type_def_is_udt(&self, row: TypeDef) -> bool {
// TODO: should this just check whether the struct has > 1 fields rather than type_def_is_handle?
// This check is used to detect virtual functions that return C-style PODs that affect how the stack is packed for x86.
// It could be defined as a struct with more than one field but that check is complicated as it would have to detect
// nested structs. Fortunately, this is rare enough that this check is sufficient.
self.type_def_kind(row) == TypeKind::Struct && !self.type_def_is_handle(row)
}
fn type_def_is_borrowed(&self, row: TypeDef) -> bool {
Expand Down
Expand Up @@ -31,7 +31,7 @@ impl IDMLBindingTable_Vtbl {
let this = (*this).get_impl();
this.BindPersistentResource(::core::mem::transmute_copy(&binding))
}
unsafe extern "system" fn Reset<Identity: ::windows::core::IUnknownImpl<Impl = Impl>, Impl: IDMLBindingTable_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, desc: *const DML_BINDING_TABLE_DESC) -> ::windows::core::HRESULT {
unsafe extern "system" fn Reset<Identity: ::windows::core::IUnknownImpl<Impl = Impl>, Impl: IDMLBindingTable_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, desc: *const ::core::mem::ManuallyDrop<DML_BINDING_TABLE_DESC>) -> ::windows::core::HRESULT {
let this = (this as *const *const ()).offset(OFFSET) as *const Identity;
let this = (*this).get_impl();
this.Reset(::core::mem::transmute_copy(&desc)).into()
Expand Down Expand Up @@ -142,7 +142,7 @@ impl IDMLDevice_Vtbl {
let this = (*this).get_impl();
this.CreateCommandRecorder(::core::mem::transmute_copy(&riid), ::core::mem::transmute_copy(&ppv)).into()
}
unsafe extern "system" fn CreateBindingTable<Identity: ::windows::core::IUnknownImpl<Impl = Impl>, Impl: IDMLDevice_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, desc: *const DML_BINDING_TABLE_DESC, riid: *const ::windows::core::GUID, ppv: *mut *mut ::core::ffi::c_void) -> ::windows::core::HRESULT {
unsafe extern "system" fn CreateBindingTable<Identity: ::windows::core::IUnknownImpl<Impl = Impl>, Impl: IDMLDevice_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, desc: *const ::core::mem::ManuallyDrop<DML_BINDING_TABLE_DESC>, riid: *const ::windows::core::GUID, ppv: *mut *mut ::core::ffi::c_void) -> ::windows::core::HRESULT {
let this = (this as *const *const ()).offset(OFFSET) as *const Identity;
let this = (*this).get_impl();
this.CreateBindingTable(::core::mem::transmute_copy(&desc), ::core::mem::transmute_copy(&riid), ::core::mem::transmute_copy(&ppv)).into()
Expand Down
Expand Up @@ -105,7 +105,7 @@ pub struct IDMLBindingTable_Vtbl {
pub BindTemporaryResource: unsafe extern "system" fn(this: *mut ::core::ffi::c_void, binding: *const DML_BINDING_DESC),
pub BindPersistentResource: unsafe extern "system" fn(this: *mut ::core::ffi::c_void, binding: *const DML_BINDING_DESC),
#[cfg(feature = "Win32_Graphics_Direct3D12")]
pub Reset: unsafe extern "system" fn(this: *mut ::core::ffi::c_void, desc: *const DML_BINDING_TABLE_DESC) -> ::windows::core::HRESULT,
pub Reset: unsafe extern "system" fn(this: *mut ::core::ffi::c_void, desc: *const ::core::mem::ManuallyDrop<DML_BINDING_TABLE_DESC>) -> ::windows::core::HRESULT,
#[cfg(not(feature = "Win32_Graphics_Direct3D12"))]
Reset: usize,
}
Expand Down Expand Up @@ -400,7 +400,7 @@ pub struct IDMLDevice_Vtbl {
pub CreateOperatorInitializer: unsafe extern "system" fn(this: *mut ::core::ffi::c_void, operatorcount: u32, operators: *const *mut ::core::ffi::c_void, riid: *const ::windows::core::GUID, ppv: *mut *mut ::core::ffi::c_void) -> ::windows::core::HRESULT,
pub CreateCommandRecorder: unsafe extern "system" fn(this: *mut ::core::ffi::c_void, riid: *const ::windows::core::GUID, ppv: *mut *mut ::core::ffi::c_void) -> ::windows::core::HRESULT,
#[cfg(feature = "Win32_Graphics_Direct3D12")]
pub CreateBindingTable: unsafe extern "system" fn(this: *mut ::core::ffi::c_void, desc: *const DML_BINDING_TABLE_DESC, riid: *const ::windows::core::GUID, ppv: *mut *mut ::core::ffi::c_void) -> ::windows::core::HRESULT,
pub CreateBindingTable: unsafe extern "system" fn(this: *mut ::core::ffi::c_void, desc: *const ::core::mem::ManuallyDrop<DML_BINDING_TABLE_DESC>, riid: *const ::windows::core::GUID, ppv: *mut *mut ::core::ffi::c_void) -> ::windows::core::HRESULT,
#[cfg(not(feature = "Win32_Graphics_Direct3D12"))]
CreateBindingTable: usize,
pub Evict: unsafe extern "system" fn(this: *mut ::core::ffi::c_void, count: u32, ppobjects: *const *mut ::core::ffi::c_void) -> ::windows::core::HRESULT,
Expand Down
Expand Up @@ -593,12 +593,12 @@ impl ::windows::core::RuntimeName for IWinMLEvaluationContext {}
#[cfg(feature = "Win32_Graphics_Direct3D12")]
impl IWinMLEvaluationContext_Vtbl {
pub const fn new<Identity: ::windows::core::IUnknownImpl<Impl = Impl>, Impl: IWinMLEvaluationContext_Impl, const OFFSET: isize>() -> IWinMLEvaluationContext_Vtbl {
unsafe extern "system" fn BindValue<Identity: ::windows::core::IUnknownImpl<Impl = Impl>, Impl: IWinMLEvaluationContext_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, pdescriptor: *const WINML_BINDING_DESC) -> ::windows::core::HRESULT {
unsafe extern "system" fn BindValue<Identity: ::windows::core::IUnknownImpl<Impl = Impl>, Impl: IWinMLEvaluationContext_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, pdescriptor: *const ::core::mem::ManuallyDrop<WINML_BINDING_DESC>) -> ::windows::core::HRESULT {
let this = (this as *const *const ()).offset(OFFSET) as *const Identity;
let this = (*this).get_impl();
this.BindValue(::core::mem::transmute_copy(&pdescriptor)).into()
}
unsafe extern "system" fn GetValueByName<Identity: ::windows::core::IUnknownImpl<Impl = Impl>, Impl: IWinMLEvaluationContext_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, name: ::windows::core::PCWSTR, pdescriptor: *mut *mut WINML_BINDING_DESC) -> ::windows::core::HRESULT {
unsafe extern "system" fn GetValueByName<Identity: ::windows::core::IUnknownImpl<Impl = Impl>, Impl: IWinMLEvaluationContext_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, name: ::windows::core::PCWSTR, pdescriptor: *mut *mut ::core::mem::ManuallyDrop<WINML_BINDING_DESC>) -> ::windows::core::HRESULT {
let this = (this as *const *const ()).offset(OFFSET) as *const Identity;
let this = (*this).get_impl();
match this.GetValueByName(::core::mem::transmute(&name)) {
Expand Down
Expand Up @@ -789,11 +789,11 @@ unsafe impl ::windows::core::Interface for IWinMLEvaluationContext {
pub struct IWinMLEvaluationContext_Vtbl {
pub base__: ::windows::core::IUnknown_Vtbl,
#[cfg(feature = "Win32_Graphics_Direct3D12")]
pub BindValue: unsafe extern "system" fn(this: *mut ::core::ffi::c_void, pdescriptor: *const WINML_BINDING_DESC) -> ::windows::core::HRESULT,
pub BindValue: unsafe extern "system" fn(this: *mut ::core::ffi::c_void, pdescriptor: *const ::core::mem::ManuallyDrop<WINML_BINDING_DESC>) -> ::windows::core::HRESULT,
#[cfg(not(feature = "Win32_Graphics_Direct3D12"))]
BindValue: usize,
#[cfg(feature = "Win32_Graphics_Direct3D12")]
pub GetValueByName: unsafe extern "system" fn(this: *mut ::core::ffi::c_void, name: ::windows::core::PCWSTR, pdescriptor: *mut *mut WINML_BINDING_DESC) -> ::windows::core::HRESULT,
pub GetValueByName: unsafe extern "system" fn(this: *mut ::core::ffi::c_void, name: ::windows::core::PCWSTR, pdescriptor: *mut *mut ::core::mem::ManuallyDrop<WINML_BINDING_DESC>) -> ::windows::core::HRESULT,
#[cfg(not(feature = "Win32_Graphics_Direct3D12"))]
GetValueByName: usize,
pub Clear: unsafe extern "system" fn(this: *mut ::core::ffi::c_void) -> ::windows::core::HRESULT,
Expand Down

0 comments on commit 3b9f912

Please sign in to comment.