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

Remove IUnknownImpl::from_inner_ref as no longer needed #3513

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions crates/libs/core/src/unknown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,6 @@ pub trait IUnknownImpl {
/// Gets the trust level of the current object.
unsafe fn GetTrustLevel(&self, value: *mut i32) -> HRESULT;

/// Given a reference to an inner type, returns a reference to the outer shared type.
///
/// # Safety
///
/// This function should only be called from methods that implement COM interfaces, i.e.
/// implementations of methods on `IFoo_Impl` traits.
// TODO: This can be made safe, if IFoo_Impl are moved to the Object_Impl types.
// That requires some substantial redesign, though.
unsafe fn from_inner_ref(inner: &Self::Impl) -> &Self;

/// Gets a borrowed reference to an interface that is implemented by this ComObject.
///
/// The returned reference does not have an additional reference count.
Expand Down Expand Up @@ -158,10 +148,6 @@ pub trait IUnknownImpl {
fn to_object(&self) -> ComObject<Self::Impl>
where
Self::Impl: ComObjectInner<Outer = Self>;

/// The distance from the start of `<Foo>_Impl` to the `this` field within it, measured in
/// pointer-sized elements. The `this` field contains the `MyApp` instance.
const INNER_OFFSET_IN_POINTERS: usize;
}

impl IUnknown_Vtbl {
Expand Down
12 changes: 0 additions & 12 deletions crates/libs/implement/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ pub fn implement(
quote!()
};

// The distance from the beginning of the generated type to the 'this' field, in units of pointers (not bytes).
let offset_of_this_in_pointers = 1 + attributes.implement.len();
let offset_of_this_in_pointers_token =
proc_macro2::Literal::usize_unsuffixed(offset_of_this_in_pointers);

let trust_level = proc_macro2::Literal::usize_unsuffixed(attributes.trust_level);

let conversions = attributes.implement.iter().enumerate().map(|(enumerate, implement)| {
Expand Down Expand Up @@ -309,11 +304,6 @@ pub fn implement(
::windows_core::HRESULT(0)
}

unsafe fn from_inner_ref(inner: &Self::Impl) -> &Self {
&*((inner as *const Self::Impl as *const *const ::core::ffi::c_void)
.sub(#offset_of_this_in_pointers_token) as *const Self)
}

fn to_object(&self) -> ::windows_core::ComObject<Self::Impl> {
self.count.add_ref();
unsafe {
Expand All @@ -322,8 +312,6 @@ pub fn implement(
)
}
}

const INNER_OFFSET_IN_POINTERS: usize = #offset_of_this_in_pointers_token;
}

impl #generics ::core::convert::From<#original_ident::#generics> for ::windows_core::IUnknown where #constraints {
Expand Down
3 changes: 1 addition & 2 deletions crates/tests/libs/implement_core/src/com_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ impl IFoo_Impl for MyApp_Impl {
}

unsafe fn get_self_as_bar(&self) -> IBar {
let outer = MyApp_Impl::from_inner_ref(self);
outer.to_interface()
self.to_interface()
}

unsafe fn common(&self) -> u32 {
Expand Down