Skip to content

Commit 4a9328e

Browse files
author
bors-servo
authored
Auto merge of #134 - jrmuizel:unsafe, r=nox
Mark FromVoid more appropriately as unsafe <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/134) <!-- Reviewable:end -->
2 parents f9e8545 + 8514c48 commit 4a9328e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

core-foundation/src/array.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ use base::{CFIndexConvertible, TCFType, CFRange};
2323
pub struct CFArray<T = *const c_void>(CFArrayRef, PhantomData<T>);
2424

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

30-
impl FromVoid for u32 {
31-
fn from_void(x: *const c_void) -> u32 {
30+
unsafe impl FromVoid for u32 {
31+
unsafe fn from_void(x: *const c_void) -> u32 {
3232
x as usize as u32
3333
}
3434
}
3535

36-
impl FromVoid for *const c_void {
37-
fn from_void(x: *const c_void) -> *const c_void {
36+
unsafe impl FromVoid for *const c_void {
37+
unsafe fn from_void(x: *const c_void) -> *const c_void {
3838
x
3939
}
4040
}
4141

42-
impl FromVoid for CFType {
43-
fn from_void(x: *const c_void) -> CFType {
44-
unsafe { TCFType::wrap_under_get_rule(mem::transmute(x)) }
42+
unsafe impl FromVoid for CFType {
43+
unsafe fn from_void(x: *const c_void) -> CFType {
44+
TCFType::wrap_under_get_rule(mem::transmute(x))
4545
}
4646
}
4747

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

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

0 commit comments

Comments
 (0)