Merge pull request #16 from brson/master

Update for language changes
This commit is contained in:
Jack Moffitt
2013-08-29 15:24:53 -07:00
9 changed files with 37 additions and 0 deletions
+4
View File
@@ -39,6 +39,7 @@ pub type CFArrayRef = *__CFArray;
impl AbstractCFTypeRef for CFArrayRef {
fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef }
#[fixed_stack_segment]
fn type_id() -> CFTypeID { unsafe { CFArrayGetTypeID() } }
}
@@ -77,6 +78,7 @@ impl<ElemRefType:AbstractCFTypeRef> CFArray<ElemRefType> {
}
}
#[fixed_stack_segment]
pub fn new(elems: &[ElemRefType]) -> CFArray<ElemRefType> {
let array_ref: CFArrayRef;
let elems_refs = do elems.map |e: &ElemRefType| { e.as_type_ref() };
@@ -103,6 +105,7 @@ impl<ElemRefType:AbstractCFTypeRef> CFArray<ElemRefType> {
}
}
#[fixed_stack_segment]
pub fn len(&self) -> uint {
unsafe {
return CFArrayGetCount(*self.contents.borrow_ref()) as uint;
@@ -114,6 +117,7 @@ impl<ElemRefType:AbstractCFTypeRef> Index<uint,ElemRefType> for CFArray<ElemRefT
// Careful; the caller must wrap any returned reference properly.
// Generally, when array elements are Core Foundation objects (not
// always true), they need to be wrapped with CFWrapper::wrap_shared.
#[fixed_stack_segment]
fn index(&self, idx: &uint) -> ElemRefType {
assert!(*idx < self.len());
unsafe {
+6
View File
@@ -51,6 +51,7 @@ impl AbstractCFTypeRef for CFTypeRef {
fn type_id() -> CFTypeID { fail!(); }
}
#[fixed_stack_segment]
pub fn downcast<T:AbstractCFTypeRef>(r: CFTypeRef) -> T {
unsafe {
assert!(CFGetTypeID(r) == AbstractCFTypeRef::type_id::<T>());
@@ -68,6 +69,7 @@ pub struct CFWrapper<T, PlaceholderType1, PlaceholderType2> {
#[unsafe_destructor]
impl<T,E1,E2> Drop for CFWrapper<T,E1,E2> {
#[fixed_stack_segment]
fn drop(&self) {
unsafe {
// sadly, cannot use obj.as_type_ref() here, because drop
@@ -104,6 +106,7 @@ impl<'self, T:Clone + AbstractCFTypeRef, E1, E2> CFWrapper<T,E1,E2> {
// Use this when following Core Foundation's "Get" rule. The wrapper does not have ownership.
// Twe need to increment object's the retain count so it isn't freed out from under our noses.
#[fixed_stack_segment]
pub fn wrap_shared(some_ref: T) -> CFWrapper<T,E1,E2> {
unsafe { CFRetain(some_ref.as_type_ref()); }
CFWrapper { obj: some_ref }
@@ -131,18 +134,21 @@ impl<'self, T:Clone + AbstractCFTypeRef, E1, E2> CFWrapper<T,E1,E2> {
CFWrapper::wrap_shared((*wrapper.borrow_ref()).clone())
}
#[fixed_stack_segment]
pub fn retain_count(&self) -> CFIndex {
unsafe {
CFGetRetainCount(*self.borrow_type_ref())
}
}
#[fixed_stack_segment]
pub fn type_id(&self) -> CFTypeID {
unsafe {
CFGetTypeID(*self.borrow_type_ref())
}
}
#[fixed_stack_segment]
pub fn show(&self) {
unsafe {
CFShow(*self.borrow_type_ref());
+1
View File
@@ -22,6 +22,7 @@ pub type CFBooleanRef = *__CFBoolean;
impl AbstractCFTypeRef for CFBooleanRef {
fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef }
#[fixed_stack_segment]
fn type_id() -> CFTypeID {
unsafe { CFBooleanGetTypeID() }
}
+4
View File
@@ -26,6 +26,7 @@ pub type CFDataRef = *__CFData;
impl AbstractCFTypeRef for CFDataRef {
fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef }
#[fixed_stack_segment]
fn type_id() -> CFTypeID {
unsafe {
CFDataGetTypeID()
@@ -46,6 +47,7 @@ impl CFData {
}
}
#[fixed_stack_segment]
pub fn new_from_buf(buf: &[u8]) -> CFData {
let result;
unsafe {
@@ -60,12 +62,14 @@ impl CFData {
}
// tread with caution; read-only
#[fixed_stack_segment]
pub fn bytes(&self) -> *u8 {
unsafe {
CFDataGetBytePtr(self.contents.obj)
}
}
#[fixed_stack_segment]
pub fn len(&self) -> uint {
unsafe {
CFDataGetLength(self.contents.obj) as uint
+5
View File
@@ -54,6 +54,7 @@ pub type CFDictionaryRef = *__CFDictionary;
impl AbstractCFTypeRef for CFDictionaryRef {
fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef }
#[fixed_stack_segment]
fn type_id() -> CFTypeID {
unsafe {
CFDictionaryGetTypeID()
@@ -77,6 +78,7 @@ impl<KeyRefType: Clone + AbstractCFTypeRef, ValueRefType: Clone + AbstractCFType
}
}
#[fixed_stack_segment]
pub fn new(pairs: &[(KeyRefType,ValueRefType)]) -> CFDictionary<KeyRefType, ValueRefType> {
let mut keys : ~[CFTypeRef] = ~[];
let mut values : ~[CFTypeRef] = ~[];
@@ -109,6 +111,7 @@ impl<KeyRefType: Clone + AbstractCFTypeRef, ValueRefType: Clone + AbstractCFType
}
}
#[fixed_stack_segment]
pub fn len(&self) -> uint {
unsafe {
CFDictionaryGetCount(self.contents.obj) as uint
@@ -119,6 +122,7 @@ impl<KeyRefType: Clone + AbstractCFTypeRef, ValueRefType: Clone + AbstractCFType
self.len() == 0
}
#[fixed_stack_segment]
pub fn contains_key(&self, key: &KeyRefType) -> bool {
unsafe {
CFDictionaryContainsKey(self.contents.obj,
@@ -127,6 +131,7 @@ impl<KeyRefType: Clone + AbstractCFTypeRef, ValueRefType: Clone + AbstractCFType
}
}
#[fixed_stack_segment]
pub fn find(&self, key: &KeyRefType) -> Option<ValueRefType> {
unsafe {
let value : *c_void = ptr::null();
+8
View File
@@ -43,6 +43,7 @@ pub type CFNumberRef = *__CFNumber;
impl AbstractCFTypeRef for CFNumberRef {
fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef }
#[fixed_stack_segment]
fn type_id() -> CFTypeID {
unsafe {
CFNumberGetTypeID()
@@ -67,6 +68,7 @@ impl CFNumber {
}
}
#[fixed_stack_segment]
pub fn new<T:Clone + ConvertibleToCFNumber>(n: T) -> CFNumber {
unsafe {
let objref = CFNumberCreate(kCFAllocatorDefault,
@@ -78,6 +80,7 @@ impl CFNumber {
}
}
#[fixed_stack_segment]
pub fn to_i8(&self) -> i8 {
let ty = kCFNumberSInt8Type;
assert!(self.has_number_type(ty));
@@ -90,6 +93,7 @@ impl CFNumber {
}
}
#[fixed_stack_segment]
pub fn to_i16(&self) -> i16 {
let ty = kCFNumberSInt16Type;
assert!(self.has_number_type(ty));
@@ -102,6 +106,7 @@ impl CFNumber {
}
}
#[fixed_stack_segment]
pub fn to_i32(&self) -> i32 {
let ty = kCFNumberSInt32Type;
assert!(self.has_number_type(ty));
@@ -114,6 +119,7 @@ impl CFNumber {
}
}
#[fixed_stack_segment]
pub fn to_float(&self) -> float {
unsafe {
assert!(self.has_float_type());
@@ -141,12 +147,14 @@ impl CFNumber {
}
}
#[fixed_stack_segment]
fn has_float_type(&self) -> bool {
unsafe {
CFNumberIsFloatType(self.contents.obj) as bool
}
}
#[fixed_stack_segment]
fn has_number_type(&self, ty: CFNumberType) -> bool {
unsafe {
CFNumberGetType(self.contents.obj) == ty
+2
View File
@@ -42,6 +42,7 @@ pub type CFSetRef = *__CFSet;
impl AbstractCFTypeRef for CFSetRef {
fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef }
#[fixed_stack_segment]
fn type_id() -> CFTypeID {
unsafe {
CFSetGetTypeID()
@@ -56,6 +57,7 @@ pub struct CFSet<ElemRefType> {
}
impl<ElemRefType : AbstractCFTypeRef> CFSet<ElemRefType> {
#[fixed_stack_segment]
pub fn new(elems: &[ElemRefType]) -> CFSet<ElemRefType> {
let result: CFSetRef;
let elems_refs = do elems.map |e: &ElemRefType| {
+5
View File
@@ -202,6 +202,7 @@ pub type CFStringRef = *__CFString;
impl AbstractCFTypeRef for CFStringRef {
fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef }
#[fixed_stack_segment]
fn type_id() -> CFTypeID {
unsafe {
CFStringGetTypeID()
@@ -233,6 +234,7 @@ impl CFString {
// like CFString::new, but references a string that can be used as
// a backing store by virtue of being statically allocated.
#[fixed_stack_segment]
pub fn new_static(string: &'static str) -> CFString {
let string_ref = do string.as_imm_buf |bytes, len| {
unsafe {
@@ -250,6 +252,7 @@ impl CFString {
}
}
#[fixed_stack_segment]
pub fn new(string: &str) -> CFString {
let string_ref = do string.as_imm_buf |bytes, len| {
unsafe {
@@ -267,6 +270,7 @@ impl CFString {
}
}
#[fixed_stack_segment]
pub fn char_len(&self) -> uint {
unsafe {
CFStringGetLength(self.contents.obj) as uint
@@ -275,6 +279,7 @@ impl CFString {
}
impl ToStr for CFString {
#[fixed_stack_segment]
fn to_str(&self) -> ~str {
unsafe {
let char_len = self.char_len();
+2
View File
@@ -19,6 +19,7 @@ pub type CFURLRef = *__CFURL;
impl AbstractCFTypeRef for CFURLRef {
fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef }
#[fixed_stack_segment]
fn type_id() -> CFTypeID {
unsafe {
CFURLGetTypeID()
@@ -29,6 +30,7 @@ impl AbstractCFTypeRef for CFURLRef {
pub type CFURL = CFWrapper<CFURLRef, (), ()>;
impl ToStr for CFURL {
#[fixed_stack_segment]
fn to_str(&self) -> ~str {
unsafe {
let cfstr: CFString = CFString {