Skip to content

Mark FromVoid more appropriately as unsafe #134

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

Merged
merged 1 commit into from
Nov 27, 2017
Merged
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
20 changes: 10 additions & 10 deletions core-foundation/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ use base::{CFIndexConvertible, TCFType, CFRange};
pub struct CFArray<T = *const c_void>(CFArrayRef, PhantomData<T>);

/// A trait describing how to convert from the stored *const c_void to the desired T
pub trait FromVoid {
fn from_void(x: *const c_void) -> Self;
pub unsafe trait FromVoid {
unsafe fn from_void(x: *const c_void) -> Self;
}

impl FromVoid for u32 {
fn from_void(x: *const c_void) -> u32 {
unsafe impl FromVoid for u32 {
unsafe fn from_void(x: *const c_void) -> u32 {
x as usize as u32
}
}

impl FromVoid for *const c_void {
fn from_void(x: *const c_void) -> *const c_void {
unsafe impl FromVoid for *const c_void {
unsafe fn from_void(x: *const c_void) -> *const c_void {
x
}
}

impl FromVoid for CFType {
fn from_void(x: *const c_void) -> CFType {
unsafe { TCFType::wrap_under_get_rule(mem::transmute(x)) }
unsafe impl FromVoid for CFType {
unsafe fn from_void(x: *const c_void) -> CFType {
TCFType::wrap_under_get_rule(mem::transmute(x))
}
}

Expand Down Expand Up @@ -121,7 +121,7 @@ impl<T> CFArray<T> {
#[inline]
pub fn get(&self, index: CFIndex) -> T where T: FromVoid {
assert!(index < self.len());
T::from_void(unsafe { CFArrayGetValueAtIndex(self.0, index) })
unsafe { T::from_void(CFArrayGetValueAtIndex(self.0, index)) }
}

pub fn get_values(&self, range: CFRange) -> Vec<*const c_void> {
Expand Down