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 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Fixed warnings.

  • Loading branch information
zummenix committed Feb 18, 2015
commit e7eb60681cd6ecc7f23b744278fea5663c7a9672
@@ -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 {
@@ -12,7 +12,7 @@

#![allow(non_snake_case)]

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

extern crate libc;

@@ -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();
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.