Skip to content

Commit

Permalink
Use core::ptr::write for out params (#1750)
Browse files Browse the repository at this point in the history
* Use std::ptr::write for writing out params since they might not be initialized

* Run codegen
  • Loading branch information
rylev authored May 10, 2022
1 parent 7efe684 commit d60b526
Show file tree
Hide file tree
Showing 261 changed files with 20,991 additions and 20,988 deletions.
11 changes: 7 additions & 4 deletions crates/libs/bindgen/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ pub fn gen_win32_upcall(sig: &Signature, inner: TokenStream) -> TokenStream {
quote! {
match #inner(#(#invoke_args,)*) {
::core::result::Result::Ok(ok__) => {
*#result = ::core::mem::transmute(ok__);
// use `core::ptr::write` since the result could be uninitialized
::core::ptr::write(#result, ::core::mem::transmute(ok__));
::windows::core::HRESULT(0)
}
::core::result::Result::Err(err) => err.into()
Expand Down Expand Up @@ -369,8 +370,9 @@ pub fn gen_winrt_upcall(sig: &Signature, inner: TokenStream) -> TokenStream {
match #inner(#(#invoke_args,)*) {
::core::result::Result::Ok(ok__) => {
let (ok_data__, ok_data_len__) = ok__.into_abi();
*result__ = ok_data__;
*result_size__ = ok_data_len__;
// use `core::ptr::write` since `result` could be uninitialized
::core::ptr::write(result__, ok_data__);
::core::ptr::write(result_size__, ok_data_len__);
::windows::core::HRESULT(0)
}
::core::result::Result::Err(err) => err.into()
Expand All @@ -381,7 +383,8 @@ pub fn gen_winrt_upcall(sig: &Signature, inner: TokenStream) -> TokenStream {
quote! {
match #inner(#(#invoke_args,)*) {
::core::result::Result::Ok(ok__) => {
*result__ = ::core::mem::transmute_copy(&ok__);
// use `core::ptr::write` since `result` could be uninitialized
::core::ptr::write(result__, ::core::mem::transmute_copy(&ok__));
::core::mem::forget(ok__);
::windows::core::HRESULT(0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl ILearningModelVariableDescriptorPreview_Vtbl {
let this = (*this).get_impl();
match this.Name() {
::core::result::Result::Ok(ok__) => {
*result__ = ::core::mem::transmute_copy(&ok__);
::core::ptr::write(result__, ::core::mem::transmute_copy(&ok__));
::core::mem::forget(ok__);
::windows::core::HRESULT(0)
}
Expand All @@ -29,7 +29,7 @@ impl ILearningModelVariableDescriptorPreview_Vtbl {
let this = (*this).get_impl();
match this.Description() {
::core::result::Result::Ok(ok__) => {
*result__ = ::core::mem::transmute_copy(&ok__);
::core::ptr::write(result__, ::core::mem::transmute_copy(&ok__));
::core::mem::forget(ok__);
::windows::core::HRESULT(0)
}
Expand All @@ -41,7 +41,7 @@ impl ILearningModelVariableDescriptorPreview_Vtbl {
let this = (*this).get_impl();
match this.ModelFeatureKind() {
::core::result::Result::Ok(ok__) => {
*result__ = ::core::mem::transmute_copy(&ok__);
::core::ptr::write(result__, ::core::mem::transmute_copy(&ok__));
::core::mem::forget(ok__);
::windows::core::HRESULT(0)
}
Expand All @@ -53,7 +53,7 @@ impl ILearningModelVariableDescriptorPreview_Vtbl {
let this = (*this).get_impl();
match this.IsRequired() {
::core::result::Result::Ok(ok__) => {
*result__ = ::core::mem::transmute_copy(&ok__);
::core::ptr::write(result__, ::core::mem::transmute_copy(&ok__));
::core::mem::forget(ok__);
::windows::core::HRESULT(0)
}
Expand Down
14 changes: 7 additions & 7 deletions crates/libs/windows/src/Windows/AI/MachineLearning/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl ILearningModelFeatureDescriptor_Vtbl {
let this = (*this).get_impl();
match this.Name() {
::core::result::Result::Ok(ok__) => {
*result__ = ::core::mem::transmute_copy(&ok__);
::core::ptr::write(result__, ::core::mem::transmute_copy(&ok__));
::core::mem::forget(ok__);
::windows::core::HRESULT(0)
}
Expand All @@ -26,7 +26,7 @@ impl ILearningModelFeatureDescriptor_Vtbl {
let this = (*this).get_impl();
match this.Description() {
::core::result::Result::Ok(ok__) => {
*result__ = ::core::mem::transmute_copy(&ok__);
::core::ptr::write(result__, ::core::mem::transmute_copy(&ok__));
::core::mem::forget(ok__);
::windows::core::HRESULT(0)
}
Expand All @@ -38,7 +38,7 @@ impl ILearningModelFeatureDescriptor_Vtbl {
let this = (*this).get_impl();
match this.Kind() {
::core::result::Result::Ok(ok__) => {
*result__ = ::core::mem::transmute_copy(&ok__);
::core::ptr::write(result__, ::core::mem::transmute_copy(&ok__));
::core::mem::forget(ok__);
::windows::core::HRESULT(0)
}
Expand All @@ -50,7 +50,7 @@ impl ILearningModelFeatureDescriptor_Vtbl {
let this = (*this).get_impl();
match this.IsRequired() {
::core::result::Result::Ok(ok__) => {
*result__ = ::core::mem::transmute_copy(&ok__);
::core::ptr::write(result__, ::core::mem::transmute_copy(&ok__));
::core::mem::forget(ok__);
::windows::core::HRESULT(0)
}
Expand Down Expand Up @@ -82,7 +82,7 @@ impl ILearningModelFeatureValue_Vtbl {
let this = (*this).get_impl();
match this.Kind() {
::core::result::Result::Ok(ok__) => {
*result__ = ::core::mem::transmute_copy(&ok__);
::core::ptr::write(result__, ::core::mem::transmute_copy(&ok__));
::core::mem::forget(ok__);
::windows::core::HRESULT(0)
}
Expand Down Expand Up @@ -124,7 +124,7 @@ impl ITensor_Vtbl {
let this = (*this).get_impl();
match this.TensorKind() {
::core::result::Result::Ok(ok__) => {
*result__ = ::core::mem::transmute_copy(&ok__);
::core::ptr::write(result__, ::core::mem::transmute_copy(&ok__));
::core::mem::forget(ok__);
::windows::core::HRESULT(0)
}
Expand All @@ -136,7 +136,7 @@ impl ITensor_Vtbl {
let this = (*this).get_impl();
match this.Shape() {
::core::result::Result::Ok(ok__) => {
*result__ = ::core::mem::transmute_copy(&ok__);
::core::ptr::write(result__, ::core::mem::transmute_copy(&ok__));
::core::mem::forget(ok__);
::windows::core::HRESULT(0)
}
Expand Down
Loading

0 comments on commit d60b526

Please sign in to comment.