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

Inconsistency in Handling Arrays with OutRef in IEnumUnknown_Impl #3489

Open
Ronbb opened this issue Feb 14, 2025 · 2 comments · May be fixed by #3517
Open

Inconsistency in Handling Arrays with OutRef in IEnumUnknown_Impl #3489

Ronbb opened this issue Feb 14, 2025 · 2 comments · May be fixed by #3517
Labels
bug Something isn't working

Comments

@Ronbb
Copy link

Ronbb commented Feb 14, 2025

Summary

When implementing the IEnumUnknown_Impl trait, the method signature for Next uses OutRef to handle the rgelt parameter, which is expected to be an array of Option<windows_core::IUnknown>. However, OutRef is designed to write only a single element, leading to difficulties in correctly implementing the Next method to handle arrays.

Here is the relevant code:

impl IEnumUnknown {
    pub unsafe fn Next(&self, rgelt: &mut [Option<windows_core::IUnknown>], pceltfetched: Option<*mut u32>) -> windows_core::HRESULT
    // ...
}

pub trait IEnumUnknown_Impl: windows_core::IUnknownImpl {
    fn Next(&self, celt: u32, rgelt: windows_core::OutRef<'_, windows_core::IUnknown>, pceltfetched: *mut u32) -> windows_core::HRESULT;
    // ...
}

impl<T: Type<T>> OutRef<'_, T> {
    // ...
    pub fn write(self, value: T::Default) -> Result<()> {
        if self.0.is_null() {
            Err(Error::from_hresult(imp::E_POINTER))
        } else {
            unsafe { *self.0 = core::mem::transmute_copy(&value) }
            core::mem::forget(value);
            Ok(())
        }
    }
}

This issue also affects other enumerator interfaces for InterfaceType, such as IEnumConnectionPoints.

Crate manifest

Crate code

@Ronbb Ronbb added the bug Something isn't working label Feb 14, 2025
@kennykerr
Copy link
Collaborator

Sorry for the delay - I have a fix for this where it does not apply the OutRef to the trait for parameters that have array metadata.

@kennykerr
Copy link
Collaborator

And here's the fix #3517 - please do take it for a spin and let me know if you run into any problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants