Skip to content

Commit

Permalink
add set_mut_ptr helper to ArcCastPtr trait
Browse files Browse the repository at this point in the history
  • Loading branch information
cpu committed Oct 3, 2023
1 parent ce31cd5 commit 473cee9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,7 @@ impl rustls_root_cert_store_builder {
Some(b) => b,
};

unsafe {
*root_cert_store_out = ArcCastPtr::to_const_ptr(builder.roots.clone());
}
ArcCastPtr::set_mut_ptr(root_cert_store_out, builder.roots.clone());

rustls_result::Ok
}
Expand Down Expand Up @@ -743,10 +741,7 @@ impl rustls_web_pki_client_cert_verifier_builder {
Err(e) => return error::map_verifier_builder_error(e),
};

// TODO(XXX): Is there a safer way to handle this ala BoxCastPtr::set_mut_ptr?
unsafe {
*verifier_out = ArcCastPtr::to_const_ptr(verifier)
}
ArcCastPtr::set_mut_ptr(verifier_out, verifier);

rustls_result::Ok
}
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ pub(crate) trait ArcCastPtr: CastConstPtr + Sized {
fn to_const_ptr(src: Self::RustType) -> *const Self {
Arc::into_raw(Arc::new(src)) as *const _
}

fn set_mut_ptr(dst: *mut *const Self, src: Self::RustType) {
unsafe {
*dst = Self::to_const_ptr(src);
}
}
}

#[doc(hidden)]
Expand Down

0 comments on commit 473cee9

Please sign in to comment.