Skip to content

Commit

Permalink
PR cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Arlie Davis committed May 16, 2024
1 parent 13f251e commit 15d5851
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 16 deletions.
10 changes: 2 additions & 8 deletions crates/libs/core/src/com_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl<T: ComObjectInner> ComObject<T> {

/// Gets a reference to the shared object's heap box.
#[inline(always)]
pub fn get_box(&self) -> &T::Outer {
fn get_box(&self) -> &T::Outer {
unsafe { self.ptr.as_ref() }
}

Expand All @@ -98,20 +98,14 @@ impl<T: ComObjectInner> ComObject<T> {
}
}

/// Returns `true` if this reference is the only reference to the `ComObject`.
#[inline(always)]
pub fn is_exclusive_reference(&self) -> bool {
self.get_box().is_reference_count_one()
}

/// If this object has only a single object reference (i.e. this [`ComObject`] is the only
/// reference to the heap allocation), then this method will extract the inner `T`
/// (and return it in an `Ok`) and then free the heap allocation.
///
/// If there is more than one reference to this object, then this returns `Err(self)`.
#[inline(always)]
pub fn take(self) -> Result<T, Self> {
if self.is_exclusive_reference() {
if self.is_reference_count_one() {
let outer_box: Box<T::Outer> = unsafe { core::mem::transmute(self) };
Ok(outer_box.into_inner())
} else {
Expand Down
2 changes: 0 additions & 2 deletions crates/libs/core/src/unknown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ pub trait IUnknownImpl {
/// Taking `&self` would violate Rust's rules on reference lifetime.
unsafe fn Release(self_: *mut Self) -> u32;

unsafe fn destroy(self_: *mut Self);

/// Returns `true` if the reference count of the box is equal to 1.
fn is_reference_count_one(&self) -> bool;

Expand Down
7 changes: 1 addition & 6 deletions crates/libs/implement/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,11 @@ pub fn implement(attributes: proc_macro::TokenStream, original_type: proc_macro:
unsafe fn Release(self_: *mut Self) -> u32 {
let remaining = (*self_).count.release();
if remaining == 0 {
Self::destroy(self_);
_ = ::windows_core::imp::Box::from_raw(self_ as *const Self as *mut Self);
}
remaining
}

#[inline(never)]
unsafe fn destroy(self_: *mut Self) {
_ = ::windows_core::imp::Box::from_raw(self_ as *const Self as *mut Self);
}

unsafe fn GetTrustLevel(&self, value: *mut i32) -> ::windows_core::HRESULT {
if value.is_null() {
return ::windows_core::imp::E_POINTER;
Expand Down

0 comments on commit 15d5851

Please sign in to comment.