From e7eb60681cd6ecc7f23b744278fea5663c7a9672 Mon Sep 17 00:00:00 2001 From: Aleksey Kuznetsov Date: Wed, 18 Feb 2015 21:04:13 +0500 Subject: [PATCH 1/2] Fixed warnings. --- src/base.rs | 1 + src/lib.rs | 2 +- src/runloop.rs | 38 ++++++++++++++++++++++---------------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/base.rs b/src/base.rs index 6962cd6..aa5d22b 100644 --- a/src/base.rs +++ b/src/base.rs @@ -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 { diff --git a/src/lib.rs b/src/lib.rs index dcccb61..6ae7350 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,7 @@ #![allow(non_snake_case)] -#![feature(core, libc)] +#![feature(core)] extern crate libc; diff --git a/src/runloop.rs b/src/runloop.rs index 8287188..4db441d 100644 --- a/src/runloop.rs +++ b/src/runloop.rs @@ -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 { @@ -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), @@ -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(); + } } From 36b7b6104d649f4a3fd4483014073c50e8d4878a Mon Sep 17 00:00:00 2001 From: Aleksey Kuznetsov Date: Wed, 18 Feb 2015 21:17:06 +0500 Subject: [PATCH 2/2] Removed dummy parametr in `type_id` method. Closes #17 Now call like: `let id = >::type_id();` [breaking-change] --- src/array.rs | 2 +- src/base.rs | 10 +++------- src/boolean.rs | 2 +- src/bundle.rs | 2 +- src/data.rs | 2 +- src/dictionary.rs | 2 +- src/number.rs | 2 +- src/runloop.rs | 4 ++-- src/set.rs | 2 +- src/string.rs | 2 +- src/url.rs | 2 +- 11 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/array.rs b/src/array.rs index 3f7cfb7..3ff7ac2 100644 --- a/src/array.rs +++ b/src/array.rs @@ -104,7 +104,7 @@ impl TCFType for CFArray { } #[inline] - fn type_id(_: Option) -> CFTypeID { + fn type_id() -> CFTypeID { unsafe { CFArrayGetTypeID() } diff --git a/src/base.rs b/src/base.rs index aa5d22b..adc2108 100644 --- a/src/base.rs +++ b/src/base.rs @@ -106,10 +106,7 @@ pub trait TCFType { 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) -> CFTypeID; + fn type_id() -> CFTypeID; /// Returns the object as a wrapped `CFType`. The reference count is incremented by one. #[inline] @@ -153,8 +150,7 @@ pub trait TCFType { /// Returns true if this value is an instance of another type. #[inline] fn instance_of>(&self) -> bool { - let dummy: Option = None; - self.type_of() == TCFType::type_id(dummy) + self.type_of() == >::type_id() } } @@ -183,7 +179,7 @@ impl TCFType for CFType { } #[inline] - fn type_id(_: Option) -> CFTypeID { + fn type_id() -> CFTypeID { // FIXME(pcwalton): Is this right? 0 } diff --git a/src/boolean.rs b/src/boolean.rs index 0f00a16..7f29ae4 100644 --- a/src/boolean.rs +++ b/src/boolean.rs @@ -60,7 +60,7 @@ impl TCFType for CFBoolean { } #[inline] - fn type_id(_: Option) -> CFTypeID { + fn type_id() -> CFTypeID { unsafe { CFBooleanGetTypeID() } diff --git a/src/bundle.rs b/src/bundle.rs index ea3b4ab..42edf88 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -61,7 +61,7 @@ impl TCFType for CFBundle { } #[inline] - fn type_id(_: Option) -> CFTypeID { + fn type_id() -> CFTypeID { unsafe { CFBundleGetTypeID() } diff --git a/src/data.rs b/src/data.rs index 0deb88f..55be5f1 100644 --- a/src/data.rs +++ b/src/data.rs @@ -60,7 +60,7 @@ impl TCFType for CFData { } #[inline] - fn type_id(_: Option) -> CFTypeID { + fn type_id() -> CFTypeID { unsafe { CFDataGetTypeID() } diff --git a/src/dictionary.rs b/src/dictionary.rs index d0fff98..73827a7 100644 --- a/src/dictionary.rs +++ b/src/dictionary.rs @@ -92,7 +92,7 @@ impl TCFType for CFDictionary { } #[inline] - fn type_id(_: Option) -> CFTypeID { + fn type_id() -> CFTypeID { unsafe { CFDictionaryGetTypeID() } diff --git a/src/number.rs b/src/number.rs index 99127ec..1a4821c 100644 --- a/src/number.rs +++ b/src/number.rs @@ -85,7 +85,7 @@ impl TCFType for CFNumber { } #[inline] - fn type_id(_: Option) -> CFTypeID { + fn type_id() -> CFTypeID { unsafe { CFNumberGetTypeID() } diff --git a/src/runloop.rs b/src/runloop.rs index 4db441d..067df84 100644 --- a/src/runloop.rs +++ b/src/runloop.rs @@ -59,7 +59,7 @@ impl TCFType for CFRunLoop { } #[inline] - fn type_id(_: Option) -> CFTypeID { + fn type_id() -> CFTypeID { unsafe { CFRunLoopGetTypeID() } @@ -246,7 +246,7 @@ impl TCFType for CFRunLoopTimer { } #[inline] - fn type_id(_: Option) -> CFTypeID { + fn type_id() -> CFTypeID { unsafe { CFRunLoopTimerGetTypeID() } diff --git a/src/set.rs b/src/set.rs index bbd78f4..43eb9a7 100644 --- a/src/set.rs +++ b/src/set.rs @@ -79,7 +79,7 @@ impl TCFType for CFSet { } #[inline] - fn type_id(_: Option) -> CFTypeID { + fn type_id() -> CFTypeID { unsafe { CFSetGetTypeID() } diff --git a/src/string.rs b/src/string.rs index 2843f6a..9dd1dbc 100644 --- a/src/string.rs +++ b/src/string.rs @@ -255,7 +255,7 @@ impl TCFType for CFString { } #[inline] - fn type_id(_: Option) -> CFTypeID { + fn type_id() -> CFTypeID { unsafe { CFStringGetTypeID() } diff --git a/src/url.rs b/src/url.rs index e21696d..243785b 100644 --- a/src/url.rs +++ b/src/url.rs @@ -62,7 +62,7 @@ impl TCFType for CFURL { } #[inline] - fn type_id(_: Option) -> CFTypeID { + fn type_id() -> CFTypeID { unsafe { CFURLGetTypeID() }