Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove win32metadata workarounds #2017

Merged
merged 7 commits into from Sep 12, 2022
4 changes: 0 additions & 4 deletions crates/libs/bindgen/src/implements.rs
Expand Up @@ -5,10 +5,6 @@ pub fn gen(gen: &Gen, def: TypeDef) -> TokenStream {
return quote! {};
}

if gen.reader.type_def_name(def).starts_with("Disp") && gen.reader.type_def_methods(def).next().is_none() {
return quote! {};
}

let generics: &Vec<Type> = &gen.reader.type_def_generics(def).collect();
let type_ident = to_ident(gen.reader.type_def_name(def));
let impl_ident = type_ident.join("_Impl");
Expand Down
9 changes: 0 additions & 9 deletions crates/libs/bindgen/src/interfaces.rs
Expand Up @@ -24,15 +24,6 @@ fn gen_sys_interface(gen: &Gen, def: TypeDef) -> TokenStream {
fn gen_win_interface(gen: &Gen, def: TypeDef) -> TokenStream {
let generics: &Vec<Type> = &gen.reader.type_def_generics(def).collect();
let ident = gen.type_def_name(def, generics);

if gen.reader.type_def_methods(def).next().is_none() && gen.reader.type_def_name(def).starts_with("Disp") {
if let Some(guid) = gen.reader.type_def_guid(def) {
let value = gen.guid(&guid);
let guid = gen.type_name(&Type::GUID);
return quote! { pub const #ident: #guid = #value; };
}
}

let is_exclusive = gen.reader.type_def_is_exclusive(def);
let phantoms = gen.generic_phantoms(generics);
let constraints = gen.generic_constraints(generics);
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/metadata/src/bindings.rs
Expand Up @@ -20,7 +20,7 @@ pub const IMAGE_FILE_EXECUTABLE_IMAGE: IMAGE_FILE_CHARACTERISTICS = 2u16;
pub const IMAGE_FILE_MACHINE_I386: IMAGE_FILE_MACHINE = 332u16;
pub const IMAGE_NT_OPTIONAL_HDR32_MAGIC: IMAGE_OPTIONAL_HEADER_MAGIC = 267u16;
pub const IMAGE_NT_OPTIONAL_HDR64_MAGIC: IMAGE_OPTIONAL_HEADER_MAGIC = 523u16;
pub const IMAGE_NT_SIGNATURE: u16 = 17744u16;
pub const IMAGE_NT_SIGNATURE: u32 = 17744u32;
pub const IMAGE_SUBSYSTEM_WINDOWS_CUI: IMAGE_SUBSYSTEM = 3u16;

#[repr(C, packed(2))]
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/metadata/src/reader/file.rs
Expand Up @@ -59,7 +59,7 @@ impl File {

let dos = result.bytes.view_as::<IMAGE_DOS_HEADER>(0);

if dos.e_magic != IMAGE_DOS_SIGNATURE as _ || result.bytes.copy_as::<u16>(dos.e_lfanew as _) != IMAGE_NT_SIGNATURE {
if dos.e_magic != IMAGE_DOS_SIGNATURE as _ || result.bytes.copy_as::<u32>(dos.e_lfanew as _) != IMAGE_NT_SIGNATURE {
return Err(error_invalid_winmd());
}

Expand Down
7 changes: 1 addition & 6 deletions crates/libs/metadata/src/reader/mod.rs
Expand Up @@ -553,10 +553,6 @@ impl<'a> Reader<'a> {
params[position].array_info = ArrayInfo::Removed;
}
}
// TODO: workaround for https://github.com/microsoft/win32metadata/issues/1014
ArrayInfo::Fixed(fixed) if fixed == 0 || self.param_free_with(params[position].def).is_some() => {
params[position].array_info = ArrayInfo::Removed;
}
_ => {}
}
}
Expand Down Expand Up @@ -954,8 +950,7 @@ impl<'a> Reader<'a> {
_ => {}
}
}
// TODO: IRestrictedErrorInfo workaround for https://github.com/microsoft/win32metadata/issues/923
matches!(self.type_def_type_name(row), TypeName::IAsyncAction | TypeName::IAsyncActionWithProgress | TypeName::IAsyncOperation | TypeName::IAsyncOperationWithProgress | TypeName::IRestrictedErrorInfo)
matches!(self.type_def_type_name(row), TypeName::IAsyncAction | TypeName::IAsyncActionWithProgress | TypeName::IAsyncOperation | TypeName::IAsyncOperationWithProgress)
}
pub fn type_def_invalid_values(&self, row: TypeDef) -> Vec<i64> {
let mut values = Vec::new();
Expand Down
3 changes: 1 addition & 2 deletions crates/libs/metadata/src/writer/file.rs
Expand Up @@ -79,8 +79,7 @@ pub fn write(filename: &str, tables: Tables) {

let mut buffer = Vec::<u8>::new();
buffer.write(&dos);
// TODO: workaround for https://github.com/microsoft/win32metadata/issues/963
buffer.write(&(IMAGE_NT_SIGNATURE as u32));
buffer.write(&IMAGE_NT_SIGNATURE);
buffer.write(&file);
buffer.write(&optional);
buffer.write(&section);
Expand Down
Expand Up @@ -3004,8 +3004,8 @@ impl IBackgroundCopyJobHttpOptions {
pub unsafe fn RemoveClientCertificate(&self) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).RemoveClientCertificate)(::windows::core::Interface::as_raw(self)).ok()
}
pub unsafe fn GetClientCertificate(&self, pstorelocation: &mut BG_CERT_STORE_LOCATION, pstorename: &mut ::windows::core::PWSTR, ppcerthashblob: *mut *mut u8, psubjectname: &mut ::windows::core::PWSTR) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).GetClientCertificate)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(pstorelocation), ::core::mem::transmute(pstorename), ::core::mem::transmute(ppcerthashblob), ::core::mem::transmute(psubjectname)).ok()
pub unsafe fn GetClientCertificate(&self, pstorelocation: &mut BG_CERT_STORE_LOCATION, pstorename: &mut ::windows::core::PWSTR, ppcerthashblob: &mut *mut u8, psubjectname: &mut ::windows::core::PWSTR) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).GetClientCertificate)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(pstorelocation), ::core::mem::transmute(pstorename), ::core::mem::transmute(ppcerthashblob.as_ptr()), ::core::mem::transmute(psubjectname)).ok()
}
pub unsafe fn SetCustomHeaders<'a, P0>(&self, requestheaders: P0) -> ::windows::core::Result<()>
where
Expand Down Expand Up @@ -3093,8 +3093,8 @@ impl IBackgroundCopyJobHttpOptions2 {
pub unsafe fn RemoveClientCertificate(&self) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).base__.RemoveClientCertificate)(::windows::core::Interface::as_raw(self)).ok()
}
pub unsafe fn GetClientCertificate(&self, pstorelocation: &mut BG_CERT_STORE_LOCATION, pstorename: &mut ::windows::core::PWSTR, ppcerthashblob: *mut *mut u8, psubjectname: &mut ::windows::core::PWSTR) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).base__.GetClientCertificate)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(pstorelocation), ::core::mem::transmute(pstorename), ::core::mem::transmute(ppcerthashblob), ::core::mem::transmute(psubjectname)).ok()
pub unsafe fn GetClientCertificate(&self, pstorelocation: &mut BG_CERT_STORE_LOCATION, pstorename: &mut ::windows::core::PWSTR, ppcerthashblob: &mut *mut u8, psubjectname: &mut ::windows::core::PWSTR) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).base__.GetClientCertificate)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(pstorelocation), ::core::mem::transmute(pstorename), ::core::mem::transmute(ppcerthashblob.as_ptr()), ::core::mem::transmute(psubjectname)).ok()
}
pub unsafe fn SetCustomHeaders<'a, P0>(&self, requestheaders: P0) -> ::windows::core::Result<()>
where
Expand Down Expand Up @@ -3201,8 +3201,8 @@ impl IBackgroundCopyJobHttpOptions3 {
pub unsafe fn RemoveClientCertificate(&self) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).base__.base__.RemoveClientCertificate)(::windows::core::Interface::as_raw(self)).ok()
}
pub unsafe fn GetClientCertificate(&self, pstorelocation: &mut BG_CERT_STORE_LOCATION, pstorename: &mut ::windows::core::PWSTR, ppcerthashblob: *mut *mut u8, psubjectname: &mut ::windows::core::PWSTR) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).base__.base__.GetClientCertificate)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(pstorelocation), ::core::mem::transmute(pstorename), ::core::mem::transmute(ppcerthashblob), ::core::mem::transmute(psubjectname)).ok()
pub unsafe fn GetClientCertificate(&self, pstorelocation: &mut BG_CERT_STORE_LOCATION, pstorename: &mut ::windows::core::PWSTR, ppcerthashblob: &mut *mut u8, psubjectname: &mut ::windows::core::PWSTR) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).base__.base__.GetClientCertificate)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(pstorelocation), ::core::mem::transmute(pstorename), ::core::mem::transmute(ppcerthashblob.as_ptr()), ::core::mem::transmute(psubjectname)).ok()
}
pub unsafe fn SetCustomHeaders<'a, P0>(&self, requestheaders: P0) -> ::windows::core::Result<()>
where
Expand Down
4 changes: 3 additions & 1 deletion crates/tests/interface/tests/com.rs
Expand Up @@ -125,12 +125,14 @@ fn test_custom_interface() -> windows::core::Result<()> {
// This works because `ICustomPersistMemory` and `IPersistMemory` share the same guid
let p: IPersistMemory = p.cast()?;
assert_eq!(p.GetClassID()?, "117fb826-2155-483a-b50d-bc99a2c7cca3".into());
// TODO: can't test IsDirty until this is fixed: https://github.com/microsoft/win32metadata/issues/838
assert_eq!(p.GetSizeMax()?, 10);
assert_eq!(p.IsDirty(), S_FALSE);
p.Load(&[0xAAu8, 0xBB, 0xCC])?;
assert_eq!(p.IsDirty(), S_OK);
let mut memory = [0x00u8, 0x00, 0x00, 0x00];
p.Save(&mut memory, true)?;
assert_eq!(memory, [0xAAu8, 0xBB, 0xCC, 0x00]);
assert_eq!(p.IsDirty(), S_FALSE);

// Use the custom implementation of `Persist` through the custom interface of `ICustomPersist`
let p: ICustomPersistMemory = p.cast()?;
Expand Down
1 change: 0 additions & 1 deletion crates/tests/win32_arrays/tests/multi_byte.rs
Expand Up @@ -9,7 +9,6 @@ fn test() {
assert_eq!(len, 5);

let mut c: [u8; 5] = [0xFF; 5];
// TODO: workaround for https://github.com/microsoft/win32metadata/issues/820
let len = WideCharToMultiByte(CP_UTF8, Default::default(), &b, Some(&mut c), None, None);
assert_eq!(len, 5);

Expand Down
1 change: 0 additions & 1 deletion crates/tests/win32_arrays/tests/xmllite.rs
Expand Up @@ -57,7 +57,6 @@ fn test() -> Result<()> {
let mut chars_read = 0;
let mut read_count = 0;

// TODO: workaround for https://github.com/microsoft/win32metadata/issues/816
while reader.ReadValueChunk(&mut chunk, &mut chars_read).is_ok() && chars_read > 0 {
message.extend_from_slice(&chunk[0..chars_read as _]);
read_count += 1;
Expand Down