Skip to content

Commit

Permalink
Make BSTR a core string type (#2006)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Sep 6, 2022
1 parent 78a7cc1 commit e4b778c
Show file tree
Hide file tree
Showing 199 changed files with 32,325 additions and 68,991 deletions.
7 changes: 7 additions & 0 deletions crates/libs/bindgen/src/gen.rs
Expand Up @@ -91,6 +91,10 @@ impl<'a> Gen<'a> {
let crate_name = self.crate_name();
quote! { ::#crate_name::core::HSTRING }
}
Type::BSTR => {
let crate_name = self.crate_name();
quote! { ::#crate_name::core::BSTR }
}
Type::IInspectable => {
let crate_name = self.crate_name();
quote! { ::#crate_name::core::IInspectable }
Expand Down Expand Up @@ -161,6 +165,9 @@ impl<'a> Gen<'a> {
Type::String => {
quote! { ::core::mem::ManuallyDrop<::windows::core::HSTRING> }
}
Type::BSTR => {
quote! { ::core::mem::ManuallyDrop<::windows::core::BSTR> }
}
Type::IUnknown | Type::IInspectable => {
quote! { *mut ::core::ffi::c_void }
}
Expand Down
1 change: 0 additions & 1 deletion crates/libs/bindgen/src/lib.rs
Expand Up @@ -11,7 +11,6 @@ mod implements;
mod interfaces;
mod iterators;
mod method_names;
mod replacements;
mod structs;
mod winrt_methods;
pub use gen::*;
Expand Down
136 changes: 0 additions & 136 deletions crates/libs/bindgen/src/replacements/bstr.rs

This file was deleted.

9 changes: 0 additions & 9 deletions crates/libs/bindgen/src/replacements/mod.rs

This file was deleted.

6 changes: 0 additions & 6 deletions crates/libs/bindgen/src/structs.rs
Expand Up @@ -5,12 +5,6 @@ pub fn gen(gen: &Gen, def: TypeDef) -> TokenStream {
return quote! {};
}

if !gen.sys {
if let Some(replacement) = replacements::gen(gen.reader.type_def_type_name(def)) {
return replacement;
}
}

if gen.reader.type_def_is_handle(def) {
return handles::gen(gen, def);
}
Expand Down
16 changes: 5 additions & 11 deletions crates/libs/metadata/src/reader/mod.rs
Expand Up @@ -791,13 +791,7 @@ impl<'a> Reader<'a> {
}
pub fn type_def_is_blittable(&self, row: TypeDef) -> bool {
match self.type_def_kind(row) {
TypeKind::Struct => {
if self.type_def_type_name(row) == TypeName::BSTR {
false
} else {
self.type_def_fields(row).all(|field| self.field_is_blittable(field, row))
}
}
TypeKind::Struct => self.type_def_fields(row).all(|field| self.field_is_blittable(field, row)),
TypeKind::Enum => true,
TypeKind::Delegate => !self.type_def_flags(row).winrt(),
_ => false,
Expand Down Expand Up @@ -860,14 +854,14 @@ impl<'a> Reader<'a> {
}
pub fn type_def_is_trivially_convertible(&self, row: TypeDef) -> bool {
match self.type_def_kind(row) {
TypeKind::Struct => self.type_def_is_handle(row) && self.type_def_type_name(row) != TypeName::BSTR,
TypeKind::Struct => self.type_def_is_handle(row),
_ => false,
}
}
pub fn type_def_is_primitive(&self, row: TypeDef) -> bool {
match self.type_def_kind(row) {
TypeKind::Enum => true,
TypeKind::Struct => self.type_def_is_handle(row) && self.type_def_type_name(row) != TypeName::BSTR,
TypeKind::Struct => self.type_def_is_handle(row),
_ => false,
}
}
Expand Down Expand Up @@ -1429,7 +1423,7 @@ impl<'a> Reader<'a> {
pub fn type_is_blittable(&self, ty: &Type) -> bool {
match ty {
Type::TypeDef((row, _)) => self.type_def_is_blittable(*row),
Type::String | Type::IInspectable | Type::IUnknown | Type::GenericParam(_) => false,
Type::String | Type::BSTR | Type::IInspectable | Type::IUnknown | Type::GenericParam(_) => false,
Type::Win32Array((kind, _)) => self.type_is_blittable(kind),
Type::WinrtArray(kind) => self.type_is_blittable(kind),
_ => true,
Expand Down Expand Up @@ -1648,4 +1642,4 @@ impl<'a> Reader<'a> {
// TODO: exclude code gen for all types that are in REMAP_TYPES
const REMAP_TYPES: [(TypeName, TypeName); 1] = [(TypeName::D2D_MATRIX_3X2_F, TypeName::Matrix3x2)];

pub const CORE_TYPES: [(TypeName, Type); 11] = [(TypeName::GUID, Type::GUID), (TypeName::IUnknown, Type::IUnknown), (TypeName::HResult, Type::HRESULT), (TypeName::HRESULT, Type::HRESULT), (TypeName::HSTRING, Type::String), (TypeName::IInspectable, Type::IInspectable), (TypeName::LARGE_INTEGER, Type::I64), (TypeName::ULARGE_INTEGER, Type::U64), (TypeName::PSTR, Type::PSTR), (TypeName::PWSTR, Type::PWSTR), (TypeName::Type, Type::TypeName)];
pub const CORE_TYPES: [(TypeName, Type); 12] = [(TypeName::GUID, Type::GUID), (TypeName::IUnknown, Type::IUnknown), (TypeName::HResult, Type::HRESULT), (TypeName::HRESULT, Type::HRESULT), (TypeName::HSTRING, Type::String), (TypeName::BSTR, Type::BSTR), (TypeName::IInspectable, Type::IInspectable), (TypeName::LARGE_INTEGER, Type::I64), (TypeName::ULARGE_INTEGER, Type::U64), (TypeName::PSTR, Type::PSTR), (TypeName::PWSTR, Type::PWSTR), (TypeName::Type, Type::TypeName)];
1 change: 1 addition & 0 deletions crates/libs/metadata/src/reader/type.rs
Expand Up @@ -26,6 +26,7 @@ pub enum Type {
PWSTR,
PCSTR,
PCWSTR,
BSTR,
TypeName,
GenericParam(GenericParam),
TypeDef((TypeDef, Vec<Self>)),
Expand Down
11 changes: 4 additions & 7 deletions crates/libs/sys/src/Windows/Win32/Data/Xml/MsXml/mod.rs
Expand Up @@ -1636,21 +1636,18 @@ impl ::core::clone::Clone for XHR_COOKIE {
}
}
#[repr(C)]
#[doc = "*Required features: `\"Win32_Data_Xml_MsXml\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
#[doc = "*Required features: `\"Win32_Data_Xml_MsXml\"`*"]
pub struct XML_ERROR {
pub _nLine: u32,
pub _pchBuf: super::super::super::Foundation::BSTR,
pub _pchBuf: ::windows_sys::core::BSTR,
pub _cchBuf: u32,
pub _ich: u32,
pub _pszFound: super::super::super::Foundation::BSTR,
pub _pszExpected: super::super::super::Foundation::BSTR,
pub _pszFound: ::windows_sys::core::BSTR,
pub _pszExpected: ::windows_sys::core::BSTR,
pub _reserved1: u32,
pub _reserved2: u32,
}
#[cfg(feature = "Win32_Foundation")]
impl ::core::marker::Copy for XML_ERROR {}
#[cfg(feature = "Win32_Foundation")]
impl ::core::clone::Clone for XML_ERROR {
fn clone(&self) -> Self {
*self
Expand Down

0 comments on commit e4b778c

Please sign in to comment.