microsoft / windows-rs

Rust for Windows
https://kennykerr.ca/rust-getting-started/
Apache License 2.0
10.13k stars 473 forks source link

Fix bug in COM interface chain support #3060

Closed sivadeilra closed 1 month ago

sivadeilra commented 1 month ago

The definition of a COM interface may inherit from another interface. These are known as "interface chains". The #[implement] macro allows designers to specify only the minimal set of interface chains that are needed for a given COM object implementation. The #[implement] macro (and the #[interface] macro) work together to pull in the implementations of all interfaces along the chain.

Unfortunately there is a bug in the implementation of QueryInterface for interface chains. The current QueryInterface implementation will only check the IIDs of the interfaces at the root of the chian, i.e. the "most-derived" interface. QueryInterface will not search the IIDs of interfaces that are in the inheritance chain.

This bug is demonstrated (detected) by the new unit tests in crates/tests/implement_core/src/com_chain.rs. This PR fixes the bug by generating an fn matches() method that checks the current IID and then checks the parent interface (if any) by calling its match() method. This fixes the unit test.

kennykerr commented 1 month ago

'matches' definitely needs to check parent IIDs.