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

windows-bindgen generated _Impl trait methods can be simplified #3398

Open
omerkattan-microsoft opened this issue Dec 16, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@omerkattan-microsoft
Copy link

Suggestion

A COM interface whose methods are SAL annotated is usually simplified. However, the generated _Impl trait is less simplified.
For example, consider the following interface:

DEFINE_INTERFACE(ITestInterface, "7E17AD3C-47AF-4A71-85BD-1122EAB7E794") : public IUnknown
{
    STDMETHOD_(HRESULT, EncryptBuffer)
    (__in_bcount(cbSize) BYTE * pBuffer, _In_ size_t cbSize, _Out_ IBuffer * *ppvObj) = 0;
};

The generated ITestInterface looks like that:

impl ITestInterface {
    pub unsafe fn EncryptBuffer(
        &self,
        pbuffer: &mut [u8],
        ) -> windows_core::Result<IBuffer> {
        // ...
    }
}

pBuffer and cbSize were nicely merged into a mutable slice thanks to the SAL annotations. However, when implementing this interface we need to implement the following trait:

pub trait ITestInterface_Impl: Sized {
    fn EncryptBuffer(
        &self,
        pbuffer: *mut u8,
        cbsize: usize,
    ) -> windows_core::Result<IBuffer>;
}

The return value for the _Impl trait method was simplified, but not the slice param. If it was simplified as well, it would allow us to implement the interface without using unsafe code

@omerkattan-microsoft omerkattan-microsoft added the enhancement New feature or request label Dec 16, 2024
@omerkattan-microsoft omerkattan-microsoft changed the title _Impl trait methods can be simplified windows-bindgen Generated _Impl trait methods can be simplified Dec 16, 2024
@omerkattan-microsoft omerkattan-microsoft changed the title windows-bindgen Generated _Impl trait methods can be simplified windows-bindgen generated _Impl trait methods can be simplified Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant