Skip to content
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

Code cleanup and warning fixes #58

Merged
merged 2 commits into from Feb 21, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -104,7 +104,7 @@ impl TCFType<CFArrayRef> for CFArray {
}

#[inline]
fn type_id(_: Option<CFArray>) -> CFTypeID {
fn type_id() -> CFTypeID {
unsafe {
CFArrayGetTypeID()
}
@@ -14,6 +14,7 @@ pub type Boolean = u8;

pub type CFIndex = c_long;

#[allow(non_camel_case_types)]
pub type mach_port_t = c_uint;

pub trait CFIndexConvertible {
@@ -105,10 +106,7 @@ pub trait TCFType<ConcreteTypeRef> {
unsafe fn wrap_under_create_rule(obj: ConcreteTypeRef) -> Self;

/// Returns the type ID for this class.
///
/// FIXME(pcwalton): The dummy parameter is there to work around the current inexpressivity of
/// the Rust language.
fn type_id(dummy: Option<Self>) -> CFTypeID;
fn type_id() -> CFTypeID;

/// Returns the object as a wrapped `CFType`. The reference count is incremented by one.
#[inline]
@@ -152,8 +150,7 @@ pub trait TCFType<ConcreteTypeRef> {
/// Returns true if this value is an instance of another type.
#[inline]
fn instance_of<OtherConcreteTypeRef,OtherCFType:TCFType<OtherConcreteTypeRef>>(&self) -> bool {
let dummy: Option<OtherCFType> = None;
self.type_of() == TCFType::type_id(dummy)
self.type_of() == <OtherCFType as TCFType<_>>::type_id()
}
}

@@ -182,7 +179,7 @@ impl TCFType<CFTypeRef> for CFType {
}

#[inline]
fn type_id(_: Option<CFType>) -> CFTypeID {
fn type_id() -> CFTypeID {
// FIXME(pcwalton): Is this right?
0
}
@@ -60,7 +60,7 @@ impl TCFType<CFBooleanRef> for CFBoolean {
}

#[inline]
fn type_id(_: Option<CFBoolean>) -> CFTypeID {
fn type_id() -> CFTypeID {
unsafe {
CFBooleanGetTypeID()
}
@@ -61,7 +61,7 @@ impl TCFType<CFBundleRef> for CFBundle {
}

#[inline]
fn type_id(_: Option<CFBundle>) -> CFTypeID {
fn type_id() -> CFTypeID {
unsafe {
CFBundleGetTypeID()
}
@@ -60,7 +60,7 @@ impl TCFType<CFDataRef> for CFData {
}

#[inline]
fn type_id(_: Option<CFData>) -> CFTypeID {
fn type_id() -> CFTypeID {
unsafe {
CFDataGetTypeID()
}
@@ -92,7 +92,7 @@ impl TCFType<CFDictionaryRef> for CFDictionary {
}

#[inline]
fn type_id(_: Option<CFDictionary>) -> CFTypeID {
fn type_id() -> CFTypeID {
unsafe {
CFDictionaryGetTypeID()
}
@@ -12,7 +12,7 @@

#![allow(non_snake_case)]

#![feature(core, libc)]
#![feature(core)]

extern crate libc;

@@ -85,7 +85,7 @@ impl TCFType<CFNumberRef> for CFNumber {
}

#[inline]
fn type_id(_: Option<CFNumber>) -> CFTypeID {
fn type_id() -> CFTypeID {
unsafe {
CFNumberGetTypeID()
}
@@ -15,10 +15,9 @@ use base::{kCFAllocatorDefault};
use base::{Boolean};
use array::{CFArrayRef};
use string::{CFString, CFStringRef};
use date::{CFAbsoluteTime, CFTimeInterval, CFAbsoluteTimeGetCurrent};
use date::{CFAbsoluteTime, CFTimeInterval};
use libc::c_void;
use std::mem;
use std::ptr;

/// FIXME(pcwalton): Should be a newtype struct, but that fails due to a Rust compiler bug.
pub struct CFRunLoop {
@@ -60,7 +59,7 @@ impl TCFType<CFRunLoopRef> for CFRunLoop {
}

#[inline]
fn type_id(_: Option<CFRunLoop>) -> CFTypeID {
fn type_id() -> CFTypeID {
unsafe {
CFRunLoopGetTypeID()
}
@@ -117,7 +116,7 @@ impl CFRunLoop {
CFRunLoopAddTimer(self.obj, timer.obj, mode);
}
}

}

#[repr(C)]
@@ -154,7 +153,7 @@ pub const kCFRunLoopAllActivities: CFOptionFlags = 0x0FFFFFFF;

#[repr(C)]
pub struct CFRunLoopSourceContext {
version: CFIndex,
version: CFIndex,
info: *mut c_void,
retain: extern "C" fn (info: *const c_void) -> *const c_void,
release: extern "C" fn (info: *const c_void),
@@ -168,7 +167,7 @@ pub struct CFRunLoopSourceContext {

#[repr(C)]
pub struct CFRunLoopSourceContext1 {
version: CFIndex,
version: CFIndex,
info: *mut c_void,
retain: extern "C" fn (info: *const c_void) -> *const c_void,
release: extern "C" fn (info: *const c_void),
@@ -182,7 +181,7 @@ pub struct CFRunLoopSourceContext1 {

#[repr(C)]
pub struct CFRunLoopObserverContext {
version: CFIndex,
version: CFIndex,
info: *mut c_void,
retain: extern "C" fn (info: *const c_void) -> *const c_void,
release: extern "C" fn (info: *const c_void),
@@ -193,7 +192,7 @@ pub type CFRunLoopObserverCallBack = extern "C" fn (observer: CFRunLoopObserverR

#[repr(C)]
pub struct CFRunLoopTimerContext {
version: CFIndex,
version: CFIndex,
info: *mut c_void,
retain: extern "C" fn (info: *const c_void) -> *const c_void,
release: extern "C" fn (info: *const c_void),
@@ -247,7 +246,7 @@ impl TCFType<CFRunLoopTimerRef> for CFRunLoopTimer {
}

#[inline]
fn type_id(_: Option<CFRunLoopTimer>) -> CFTypeID {
fn type_id() -> CFTypeID {
unsafe {
CFRunLoopTimerGetTypeID()
}
@@ -328,9 +327,15 @@ extern {
fn CFRunLoopTimerSetTolerance(timer: CFRunLoopTimerRef, tolerance: CFTimeInterval);
}

#[cfg(test)]
mod test {
use super::*;
use date::{CFAbsoluteTime, CFAbsoluteTimeGetCurrent};
use std::mem;
use libc::c_void;

#[test]
fn wait_200_milliseconds() {
#[test]
fn wait_200_milliseconds() {
let run_loop = CFRunLoop::get_current();
let mut now = unsafe { CFAbsoluteTimeGetCurrent() };
let mut context = unsafe { CFRunLoopTimerContext {
@@ -346,12 +351,13 @@ fn wait_200_milliseconds() {
run_loop.add_timer(&run_loop_timer, kCFRunLoopDefaultMode);

CFRunLoop::run_current();
}
}

extern "C" fn timer_popped(_timer: CFRunLoopTimerRef, _info: *mut c_void) {
let previous_now_ptr: *const CFAbsoluteTime = unsafe { mem::transmute(_info) };
let previous_now = unsafe { *previous_now_ptr };
let now = unsafe { CFAbsoluteTimeGetCurrent() };
assert!(now - previous_now > 0.19 && now - previous_now < 0.21);
CFRunLoop::get_current().stop();
extern "C" fn timer_popped(_timer: CFRunLoopTimerRef, _info: *mut c_void) {
let previous_now_ptr: *const CFAbsoluteTime = unsafe { mem::transmute(_info) };
let previous_now = unsafe { *previous_now_ptr };
let now = unsafe { CFAbsoluteTimeGetCurrent() };
assert!(now - previous_now > 0.19 && now - previous_now < 0.21);
CFRunLoop::get_current().stop();
}
}
@@ -79,7 +79,7 @@ impl TCFType<CFSetRef> for CFSet {
}

#[inline]
fn type_id(_: Option<CFSet>) -> CFTypeID {
fn type_id() -> CFTypeID {
unsafe {
CFSetGetTypeID()
}
@@ -255,7 +255,7 @@ impl TCFType<CFStringRef> for CFString {
}

#[inline]
fn type_id(_: Option<CFString>) -> CFTypeID {
fn type_id() -> CFTypeID {
unsafe {
CFStringGetTypeID()
}
@@ -62,7 +62,7 @@ impl TCFType<CFURLRef> for CFURL {
}

#[inline]
fn type_id(_: Option<CFURL>) -> CFTypeID {
fn type_id() -> CFTypeID {
unsafe {
CFURLGetTypeID()
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.