Skip to content

Commit 0a68b66

Browse files
authored
Avoid generating transmute for input value type parameter bindings (#3377)
1 parent 2291719 commit 0a68b66

File tree

306 files changed

+31729
-33580
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

306 files changed

+31729
-33580
lines changed

crates/libs/bindgen/src/types/cpp_method.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,11 @@ impl CppMethod {
680680
quote! { #name.into(), }
681681
}
682682
ParamHint::ValueType => {
683-
quote! { core::mem::transmute(#name), }
683+
if flags.contains(ParamAttributes::Out) {
684+
quote! { core::mem::transmute(#name), }
685+
} else {
686+
quote! { #name, }
687+
}
684688
}
685689
ParamHint::Blittable => {
686690
if matches!(ty, Type::PrimitiveOrEnum(_, _)) {

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,8 @@ where
2323
{
2424
windows_targets::link!("ole32.dll" "system" fn RoGetAgileReference(options : AgileReferenceOptions, riid : *const windows_core::GUID, punk : * mut core::ffi::c_void, ppagilereference : *mut * mut core::ffi::c_void) -> windows_core::HRESULT);
2525
let mut result__ = core::mem::zeroed();
26-
RoGetAgileReference(
27-
core::mem::transmute(options),
28-
core::mem::transmute(riid),
29-
punk.param().abi(),
30-
&mut result__,
31-
)
32-
.and_then(|| windows_core::Type::from_abi(result__))
26+
RoGetAgileReference(options, riid, punk.param().abi(), &mut result__)
27+
.and_then(|| windows_core::Type::from_abi(result__))
3328
}
3429
pub const AGILEREFERENCE_DEFAULT: AgileReferenceOptions = AgileReferenceOptions(0i32);
3530
#[repr(transparent)]

crates/libs/windows/src/Windows/Wdk/Devices/HumanInterfaceDevice/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
#[inline]
22
pub unsafe fn VhfAsyncOperationComplete(vhfoperationhandle: *const core::ffi::c_void, completionstatus: super::super::super::Win32::Foundation::NTSTATUS) -> super::super::super::Win32::Foundation::NTSTATUS {
33
windows_targets::link!("vhfum.dll" "system" fn VhfAsyncOperationComplete(vhfoperationhandle : *const core::ffi::c_void, completionstatus : super::super::super::Win32::Foundation:: NTSTATUS) -> super::super::super::Win32::Foundation:: NTSTATUS);
4-
VhfAsyncOperationComplete(core::mem::transmute(vhfoperationhandle), core::mem::transmute(completionstatus))
4+
VhfAsyncOperationComplete(vhfoperationhandle, completionstatus)
55
}
66
#[inline]
77
pub unsafe fn VhfCreate(vhfconfig: *const VHF_CONFIG, vhfhandle: *mut *mut core::ffi::c_void) -> super::super::super::Win32::Foundation::NTSTATUS {
88
windows_targets::link!("vhfum.dll" "system" fn VhfCreate(vhfconfig : *const VHF_CONFIG, vhfhandle : *mut *mut core::ffi::c_void) -> super::super::super::Win32::Foundation:: NTSTATUS);
9-
VhfCreate(core::mem::transmute(vhfconfig), core::mem::transmute(vhfhandle))
9+
VhfCreate(vhfconfig, core::mem::transmute(vhfhandle))
1010
}
1111
#[inline]
1212
pub unsafe fn VhfDelete(vhfhandle: *const core::ffi::c_void, wait: bool) {
1313
windows_targets::link!("vhfum.dll" "system" fn VhfDelete(vhfhandle : *const core::ffi::c_void, wait : bool));
14-
VhfDelete(core::mem::transmute(vhfhandle), core::mem::transmute(wait))
14+
VhfDelete(vhfhandle, wait)
1515
}
1616
#[inline]
1717
pub unsafe fn VhfReadReportSubmit(vhfhandle: *const core::ffi::c_void, hidtransferpacket: *const HID_XFER_PACKET) -> super::super::super::Win32::Foundation::NTSTATUS {
1818
windows_targets::link!("vhfum.dll" "system" fn VhfReadReportSubmit(vhfhandle : *const core::ffi::c_void, hidtransferpacket : *const HID_XFER_PACKET) -> super::super::super::Win32::Foundation:: NTSTATUS);
19-
VhfReadReportSubmit(core::mem::transmute(vhfhandle), core::mem::transmute(hidtransferpacket))
19+
VhfReadReportSubmit(vhfhandle, hidtransferpacket)
2020
}
2121
#[inline]
2222
pub unsafe fn VhfStart(vhfhandle: *const core::ffi::c_void) -> super::super::super::Win32::Foundation::NTSTATUS {
2323
windows_targets::link!("vhfum.dll" "system" fn VhfStart(vhfhandle : *const core::ffi::c_void) -> super::super::super::Win32::Foundation:: NTSTATUS);
24-
VhfStart(core::mem::transmute(vhfhandle))
24+
VhfStart(vhfhandle)
2525
}
2626
pub type EVT_VHF_ASYNC_OPERATION = Option<unsafe extern "system" fn(vhfclientcontext: *const core::ffi::c_void, vhfoperationhandle: *const core::ffi::c_void, vhfoperationcontext: *const core::ffi::c_void, hidtransferpacket: *const HID_XFER_PACKET)>;
2727
pub type EVT_VHF_CLEANUP = Option<unsafe extern "system" fn(vhfclientcontext: *const core::ffi::c_void)>;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#[inline]
22
pub unsafe fn NtClose(handle: super::super::Win32::Foundation::HANDLE) -> super::super::Win32::Foundation::NTSTATUS {
33
windows_targets::link!("ntdll.dll" "system" fn NtClose(handle : super::super::Win32::Foundation:: HANDLE) -> super::super::Win32::Foundation:: NTSTATUS);
4-
NtClose(core::mem::transmute(handle))
4+
NtClose(handle)
55
}
66
#[inline]
77
pub unsafe fn NtQueryObject(handle: Option<super::super::Win32::Foundation::HANDLE>, objectinformationclass: OBJECT_INFORMATION_CLASS, objectinformation: Option<*mut core::ffi::c_void>, objectinformationlength: u32, returnlength: Option<*mut u32>) -> super::super::Win32::Foundation::NTSTATUS {
88
windows_targets::link!("ntdll.dll" "system" fn NtQueryObject(handle : super::super::Win32::Foundation:: HANDLE, objectinformationclass : OBJECT_INFORMATION_CLASS, objectinformation : *mut core::ffi::c_void, objectinformationlength : u32, returnlength : *mut u32) -> super::super::Win32::Foundation:: NTSTATUS);
9-
NtQueryObject(core::mem::transmute(handle.unwrap_or(core::mem::zeroed())), core::mem::transmute(objectinformationclass), core::mem::transmute(objectinformation.unwrap_or(core::mem::zeroed())), core::mem::transmute(objectinformationlength), core::mem::transmute(returnlength.unwrap_or(core::mem::zeroed())))
9+
NtQueryObject(core::mem::transmute(handle.unwrap_or(core::mem::zeroed())), objectinformationclass, core::mem::transmute(objectinformation.unwrap_or(core::mem::zeroed())), objectinformationlength, core::mem::transmute(returnlength.unwrap_or(core::mem::zeroed())))
1010
}
1111
#[repr(C)]
1212
#[cfg(all(feature = "Wdk_System_SystemServices", feature = "Win32_Security"))]

0 commit comments

Comments
 (0)