From 5f4bdb2b08b2cc318f022b2dccb47f4720d09ce5 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 9 May 2013 11:13:20 -0600 Subject: [PATCH] Fix C FFI to use *mut pointers correctly and update code. This was found because of unused mut warnings. --- number.rs | 18 +++++++++--------- string.rs | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/number.rs b/number.rs index 8c99400..03a3062 100644 --- a/number.rs +++ b/number.rs @@ -78,8 +78,8 @@ pub impl CFNumber { let ty = kCFNumberSInt8Type; assert!(self.has_number_type(ty)); unsafe { - let val: i8 = 0i8; - if !CFNumberGetValue(self.contents.obj, ty, cast::transmute::<&i8, *c_void>(&val)) { + let mut val: i8 = 0i8; + if !CFNumberGetValue(self.contents.obj, ty, cast::transmute::<&mut i8, *mut c_void>(&mut val)) { fail!(~"Error in unwrapping CFNumber to i8"); } return val; @@ -90,8 +90,8 @@ pub impl CFNumber { let ty = kCFNumberSInt16Type; assert!(self.has_number_type(ty)); unsafe { - let val: i16 = 0i16; - if !CFNumberGetValue(self.contents.obj, ty, cast::transmute::<&i16, *c_void>(&val)) { + let mut val: i16 = 0i16; + if !CFNumberGetValue(self.contents.obj, ty, cast::transmute::<&mut i16, *mut c_void>(&mut val)) { fail!(~"Error in unwrapping CFNumber to i16"); } return val; @@ -102,8 +102,8 @@ pub impl CFNumber { let ty = kCFNumberSInt32Type; assert!(self.has_number_type(ty)); unsafe { - let val: i32 = 0i32; - if !CFNumberGetValue(self.contents.obj, ty, cast::transmute::<&i32, *c_void>(&val)) { + let mut val: i32 = 0i32; + if !CFNumberGetValue(self.contents.obj, ty, cast::transmute::<&mut i32, *mut c_void>(&mut val)) { fail!(~"Error in unwrapping CFNumber to i32"); } return val; @@ -118,7 +118,7 @@ pub impl CFNumber { let mut val: libc::c_float = 0.0f as libc::c_float; if !CFNumberGetValue(self.contents.obj, ty, - cast::transmute::<&libc::c_float, *c_void>(&val)) { + cast::transmute::<&mut libc::c_float, *mut c_void>(&mut val)) { fail!(~"Error in unwrapping CFNumber to libc::c_float"); } return val as float; @@ -127,7 +127,7 @@ pub impl CFNumber { let mut val: libc::c_double = 0.0f as libc::c_double; if !CFNumberGetValue(self.contents.obj, ty, - cast::transmute::<&libc::c_double, *c_void>(&val)) { + cast::transmute::<&mut libc::c_double, *mut c_void>(&mut val)) { fail!(~"Error in unwrapping CFNumber to libc::c_double"); } return val as float; @@ -200,7 +200,7 @@ extern { -> CFNumberRef; //fn CFNumberGetByteSize fn CFNumberGetType(number: CFNumberRef) -> CFNumberType; - fn CFNumberGetValue(number: CFNumberRef, theType: CFNumberType, valuePtr: *c_void) -> bool; + fn CFNumberGetValue(number: CFNumberRef, theType: CFNumberType, valuePtr: *mut c_void) -> bool; fn CFNumberIsFloatType(number: CFNumberRef) -> Boolean; //fn CFNumberCompare fn CFNumberGetTypeID() -> CFTypeID; diff --git a/string.rs b/string.rs index cdbf27c..b3daddf 100644 --- a/string.rs +++ b/string.rs @@ -282,7 +282,7 @@ impl ToStr for CFString { false as Boolean, ptr::null(), 0, - &bytes_required); + &mut bytes_required); let buffer : ~[u8] = vec::from_elem(1+bytes_required as uint, '\x00' as u8); let mut bytes_used: CFIndex = 0 as CFIndex; @@ -294,7 +294,7 @@ impl ToStr for CFString { false as Boolean, vec::raw::to_ptr(buffer), buffer.len() as CFIndex, - ptr::to_unsafe_ptr(&bytes_used)) as uint; + ptr::to_mut_unsafe_ptr(&mut bytes_used)) as uint; assert!(chars_written == char_len); // this is dangerous; we over-allocate and nul-terminate the string (during @@ -371,7 +371,7 @@ extern { isExternalRepresentation: Boolean, buffer: *u8, maxBufLen: CFIndex, - usedBufLen: *CFIndex) + usedBufLen: *mut CFIndex) -> CFIndex; //fn CFStringGetCharacterAtIndex //fn CFStringGetCharacters