From 48b341bb4b2375707c985cf209610f1345c59bc9 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 22 Aug 2015 22:40:20 -0700 Subject: [PATCH 01/19] Move core-foundation to a subdirectory --- Cargo.toml => core-foundation/Cargo.toml | 0 {src => core-foundation/src}/array.rs | 0 {src => core-foundation/src}/base.rs | 0 {src => core-foundation/src}/boolean.rs | 0 {src => core-foundation/src}/bundle.rs | 0 {src => core-foundation/src}/data.rs | 0 {src => core-foundation/src}/date.rs | 0 {src => core-foundation/src}/dictionary.rs | 0 {src => core-foundation/src}/lib.rs | 0 {src => core-foundation/src}/number.rs | 0 {src => core-foundation/src}/runloop.rs | 0 {src => core-foundation/src}/set.rs | 0 {src => core-foundation/src}/string.rs | 0 {src => core-foundation/src}/url.rs | 0 14 files changed, 0 insertions(+), 0 deletions(-) rename Cargo.toml => core-foundation/Cargo.toml (100%) rename {src => core-foundation/src}/array.rs (100%) rename {src => core-foundation/src}/base.rs (100%) rename {src => core-foundation/src}/boolean.rs (100%) rename {src => core-foundation/src}/bundle.rs (100%) rename {src => core-foundation/src}/data.rs (100%) rename {src => core-foundation/src}/date.rs (100%) rename {src => core-foundation/src}/dictionary.rs (100%) rename {src => core-foundation/src}/lib.rs (100%) rename {src => core-foundation/src}/number.rs (100%) rename {src => core-foundation/src}/runloop.rs (100%) rename {src => core-foundation/src}/set.rs (100%) rename {src => core-foundation/src}/string.rs (100%) rename {src => core-foundation/src}/url.rs (100%) diff --git a/Cargo.toml b/core-foundation/Cargo.toml similarity index 100% rename from Cargo.toml rename to core-foundation/Cargo.toml diff --git a/src/array.rs b/core-foundation/src/array.rs similarity index 100% rename from src/array.rs rename to core-foundation/src/array.rs diff --git a/src/base.rs b/core-foundation/src/base.rs similarity index 100% rename from src/base.rs rename to core-foundation/src/base.rs diff --git a/src/boolean.rs b/core-foundation/src/boolean.rs similarity index 100% rename from src/boolean.rs rename to core-foundation/src/boolean.rs diff --git a/src/bundle.rs b/core-foundation/src/bundle.rs similarity index 100% rename from src/bundle.rs rename to core-foundation/src/bundle.rs diff --git a/src/data.rs b/core-foundation/src/data.rs similarity index 100% rename from src/data.rs rename to core-foundation/src/data.rs diff --git a/src/date.rs b/core-foundation/src/date.rs similarity index 100% rename from src/date.rs rename to core-foundation/src/date.rs diff --git a/src/dictionary.rs b/core-foundation/src/dictionary.rs similarity index 100% rename from src/dictionary.rs rename to core-foundation/src/dictionary.rs diff --git a/src/lib.rs b/core-foundation/src/lib.rs similarity index 100% rename from src/lib.rs rename to core-foundation/src/lib.rs diff --git a/src/number.rs b/core-foundation/src/number.rs similarity index 100% rename from src/number.rs rename to core-foundation/src/number.rs diff --git a/src/runloop.rs b/core-foundation/src/runloop.rs similarity index 100% rename from src/runloop.rs rename to core-foundation/src/runloop.rs diff --git a/src/set.rs b/core-foundation/src/set.rs similarity index 100% rename from src/set.rs rename to core-foundation/src/set.rs diff --git a/src/string.rs b/core-foundation/src/string.rs similarity index 100% rename from src/string.rs rename to core-foundation/src/string.rs diff --git a/src/url.rs b/core-foundation/src/url.rs similarity index 100% rename from src/url.rs rename to core-foundation/src/url.rs From 93cd6c6639faa5c8739020a6d1618113324a5cef Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 22 Aug 2015 22:41:11 -0700 Subject: [PATCH 02/19] Restrict libc version --- core-foundation/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-foundation/Cargo.toml b/core-foundation/Cargo.toml index 9f07bae..e20a0b7 100644 --- a/core-foundation/Cargo.toml +++ b/core-foundation/Cargo.toml @@ -8,4 +8,4 @@ authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" [dependencies] -libc = "*" +libc = "0.1" From 3f725f97eb500aad7697b25e2ab2a40739428b36 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 24 Aug 2015 23:08:37 -0700 Subject: [PATCH 03/19] Start splitting out a separate sys package Moved array and base so far --- .gitignore | 4 +- core-foundation-sys/Cargo.toml | 13 +++++ core-foundation-sys/build.rs | 3 ++ core-foundation-sys/src/array.rs | 48 ++++++++++++++++++ core-foundation-sys/src/base.rs | 54 ++++++++++++++++++++ core-foundation-sys/src/lib.rs | 6 +++ core-foundation/Cargo.toml | 1 + core-foundation/src/array.rs | 56 ++------------------- core-foundation/src/base.rs | 84 +------------------------------ core-foundation/src/boolean.rs | 4 +- core-foundation/src/bundle.rs | 3 +- core-foundation/src/data.rs | 7 +-- core-foundation/src/dictionary.rs | 7 +-- core-foundation/src/lib.rs | 11 ++-- core-foundation/src/number.rs | 7 +-- core-foundation/src/runloop.rs | 16 +++--- core-foundation/src/set.rs | 6 ++- core-foundation/src/string.rs | 11 ++-- core-foundation/src/url.rs | 6 +-- 19 files changed, 175 insertions(+), 172 deletions(-) create mode 100644 core-foundation-sys/Cargo.toml create mode 100644 core-foundation-sys/build.rs create mode 100644 core-foundation-sys/src/array.rs create mode 100644 core-foundation-sys/src/base.rs create mode 100644 core-foundation-sys/src/lib.rs diff --git a/.gitignore b/.gitignore index 2a66ba7..be576c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -/Cargo.lock -/target +Cargo.lock +target/ diff --git a/core-foundation-sys/Cargo.toml b/core-foundation-sys/Cargo.toml new file mode 100644 index 0000000..523bd46 --- /dev/null +++ b/core-foundation-sys/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "core-foundation-sys" +description = "Bindings to Core Foundation for OS X" +homepage = "https://github.com/servo/core-foundation-rs" +repository = "https://github.com/servo/core-foundation-rs" +version = "0.1.0" +authors = ["The Servo Project Developers"] +license = "MIT / Apache-2.0" +build = "build.rs" +links = "CoreFoundation.framework" + +[dependencies] +libc = "0.1" diff --git a/core-foundation-sys/build.rs b/core-foundation-sys/build.rs new file mode 100644 index 0000000..94e6e93 --- /dev/null +++ b/core-foundation-sys/build.rs @@ -0,0 +1,3 @@ +fn main() { + println!("cargo:rustc-link-lib=framework=CoreFoundation"); +} diff --git a/core-foundation-sys/src/array.rs b/core-foundation-sys/src/array.rs new file mode 100644 index 0000000..0e982c6 --- /dev/null +++ b/core-foundation-sys/src/array.rs @@ -0,0 +1,48 @@ +use libc::c_void; + +use base::{CFIndex, CFAllocatorRef, CFTypeID}; + +/// FIXME(pcwalton): This is wrong. +pub type CFArrayRetainCallBack = *const u8; + +/// FIXME(pcwalton): This is wrong. +pub type CFArrayReleaseCallBack = *const u8; + +/// FIXME(pcwalton): This is wrong. +pub type CFArrayCopyDescriptionCallBack = *const u8; + +/// FIXME(pcwalton): This is wrong. +pub type CFArrayEqualCallBack = *const u8; + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct CFArrayCallBacks { + pub version: CFIndex, + pub retain: CFArrayRetainCallBack, + pub release: CFArrayReleaseCallBack, + pub copyDescription: CFArrayCopyDescriptionCallBack, + pub equal: CFArrayEqualCallBack, +} + +pub type CFArrayRef = *const c_void; + +extern { + /* + * CFArray.h + */ + pub static kCFTypeArrayCallBacks: CFArrayCallBacks; + + pub fn CFArrayCreate(allocator: CFAllocatorRef, values: *const *const c_void, + numValues: CFIndex, callBacks: *const CFArrayCallBacks) -> CFArrayRef; + // CFArrayCreateCopy + // CFArrayBSearchValues + // CFArrayContainsValue + pub fn CFArrayGetCount(theArray: CFArrayRef) -> CFIndex; + // CFArrayGetCountOfValue + // CFArrayGetFirstIndexOfValue + // CFArrayGetLastIndexOfValue + // CFArrayGetValues + pub fn CFArrayGetValueAtIndex(theArray: CFArrayRef, idx: CFIndex) -> *const c_void; + // CFArrayApplyFunction + pub fn CFArrayGetTypeID() -> CFTypeID; +} diff --git a/core-foundation-sys/src/base.rs b/core-foundation-sys/src/base.rs new file mode 100644 index 0000000..a9c06d0 --- /dev/null +++ b/core-foundation-sys/src/base.rs @@ -0,0 +1,54 @@ +use libc::{c_uint, c_long, c_ulong, c_void}; + +pub type Boolean = u8; +pub type CFIndex = c_long; +pub type mach_port_t = c_uint; +pub type CFAllocatorRef = *const c_void; +pub type CFNullRef = *const c_void; +pub type CFHashCode = c_ulong; +pub type CFTypeID = c_ulong; +pub type CFTypeRef = *const c_void; +pub type CFOptionFlags = u32; + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct CFRange { + pub location: CFIndex, + pub length: CFIndex +} + +extern { + /* + * CFBase.h + */ + + /* CFAllocator Reference */ + // N.B. Many CFAllocator functions and constants are omitted here. + pub static kCFAllocatorDefault: CFAllocatorRef; + pub static kCFAllocatorSystemDefault: CFAllocatorRef; + pub static kCFAllocatorMalloc: CFAllocatorRef; + pub static kCFAllocatorMallocZone: CFAllocatorRef; + pub static kCFAllocatorNull: CFAllocatorRef; + pub static kCFAllocatorUseContext: CFAllocatorRef; + + /* CFNull Reference */ + + pub static kCFNull: CFNullRef; + + /* CFType Reference */ + + //fn CFCopyDescription + //fn CFCopyTypeIDDescription + //fn CFEqual + //fn CFGetAllocator + pub fn CFGetRetainCount(cf: CFTypeRef) -> CFIndex; + pub fn CFGetTypeID(cf: CFTypeRef) -> CFTypeID; + pub fn CFHash(cf: CFTypeRef) -> CFHashCode; + //fn CFMakeCollectable + pub fn CFRelease(cf: CFTypeRef); + pub fn CFRetain(cf: CFTypeRef) -> CFTypeRef; + pub fn CFShow(obj: CFTypeRef); + + /* Base Utilities Reference */ + // N.B. Some things missing here. +} diff --git a/core-foundation-sys/src/lib.rs b/core-foundation-sys/src/lib.rs new file mode 100644 index 0000000..b4e8825 --- /dev/null +++ b/core-foundation-sys/src/lib.rs @@ -0,0 +1,6 @@ +#![allow(non_snake_case, non_camel_case_types)] + +extern crate libc; + +pub mod array; +pub mod base; diff --git a/core-foundation/Cargo.toml b/core-foundation/Cargo.toml index e20a0b7..122b69a 100644 --- a/core-foundation/Cargo.toml +++ b/core-foundation/Cargo.toml @@ -9,3 +9,4 @@ license = "MIT / Apache-2.0" [dependencies] libc = "0.1" +core-foundation-sys = { path = "../core-foundation-sys" } diff --git a/core-foundation/src/array.rs b/core-foundation/src/array.rs index 0a47a2c..b077552 100644 --- a/core-foundation/src/array.rs +++ b/core-foundation/src/array.rs @@ -9,39 +9,13 @@ //! Heterogeneous immutable arrays. -use base::{CFAllocatorRef, CFIndex, CFIndexConvertible, CFRelease}; -use base::{CFTypeID, CFTypeRef, TCFType}; -use base::{kCFAllocatorDefault}; +use core_foundation_sys::array::*; +use core_foundation_sys::base::{CFIndex, CFRelease}; +use core_foundation_sys::base::{CFTypeRef, kCFAllocatorDefault}; use libc::c_void; use std::mem; -/// FIXME(pcwalton): This is wrong. -pub type CFArrayRetainCallBack = *const u8; - -/// FIXME(pcwalton): This is wrong. -pub type CFArrayReleaseCallBack = *const u8; - -/// FIXME(pcwalton): This is wrong. -pub type CFArrayCopyDescriptionCallBack = *const u8; - -/// FIXME(pcwalton): This is wrong. -pub type CFArrayEqualCallBack = *const u8; - -#[allow(dead_code)] -#[repr(C)] -#[derive(Clone, Copy)] -pub struct CFArrayCallBacks { - version: CFIndex, - retain: CFArrayRetainCallBack, - release: CFArrayReleaseCallBack, - copyDescription: CFArrayCopyDescriptionCallBack, - equal: CFArrayEqualCallBack, -} - -#[repr(C)] -struct __CFArray; - -pub type CFArrayRef = *const __CFArray; +use base::{CFIndexConvertible, TCFType}; /// A heterogeneous immutable array. pub struct CFArray(CFArrayRef); @@ -126,28 +100,6 @@ impl<'a> IntoIterator for &'a CFArray { } } -#[link(name = "CoreFoundation", kind = "framework")] -extern { - /* - * CFArray.h - */ - static kCFTypeArrayCallBacks: CFArrayCallBacks; - - fn CFArrayCreate(allocator: CFAllocatorRef, values: *const *const c_void, - numValues: CFIndex, callBacks: *const CFArrayCallBacks) -> CFArrayRef; - // CFArrayCreateCopy - // CFArrayBSearchValues - // CFArrayContainsValue - fn CFArrayGetCount(theArray: CFArrayRef) -> CFIndex; - // CFArrayGetCountOfValue - // CFArrayGetFirstIndexOfValue - // CFArrayGetLastIndexOfValue - // CFArrayGetValues - fn CFArrayGetValueAtIndex(theArray: CFArrayRef, idx: CFIndex) -> *const c_void; - // CFArrayApplyFunction - fn CFArrayGetTypeID() -> CFTypeID; -} - #[test] fn should_box_and_unbox() { use number::{CFNumber, number}; diff --git a/core-foundation/src/base.rs b/core-foundation/src/base.rs index fb1dadf..60fa4e1 100644 --- a/core-foundation/src/base.rs +++ b/core-foundation/src/base.rs @@ -7,14 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use libc::{c_long, c_ulong, c_uint}; - -pub type Boolean = u8; - -pub type CFIndex = c_long; - -#[allow(non_camel_case_types)] -pub type mach_port_t = c_uint; +use core_foundation_sys::base::*; pub trait CFIndexConvertible { /// Always use this method to construct a `CFIndex` value. It performs bounds checking to @@ -33,44 +26,6 @@ impl CFIndexConvertible for usize { } } -pub type CFOptionFlags = u32; - -#[allow(dead_code)] -#[repr(C)] -#[derive(Clone, Copy)] -pub struct CFRange { - location: CFIndex, - length: CFIndex -} - -impl CFRange { - pub fn init(offset: CFIndex, length: CFIndex) -> CFRange { - CFRange { - location: offset, - length: length, - } - } -} - -#[repr(C)] -struct __CFAllocator; - -pub type CFAllocatorRef = *const __CFAllocator; - -#[repr(C)] -struct __CFNull; - -pub type CFNullRef = *const __CFNull; - -pub type CFHashCode = c_ulong; - -pub type CFTypeID = c_ulong; - -#[repr(C)] -struct __CFType; - -pub type CFTypeRef = *const __CFType; - /// Superclass of all Core Foundation objects. pub struct CFType(CFTypeRef); @@ -185,40 +140,3 @@ impl TCFType for CFType { true } } - -#[link(name = "CoreFoundation", kind = "framework")] -extern { - /* - * CFBase.h - */ - - /* CFAllocator Reference */ - // N.B. Many CFAllocator functions and constants are omitted here. - pub static kCFAllocatorDefault: CFAllocatorRef; - pub static kCFAllocatorSystemDefault: CFAllocatorRef; - pub static kCFAllocatorMalloc: CFAllocatorRef; - pub static kCFAllocatorMallocZone: CFAllocatorRef; - pub static kCFAllocatorNull: CFAllocatorRef; - pub static kCFAllocatorUseContext: CFAllocatorRef; - - /* CFNull Reference */ - - pub static kCFNull: CFNullRef; - - /* CFType Reference */ - - //fn CFCopyDescription - //fn CFCopyTypeIDDescription - //fn CFEqual - //fn CFGetAllocator - pub fn CFGetRetainCount(cf: CFTypeRef) -> CFIndex; - pub fn CFGetTypeID(cf: CFTypeRef) -> CFTypeID; - pub fn CFHash(cf: CFTypeRef) -> CFHashCode; - //fn CFMakeCollectable - pub fn CFRelease(cf: CFTypeRef); - pub fn CFRetain(cf: CFTypeRef) -> CFTypeRef; - pub fn CFShow(obj: CFTypeRef); - - /* Base Utilities Reference */ - // N.B. Some things missing here. -} diff --git a/core-foundation/src/boolean.rs b/core-foundation/src/boolean.rs index 9ededa8..06b2f57 100644 --- a/core-foundation/src/boolean.rs +++ b/core-foundation/src/boolean.rs @@ -9,9 +9,11 @@ //! A Boolean type. -use base::{CFRelease, CFTypeID, TCFType}; +use core_foundation_sys::base::{CFRelease, CFTypeID}; use std::mem; +use base::TCFType; + pub type Boolean = u32; #[repr(C)] diff --git a/core-foundation/src/bundle.rs b/core-foundation/src/bundle.rs index 76edb33..7645fa6 100644 --- a/core-foundation/src/bundle.rs +++ b/core-foundation/src/bundle.rs @@ -9,9 +9,10 @@ //! Core Foundation Bundle Type -use base::{CFRelease, CFTypeID, TCFType}; +use core_foundation_sys::base::{CFRelease, CFTypeID}; use std::mem; +use base::{TCFType}; use string::CFStringRef; use libc::c_void; diff --git a/core-foundation/src/data.rs b/core-foundation/src/data.rs index 9c8ace9..1b75677 100644 --- a/core-foundation/src/data.rs +++ b/core-foundation/src/data.rs @@ -9,13 +9,14 @@ //! Core Foundation byte buffers. -use base::{CFAllocatorRef, CFIndex, CFIndexConvertible, CFRelease}; -use base::{CFTypeID, TCFType, kCFAllocatorDefault}; - +use core_foundation_sys::base::{CFAllocatorRef, CFIndex, CFRelease}; +use core_foundation_sys::base::{CFTypeID, kCFAllocatorDefault}; use std::mem; use std::ops::Deref; use std::slice; +use base::{CFIndexConvertible, TCFType}; + #[repr(C)] struct __CFData; diff --git a/core-foundation/src/dictionary.rs b/core-foundation/src/dictionary.rs index e2fbd7c..5540d20 100644 --- a/core-foundation/src/dictionary.rs +++ b/core-foundation/src/dictionary.rs @@ -9,13 +9,14 @@ //! Dictionaries of key-value pairs. -use base::{Boolean, CFAllocatorRef, CFIndex, CFIndexConvertible, CFRelease}; -use base::{CFType, CFTypeID, CFTypeRef, TCFType, kCFAllocatorDefault}; - +use core_foundation_sys::base::{Boolean, CFAllocatorRef, CFIndex, CFRelease}; +use core_foundation_sys::base::{CFTypeID, CFTypeRef, kCFAllocatorDefault}; use libc::c_void; use std::mem; use std::ptr; +use base::{CFType, CFIndexConvertible, TCFType}; + pub type CFDictionaryApplierFunction = *const u8; pub type CFDictionaryCopyDescriptionCallBack = *const u8; pub type CFDictionaryEqualCallBack = *const u8; diff --git a/core-foundation/src/lib.rs b/core-foundation/src/lib.rs index 569a2e0..b8fb276 100644 --- a/core-foundation/src/lib.rs +++ b/core-foundation/src/lib.rs @@ -6,12 +6,9 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. - -#![crate_name = "core_foundation"] -#![crate_type = "rlib"] - #![allow(non_snake_case)] +extern crate core_foundation_sys; extern crate libc; #[macro_export] @@ -25,12 +22,12 @@ macro_rules! impl_TCFType { #[inline] unsafe fn wrap_under_get_rule(reference: $raw) -> $ty { - let reference = mem::transmute($crate::base::CFRetain(mem::transmute(reference))); + let reference = mem::transmute(::core_foundation_sys::base::CFRetain(mem::transmute(reference))); $crate::base::TCFType::wrap_under_create_rule(reference) } #[inline] - fn as_CFTypeRef(&self) -> $crate::base::CFTypeRef { + fn as_CFTypeRef(&self) -> ::core_foundation_sys::base::CFTypeRef { unsafe { mem::transmute(self.as_concrete_TypeRef()) } @@ -42,7 +39,7 @@ macro_rules! impl_TCFType { } #[inline] - fn type_id() -> $crate::base::CFTypeID { + fn type_id() -> ::core_foundation_sys::base::CFTypeID { unsafe { $ty_id() } diff --git a/core-foundation/src/number.rs b/core-foundation/src/number.rs index 198dbad..0309bc8 100644 --- a/core-foundation/src/number.rs +++ b/core-foundation/src/number.rs @@ -11,12 +11,13 @@ #![allow(non_upper_case_globals)] -use base::{CFAllocatorRef, CFRelease, CFTypeID}; -use base::{TCFType, kCFAllocatorDefault}; - +use core_foundation_sys::base::{CFAllocatorRef, CFRelease, CFTypeID}; +use core_foundation_sys::base::{kCFAllocatorDefault}; use libc::c_void; use std::mem; +use base::{TCFType}; + pub type CFNumberType = u32; // members of enum CFNumberType diff --git a/core-foundation/src/runloop.rs b/core-foundation/src/runloop.rs index b0782a2..ee71bef 100644 --- a/core-foundation/src/runloop.rs +++ b/core-foundation/src/runloop.rs @@ -9,16 +9,18 @@ #![allow(non_upper_case_globals)] -use base::{CFAllocatorRef, CFIndex, CFOptionFlags, CFRelease}; -use base::{CFTypeID, TCFType, CFHashCode, mach_port_t}; -use base::{kCFAllocatorDefault}; -use base::{Boolean}; -use array::{CFArrayRef}; -use string::{CFString, CFStringRef}; -use date::{CFAbsoluteTime, CFTimeInterval}; + +use core_foundation_sys::base::{CFAllocatorRef, CFIndex, CFRelease}; +use core_foundation_sys::base::{CFTypeID, CFHashCode, mach_port_t}; +use core_foundation_sys::base::{kCFAllocatorDefault, Boolean, CFOptionFlags}; +use core_foundation_sys::array::{CFArrayRef}; use libc::c_void; use std::mem; +use base::{TCFType}; +use string::{CFString, CFStringRef}; +use date::{CFAbsoluteTime, CFTimeInterval}; + pub struct CFRunLoop(CFRunLoopRef); impl Drop for CFRunLoop { diff --git a/core-foundation/src/set.rs b/core-foundation/src/set.rs index b5e26b8..680007f 100644 --- a/core-foundation/src/set.rs +++ b/core-foundation/src/set.rs @@ -9,8 +9,10 @@ //! An immutable bag of elements. -use base::{CFAllocatorRef, CFIndex, CFIndexConvertible, CFRelease}; -use base::{CFTypeID, CFTypeRef, TCFType, kCFAllocatorDefault}; +use core_foundation_sys::base::{CFAllocatorRef, CFIndex, CFRelease}; +use core_foundation_sys::base::{CFTypeID, CFTypeRef, kCFAllocatorDefault}; + +use base::{CFIndexConvertible, TCFType}; use libc::c_void; use std::mem; diff --git a/core-foundation/src/string.rs b/core-foundation/src/string.rs index 99bb397..e502074 100644 --- a/core-foundation/src/string.rs +++ b/core-foundation/src/string.rs @@ -11,10 +11,11 @@ #![allow(non_upper_case_globals)] -use base::{Boolean, CFAllocatorRef, CFIndex, CFIndexConvertible, CFOptionFlags, CFRange}; -use base::{CFRelease, CFTypeID, TCFType}; -use base::{kCFAllocatorDefault, kCFAllocatorNull}; +use base::{CFIndexConvertible, TCFType}; +use core_foundation_sys::base::{Boolean, CFAllocatorRef, CFIndex, CFRange}; +use core_foundation_sys::base::{CFRelease, CFTypeID}; +use core_foundation_sys::base::{kCFAllocatorDefault, kCFAllocatorNull, CFOptionFlags}; use libc; use std::ffi::CStr; use std::fmt; @@ -250,7 +251,7 @@ impl fmt::Display for CFString { // First, ask how big the buffer ought to be. let mut bytes_required: CFIndex = 0; CFStringGetBytes(self.0, - CFRange::init(0, char_len), + CFRange { location: 0, length: char_len }, kCFStringEncodingUTF8, 0, false as Boolean, @@ -264,7 +265,7 @@ impl fmt::Display for CFString { let mut bytes_used: CFIndex = 0; let chars_written = CFStringGetBytes(self.0, - CFRange::init(0, char_len), + CFRange { location: 0, length: char_len }, kCFStringEncodingUTF8, 0, false as Boolean, diff --git a/core-foundation/src/url.rs b/core-foundation/src/url.rs index c6c5708..95b5612 100644 --- a/core-foundation/src/url.rs +++ b/core-foundation/src/url.rs @@ -11,11 +11,11 @@ #![allow(non_upper_case_globals)] -use base::{CFAllocatorRef, CFIndex, CFOptionFlags, CFRelease}; -use base::{Boolean, CFTypeID, TCFType}; -use base::{kCFAllocatorDefault}; +use base::{TCFType}; use string::{CFString, CFStringRef}; +use core_foundation_sys::base::{CFAllocatorRef, CFIndex, CFRelease, CFOptionFlags}; +use core_foundation_sys::base::{Boolean, CFTypeID, kCFAllocatorDefault}; use std::fmt; use std::mem; From 6ffe3ea04f05fb5179d2a6b31929207badf277e4 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 24 Aug 2015 23:14:07 -0700 Subject: [PATCH 04/19] Port boolean to sys crate --- core-foundation-sys/src/lib.rs | 1 + core-foundation-sys/src/number.rs | 12 ++++++++++++ core-foundation/src/boolean.rs | 19 ++----------------- 3 files changed, 15 insertions(+), 17 deletions(-) create mode 100644 core-foundation-sys/src/number.rs diff --git a/core-foundation-sys/src/lib.rs b/core-foundation-sys/src/lib.rs index b4e8825..a00e8bb 100644 --- a/core-foundation-sys/src/lib.rs +++ b/core-foundation-sys/src/lib.rs @@ -4,3 +4,4 @@ extern crate libc; pub mod array; pub mod base; +pub mod number; diff --git a/core-foundation-sys/src/number.rs b/core-foundation-sys/src/number.rs new file mode 100644 index 0000000..99b9c49 --- /dev/null +++ b/core-foundation-sys/src/number.rs @@ -0,0 +1,12 @@ +use libc::c_void; + +use base::CFTypeID; + +pub type CFBooleanRef = *const c_void; + +extern { + pub static kCFBooleanTrue: CFBooleanRef; + pub static kCFBooleanFalse: CFBooleanRef; + + pub fn CFBooleanGetTypeID() -> CFTypeID; +} diff --git a/core-foundation/src/boolean.rs b/core-foundation/src/boolean.rs index 06b2f57..b8d4288 100644 --- a/core-foundation/src/boolean.rs +++ b/core-foundation/src/boolean.rs @@ -9,18 +9,12 @@ //! A Boolean type. -use core_foundation_sys::base::{CFRelease, CFTypeID}; +use core_foundation_sys::base::{CFRelease}; +use core_foundation_sys::number::{CFBooleanRef, CFBooleanGetTypeID, kCFBooleanTrue, kCFBooleanFalse}; use std::mem; use base::TCFType; -pub type Boolean = u32; - -#[repr(C)] -struct __CFBoolean; - -pub type CFBooleanRef = *const __CFBoolean; - /// A Boolean type. /// /// FIXME(pcwalton): Should be a newtype struct, but that fails due to a Rust compiler bug. @@ -49,12 +43,3 @@ impl CFBoolean { } } } - -#[link(name = "CoreFoundation", kind = "framework")] -extern { - static kCFBooleanTrue: CFBooleanRef; - static kCFBooleanFalse: CFBooleanRef; - - fn CFBooleanGetTypeID() -> CFTypeID; -} - From 4e6b1006e1922d53d3af8913cccf1e043a43bb71 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 24 Aug 2015 23:31:01 -0700 Subject: [PATCH 05/19] Port bundle and string to sys crate --- core-foundation-sys/src/bundle.rs | 16 ++ core-foundation-sys/src/lib.rs | 4 +- core-foundation-sys/src/string.rs | 301 +++++++++++++++++++++++++++++ core-foundation/src/bundle.rs | 24 +-- core-foundation/src/runloop.rs | 3 +- core-foundation/src/string.rs | 311 +----------------------------- core-foundation/src/url.rs | 3 +- 7 files changed, 330 insertions(+), 332 deletions(-) create mode 100644 core-foundation-sys/src/bundle.rs create mode 100644 core-foundation-sys/src/string.rs diff --git a/core-foundation-sys/src/bundle.rs b/core-foundation-sys/src/bundle.rs new file mode 100644 index 0000000..6df6723 --- /dev/null +++ b/core-foundation-sys/src/bundle.rs @@ -0,0 +1,16 @@ +use libc::c_void; + +use base::CFTypeID; +use string::CFStringRef; + +pub type CFBundleRef = *const c_void; + +extern { + /* + * CFBundle.h + */ + pub fn CFBundleGetBundleWithIdentifier(bundleID: CFStringRef) -> CFBundleRef; + pub fn CFBundleGetFunctionPointerForName(bundle: CFBundleRef, function_name: CFStringRef) -> *const c_void; + + pub fn CFBundleGetTypeID() -> CFTypeID; +} diff --git a/core-foundation-sys/src/lib.rs b/core-foundation-sys/src/lib.rs index a00e8bb..827d9b9 100644 --- a/core-foundation-sys/src/lib.rs +++ b/core-foundation-sys/src/lib.rs @@ -1,7 +1,9 @@ -#![allow(non_snake_case, non_camel_case_types)] +#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] extern crate libc; pub mod array; pub mod base; +pub mod bundle; pub mod number; +pub mod string; diff --git a/core-foundation-sys/src/string.rs b/core-foundation-sys/src/string.rs new file mode 100644 index 0000000..35975d0 --- /dev/null +++ b/core-foundation-sys/src/string.rs @@ -0,0 +1,301 @@ +use libc::{c_char, c_void, c_ushort}; + +use base::{Boolean, CFOptionFlags, CFIndex, CFAllocatorRef, CFRange, CFTypeID}; + +pub type UniChar = c_ushort; + +// CFString.h + +pub type CFStringCompareFlags = CFOptionFlags; +//static kCFCompareCaseInsensitive: CFStringCompareFlags = 1; +//static kCFCompareBackwards: CFStringCompareFlags = 4; +//static kCFCompareAnchored: CFStringCompareFlags = 8; +//static kCFCompareNonliteral: CFStringCompareFlags = 16; +//static kCFCompareLocalized: CFStringCompareFlags = 32; +//static kCFCompareNumerically: CFStringCompareFlags = 64; +//static kCFCompareDiacriticInsensitive: CFStringCompareFlags = 128; +//static kCFCompareWidthInsensitive: CFStringCompareFlags = 256; +//static kCFCompareForcedOrdering: CFStringCompareFlags = 512; + +pub type CFStringEncoding = u32; + +// OS X built-in encodings. + +//static kCFStringEncodingMacRoman: CFStringEncoding = 0; +//static kCFStringEncodingWindowsLatin1: CFStringEncoding = 0x0500; +//static kCFStringEncodingISOLatin1: CFStringEncoding = 0x0201; +//static kCFStringEncodingNextStepLatin: CFStringEncoding = 0x0B01; +//static kCFStringEncodingASCII: CFStringEncoding = 0x0600; +//static kCFStringEncodingUnicode: CFStringEncoding = 0x0100; +pub static kCFStringEncodingUTF8: CFStringEncoding = 0x08000100; +//static kCFStringEncodingNonLossyASCII: CFStringEncoding = 0x0BFF; + +//static kCFStringEncodingUTF16: CFStringEncoding = 0x0100; +//static kCFStringEncodingUTF16BE: CFStringEncoding = 0x10000100; +//static kCFStringEncodingUTF16LE: CFStringEncoding = 0x14000100; +//static kCFStringEncodingUTF32: CFStringEncoding = 0x0c000100; +//static kCFStringEncodingUTF32BE: CFStringEncoding = 0x18000100; +//static kCFStringEncodingUTF32LE: CFStringEncoding = 0x1c000100; + + +// CFStringEncodingExt.h + +type CFStringEncodings = CFIndex; + +// External encodings, except those defined above. +// Defined above: kCFStringEncodingMacRoman = 0 +//static kCFStringEncodingMacJapanese: CFStringEncoding = 1; +//static kCFStringEncodingMacChineseTrad: CFStringEncoding = 2; +//static kCFStringEncodingMacKorean: CFStringEncoding = 3; +//static kCFStringEncodingMacArabic: CFStringEncoding = 4; +//static kCFStringEncodingMacHebrew: CFStringEncoding = 5; +//static kCFStringEncodingMacGreek: CFStringEncoding = 6; +//static kCFStringEncodingMacCyrillic: CFStringEncoding = 7; +//static kCFStringEncodingMacDevanagari: CFStringEncoding = 9; +//static kCFStringEncodingMacGurmukhi: CFStringEncoding = 10; +//static kCFStringEncodingMacGujarati: CFStringEncoding = 11; +//static kCFStringEncodingMacOriya: CFStringEncoding = 12; +//static kCFStringEncodingMacBengali: CFStringEncoding = 13; +//static kCFStringEncodingMacTamil: CFStringEncoding = 14; +//static kCFStringEncodingMacTelugu: CFStringEncoding = 15; +//static kCFStringEncodingMacKannada: CFStringEncoding = 16; +//static kCFStringEncodingMacMalayalam: CFStringEncoding = 17; +//static kCFStringEncodingMacSinhalese: CFStringEncoding = 18; +//static kCFStringEncodingMacBurmese: CFStringEncoding = 19; +//static kCFStringEncodingMacKhmer: CFStringEncoding = 20; +//static kCFStringEncodingMacThai: CFStringEncoding = 21; +//static kCFStringEncodingMacLaotian: CFStringEncoding = 22; +//static kCFStringEncodingMacGeorgian: CFStringEncoding = 23; +//static kCFStringEncodingMacArmenian: CFStringEncoding = 24; +//static kCFStringEncodingMacChineseSimp: CFStringEncoding = 25; +//static kCFStringEncodingMacTibetan: CFStringEncoding = 26; +//static kCFStringEncodingMacMongolian: CFStringEncoding = 27; +//static kCFStringEncodingMacEthiopic: CFStringEncoding = 28; +//static kCFStringEncodingMacCentralEurRoman: CFStringEncoding = 29; +//static kCFStringEncodingMacVietnamese: CFStringEncoding = 30; +//static kCFStringEncodingMacExtArabic: CFStringEncoding = 31; +//static kCFStringEncodingMacSymbol: CFStringEncoding = 33; +//static kCFStringEncodingMacDingbats: CFStringEncoding = 34; +//static kCFStringEncodingMacTurkish: CFStringEncoding = 35; +//static kCFStringEncodingMacCroatian: CFStringEncoding = 36; +//static kCFStringEncodingMacIcelandic: CFStringEncoding = 37; +//static kCFStringEncodingMacRomanian: CFStringEncoding = 38; +//static kCFStringEncodingMacCeltic: CFStringEncoding = 39; +//static kCFStringEncodingMacGaelic: CFStringEncoding = 40; +//static kCFStringEncodingMacFarsi: CFStringEncoding = 0x8C; +//static kCFStringEncodingMacUkrainian: CFStringEncoding = 0x98; +//static kCFStringEncodingMacInuit: CFStringEncoding = 0xEC; +//static kCFStringEncodingMacVT100: CFStringEncoding = 0xFC; +//static kCFStringEncodingMacHFS: CFStringEncoding = 0xFF; +// Defined above: kCFStringEncodingISOLatin1 = 0x0201 +//static kCFStringEncodingISOLatin2: CFStringEncoding = 0x0202; +//static kCFStringEncodingISOLatin3: CFStringEncoding = 0x0203; +//static kCFStringEncodingISOLatin4: CFStringEncoding = 0x0204; +//static kCFStringEncodingISOLatinCyrillic: CFStringEncoding = 0x0205; +//static kCFStringEncodingISOLatinArabic: CFStringEncoding = 0x0206; +//static kCFStringEncodingISOLatinGreek: CFStringEncoding = 0x0207; +//static kCFStringEncodingISOLatinHebrew: CFStringEncoding = 0x0208; +//static kCFStringEncodingISOLatin5: CFStringEncoding = 0x0209; +//static kCFStringEncodingISOLatin6: CFStringEncoding = 0x020A; +//static kCFStringEncodingISOLatinThai: CFStringEncoding = 0x020B; +//static kCFStringEncodingISOLatin7: CFStringEncoding = 0x020D; +//static kCFStringEncodingISOLatin8: CFStringEncoding = 0x020E; +//static kCFStringEncodingISOLatin9: CFStringEncoding = 0x020F; +//static kCFStringEncodingISOLatin10: CFStringEncoding = 0x0210; +//static kCFStringEncodingDOSLatinUS: CFStringEncoding = 0x0400; +//static kCFStringEncodingDOSGreek: CFStringEncoding = 0x0405; +//static kCFStringEncodingDOSBalticRim: CFStringEncoding = 0x0406; +//static kCFStringEncodingDOSLatin1: CFStringEncoding = 0x0410; +//static kCFStringEncodingDOSGreek1: CFStringEncoding = 0x0411; +//static kCFStringEncodingDOSLatin2: CFStringEncoding = 0x0412; +//static kCFStringEncodingDOSCyrillic: CFStringEncoding = 0x0413; +//static kCFStringEncodingDOSTurkish: CFStringEncoding = 0x0414; +//static kCFStringEncodingDOSPortuguese: CFStringEncoding = 0x0415; +//static kCFStringEncodingDOSIcelandic: CFStringEncoding = 0x0416; +//static kCFStringEncodingDOSHebrew: CFStringEncoding = 0x0417; +//static kCFStringEncodingDOSCanadianFrench: CFStringEncoding = 0x0418; +//static kCFStringEncodingDOSArabic: CFStringEncoding = 0x0419; +//static kCFStringEncodingDOSNordic: CFStringEncoding = 0x041A; +//static kCFStringEncodingDOSRussian: CFStringEncoding = 0x041B; +//static kCFStringEncodingDOSGreek2: CFStringEncoding = 0x041C; +//static kCFStringEncodingDOSThai: CFStringEncoding = 0x041D; +//static kCFStringEncodingDOSJapanese: CFStringEncoding = 0x0420; +//static kCFStringEncodingDOSChineseSimplif: CFStringEncoding = 0x0421; +//static kCFStringEncodingDOSKorean: CFStringEncoding = 0x0422; +//static kCFStringEncodingDOSChineseTrad: CFStringEncoding = 0x0423; +// Defined above: kCFStringEncodingWindowsLatin1 = 0x0500 +//static kCFStringEncodingWindowsLatin2: CFStringEncoding = 0x0501; +//static kCFStringEncodingWindowsCyrillic: CFStringEncoding = 0x0502; +//static kCFStringEncodingWindowsGreek: CFStringEncoding = 0x0503; +//static kCFStringEncodingWindowsLatin5: CFStringEncoding = 0x0504; +//static kCFStringEncodingWindowsHebrew: CFStringEncoding = 0x0505; +//static kCFStringEncodingWindowsArabic: CFStringEncoding = 0x0506; +//static kCFStringEncodingWindowsBalticRim: CFStringEncoding = 0x0507; +//static kCFStringEncodingWindowsVietnamese: CFStringEncoding = 0x0508; +//static kCFStringEncodingWindowsKoreanJohab: CFStringEncoding = 0x0510; +// Defined above: kCFStringEncodingASCII = 0x0600 +//static kCFStringEncodingANSEL: CFStringEncoding = 0x0601; +//static kCFStringEncodingJIS_X0201_76: CFStringEncoding = 0x0620; +//static kCFStringEncodingJIS_X0208_83: CFStringEncoding = 0x0621; +//static kCFStringEncodingJIS_X0208_90: CFStringEncoding = 0x0622; +//static kCFStringEncodingJIS_X0212_90: CFStringEncoding = 0x0623; +//static kCFStringEncodingJIS_C6226_78: CFStringEncoding = 0x0624; +//static kCFStringEncodingShiftJIS_X0213: CFStringEncoding = 0x0628; +//static kCFStringEncodingShiftJIS_X0213_MenKuTen: CFStringEncoding = 0x0629; +//static kCFStringEncodingGB_2312_80: CFStringEncoding = 0x0630; +//static kCFStringEncodingGBK_95: CFStringEncoding = 0x0631; +//static kCFStringEncodingGB_18030_2000: CFStringEncoding = 0x0632; +//static kCFStringEncodingKSC_5601_87: CFStringEncoding = 0x0640; +//static kCFStringEncodingKSC_5601_92_Johab: CFStringEncoding = 0x0641; +//static kCFStringEncodingCNS_11643_92_P1: CFStringEncoding = 0x0651; +//static kCFStringEncodingCNS_11643_92_P2: CFStringEncoding = 0x0652; +//static kCFStringEncodingCNS_11643_92_P3: CFStringEncoding = 0x0653; +//static kCFStringEncodingISO_2022_JP: CFStringEncoding = 0x0820; +//static kCFStringEncodingISO_2022_JP_2: CFStringEncoding = 0x0821; +//static kCFStringEncodingISO_2022_JP_1: CFStringEncoding = 0x0822; +//static kCFStringEncodingISO_2022_JP_3: CFStringEncoding = 0x0823; +//static kCFStringEncodingISO_2022_CN: CFStringEncoding = 0x0830; +//static kCFStringEncodingISO_2022_CN_EXT: CFStringEncoding = 0x0831; +//static kCFStringEncodingISO_2022_KR: CFStringEncoding = 0x0840; +//static kCFStringEncodingEUC_JP: CFStringEncoding = 0x0920; +//static kCFStringEncodingEUC_CN: CFStringEncoding = 0x0930; +//static kCFStringEncodingEUC_TW: CFStringEncoding = 0x0931; +//static kCFStringEncodingEUC_KR: CFStringEncoding = 0x0940; +//static kCFStringEncodingShiftJIS: CFStringEncoding = 0x0A01; +//static kCFStringEncodingKOI8_R: CFStringEncoding = 0x0A02; +//static kCFStringEncodingBig5: CFStringEncoding = 0x0A03; +//static kCFStringEncodingMacRomanLatin1: CFStringEncoding = 0x0A04; +//static kCFStringEncodingHZ_GB_2312: CFStringEncoding = 0x0A05; +//static kCFStringEncodingBig5_HKSCS_1999: CFStringEncoding = 0x0A06; +//static kCFStringEncodingVISCII: CFStringEncoding = 0x0A07; +//static kCFStringEncodingKOI8_U: CFStringEncoding = 0x0A08; +//static kCFStringEncodingBig5_E: CFStringEncoding = 0x0A09; +// Defined above: kCFStringEncodingNextStepLatin = 0x0B01 +//static kCFStringEncodingNextStepJapanese: CFStringEncoding = 0x0B02; +//static kCFStringEncodingEBCDIC_US: CFStringEncoding = 0x0C01; +//static kCFStringEncodingEBCDIC_CP037: CFStringEncoding = 0x0C02; +//static kCFStringEncodingUTF7: CFStringEncoding = 0x04000100; +//static kCFStringEncodingUTF7_IMAP: CFStringEncoding = 0x0A10; +//static kCFStringEncodingShiftJIS_X0213_00: CFStringEncoding = 0x0628; /* Deprecated */ + +pub type CFStringRef = *const c_void; + +extern { + /* + * CFString.h + */ + + // N.B. organized according to "Functions by task" in docs + + /* Creating a CFString */ + //fn CFSTR + //fn CFStringCreateArrayBySeparatingStrings + //fn CFStringCreateByCombiningStrings + //fn CFStringCreateCopy + //fn CFStringCreateFromExternalRepresentation + pub fn CFStringCreateWithBytes(alloc: CFAllocatorRef, + bytes: *const u8, + numBytes: CFIndex, + encoding: CFStringEncoding, + isExternalRepresentation: Boolean, + contentsDeallocator: CFAllocatorRef) + -> CFStringRef; + pub fn CFStringCreateWithBytesNoCopy(alloc: CFAllocatorRef, + bytes: *const u8, + numBytes: CFIndex, + encoding: CFStringEncoding, + isExternalRepresentation: Boolean, + contentsDeallocator: CFAllocatorRef) + -> CFStringRef; + //fn CFStringCreateWithCharacters + //fn CFStringCreateWithCharactersNoCopy + //fn CFStringCreateWithCString + //fn CFStringCreateWithCStringNoCopy + //fn CFStringCreateWithFormat + //fn CFStringCreateWithFormatAndArguments + //fn CFStringCreateWithPascalString + //fn CFStringCreateWithPascalStringNoCopy + //fn CFStringCreateWithSubstring + + /* Searching Strings */ + //fn CFStringCreateArrayWithFindResults + //fn CFStringFind + //fn CFStringFindCharacterFromSet + //fn CFStringFindWithOptions + //fn CFStringFindWithOptionsAndLocale + //fn CFStringGetLineBounds + + /* Comparing Strings */ + //fn CFStringCompare + //fn CFStringCompareWithOptions + //fn CFStringCompareWithOptionsAndLocale + //fn CFStringHasPrefix + //fn CFStringHasSuffix + + /* Accessing Characters */ + //fn CFStringCreateExternalRepresentation + pub fn CFStringGetBytes(theString: CFStringRef, + range: CFRange, + encoding: CFStringEncoding, + lossByte: u8, + isExternalRepresentation: Boolean, + buffer: *mut u8, + maxBufLen: CFIndex, + usedBufLen: *mut CFIndex) + -> CFIndex; + //fn CFStringGetCharacterAtIndex + //fn CFStringGetCharacters + //fn CFStringGetCharactersPtr + //fn CFStringGetCharacterFromInlineBuffer + //fn CFStringGetCString + pub fn CFStringGetCStringPtr(theString: CFStringRef, + encoding: CFStringEncoding) + -> *const c_char; + pub fn CFStringGetLength(theString: CFStringRef) -> CFIndex; + //fn CFStringGetPascalString + //fn CFStringGetPascalStringPtr + //fn CFStringGetRangeOfComposedCharactersAtIndex + //fn CFStringInitInlineBuffer + + /* Working With Hyphenation */ + //fn CFStringGetHyphenationLocationBeforeIndex + //fn CFStringIsHyphenationAvailableForLocale + + /* Working With Encodings */ + //fn CFStringConvertEncodingToIANACharSetName + //fn CFStringConvertEncodingToNSStringEncoding + //fn CFStringConvertEncodingToWindowsCodepage + //fn CFStringConvertIANACharSetNameToEncoding + //fn CFStringConvertNSStringEncodingToEncoding + //fn CFStringConvertWindowsCodepageToEncoding + //fn CFStringGetFastestEncoding + //fn CFStringGetListOfAvailableEncodings + //fn CFStringGetMaximumSizeForEncoding + //fn CFStringGetMostCompatibleMacStringEncoding + //fn CFStringGetNameOfEncoding + //fn CFStringGetSmallestEncoding + //fn CFStringGetSystemEncoding + //fn CFStringIsEncodingAvailable + + /* Getting Numeric Values */ + //fn CFStringGetDoubleValue + //fn CFStringGetIntValue + + /* Getting String Properties */ + //fn CFShowStr + pub fn CFStringGetTypeID() -> CFTypeID; + + /* String File System Representations */ + //fn CFStringCreateWithFileSystemRepresentation + //fn CFStringGetFileSystemRepresentation + //fn CFStringGetMaximumSizeOfFileSystemRepresentation + + /* Getting Paragraph Bounds */ + //fn CFStringGetParagraphBounds + + /* Managing Surrogates */ + //fn CFStringGetLongCharacterForSurrogatePair + //fn CFStringGetSurrogatePairForLongCharacter + //fn CFStringIsSurrogateHighCharacter + //fn CFStringIsSurrogateLowCharacter +} diff --git a/core-foundation/src/bundle.rs b/core-foundation/src/bundle.rs index 7645fa6..7a25c77 100644 --- a/core-foundation/src/bundle.rs +++ b/core-foundation/src/bundle.rs @@ -9,17 +9,11 @@ //! Core Foundation Bundle Type -use core_foundation_sys::base::{CFRelease, CFTypeID}; +use core_foundation_sys::base::CFRelease; +use core_foundation_sys::bundle::{CFBundleRef, CFBundleGetTypeID}; use std::mem; use base::{TCFType}; -use string::CFStringRef; -use libc::c_void; - -#[repr(C)] -struct __CFBundle; - -pub type CFBundleRef = *const __CFBundle; /// A Bundle type. pub struct CFBundle(CFBundleRef); @@ -33,17 +27,3 @@ impl Drop for CFBundle { } impl_TCFType!(CFBundle, CFBundleRef, CFBundleGetTypeID); - -#[link(name = "CoreFoundation", kind = "framework")] -extern { - /* - * CFBundle.h - */ - - - pub fn CFBundleGetBundleWithIdentifier(bundleID: CFStringRef) -> CFBundleRef; - pub fn CFBundleGetFunctionPointerForName(bundle: CFBundleRef, function_name: CFStringRef) -> *const c_void; - - fn CFBundleGetTypeID() -> CFTypeID; -} - diff --git a/core-foundation/src/runloop.rs b/core-foundation/src/runloop.rs index ee71bef..1637562 100644 --- a/core-foundation/src/runloop.rs +++ b/core-foundation/src/runloop.rs @@ -14,11 +14,12 @@ use core_foundation_sys::base::{CFAllocatorRef, CFIndex, CFRelease}; use core_foundation_sys::base::{CFTypeID, CFHashCode, mach_port_t}; use core_foundation_sys::base::{kCFAllocatorDefault, Boolean, CFOptionFlags}; use core_foundation_sys::array::{CFArrayRef}; +use core_foundation_sys::string::CFStringRef; use libc::c_void; use std::mem; use base::{TCFType}; -use string::{CFString, CFStringRef}; +use string::{CFString}; use date::{CFAbsoluteTime, CFTimeInterval}; pub struct CFRunLoop(CFRunLoopRef); diff --git a/core-foundation/src/string.rs b/core-foundation/src/string.rs index e502074..10ad735 100644 --- a/core-foundation/src/string.rs +++ b/core-foundation/src/string.rs @@ -13,197 +13,15 @@ use base::{CFIndexConvertible, TCFType}; -use core_foundation_sys::base::{Boolean, CFAllocatorRef, CFIndex, CFRange}; -use core_foundation_sys::base::{CFRelease, CFTypeID}; -use core_foundation_sys::base::{kCFAllocatorDefault, kCFAllocatorNull, CFOptionFlags}; -use libc; -use std::ffi::CStr; +use core_foundation_sys::base::{Boolean, CFIndex, CFRange, CFRelease}; +use core_foundation_sys::base::{kCFAllocatorDefault, kCFAllocatorNull}; +use core_foundation_sys::string::*; use std::fmt; use std::str::{self, FromStr}; use std::mem; use std::ptr; use std::vec::Vec; - -pub type UniChar = libc::c_ushort; - -// CFString.h - -pub type CFStringCompareFlags = CFOptionFlags; -//static kCFCompareCaseInsensitive: CFStringCompareFlags = 1; -//static kCFCompareBackwards: CFStringCompareFlags = 4; -//static kCFCompareAnchored: CFStringCompareFlags = 8; -//static kCFCompareNonliteral: CFStringCompareFlags = 16; -//static kCFCompareLocalized: CFStringCompareFlags = 32; -//static kCFCompareNumerically: CFStringCompareFlags = 64; -//static kCFCompareDiacriticInsensitive: CFStringCompareFlags = 128; -//static kCFCompareWidthInsensitive: CFStringCompareFlags = 256; -//static kCFCompareForcedOrdering: CFStringCompareFlags = 512; - -pub type CFStringEncoding = u32; - -// OS X built-in encodings. - -//static kCFStringEncodingMacRoman: CFStringEncoding = 0; -//static kCFStringEncodingWindowsLatin1: CFStringEncoding = 0x0500; -//static kCFStringEncodingISOLatin1: CFStringEncoding = 0x0201; -//static kCFStringEncodingNextStepLatin: CFStringEncoding = 0x0B01; -//static kCFStringEncodingASCII: CFStringEncoding = 0x0600; -//static kCFStringEncodingUnicode: CFStringEncoding = 0x0100; -static kCFStringEncodingUTF8: CFStringEncoding = 0x08000100; -//static kCFStringEncodingNonLossyASCII: CFStringEncoding = 0x0BFF; - -//static kCFStringEncodingUTF16: CFStringEncoding = 0x0100; -//static kCFStringEncodingUTF16BE: CFStringEncoding = 0x10000100; -//static kCFStringEncodingUTF16LE: CFStringEncoding = 0x14000100; -//static kCFStringEncodingUTF32: CFStringEncoding = 0x0c000100; -//static kCFStringEncodingUTF32BE: CFStringEncoding = 0x18000100; -//static kCFStringEncodingUTF32LE: CFStringEncoding = 0x1c000100; - - -// CFStringEncodingExt.h - -type CFStringEncodings = CFIndex; - -// External encodings, except those defined above. -// Defined above: kCFStringEncodingMacRoman = 0 -//static kCFStringEncodingMacJapanese: CFStringEncoding = 1; -//static kCFStringEncodingMacChineseTrad: CFStringEncoding = 2; -//static kCFStringEncodingMacKorean: CFStringEncoding = 3; -//static kCFStringEncodingMacArabic: CFStringEncoding = 4; -//static kCFStringEncodingMacHebrew: CFStringEncoding = 5; -//static kCFStringEncodingMacGreek: CFStringEncoding = 6; -//static kCFStringEncodingMacCyrillic: CFStringEncoding = 7; -//static kCFStringEncodingMacDevanagari: CFStringEncoding = 9; -//static kCFStringEncodingMacGurmukhi: CFStringEncoding = 10; -//static kCFStringEncodingMacGujarati: CFStringEncoding = 11; -//static kCFStringEncodingMacOriya: CFStringEncoding = 12; -//static kCFStringEncodingMacBengali: CFStringEncoding = 13; -//static kCFStringEncodingMacTamil: CFStringEncoding = 14; -//static kCFStringEncodingMacTelugu: CFStringEncoding = 15; -//static kCFStringEncodingMacKannada: CFStringEncoding = 16; -//static kCFStringEncodingMacMalayalam: CFStringEncoding = 17; -//static kCFStringEncodingMacSinhalese: CFStringEncoding = 18; -//static kCFStringEncodingMacBurmese: CFStringEncoding = 19; -//static kCFStringEncodingMacKhmer: CFStringEncoding = 20; -//static kCFStringEncodingMacThai: CFStringEncoding = 21; -//static kCFStringEncodingMacLaotian: CFStringEncoding = 22; -//static kCFStringEncodingMacGeorgian: CFStringEncoding = 23; -//static kCFStringEncodingMacArmenian: CFStringEncoding = 24; -//static kCFStringEncodingMacChineseSimp: CFStringEncoding = 25; -//static kCFStringEncodingMacTibetan: CFStringEncoding = 26; -//static kCFStringEncodingMacMongolian: CFStringEncoding = 27; -//static kCFStringEncodingMacEthiopic: CFStringEncoding = 28; -//static kCFStringEncodingMacCentralEurRoman: CFStringEncoding = 29; -//static kCFStringEncodingMacVietnamese: CFStringEncoding = 30; -//static kCFStringEncodingMacExtArabic: CFStringEncoding = 31; -//static kCFStringEncodingMacSymbol: CFStringEncoding = 33; -//static kCFStringEncodingMacDingbats: CFStringEncoding = 34; -//static kCFStringEncodingMacTurkish: CFStringEncoding = 35; -//static kCFStringEncodingMacCroatian: CFStringEncoding = 36; -//static kCFStringEncodingMacIcelandic: CFStringEncoding = 37; -//static kCFStringEncodingMacRomanian: CFStringEncoding = 38; -//static kCFStringEncodingMacCeltic: CFStringEncoding = 39; -//static kCFStringEncodingMacGaelic: CFStringEncoding = 40; -//static kCFStringEncodingMacFarsi: CFStringEncoding = 0x8C; -//static kCFStringEncodingMacUkrainian: CFStringEncoding = 0x98; -//static kCFStringEncodingMacInuit: CFStringEncoding = 0xEC; -//static kCFStringEncodingMacVT100: CFStringEncoding = 0xFC; -//static kCFStringEncodingMacHFS: CFStringEncoding = 0xFF; -// Defined above: kCFStringEncodingISOLatin1 = 0x0201 -//static kCFStringEncodingISOLatin2: CFStringEncoding = 0x0202; -//static kCFStringEncodingISOLatin3: CFStringEncoding = 0x0203; -//static kCFStringEncodingISOLatin4: CFStringEncoding = 0x0204; -//static kCFStringEncodingISOLatinCyrillic: CFStringEncoding = 0x0205; -//static kCFStringEncodingISOLatinArabic: CFStringEncoding = 0x0206; -//static kCFStringEncodingISOLatinGreek: CFStringEncoding = 0x0207; -//static kCFStringEncodingISOLatinHebrew: CFStringEncoding = 0x0208; -//static kCFStringEncodingISOLatin5: CFStringEncoding = 0x0209; -//static kCFStringEncodingISOLatin6: CFStringEncoding = 0x020A; -//static kCFStringEncodingISOLatinThai: CFStringEncoding = 0x020B; -//static kCFStringEncodingISOLatin7: CFStringEncoding = 0x020D; -//static kCFStringEncodingISOLatin8: CFStringEncoding = 0x020E; -//static kCFStringEncodingISOLatin9: CFStringEncoding = 0x020F; -//static kCFStringEncodingISOLatin10: CFStringEncoding = 0x0210; -//static kCFStringEncodingDOSLatinUS: CFStringEncoding = 0x0400; -//static kCFStringEncodingDOSGreek: CFStringEncoding = 0x0405; -//static kCFStringEncodingDOSBalticRim: CFStringEncoding = 0x0406; -//static kCFStringEncodingDOSLatin1: CFStringEncoding = 0x0410; -//static kCFStringEncodingDOSGreek1: CFStringEncoding = 0x0411; -//static kCFStringEncodingDOSLatin2: CFStringEncoding = 0x0412; -//static kCFStringEncodingDOSCyrillic: CFStringEncoding = 0x0413; -//static kCFStringEncodingDOSTurkish: CFStringEncoding = 0x0414; -//static kCFStringEncodingDOSPortuguese: CFStringEncoding = 0x0415; -//static kCFStringEncodingDOSIcelandic: CFStringEncoding = 0x0416; -//static kCFStringEncodingDOSHebrew: CFStringEncoding = 0x0417; -//static kCFStringEncodingDOSCanadianFrench: CFStringEncoding = 0x0418; -//static kCFStringEncodingDOSArabic: CFStringEncoding = 0x0419; -//static kCFStringEncodingDOSNordic: CFStringEncoding = 0x041A; -//static kCFStringEncodingDOSRussian: CFStringEncoding = 0x041B; -//static kCFStringEncodingDOSGreek2: CFStringEncoding = 0x041C; -//static kCFStringEncodingDOSThai: CFStringEncoding = 0x041D; -//static kCFStringEncodingDOSJapanese: CFStringEncoding = 0x0420; -//static kCFStringEncodingDOSChineseSimplif: CFStringEncoding = 0x0421; -//static kCFStringEncodingDOSKorean: CFStringEncoding = 0x0422; -//static kCFStringEncodingDOSChineseTrad: CFStringEncoding = 0x0423; -// Defined above: kCFStringEncodingWindowsLatin1 = 0x0500 -//static kCFStringEncodingWindowsLatin2: CFStringEncoding = 0x0501; -//static kCFStringEncodingWindowsCyrillic: CFStringEncoding = 0x0502; -//static kCFStringEncodingWindowsGreek: CFStringEncoding = 0x0503; -//static kCFStringEncodingWindowsLatin5: CFStringEncoding = 0x0504; -//static kCFStringEncodingWindowsHebrew: CFStringEncoding = 0x0505; -//static kCFStringEncodingWindowsArabic: CFStringEncoding = 0x0506; -//static kCFStringEncodingWindowsBalticRim: CFStringEncoding = 0x0507; -//static kCFStringEncodingWindowsVietnamese: CFStringEncoding = 0x0508; -//static kCFStringEncodingWindowsKoreanJohab: CFStringEncoding = 0x0510; -// Defined above: kCFStringEncodingASCII = 0x0600 -//static kCFStringEncodingANSEL: CFStringEncoding = 0x0601; -//static kCFStringEncodingJIS_X0201_76: CFStringEncoding = 0x0620; -//static kCFStringEncodingJIS_X0208_83: CFStringEncoding = 0x0621; -//static kCFStringEncodingJIS_X0208_90: CFStringEncoding = 0x0622; -//static kCFStringEncodingJIS_X0212_90: CFStringEncoding = 0x0623; -//static kCFStringEncodingJIS_C6226_78: CFStringEncoding = 0x0624; -//static kCFStringEncodingShiftJIS_X0213: CFStringEncoding = 0x0628; -//static kCFStringEncodingShiftJIS_X0213_MenKuTen: CFStringEncoding = 0x0629; -//static kCFStringEncodingGB_2312_80: CFStringEncoding = 0x0630; -//static kCFStringEncodingGBK_95: CFStringEncoding = 0x0631; -//static kCFStringEncodingGB_18030_2000: CFStringEncoding = 0x0632; -//static kCFStringEncodingKSC_5601_87: CFStringEncoding = 0x0640; -//static kCFStringEncodingKSC_5601_92_Johab: CFStringEncoding = 0x0641; -//static kCFStringEncodingCNS_11643_92_P1: CFStringEncoding = 0x0651; -//static kCFStringEncodingCNS_11643_92_P2: CFStringEncoding = 0x0652; -//static kCFStringEncodingCNS_11643_92_P3: CFStringEncoding = 0x0653; -//static kCFStringEncodingISO_2022_JP: CFStringEncoding = 0x0820; -//static kCFStringEncodingISO_2022_JP_2: CFStringEncoding = 0x0821; -//static kCFStringEncodingISO_2022_JP_1: CFStringEncoding = 0x0822; -//static kCFStringEncodingISO_2022_JP_3: CFStringEncoding = 0x0823; -//static kCFStringEncodingISO_2022_CN: CFStringEncoding = 0x0830; -//static kCFStringEncodingISO_2022_CN_EXT: CFStringEncoding = 0x0831; -//static kCFStringEncodingISO_2022_KR: CFStringEncoding = 0x0840; -//static kCFStringEncodingEUC_JP: CFStringEncoding = 0x0920; -//static kCFStringEncodingEUC_CN: CFStringEncoding = 0x0930; -//static kCFStringEncodingEUC_TW: CFStringEncoding = 0x0931; -//static kCFStringEncodingEUC_KR: CFStringEncoding = 0x0940; -//static kCFStringEncodingShiftJIS: CFStringEncoding = 0x0A01; -//static kCFStringEncodingKOI8_R: CFStringEncoding = 0x0A02; -//static kCFStringEncodingBig5: CFStringEncoding = 0x0A03; -//static kCFStringEncodingMacRomanLatin1: CFStringEncoding = 0x0A04; -//static kCFStringEncodingHZ_GB_2312: CFStringEncoding = 0x0A05; -//static kCFStringEncodingBig5_HKSCS_1999: CFStringEncoding = 0x0A06; -//static kCFStringEncodingVISCII: CFStringEncoding = 0x0A07; -//static kCFStringEncodingKOI8_U: CFStringEncoding = 0x0A08; -//static kCFStringEncodingBig5_E: CFStringEncoding = 0x0A09; -// Defined above: kCFStringEncodingNextStepLatin = 0x0B01 -//static kCFStringEncodingNextStepJapanese: CFStringEncoding = 0x0B02; -//static kCFStringEncodingEBCDIC_US: CFStringEncoding = 0x0C01; -//static kCFStringEncodingEBCDIC_CP037: CFStringEncoding = 0x0C02; -//static kCFStringEncodingUTF7: CFStringEncoding = 0x04000100; -//static kCFStringEncodingUTF7_IMAP: CFStringEncoding = 0x0A10; -//static kCFStringEncodingShiftJIS_X0213_00: CFStringEncoding = 0x0628; /* Deprecated */ - -#[repr(C)] -struct __CFString; - -pub type CFStringRef = *const __CFString; +use std::ffi::CStr; /// An immutable string in one of a variety of encodings. pub struct CFString(CFStringRef); @@ -329,127 +147,6 @@ impl CFString { } } -#[link(name = "CoreFoundation", kind = "framework")] -extern { - /* - * CFString.h - */ - - // N.B. organized according to "Functions by task" in docs - - /* Creating a CFString */ - //fn CFSTR - //fn CFStringCreateArrayBySeparatingStrings - //fn CFStringCreateByCombiningStrings - //fn CFStringCreateCopy - //fn CFStringCreateFromExternalRepresentation - fn CFStringCreateWithBytes(alloc: CFAllocatorRef, - bytes: *const u8, - numBytes: CFIndex, - encoding: CFStringEncoding, - isExternalRepresentation: Boolean, - contentsDeallocator: CFAllocatorRef) - -> CFStringRef; - fn CFStringCreateWithBytesNoCopy(alloc: CFAllocatorRef, - bytes: *const u8, - numBytes: CFIndex, - encoding: CFStringEncoding, - isExternalRepresentation: Boolean, - contentsDeallocator: CFAllocatorRef) - -> CFStringRef; - //fn CFStringCreateWithCharacters - //fn CFStringCreateWithCharactersNoCopy - //fn CFStringCreateWithCString - //fn CFStringCreateWithCStringNoCopy - //fn CFStringCreateWithFormat - //fn CFStringCreateWithFormatAndArguments - //fn CFStringCreateWithPascalString - //fn CFStringCreateWithPascalStringNoCopy - //fn CFStringCreateWithSubstring - - /* Searching Strings */ - //fn CFStringCreateArrayWithFindResults - //fn CFStringFind - //fn CFStringFindCharacterFromSet - //fn CFStringFindWithOptions - //fn CFStringFindWithOptionsAndLocale - //fn CFStringGetLineBounds - - /* Comparing Strings */ - //fn CFStringCompare - //fn CFStringCompareWithOptions - //fn CFStringCompareWithOptionsAndLocale - //fn CFStringHasPrefix - //fn CFStringHasSuffix - - /* Accessing Characters */ - //fn CFStringCreateExternalRepresentation - fn CFStringGetBytes(theString: CFStringRef, - range: CFRange, - encoding: CFStringEncoding, - lossByte: u8, - isExternalRepresentation: Boolean, - buffer: *mut u8, - maxBufLen: CFIndex, - usedBufLen: *mut CFIndex) - -> CFIndex; - //fn CFStringGetCharacterAtIndex - //fn CFStringGetCharacters - //fn CFStringGetCharactersPtr - //fn CFStringGetCharacterFromInlineBuffer - //fn CFStringGetCString - fn CFStringGetCStringPtr(theString: CFStringRef, - encoding: CFStringEncoding) - -> *const libc::c_char; - fn CFStringGetLength(theString: CFStringRef) -> CFIndex; - //fn CFStringGetPascalString - //fn CFStringGetPascalStringPtr - //fn CFStringGetRangeOfComposedCharactersAtIndex - //fn CFStringInitInlineBuffer - - /* Working With Hyphenation */ - //fn CFStringGetHyphenationLocationBeforeIndex - //fn CFStringIsHyphenationAvailableForLocale - - /* Working With Encodings */ - //fn CFStringConvertEncodingToIANACharSetName - //fn CFStringConvertEncodingToNSStringEncoding - //fn CFStringConvertEncodingToWindowsCodepage - //fn CFStringConvertIANACharSetNameToEncoding - //fn CFStringConvertNSStringEncodingToEncoding - //fn CFStringConvertWindowsCodepageToEncoding - //fn CFStringGetFastestEncoding - //fn CFStringGetListOfAvailableEncodings - //fn CFStringGetMaximumSizeForEncoding - //fn CFStringGetMostCompatibleMacStringEncoding - //fn CFStringGetNameOfEncoding - //fn CFStringGetSmallestEncoding - //fn CFStringGetSystemEncoding - //fn CFStringIsEncodingAvailable - - /* Getting Numeric Values */ - //fn CFStringGetDoubleValue - //fn CFStringGetIntValue - - /* Getting String Properties */ - //fn CFShowStr - fn CFStringGetTypeID() -> CFTypeID; - - /* String File System Representations */ - //fn CFStringCreateWithFileSystemRepresentation - //fn CFStringGetFileSystemRepresentation - //fn CFStringGetMaximumSizeOfFileSystemRepresentation - - /* Getting Paragraph Bounds */ - //fn CFStringGetParagraphBounds - - /* Managing Surrogates */ - //fn CFStringGetLongCharacterForSurrogatePair - //fn CFStringGetSurrogatePairForLongCharacter - //fn CFStringIsSurrogateHighCharacter - //fn CFStringIsSurrogateLowCharacter -} - #[test] fn string_and_back() { let original = "The quick brown fox jumped over the slow lazy dog."; diff --git a/core-foundation/src/url.rs b/core-foundation/src/url.rs index 95b5612..4261e5a 100644 --- a/core-foundation/src/url.rs +++ b/core-foundation/src/url.rs @@ -12,10 +12,11 @@ #![allow(non_upper_case_globals)] use base::{TCFType}; -use string::{CFString, CFStringRef}; +use string::{CFString}; use core_foundation_sys::base::{CFAllocatorRef, CFIndex, CFRelease, CFOptionFlags}; use core_foundation_sys::base::{Boolean, CFTypeID, kCFAllocatorDefault}; +use core_foundation_sys::string::CFStringRef; use std::fmt; use std::mem; From 80593ffc5de0b3d289fe0f12eed4e6d049314017 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 24 Aug 2015 23:35:14 -0700 Subject: [PATCH 06/19] Port data to sys crate --- core-foundation-sys/src/data.rs | 19 +++++++++++++++++++ core-foundation-sys/src/lib.rs | 1 + core-foundation/src/data.rs | 25 +++---------------------- 3 files changed, 23 insertions(+), 22 deletions(-) create mode 100644 core-foundation-sys/src/data.rs diff --git a/core-foundation-sys/src/data.rs b/core-foundation-sys/src/data.rs new file mode 100644 index 0000000..a62da4b --- /dev/null +++ b/core-foundation-sys/src/data.rs @@ -0,0 +1,19 @@ +use libc::c_void; + +use base::{CFAllocatorRef, CFTypeID, CFIndex}; + +pub type CFDataRef = *const c_void; + +extern { + /* + * CFData.h + */ + + pub fn CFDataCreate(allocator: CFAllocatorRef, + bytes: *const u8, length: CFIndex) -> CFDataRef; + //fn CFDataFind + pub fn CFDataGetBytePtr(theData: CFDataRef) -> *const u8; + pub fn CFDataGetLength(theData: CFDataRef) -> CFIndex; + + pub fn CFDataGetTypeID() -> CFTypeID; +} diff --git a/core-foundation-sys/src/lib.rs b/core-foundation-sys/src/lib.rs index 827d9b9..4379f7d 100644 --- a/core-foundation-sys/src/lib.rs +++ b/core-foundation-sys/src/lib.rs @@ -5,5 +5,6 @@ extern crate libc; pub mod array; pub mod base; pub mod bundle; +pub mod data; pub mod number; pub mod string; diff --git a/core-foundation/src/data.rs b/core-foundation/src/data.rs index 1b75677..4d6826b 100644 --- a/core-foundation/src/data.rs +++ b/core-foundation/src/data.rs @@ -9,19 +9,15 @@ //! Core Foundation byte buffers. -use core_foundation_sys::base::{CFAllocatorRef, CFIndex, CFRelease}; -use core_foundation_sys::base::{CFTypeID, kCFAllocatorDefault}; +use core_foundation_sys::base::{CFIndex, CFRelease}; +use core_foundation_sys::base::{kCFAllocatorDefault}; +use core_foundation_sys::data::*; use std::mem; use std::ops::Deref; use std::slice; use base::{CFIndexConvertible, TCFType}; -#[repr(C)] -struct __CFData; - -pub type CFDataRef = *const __CFData; - /// A byte buffer. pub struct CFData(CFDataRef); @@ -71,18 +67,3 @@ impl Deref for CFData { self.bytes() } } - -#[link(name = "CoreFoundation", kind = "framework")] -extern { - /* - * CFData.h - */ - - fn CFDataCreate(allocator: CFAllocatorRef, - bytes: *const u8, length: CFIndex) -> CFDataRef; - //fn CFDataFind - fn CFDataGetBytePtr(theData: CFDataRef) -> *const u8; - fn CFDataGetLength(theData: CFDataRef) -> CFIndex; - - fn CFDataGetTypeID() -> CFTypeID; -} From 9c6d29219c745ebd3d3801608d9ebdc38ceb469d Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 24 Aug 2015 23:36:29 -0700 Subject: [PATCH 07/19] Port date to sys crate --- {core-foundation => core-foundation-sys}/src/date.rs | 0 core-foundation-sys/src/lib.rs | 1 + core-foundation/src/lib.rs | 1 - core-foundation/src/runloop.rs | 2 +- 4 files changed, 2 insertions(+), 2 deletions(-) rename {core-foundation => core-foundation-sys}/src/date.rs (100%) diff --git a/core-foundation/src/date.rs b/core-foundation-sys/src/date.rs similarity index 100% rename from core-foundation/src/date.rs rename to core-foundation-sys/src/date.rs diff --git a/core-foundation-sys/src/lib.rs b/core-foundation-sys/src/lib.rs index 4379f7d..7af117d 100644 --- a/core-foundation-sys/src/lib.rs +++ b/core-foundation-sys/src/lib.rs @@ -6,5 +6,6 @@ pub mod array; pub mod base; pub mod bundle; pub mod data; +pub mod date; pub mod number; pub mod string; diff --git a/core-foundation/src/lib.rs b/core-foundation/src/lib.rs index b8fb276..f8541e1 100644 --- a/core-foundation/src/lib.rs +++ b/core-foundation/src/lib.rs @@ -58,7 +58,6 @@ pub mod set; pub mod string; pub mod url; pub mod bundle; -pub mod date; pub mod runloop; #[cfg(test)] diff --git a/core-foundation/src/runloop.rs b/core-foundation/src/runloop.rs index 1637562..5f61730 100644 --- a/core-foundation/src/runloop.rs +++ b/core-foundation/src/runloop.rs @@ -15,12 +15,12 @@ use core_foundation_sys::base::{CFTypeID, CFHashCode, mach_port_t}; use core_foundation_sys::base::{kCFAllocatorDefault, Boolean, CFOptionFlags}; use core_foundation_sys::array::{CFArrayRef}; use core_foundation_sys::string::CFStringRef; +use core_foundation_sys::date::{CFAbsoluteTime, CFTimeInterval}; use libc::c_void; use std::mem; use base::{TCFType}; use string::{CFString}; -use date::{CFAbsoluteTime, CFTimeInterval}; pub struct CFRunLoop(CFRunLoopRef); From e53893b80998b03ef0ee5110798f83ed8779c537 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 25 Aug 2015 21:06:50 -0700 Subject: [PATCH 08/19] Move dictionary and number to sys crate --- core-foundation-sys/src/dictionary.rs | 57 +++++++++++++++++++++++++ core-foundation-sys/src/lib.rs | 1 + core-foundation-sys/src/number.rs | 37 ++++++++++++++++- core-foundation/src/dictionary.rs | 60 ++------------------------- core-foundation/src/number.rs | 46 +------------------- 5 files changed, 99 insertions(+), 102 deletions(-) create mode 100644 core-foundation-sys/src/dictionary.rs diff --git a/core-foundation-sys/src/dictionary.rs b/core-foundation-sys/src/dictionary.rs new file mode 100644 index 0000000..2800d4c --- /dev/null +++ b/core-foundation-sys/src/dictionary.rs @@ -0,0 +1,57 @@ +use libc::{c_void}; + +use base::{CFAllocatorRef, CFIndex, CFTypeID, Boolean}; + +pub type CFDictionaryApplierFunction = *const u8; +pub type CFDictionaryCopyDescriptionCallBack = *const u8; +pub type CFDictionaryEqualCallBack = *const u8; +pub type CFDictionaryHashCallBack = *const u8; +pub type CFDictionaryReleaseCallBack = *const u8; +pub type CFDictionaryRetainCallBack = *const u8; + +#[allow(dead_code)] +#[repr(C)] +#[derive(Clone, Copy)] +pub struct CFDictionaryKeyCallBacks { + pub version: CFIndex, + pub retain: CFDictionaryRetainCallBack, + pub release: CFDictionaryReleaseCallBack, + pub copyDescription: CFDictionaryCopyDescriptionCallBack, + pub equal: CFDictionaryEqualCallBack, + pub hash: CFDictionaryHashCallBack +} + +#[allow(dead_code)] +#[repr(C)] +#[derive(Clone, Copy)] +pub struct CFDictionaryValueCallBacks { + pub version: CFIndex, + pub retain: CFDictionaryRetainCallBack, + pub release: CFDictionaryReleaseCallBack, + pub copyDescription: CFDictionaryCopyDescriptionCallBack, + pub equal: CFDictionaryEqualCallBack +} + +#[repr(C)] +struct __CFDictionary; + +pub type CFDictionaryRef = *const __CFDictionary; + +extern { + /* + * CFDictionary.h + */ + + pub static kCFTypeDictionaryKeyCallBacks: CFDictionaryKeyCallBacks; + pub static kCFTypeDictionaryValueCallBacks: CFDictionaryValueCallBacks; + + pub fn CFDictionaryContainsKey(theDict: CFDictionaryRef, key: *const c_void) -> Boolean; + pub fn CFDictionaryCreate(allocator: CFAllocatorRef, keys: *const *const c_void, values: *const *const c_void, + numValues: CFIndex, keyCallBacks: *const CFDictionaryKeyCallBacks, + valueCallBacks: *const CFDictionaryValueCallBacks) + -> CFDictionaryRef; + pub fn CFDictionaryGetCount(theDict: CFDictionaryRef) -> CFIndex; + pub fn CFDictionaryGetTypeID() -> CFTypeID; + pub fn CFDictionaryGetValueIfPresent(theDict: CFDictionaryRef, key: *const c_void, value: *mut *const c_void) + -> Boolean; +} diff --git a/core-foundation-sys/src/lib.rs b/core-foundation-sys/src/lib.rs index 7af117d..68bcdb4 100644 --- a/core-foundation-sys/src/lib.rs +++ b/core-foundation-sys/src/lib.rs @@ -7,5 +7,6 @@ pub mod base; pub mod bundle; pub mod data; pub mod date; +pub mod dictionary; pub mod number; pub mod string; diff --git a/core-foundation-sys/src/number.rs b/core-foundation-sys/src/number.rs index 99b9c49..026a7b0 100644 --- a/core-foundation-sys/src/number.rs +++ b/core-foundation-sys/src/number.rs @@ -1,12 +1,47 @@ use libc::c_void; -use base::CFTypeID; +use base::{CFAllocatorRef, CFTypeID}; pub type CFBooleanRef = *const c_void; +pub type CFNumberType = u32; + +// members of enum CFNumberType +// static kCFNumberSInt8Type: CFNumberType = 1; +// static kCFNumberSInt16Type: CFNumberType = 2; +pub static kCFNumberSInt32Type: CFNumberType = 3; +pub static kCFNumberSInt64Type: CFNumberType = 4; +// static kCFNumberFloat32Type: CFNumberType = 5; +pub static kCFNumberFloat64Type: CFNumberType = 6; +// static kCFNumberCharType: CFNumberType = 7; +// static kCFNumberShortType: CFNumberType = 8; +// static kCFNumberIntType: CFNumberType = 9; +// static kCFNumberLongType: CFNumberType = 10; +// static kCFNumberLongLongType: CFNumberType = 11; +// static kCFNumberFloatType: CFNumberType = 12; +// static kCFNumberDoubleType: CFNumberType = 13; +// static kCFNumberCFIndexType: CFNumberType = 14; +// static kCFNumberNSIntegerType: CFNumberType = 15; +// static kCFNumberCGFloatType: CFNumberType = 16; +// static kCFNumberMaxType: CFNumberType = 16; + +#[repr(C)] +struct __CFNumber; + +pub type CFNumberRef = *const __CFNumber; + extern { + /* + * CFNumber.h + */ pub static kCFBooleanTrue: CFBooleanRef; pub static kCFBooleanFalse: CFBooleanRef; pub fn CFBooleanGetTypeID() -> CFTypeID; + pub fn CFNumberCreate(allocator: CFAllocatorRef, theType: CFNumberType, valuePtr: *const c_void) + -> CFNumberRef; + //fn CFNumberGetByteSize + pub fn CFNumberGetValue(number: CFNumberRef, theType: CFNumberType, valuePtr: *mut c_void) -> bool; + //fn CFNumberCompare + pub fn CFNumberGetTypeID() -> CFTypeID; } diff --git a/core-foundation/src/dictionary.rs b/core-foundation/src/dictionary.rs index 5540d20..b08bdc1 100644 --- a/core-foundation/src/dictionary.rs +++ b/core-foundation/src/dictionary.rs @@ -9,49 +9,15 @@ //! Dictionaries of key-value pairs. -use core_foundation_sys::base::{Boolean, CFAllocatorRef, CFIndex, CFRelease}; -use core_foundation_sys::base::{CFTypeID, CFTypeRef, kCFAllocatorDefault}; +use core_foundation_sys::base::CFRelease; +use core_foundation_sys::base::{CFTypeRef, kCFAllocatorDefault}; +use core_foundation_sys::dictionary::*; use libc::c_void; use std::mem; use std::ptr; use base::{CFType, CFIndexConvertible, TCFType}; -pub type CFDictionaryApplierFunction = *const u8; -pub type CFDictionaryCopyDescriptionCallBack = *const u8; -pub type CFDictionaryEqualCallBack = *const u8; -pub type CFDictionaryHashCallBack = *const u8; -pub type CFDictionaryReleaseCallBack = *const u8; -pub type CFDictionaryRetainCallBack = *const u8; - -#[allow(dead_code)] -#[repr(C)] -#[derive(Clone, Copy)] -pub struct CFDictionaryKeyCallBacks { - version: CFIndex, - retain: CFDictionaryRetainCallBack, - release: CFDictionaryReleaseCallBack, - copyDescription: CFDictionaryCopyDescriptionCallBack, - equal: CFDictionaryEqualCallBack, - hash: CFDictionaryHashCallBack -} - -#[allow(dead_code)] -#[repr(C)] -#[derive(Clone, Copy)] -pub struct CFDictionaryValueCallBacks { - version: CFIndex, - retain: CFDictionaryRetainCallBack, - release: CFDictionaryReleaseCallBack, - copyDescription: CFDictionaryCopyDescriptionCallBack, - equal: CFDictionaryEqualCallBack -} - -#[repr(C)] -struct __CFDictionary; - -pub type CFDictionaryRef = *const __CFDictionary; - /// An immutable dictionary of key-value pairs. pub struct CFDictionary(CFDictionaryRef); @@ -131,23 +97,3 @@ impl CFDictionary { TCFType::wrap_under_get_rule(value) } } - -#[link(name = "CoreFoundation", kind = "framework")] -extern { - /* - * CFDictionary.h - */ - - static kCFTypeDictionaryKeyCallBacks: CFDictionaryKeyCallBacks; - static kCFTypeDictionaryValueCallBacks: CFDictionaryValueCallBacks; - - fn CFDictionaryContainsKey(theDict: CFDictionaryRef, key: *const c_void) -> Boolean; - fn CFDictionaryCreate(allocator: CFAllocatorRef, keys: *const *const c_void, values: *const *const c_void, - numValues: CFIndex, keyCallBacks: *const CFDictionaryKeyCallBacks, - valueCallBacks: *const CFDictionaryValueCallBacks) - -> CFDictionaryRef; - fn CFDictionaryGetCount(theDict: CFDictionaryRef) -> CFIndex; - fn CFDictionaryGetTypeID() -> CFTypeID; - fn CFDictionaryGetValueIfPresent(theDict: CFDictionaryRef, key: *const c_void, value: *mut *const c_void) - -> Boolean; -} diff --git a/core-foundation/src/number.rs b/core-foundation/src/number.rs index 0309bc8..22869e8 100644 --- a/core-foundation/src/number.rs +++ b/core-foundation/src/number.rs @@ -11,39 +11,12 @@ #![allow(non_upper_case_globals)] -use core_foundation_sys::base::{CFAllocatorRef, CFRelease, CFTypeID}; -use core_foundation_sys::base::{kCFAllocatorDefault}; -use libc::c_void; +use core_foundation_sys::base::{CFRelease, kCFAllocatorDefault}; +use core_foundation_sys::number::*; use std::mem; use base::{TCFType}; -pub type CFNumberType = u32; - -// members of enum CFNumberType -// static kCFNumberSInt8Type: CFNumberType = 1; -// static kCFNumberSInt16Type: CFNumberType = 2; -static kCFNumberSInt32Type: CFNumberType = 3; -static kCFNumberSInt64Type: CFNumberType = 4; -// static kCFNumberFloat32Type: CFNumberType = 5; -static kCFNumberFloat64Type: CFNumberType = 6; -// static kCFNumberCharType: CFNumberType = 7; -// static kCFNumberShortType: CFNumberType = 8; -// static kCFNumberIntType: CFNumberType = 9; -// static kCFNumberLongType: CFNumberType = 10; -// static kCFNumberLongLongType: CFNumberType = 11; -// static kCFNumberFloatType: CFNumberType = 12; -// static kCFNumberDoubleType: CFNumberType = 13; -// static kCFNumberCFIndexType: CFNumberType = 14; -// static kCFNumberNSIntegerType: CFNumberType = 15; -// static kCFNumberCGFloatType: CFNumberType = 16; -// static kCFNumberMaxType: CFNumberType = 16; - -#[repr(C)] -struct __CFNumber; - -pub type CFNumberRef = *const __CFNumber; - /// An immutable numeric value. pub struct CFNumber(CFNumberRef); @@ -112,18 +85,3 @@ impl CFNumber { pub fn number(value: i64) -> CFNumber { CFNumber::from_i64(value) } - -#[link(name = "CoreFoundation", kind = "framework")] -extern { - /* - * CFNumber.h - */ - - - fn CFNumberCreate(allocator: CFAllocatorRef, theType: CFNumberType, valuePtr: *const c_void) - -> CFNumberRef; - //fn CFNumberGetByteSize - fn CFNumberGetValue(number: CFNumberRef, theType: CFNumberType, valuePtr: *mut c_void) -> bool; - //fn CFNumberCompare - fn CFNumberGetTypeID() -> CFTypeID; -} From ed048f1c62dcfda9e2865cc9a8edf866a6dac970 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 25 Aug 2015 21:15:32 -0700 Subject: [PATCH 09/19] Move runloop to sys directory --- core-foundation-sys/src/lib.rs | 1 + core-foundation-sys/src/runloop.rs | 155 +++++++++++++++++++++++++++ core-foundation/src/runloop.rs | 161 +---------------------------- 3 files changed, 159 insertions(+), 158 deletions(-) create mode 100644 core-foundation-sys/src/runloop.rs diff --git a/core-foundation-sys/src/lib.rs b/core-foundation-sys/src/lib.rs index 68bcdb4..cc84bc3 100644 --- a/core-foundation-sys/src/lib.rs +++ b/core-foundation-sys/src/lib.rs @@ -9,4 +9,5 @@ pub mod data; pub mod date; pub mod dictionary; pub mod number; +pub mod runloop; pub mod string; diff --git a/core-foundation-sys/src/runloop.rs b/core-foundation-sys/src/runloop.rs new file mode 100644 index 0000000..e0270e2 --- /dev/null +++ b/core-foundation-sys/src/runloop.rs @@ -0,0 +1,155 @@ +use libc::c_void; + +use array::CFArrayRef; +use base::{Boolean, CFIndex, CFTypeID, CFAllocatorRef, CFOptionFlags, CFHashCode, mach_port_t}; +use date::{CFAbsoluteTime, CFTimeInterval}; +use string::CFStringRef; + +#[repr(C)] +struct __CFRunLoop; + +pub type CFRunLoopRef = *const __CFRunLoop; + +#[repr(C)] +struct __CFRunLoopSource; + +pub type CFRunLoopSourceRef = *const __CFRunLoopSource; + +#[repr(C)] +struct __CFRunLoopObserver; + +pub type CFRunLoopObserverRef = *const __CFRunLoopObserver; + +// Reasons for CFRunLoopRunInMode() to Return +pub const kCFRunLoopRunFinished: i32 = 1; +pub const kCFRunLoopRunStopped: i32 = 2; +pub const kCFRunLoopRunTimedOut: i32 = 3; +pub const kCFRunLoopRunHandledSource: i32 = 4; + +// Run Loop Observer Activities +//typedef CF_OPTIONS(CFOptionFlags, CFRunLoopActivity) { +pub type CFRunLoopActivity = CFOptionFlags; +pub const kCFRunLoopEntry: CFOptionFlags = 1 << 0; +pub const kCFRunLoopBeforeTimers: CFOptionFlags = 1 << 1; +pub const kCFRunLoopBeforeSources: CFOptionFlags = 1 << 2; +pub const kCFRunLoopBeforeWaiting: CFOptionFlags = 1 << 5; +pub const kCFRunLoopAfterWaiting: CFOptionFlags = 1 << 6; +pub const kCFRunLoopExit: CFOptionFlags = 1 << 7; +pub const kCFRunLoopAllActivities: CFOptionFlags = 0x0FFFFFFF; + +#[repr(C)] +pub struct CFRunLoopSourceContext { + pub version: CFIndex, + pub info: *mut c_void, + pub retain: extern "C" fn (info: *const c_void) -> *const c_void, + pub release: extern "C" fn (info: *const c_void), + pub copyDescription: extern "C" fn (info: *const c_void) -> CFStringRef, + pub equal: extern "C" fn (info1: *const c_void, info2: *const c_void) -> Boolean, + pub hash: extern "C" fn (info: *const c_void) -> CFHashCode, + pub schedule: extern "C" fn (info: *const c_void, rl: CFRunLoopRef, mode: CFStringRef), + pub cancel: extern "C" fn (info: *const c_void, rl: CFRunLoopRef, mode: CFStringRef), + pub perform: extern "C" fn (info: *const c_void), +} + +#[repr(C)] +pub struct CFRunLoopSourceContext1 { + pub version: CFIndex, + pub info: *mut c_void, + pub retain: extern "C" fn (info: *const c_void) -> *const c_void, + pub release: extern "C" fn (info: *const c_void), + pub copyDescription: extern "C" fn (info: *const c_void) -> CFStringRef, + pub equal: extern "C" fn (info1: *const c_void, info2: *const c_void) -> Boolean, + pub hash: extern "C" fn (info: *const c_void) -> CFHashCode, + // note that the following two fields are platform dependent in the C header, the ones here are for OS X + pub getPort: extern "C" fn (info: *mut c_void) -> mach_port_t, + pub perform: extern "C" fn (msg: *mut c_void, size: CFIndex, allocator: CFAllocatorRef, info: *mut c_void) -> *mut c_void, +} + +#[repr(C)] +pub struct CFRunLoopObserverContext { + pub version: CFIndex, + pub info: *mut c_void, + pub retain: extern "C" fn (info: *const c_void) -> *const c_void, + pub release: extern "C" fn (info: *const c_void), + pub copyDescription: extern "C" fn (info: *const c_void) -> CFStringRef, +} + +pub type CFRunLoopObserverCallBack = extern "C" fn (observer: CFRunLoopObserverRef, activity: CFRunLoopActivity, info: *mut c_void); + +#[repr(C)] +pub struct CFRunLoopTimerContext { + pub version: CFIndex, + pub info: *mut c_void, + pub retain: extern "C" fn (info: *const c_void) -> *const c_void, + pub release: extern "C" fn (info: *const c_void), + pub copyDescription: extern "C" fn (info: *const c_void) -> CFStringRef, +} + +pub type CFRunLoopTimerCallBack = extern "C" fn (timer: CFRunLoopTimerRef, info: *mut c_void); + +#[repr(C)] +struct __CFRunLoopTimer; + +pub type CFRunLoopTimerRef = *const __CFRunLoopTimer; + +extern { + /* + * CFRunLoop.h + */ + pub static kCFRunLoopDefaultMode: CFStringRef; + pub static kCFRunLoopCommonModes: CFStringRef; + pub fn CFRunLoopGetTypeID() -> CFTypeID; + pub fn CFRunLoopGetCurrent() -> CFRunLoopRef; + pub fn CFRunLoopGetMain() -> CFRunLoopRef; + pub fn CFRunLoopCopyCurrentMode(rl: CFRunLoopRef) -> CFStringRef; + pub fn CFRunLoopCopyAllModes(rl: CFRunLoopRef) -> CFArrayRef; + pub fn CFRunLoopAddCommonMode(rl: CFRunLoopRef, mode: CFStringRef); + pub fn CFRunLoopGetNextTimerFireDate(rl: CFRunLoopRef, mode: CFStringRef) -> CFAbsoluteTime; + pub fn CFRunLoopRun(); + pub fn CFRunLoopRunInMode(mode: CFStringRef, seconds: CFTimeInterval, returnAfterSourceHandled: Boolean) -> i32; + pub fn CFRunLoopIsWaiting(rl: CFRunLoopRef) -> Boolean; + pub fn CFRunLoopWakeUp(rl: CFRunLoopRef); + pub fn CFRunLoopStop(rl: CFRunLoopRef); + // fn CFRunLoopPerformBlock(rl: CFRunLoopRef, mode: CFTypeRef, block: void (^)(void)); + pub fn CFRunLoopContainsSource(rl: CFRunLoopRef, source: CFRunLoopSourceRef, mode: CFStringRef) -> Boolean; + pub fn CFRunLoopAddSource(rl: CFRunLoopRef, source: CFRunLoopSourceRef, mode: CFStringRef); + pub fn CFRunLoopRemoveSource(rl: CFRunLoopRef, source: CFRunLoopSourceRef, mode: CFStringRef); + pub fn CFRunLoopContainsObserver(rl: CFRunLoopRef, observer: CFRunLoopObserverRef, mode: CFStringRef) -> Boolean; + pub fn CFRunLoopAddObserver(rl: CFRunLoopRef, observer: CFRunLoopObserverRef, mode: CFStringRef); + pub fn CFRunLoopRemoveObserver(rl: CFRunLoopRef, observer: CFRunLoopObserverRef, mode: CFStringRef); + pub fn CFRunLoopContainsTimer(rl: CFRunLoopRef, timer: CFRunLoopTimerRef, mode: CFStringRef) -> Boolean; + pub fn CFRunLoopAddTimer(rl: CFRunLoopRef, timer: CFRunLoopTimerRef, mode: CFStringRef); + pub fn CFRunLoopRemoveTimer(rl: CFRunLoopRef, timer: CFRunLoopTimerRef, mode: CFStringRef); + + pub fn CFRunLoopSourceGetTypeID() -> CFTypeID; + pub fn CFRunLoopSourceCreate(allocator: CFAllocatorRef, order: CFIndex, context: *mut CFRunLoopSourceContext) -> CFRunLoopSourceRef; + pub fn CFRunLoopSourceGetOrder(source: CFRunLoopSourceRef) -> CFIndex; + pub fn CFRunLoopSourceInvalidate(source: CFRunLoopSourceRef); + pub fn CFRunLoopSourceIsValid(source: CFRunLoopSourceRef) -> Boolean; + pub fn CFRunLoopSourceGetContext(source: CFRunLoopSourceRef, context: *mut CFRunLoopSourceContext); + pub fn CFRunLoopSourceSignal(source: CFRunLoopSourceRef); + + pub fn CFRunLoopObserverGetTypeID() -> CFTypeID; + pub fn CFRunLoopObserverCreate(allocator: CFAllocatorRef, activities: CFOptionFlags, repeats: Boolean, order: CFIndex, callout: CFRunLoopObserverCallBack, context: *mut CFRunLoopObserverContext) -> CFRunLoopObserverRef; + // fn CFRunLoopObserverCreateWithHandler(allocator: CFAllocatorRef, activities: CFOptionFlags, repeats: Boolean, order: CFIndex, block: void (^) (CFRunLoopObserverRef observer, CFRunLoopActivity activity)) -> CFRunLoopObserverRef; + pub fn CFRunLoopObserverGetActivities(observer: CFRunLoopObserverRef) -> CFOptionFlags; + pub fn CFRunLoopObserverDoesRepeat(observer: CFRunLoopObserverRef) -> Boolean; + pub fn CFRunLoopObserverGetOrder(observer: CFRunLoopObserverRef) -> CFIndex; + pub fn CFRunLoopObserverInvalidate(observer: CFRunLoopObserverRef); + pub fn CFRunLoopObserverIsValid(observer: CFRunLoopObserverRef) -> Boolean; + pub fn CFRunLoopObserverGetContext(observer: CFRunLoopObserverRef, context: *mut CFRunLoopObserverContext); + + pub fn CFRunLoopTimerGetTypeID() -> CFTypeID; + pub fn CFRunLoopTimerCreate(allocator: CFAllocatorRef, fireDate: CFAbsoluteTime, interval: CFTimeInterval, flags: CFOptionFlags, order: CFIndex, callout: CFRunLoopTimerCallBack, context: *mut CFRunLoopTimerContext) -> CFRunLoopTimerRef; + // fn CFRunLoopTimerCreateWithHandler(allocator: CFAllocatorRef, fireDate: CFAbsoluteTime, interval: CFTimeInterval, flags: CFOptionFlags, order: CFIndex, block: void (^) (CFRunLoopTimerRef timer)) -> CFRunLoopTimerRef; + pub fn CFRunLoopTimerGetNextFireDate(timer: CFRunLoopTimerRef) -> CFAbsoluteTime; + pub fn CFRunLoopTimerSetNextFireDate(timer: CFRunLoopTimerRef, fireDate: CFAbsoluteTime); + pub fn CFRunLoopTimerGetInterval(timer: CFRunLoopTimerRef) -> CFTimeInterval; + pub fn CFRunLoopTimerDoesRepeat(timer: CFRunLoopTimerRef) -> Boolean; + pub fn CFRunLoopTimerGetOrder(timer: CFRunLoopTimerRef) -> CFIndex; + pub fn CFRunLoopTimerInvalidate(timer: CFRunLoopTimerRef); + pub fn CFRunLoopTimerIsValid(timer: CFRunLoopTimerRef) -> Boolean; + pub fn CFRunLoopTimerGetContext(timer: CFRunLoopTimerRef, context: *mut CFRunLoopTimerContext); + pub fn CFRunLoopTimerGetTolerance(timer: CFRunLoopTimerRef) -> CFTimeInterval; + pub fn CFRunLoopTimerSetTolerance(timer: CFRunLoopTimerRef, tolerance: CFTimeInterval); +} diff --git a/core-foundation/src/runloop.rs b/core-foundation/src/runloop.rs index 5f61730..23b8f68 100644 --- a/core-foundation/src/runloop.rs +++ b/core-foundation/src/runloop.rs @@ -9,14 +9,11 @@ #![allow(non_upper_case_globals)] - -use core_foundation_sys::base::{CFAllocatorRef, CFIndex, CFRelease}; -use core_foundation_sys::base::{CFTypeID, CFHashCode, mach_port_t}; -use core_foundation_sys::base::{kCFAllocatorDefault, Boolean, CFOptionFlags}; -use core_foundation_sys::array::{CFArrayRef}; +use core_foundation_sys::base::{CFIndex, CFRelease}; +use core_foundation_sys::base::{kCFAllocatorDefault, CFOptionFlags}; use core_foundation_sys::string::CFStringRef; use core_foundation_sys::date::{CFAbsoluteTime, CFTimeInterval}; -use libc::c_void; +use core_foundation_sys::runloop::*; use std::mem; use base::{TCFType}; @@ -87,93 +84,6 @@ impl CFRunLoop { } -#[repr(C)] -struct __CFRunLoop; - -pub type CFRunLoopRef = *const __CFRunLoop; - -#[repr(C)] -struct __CFRunLoopSource; - -pub type CFRunLoopSourceRef = *const __CFRunLoopSource; - -#[repr(C)] -struct __CFRunLoopObserver; - -pub type CFRunLoopObserverRef = *const __CFRunLoopObserver; - -// Reasons for CFRunLoopRunInMode() to Return -pub const kCFRunLoopRunFinished: i32 = 1; -pub const kCFRunLoopRunStopped: i32 = 2; -pub const kCFRunLoopRunTimedOut: i32 = 3; -pub const kCFRunLoopRunHandledSource: i32 = 4; - -// Run Loop Observer Activities -//typedef CF_OPTIONS(CFOptionFlags, CFRunLoopActivity) { -pub type CFRunLoopActivity = CFOptionFlags; -pub const kCFRunLoopEntry: CFOptionFlags = 1 << 0; -pub const kCFRunLoopBeforeTimers: CFOptionFlags = 1 << 1; -pub const kCFRunLoopBeforeSources: CFOptionFlags = 1 << 2; -pub const kCFRunLoopBeforeWaiting: CFOptionFlags = 1 << 5; -pub const kCFRunLoopAfterWaiting: CFOptionFlags = 1 << 6; -pub const kCFRunLoopExit: CFOptionFlags = 1 << 7; -pub const kCFRunLoopAllActivities: CFOptionFlags = 0x0FFFFFFF; - -#[repr(C)] -pub struct CFRunLoopSourceContext { - 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), - copyDescription: extern "C" fn (info: *const c_void) -> CFStringRef, - equal: extern "C" fn (info1: *const c_void, info2: *const c_void) -> Boolean, - hash: extern "C" fn (info: *const c_void) -> CFHashCode, - schedule: extern "C" fn (info: *const c_void, rl: CFRunLoopRef, mode: CFStringRef), - cancel: extern "C" fn (info: *const c_void, rl: CFRunLoopRef, mode: CFStringRef), - perform: extern "C" fn (info: *const c_void), -} - -#[repr(C)] -pub struct CFRunLoopSourceContext1 { - 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), - copyDescription: extern "C" fn (info: *const c_void) -> CFStringRef, - equal: extern "C" fn (info1: *const c_void, info2: *const c_void) -> Boolean, - hash: extern "C" fn (info: *const c_void) -> CFHashCode, - // note that the following two fields are platform dependent in the C header, the ones here are for OS X - getPort: extern "C" fn (info: *mut c_void) -> mach_port_t, - perform: extern "C" fn (msg: *mut c_void, size: CFIndex, allocator: CFAllocatorRef, info: *mut c_void) -> *mut c_void, -} - -#[repr(C)] -pub struct CFRunLoopObserverContext { - 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), - copyDescription: extern "C" fn (info: *const c_void) -> CFStringRef, -} - -pub type CFRunLoopObserverCallBack = extern "C" fn (observer: CFRunLoopObserverRef, activity: CFRunLoopActivity, info: *mut c_void); - -#[repr(C)] -pub struct CFRunLoopTimerContext { - 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), - copyDescription: extern "C" fn (info: *const c_void) -> CFStringRef, -} - -pub type CFRunLoopTimerCallBack = extern "C" fn (timer: CFRunLoopTimerRef, info: *mut c_void); - -#[repr(C)] -struct __CFRunLoopTimer; - -pub type CFRunLoopTimerRef = *const __CFRunLoopTimer; - pub struct CFRunLoopTimer(CFRunLoopTimerRef); impl Drop for CFRunLoopTimer { @@ -195,71 +105,6 @@ impl CFRunLoopTimer { } } - -#[allow(dead_code)] -#[link(name = "CoreFoundation", kind = "framework")] -extern { - /* - * CFRunLoop.h - */ - pub static kCFRunLoopDefaultMode: CFStringRef; - pub static kCFRunLoopCommonModes: CFStringRef; - fn CFRunLoopGetTypeID() -> CFTypeID; - fn CFRunLoopGetCurrent() -> CFRunLoopRef; - fn CFRunLoopGetMain() -> CFRunLoopRef; - fn CFRunLoopCopyCurrentMode(rl: CFRunLoopRef) -> CFStringRef; - fn CFRunLoopCopyAllModes(rl: CFRunLoopRef) -> CFArrayRef; - fn CFRunLoopAddCommonMode(rl: CFRunLoopRef, mode: CFStringRef); - fn CFRunLoopGetNextTimerFireDate(rl: CFRunLoopRef, mode: CFStringRef) -> CFAbsoluteTime; - fn CFRunLoopRun(); - fn CFRunLoopRunInMode(mode: CFStringRef, seconds: CFTimeInterval, returnAfterSourceHandled: Boolean) -> i32; - fn CFRunLoopIsWaiting(rl: CFRunLoopRef) -> Boolean; - fn CFRunLoopWakeUp(rl: CFRunLoopRef); - fn CFRunLoopStop(rl: CFRunLoopRef); - // fn CFRunLoopPerformBlock(rl: CFRunLoopRef, mode: CFTypeRef, block: void (^)(void)); - fn CFRunLoopContainsSource(rl: CFRunLoopRef, source: CFRunLoopSourceRef, mode: CFStringRef) -> Boolean; - fn CFRunLoopAddSource(rl: CFRunLoopRef, source: CFRunLoopSourceRef, mode: CFStringRef); - fn CFRunLoopRemoveSource(rl: CFRunLoopRef, source: CFRunLoopSourceRef, mode: CFStringRef); - fn CFRunLoopContainsObserver(rl: CFRunLoopRef, observer: CFRunLoopObserverRef, mode: CFStringRef) -> Boolean; - fn CFRunLoopAddObserver(rl: CFRunLoopRef, observer: CFRunLoopObserverRef, mode: CFStringRef); - fn CFRunLoopRemoveObserver(rl: CFRunLoopRef, observer: CFRunLoopObserverRef, mode: CFStringRef); - fn CFRunLoopContainsTimer(rl: CFRunLoopRef, timer: CFRunLoopTimerRef, mode: CFStringRef) -> Boolean; - fn CFRunLoopAddTimer(rl: CFRunLoopRef, timer: CFRunLoopTimerRef, mode: CFStringRef); - fn CFRunLoopRemoveTimer(rl: CFRunLoopRef, timer: CFRunLoopTimerRef, mode: CFStringRef); - - fn CFRunLoopSourceGetTypeID() -> CFTypeID; - fn CFRunLoopSourceCreate(allocator: CFAllocatorRef, order: CFIndex, context: *mut CFRunLoopSourceContext) -> CFRunLoopSourceRef; - fn CFRunLoopSourceGetOrder(source: CFRunLoopSourceRef) -> CFIndex; - fn CFRunLoopSourceInvalidate(source: CFRunLoopSourceRef); - fn CFRunLoopSourceIsValid(source: CFRunLoopSourceRef) -> Boolean; - fn CFRunLoopSourceGetContext(source: CFRunLoopSourceRef, context: *mut CFRunLoopSourceContext); - fn CFRunLoopSourceSignal(source: CFRunLoopSourceRef); - - fn CFRunLoopObserverGetTypeID() -> CFTypeID; - fn CFRunLoopObserverCreate(allocator: CFAllocatorRef, activities: CFOptionFlags, repeats: Boolean, order: CFIndex, callout: CFRunLoopObserverCallBack, context: *mut CFRunLoopObserverContext) -> CFRunLoopObserverRef; - // fn CFRunLoopObserverCreateWithHandler(allocator: CFAllocatorRef, activities: CFOptionFlags, repeats: Boolean, order: CFIndex, block: void (^) (CFRunLoopObserverRef observer, CFRunLoopActivity activity)) -> CFRunLoopObserverRef; - fn CFRunLoopObserverGetActivities(observer: CFRunLoopObserverRef) -> CFOptionFlags; - fn CFRunLoopObserverDoesRepeat(observer: CFRunLoopObserverRef) -> Boolean; - fn CFRunLoopObserverGetOrder(observer: CFRunLoopObserverRef) -> CFIndex; - fn CFRunLoopObserverInvalidate(observer: CFRunLoopObserverRef); - fn CFRunLoopObserverIsValid(observer: CFRunLoopObserverRef) -> Boolean; - fn CFRunLoopObserverGetContext(observer: CFRunLoopObserverRef, context: *mut CFRunLoopObserverContext); - - fn CFRunLoopTimerGetTypeID() -> CFTypeID; - fn CFRunLoopTimerCreate(allocator: CFAllocatorRef, fireDate: CFAbsoluteTime, interval: CFTimeInterval, flags: CFOptionFlags, order: CFIndex, callout: CFRunLoopTimerCallBack, context: *mut CFRunLoopTimerContext) -> CFRunLoopTimerRef; - // fn CFRunLoopTimerCreateWithHandler(allocator: CFAllocatorRef, fireDate: CFAbsoluteTime, interval: CFTimeInterval, flags: CFOptionFlags, order: CFIndex, block: void (^) (CFRunLoopTimerRef timer)) -> CFRunLoopTimerRef; - fn CFRunLoopTimerGetNextFireDate(timer: CFRunLoopTimerRef) -> CFAbsoluteTime; - fn CFRunLoopTimerSetNextFireDate(timer: CFRunLoopTimerRef, fireDate: CFAbsoluteTime); - fn CFRunLoopTimerGetInterval(timer: CFRunLoopTimerRef) -> CFTimeInterval; - fn CFRunLoopTimerDoesRepeat(timer: CFRunLoopTimerRef) -> Boolean; - fn CFRunLoopTimerGetOrder(timer: CFRunLoopTimerRef) -> CFIndex; - fn CFRunLoopTimerInvalidate(timer: CFRunLoopTimerRef); - fn CFRunLoopTimerIsValid(timer: CFRunLoopTimerRef) -> Boolean; - fn CFRunLoopTimerGetContext(timer: CFRunLoopTimerRef, context: *mut CFRunLoopTimerContext); - fn CFRunLoopTimerGetTolerance(timer: CFRunLoopTimerRef) -> CFTimeInterval; - fn CFRunLoopTimerSetTolerance(timer: CFRunLoopTimerRef, tolerance: CFTimeInterval); -} - #[cfg(test)] mod test { use super::*; From 59632fcae628d4add5eb6a30f1c53b85e14a487c Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 25 Aug 2015 21:18:01 -0700 Subject: [PATCH 10/19] Move set to sys crate --- core-foundation-sys/src/lib.rs | 1 + core-foundation-sys/src/set.rs | 43 ++++++++++++++++++++++++++++++ core-foundation/src/set.rs | 48 +++------------------------------- 3 files changed, 47 insertions(+), 45 deletions(-) create mode 100644 core-foundation-sys/src/set.rs diff --git a/core-foundation-sys/src/lib.rs b/core-foundation-sys/src/lib.rs index cc84bc3..a32eae8 100644 --- a/core-foundation-sys/src/lib.rs +++ b/core-foundation-sys/src/lib.rs @@ -10,4 +10,5 @@ pub mod date; pub mod dictionary; pub mod number; pub mod runloop; +pub mod set; pub mod string; diff --git a/core-foundation-sys/src/set.rs b/core-foundation-sys/src/set.rs new file mode 100644 index 0000000..9ef4a24 --- /dev/null +++ b/core-foundation-sys/src/set.rs @@ -0,0 +1,43 @@ +use libc::c_void; + +use base::{CFAllocatorRef, CFIndex, CFTypeID}; + +pub type CFSetRetainCallBack = *const u8; +pub type CFSetReleaseCallBack = *const u8; +pub type CFSetCopyDescriptionCallBack = *const u8; +pub type CFSetEqualCallBack = *const u8; +pub type CFSetHashCallBack = *const u8; + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct CFSetCallBacks { + pub version: CFIndex, + pub retain: CFSetRetainCallBack, + pub release: CFSetReleaseCallBack, + pub copyDescription: CFSetCopyDescriptionCallBack, + pub equal: CFSetEqualCallBack, + pub hash: CFSetHashCallBack, +} + +#[repr(C)] +struct __CFSet; + +pub type CFSetRef = *const __CFSet; + +extern { + /* + * CFSet.h + */ + + pub static kCFTypeSetCallBacks: CFSetCallBacks; + + /* Creating Sets */ + pub fn CFSetCreate(allocator: CFAllocatorRef, values: *const *const c_void, numValues: CFIndex, + callBacks: *const CFSetCallBacks) -> CFSetRef; + + /* Applying a Function to Set Members */ + //fn CFSetApplyFunction + + pub fn CFSetGetTypeID() -> CFTypeID; +} + diff --git a/core-foundation/src/set.rs b/core-foundation/src/set.rs index 680007f..00f9190 100644 --- a/core-foundation/src/set.rs +++ b/core-foundation/src/set.rs @@ -9,37 +9,14 @@ //! An immutable bag of elements. -use core_foundation_sys::base::{CFAllocatorRef, CFIndex, CFRelease}; -use core_foundation_sys::base::{CFTypeID, CFTypeRef, kCFAllocatorDefault}; +use core_foundation_sys::base::CFRelease; +use core_foundation_sys::base::{CFTypeRef, kCFAllocatorDefault}; +use core_foundation_sys::set::*; use base::{CFIndexConvertible, TCFType}; -use libc::c_void; use std::mem; -pub type CFSetRetainCallBack = *const u8; -pub type CFSetReleaseCallBack = *const u8; -pub type CFSetCopyDescriptionCallBack = *const u8; -pub type CFSetEqualCallBack = *const u8; -pub type CFSetHashCallBack = *const u8; - -#[allow(dead_code)] -#[repr(C)] -#[derive(Clone, Copy)] -pub struct CFSetCallBacks { - version: CFIndex, - retain: CFSetRetainCallBack, - release: CFSetReleaseCallBack, - copyDescription: CFSetCopyDescriptionCallBack, - equal: CFSetEqualCallBack, - hash: CFSetHashCallBack, -} - -#[repr(C)] -struct __CFSet; - -pub type CFSetRef = *const __CFSet; - /// An immutable bag of elements. pub struct CFSet(CFSetRef); @@ -66,22 +43,3 @@ impl CFSet { } } } - -#[link(name = "CoreFoundation", kind = "framework")] -extern { - /* - * CFSet.h - */ - - static kCFTypeSetCallBacks: CFSetCallBacks; - - /* Creating Sets */ - fn CFSetCreate(allocator: CFAllocatorRef, values: *const *const c_void, numValues: CFIndex, - callBacks: *const CFSetCallBacks) -> CFSetRef; - - /* Applying a Function to Set Members */ - //fn CFSetApplyFunction - - fn CFSetGetTypeID() -> CFTypeID; -} - From a16dedd6d968daecb71f724ed74daf1ec579e36a Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 25 Aug 2015 21:21:40 -0700 Subject: [PATCH 11/19] Move url to sys crate --- core-foundation-sys/src/lib.rs | 1 + core-foundation-sys/src/url.rs | 146 +++++++++++++++++++++++++++++++ core-foundation/src/url.rs | 151 +-------------------------------- 3 files changed, 149 insertions(+), 149 deletions(-) create mode 100644 core-foundation-sys/src/url.rs diff --git a/core-foundation-sys/src/lib.rs b/core-foundation-sys/src/lib.rs index a32eae8..e47d5ac 100644 --- a/core-foundation-sys/src/lib.rs +++ b/core-foundation-sys/src/lib.rs @@ -12,3 +12,4 @@ pub mod number; pub mod runloop; pub mod set; pub mod string; +pub mod url; diff --git a/core-foundation-sys/src/url.rs b/core-foundation-sys/src/url.rs new file mode 100644 index 0000000..6013183 --- /dev/null +++ b/core-foundation-sys/src/url.rs @@ -0,0 +1,146 @@ +use base::{CFOptionFlags, CFIndex, CFAllocatorRef, Boolean, CFTypeID}; +use string::CFStringRef; + +#[repr(C)] +struct __CFURL; + +pub type CFURLRef = *const __CFURL; + +pub type CFURLBookmarkCreationOptions = CFOptionFlags; + +pub type CFURLPathStyle = CFIndex; + +/* typedef CF_ENUM(CFIndex, CFURLPathStyle) */ +pub const kCFURLPOSIXPathStyle: CFURLPathStyle = 0; +pub const kCFURLHFSPathStyle: CFURLPathStyle = 1; +pub const kCFURLWindowsPathStyle: CFURLPathStyle = 2; + +// static kCFURLBookmarkCreationPreferFileIDResolutionMask: CFURLBookmarkCreationOptions = +// (1 << 8) as u32; +// static kCFURLBookmarkCreationMinimalBookmarkMask: CFURLBookmarkCreationOptions = +// (1 << 9) as u32; +// static kCFURLBookmarkCreationSuitableForBookmarkFile: CFURLBookmarkCreationOptions = +// (1 << 10) as u32; +// static kCFURLBookmarkCreationWithSecurityScope: CFURLBookmarkCreationOptions = +// (1 << 11) as u32; +// static kCFURLBookmarkCreationSecurityScopeAllowOnlyReadAccess: CFURLBookmarkCreationOptions = +// (1 << 12) as u32; + +// TODO: there are a lot of missing keys and constants. Add if you are bored or need them. + +extern { + /* + * CFURL.h + */ + + /* Common File System Resource Keys */ + // static kCFURLAttributeModificationDateKey: CFStringRef; + // static kCFURLContentAccessDateKey: CFStringRef; + // static kCFURLContentModificationDateKey: CFStringRef; + // static kCFURLCreationDateKey: CFStringRef; + // static kCFURLCustomIconKey: CFStringRef; + // static kCFURLEffectiveIconKey: CFStringRef; + // static kCFURLFileResourceIdentifierKey: CFStringRef; + // static kCFURLFileSecurityKey: CFStringRef; + // static kCFURLHasHiddenExtensionKey: CFStringRef; + // static kCFURLIsDirectoryKey: CFStringRef; + // static kCFURLIsExecutableKey: CFStringRef; + // static kCFURLIsHiddenKey: CFStringRef; + // static kCFURLIsPackageKey: CFStringRef; + // static kCFURLIsReadableKey: CFStringRef; + // static kCFURLIsRegularFileKey: CFStringRef; + // static kCFURLIsSymbolicLinkKey: CFStringRef; + // static kCFURLIsSystemImmutableKey: CFStringRef; + // static kCFURLIsUserImmutableKey: CFStringRef; + // static kCFURLIsVolumeKey: CFStringRef; + // static kCFURLIsWritableKey: CFStringRef; + // static kCFURLLabelColorKey: CFStringRef; + // static kCFURLLabelNumberKey: CFStringRef; + // static kCFURLLinkCountKey: CFStringRef; + // static kCFURLLocalizedLabelKey: CFStringRef; + // static kCFURLLocalizedNameKey: CFStringRef; + // static kCFURLLocalizedTypeDescriptionKey: CFStringRef; + // static kCFURLNameKey: CFStringRef; + // static kCFURLParentDirectoryURLKey: CFStringRef; + // static kCFURLPreferredIOBlockSizeKey: CFStringRef; + // static kCFURLTypeIdentifierKey: CFStringRef; + // static kCFURLVolumeIdentifierKey: CFStringRef; + // static kCFURLVolumeURLKey: CFStringRef; + // static kCFURLIsExcludedFromBackupKey: CFStringRef; + // static kCFURLFileResourceTypeKey: CFStringRef; + + /* Creating a CFURL */ + //fn CFURLCopyAbsoluteURL + //fn CFURLCreateAbsoluteURLWithBytes + //fn CFURLCreateByResolvingBookmarkData + //fn CFURLCreateCopyAppendingPathComponent + //fn CFURLCreateCopyAppendingPathExtension + //fn CFURLCreateCopyDeletingLastPathComponent + //fn CFURLCreateCopyDeletingPathExtension + //fn CFURLCreateFilePathURL + //fn CFURLCreateFileReferenceURL + //fn CFURLCreateFromFileSystemRepresentation + //fn CFURLCreateFromFileSystemRepresentationRelativeToBase + //fn CFURLCreateFromFSRef + //fn CFURLCreateWithBytes + //fn CFURLCreateWithFileSystemPath + pub fn CFURLCreateWithFileSystemPath(allocator: CFAllocatorRef, filePath: CFStringRef, pathStyle: CFURLPathStyle, isDirectory: Boolean) -> CFURLRef; + //fn CFURLCreateWithFileSystemPathRelativeToBase + //fn CFURLCreateWithString(allocator: CFAllocatorRef, urlString: CFStringRef, + // baseURL: CFURLRef) -> CFURLRef; + + /* Accessing the Parts of a URL */ + //fn CFURLCanBeDecomposed + //fn CFURLCopyFileSystemPath + //fn CFURLCopyFragment + //fn CFURLCopyHostName + //fn CFURLCopyLastPathComponent + //fn CFURLCopyNetLocation + //fn CFURLCopyParameterString + //fn CFURLCopyPassword + //fn CFURLCopyPath + //fn CFURLCopyPathExtension + //fn CFURLCopyQueryString + //fn CFURLCopyResourceSpecifier + //fn CFURLCopyScheme + //fn CFURLCopyStrictPath + //fn CFURLCopyUserName + //fn CFURLGetPortNumber + //fn CFURLHasDirectoryPath + + /* Converting URLs to Other Representations */ + //fn CFURLCreateData(allocator: CFAllocatorRef, url: CFURLRef, + // encoding: CFStringEncoding, escapeWhitespace: bool) -> CFDataRef; + //fn CFURLCreateStringByAddingPercentEscapes + //fn CFURLCreateStringByReplacingPercentEscapes + //fn CFURLCreateStringByReplacingPercentEscapesUsingEncoding + //fn CFURLGetFileSystemRepresentation + //fn CFURLGetFSRef + pub fn CFURLGetString(anURL: CFURLRef) -> CFStringRef; + + /* Getting URL Properties */ + //fn CFURLGetBaseURL(anURL: CFURLRef) -> CFURLRef; + //fn CFURLGetBytes + //fn CFURLGetByteRangeForComponent + pub fn CFURLGetTypeID() -> CFTypeID; + //fn CFURLResourceIsReachable + + /* Getting and Setting File System Resource Properties */ + //fn CFURLClearResourcePropertyCache + //fn CFURLClearResourcePropertyCacheForKey + //fn CFURLCopyResourcePropertiesForKeys + //fn CFURLCopyResourcePropertyForKey + //fn CFURLCreateResourcePropertiesForKeysFromBookmarkData + //fn CFURLCreateResourcePropertyForKeyFromBookmarkData + //fn CFURLSetResourcePropertiesForKeys + //fn CFURLSetResourcePropertyForKey + //fn CFURLSetTemporaryResourcePropertyForKey + + /* Working with Bookmark Data */ + //fn CFURLCreateBookmarkData + //fn CFURLCreateBookmarkDataFromAliasRecord + //fn CFURLCreateBookmarkDataFromFile + //fn CFURLWriteBookmarkDataToFile + //fn CFURLStartAccessingSecurityScopedResource + //fn CFURLStopAccessingSecurityScopedResource +} diff --git a/core-foundation/src/url.rs b/core-foundation/src/url.rs index 4261e5a..3fba536 100644 --- a/core-foundation/src/url.rs +++ b/core-foundation/src/url.rs @@ -14,17 +14,11 @@ use base::{TCFType}; use string::{CFString}; -use core_foundation_sys::base::{CFAllocatorRef, CFIndex, CFRelease, CFOptionFlags}; -use core_foundation_sys::base::{Boolean, CFTypeID, kCFAllocatorDefault}; -use core_foundation_sys::string::CFStringRef; +use core_foundation_sys::base::{kCFAllocatorDefault, CFRelease}; +use core_foundation_sys::url::*; use std::fmt; use std::mem; -#[repr(C)] -struct __CFURL; - -pub type CFURLRef = *const __CFURL; - pub struct CFURL(CFURLRef); impl Drop for CFURL { @@ -62,147 +56,6 @@ impl CFURL { } } -type CFURLBookmarkCreationOptions = CFOptionFlags; - -pub type CFURLPathStyle = CFIndex; - -/* typedef CF_ENUM(CFIndex, CFURLPathStyle) */ -pub const kCFURLPOSIXPathStyle: CFURLPathStyle = 0; -pub const kCFURLHFSPathStyle: CFURLPathStyle = 1; -pub const kCFURLWindowsPathStyle: CFURLPathStyle = 2; - - -// static kCFURLBookmarkCreationPreferFileIDResolutionMask: CFURLBookmarkCreationOptions = -// (1 << 8) as u32; -// static kCFURLBookmarkCreationMinimalBookmarkMask: CFURLBookmarkCreationOptions = -// (1 << 9) as u32; -// static kCFURLBookmarkCreationSuitableForBookmarkFile: CFURLBookmarkCreationOptions = -// (1 << 10) as u32; -// static kCFURLBookmarkCreationWithSecurityScope: CFURLBookmarkCreationOptions = -// (1 << 11) as u32; -// static kCFURLBookmarkCreationSecurityScopeAllowOnlyReadAccess: CFURLBookmarkCreationOptions = -// (1 << 12) as u32; - -// TODO: there are a lot of missing keys and constants. Add if you are bored or need them. - -#[link(name = "CoreFoundation", kind = "framework")] -extern { - /* - * CFURL.h - */ - - /* Common File System Resource Keys */ - // static kCFURLAttributeModificationDateKey: CFStringRef; - // static kCFURLContentAccessDateKey: CFStringRef; - // static kCFURLContentModificationDateKey: CFStringRef; - // static kCFURLCreationDateKey: CFStringRef; - // static kCFURLCustomIconKey: CFStringRef; - // static kCFURLEffectiveIconKey: CFStringRef; - // static kCFURLFileResourceIdentifierKey: CFStringRef; - // static kCFURLFileSecurityKey: CFStringRef; - // static kCFURLHasHiddenExtensionKey: CFStringRef; - // static kCFURLIsDirectoryKey: CFStringRef; - // static kCFURLIsExecutableKey: CFStringRef; - // static kCFURLIsHiddenKey: CFStringRef; - // static kCFURLIsPackageKey: CFStringRef; - // static kCFURLIsReadableKey: CFStringRef; - // static kCFURLIsRegularFileKey: CFStringRef; - // static kCFURLIsSymbolicLinkKey: CFStringRef; - // static kCFURLIsSystemImmutableKey: CFStringRef; - // static kCFURLIsUserImmutableKey: CFStringRef; - // static kCFURLIsVolumeKey: CFStringRef; - // static kCFURLIsWritableKey: CFStringRef; - // static kCFURLLabelColorKey: CFStringRef; - // static kCFURLLabelNumberKey: CFStringRef; - // static kCFURLLinkCountKey: CFStringRef; - // static kCFURLLocalizedLabelKey: CFStringRef; - // static kCFURLLocalizedNameKey: CFStringRef; - // static kCFURLLocalizedTypeDescriptionKey: CFStringRef; - // static kCFURLNameKey: CFStringRef; - // static kCFURLParentDirectoryURLKey: CFStringRef; - // static kCFURLPreferredIOBlockSizeKey: CFStringRef; - // static kCFURLTypeIdentifierKey: CFStringRef; - // static kCFURLVolumeIdentifierKey: CFStringRef; - // static kCFURLVolumeURLKey: CFStringRef; - // static kCFURLIsExcludedFromBackupKey: CFStringRef; - // static kCFURLFileResourceTypeKey: CFStringRef; - - /* Creating a CFURL */ - //fn CFURLCopyAbsoluteURL - //fn CFURLCreateAbsoluteURLWithBytes - //fn CFURLCreateByResolvingBookmarkData - //fn CFURLCreateCopyAppendingPathComponent - //fn CFURLCreateCopyAppendingPathExtension - //fn CFURLCreateCopyDeletingLastPathComponent - //fn CFURLCreateCopyDeletingPathExtension - //fn CFURLCreateFilePathURL - //fn CFURLCreateFileReferenceURL - //fn CFURLCreateFromFileSystemRepresentation - //fn CFURLCreateFromFileSystemRepresentationRelativeToBase - //fn CFURLCreateFromFSRef - //fn CFURLCreateWithBytes - //fn CFURLCreateWithFileSystemPath - fn CFURLCreateWithFileSystemPath(allocator: CFAllocatorRef, filePath: CFStringRef, pathStyle: CFURLPathStyle, isDirectory: Boolean) -> CFURLRef; - //fn CFURLCreateWithFileSystemPathRelativeToBase - //fn CFURLCreateWithString(allocator: CFAllocatorRef, urlString: CFStringRef, - // baseURL: CFURLRef) -> CFURLRef; - - /* Accessing the Parts of a URL */ - //fn CFURLCanBeDecomposed - //fn CFURLCopyFileSystemPath - //fn CFURLCopyFragment - //fn CFURLCopyHostName - //fn CFURLCopyLastPathComponent - //fn CFURLCopyNetLocation - //fn CFURLCopyParameterString - //fn CFURLCopyPassword - //fn CFURLCopyPath - //fn CFURLCopyPathExtension - //fn CFURLCopyQueryString - //fn CFURLCopyResourceSpecifier - //fn CFURLCopyScheme - //fn CFURLCopyStrictPath - //fn CFURLCopyUserName - //fn CFURLGetPortNumber - //fn CFURLHasDirectoryPath - - /* Converting URLs to Other Representations */ - //fn CFURLCreateData(allocator: CFAllocatorRef, url: CFURLRef, - // encoding: CFStringEncoding, escapeWhitespace: bool) -> CFDataRef; - //fn CFURLCreateStringByAddingPercentEscapes - //fn CFURLCreateStringByReplacingPercentEscapes - //fn CFURLCreateStringByReplacingPercentEscapesUsingEncoding - //fn CFURLGetFileSystemRepresentation - //fn CFURLGetFSRef - fn CFURLGetString(anURL: CFURLRef) -> CFStringRef; - - /* Getting URL Properties */ - //fn CFURLGetBaseURL(anURL: CFURLRef) -> CFURLRef; - //fn CFURLGetBytes - //fn CFURLGetByteRangeForComponent - fn CFURLGetTypeID() -> CFTypeID; - //fn CFURLResourceIsReachable - - /* Getting and Setting File System Resource Properties */ - //fn CFURLClearResourcePropertyCache - //fn CFURLClearResourcePropertyCacheForKey - //fn CFURLCopyResourcePropertiesForKeys - //fn CFURLCopyResourcePropertyForKey - //fn CFURLCreateResourcePropertiesForKeysFromBookmarkData - //fn CFURLCreateResourcePropertyForKeyFromBookmarkData - //fn CFURLSetResourcePropertiesForKeys - //fn CFURLSetResourcePropertyForKey - //fn CFURLSetTemporaryResourcePropertyForKey - - /* Working with Bookmark Data */ - //fn CFURLCreateBookmarkData - //fn CFURLCreateBookmarkDataFromAliasRecord - //fn CFURLCreateBookmarkDataFromFile - //fn CFURLWriteBookmarkDataToFile - //fn CFURLStartAccessingSecurityScopedResource - //fn CFURLStopAccessingSecurityScopedResource -} - #[test] fn file_url_from_path() { let path = "/usr/local/foo/"; From 00dc99e36bf0a31e8f1a90576bb97b4b553812e2 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 25 Aug 2015 21:23:08 -0700 Subject: [PATCH 12/19] Add licenses to sys crate --- core-foundation-sys/build.rs | 9 +++++++++ core-foundation-sys/src/array.rs | 9 +++++++++ core-foundation-sys/src/base.rs | 9 +++++++++ core-foundation-sys/src/bundle.rs | 9 +++++++++ core-foundation-sys/src/date.rs | 2 +- core-foundation-sys/src/dictionary.rs | 9 +++++++++ core-foundation-sys/src/lib.rs | 9 +++++++++ core-foundation-sys/src/number.rs | 9 +++++++++ core-foundation-sys/src/runloop.rs | 9 +++++++++ core-foundation-sys/src/set.rs | 9 +++++++++ core-foundation-sys/src/string.rs | 9 +++++++++ core-foundation-sys/src/url.rs | 9 +++++++++ 12 files changed, 100 insertions(+), 1 deletion(-) diff --git a/core-foundation-sys/build.rs b/core-foundation-sys/build.rs index 94e6e93..a1a0ea1 100644 --- a/core-foundation-sys/build.rs +++ b/core-foundation-sys/build.rs @@ -1,3 +1,12 @@ +// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + fn main() { println!("cargo:rustc-link-lib=framework=CoreFoundation"); } diff --git a/core-foundation-sys/src/array.rs b/core-foundation-sys/src/array.rs index 0e982c6..9c38cac 100644 --- a/core-foundation-sys/src/array.rs +++ b/core-foundation-sys/src/array.rs @@ -1,3 +1,12 @@ +// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use libc::c_void; use base::{CFIndex, CFAllocatorRef, CFTypeID}; diff --git a/core-foundation-sys/src/base.rs b/core-foundation-sys/src/base.rs index a9c06d0..c3fbec3 100644 --- a/core-foundation-sys/src/base.rs +++ b/core-foundation-sys/src/base.rs @@ -1,3 +1,12 @@ +// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use libc::{c_uint, c_long, c_ulong, c_void}; pub type Boolean = u8; diff --git a/core-foundation-sys/src/bundle.rs b/core-foundation-sys/src/bundle.rs index 6df6723..0a8b48d 100644 --- a/core-foundation-sys/src/bundle.rs +++ b/core-foundation-sys/src/bundle.rs @@ -1,3 +1,12 @@ +// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use libc::c_void; use base::CFTypeID; diff --git a/core-foundation-sys/src/date.rs b/core-foundation-sys/src/date.rs index df1c818..81b3f58 100644 --- a/core-foundation-sys/src/date.rs +++ b/core-foundation-sys/src/date.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Servo Project Developers. See the COPYRIGHT +// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use libc::{c_void}; use base::{CFAllocatorRef, CFIndex, CFTypeID, Boolean}; diff --git a/core-foundation-sys/src/lib.rs b/core-foundation-sys/src/lib.rs index e47d5ac..9ad0e9c 100644 --- a/core-foundation-sys/src/lib.rs +++ b/core-foundation-sys/src/lib.rs @@ -1,3 +1,12 @@ +// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + #![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] extern crate libc; diff --git a/core-foundation-sys/src/number.rs b/core-foundation-sys/src/number.rs index 026a7b0..ce2bfc9 100644 --- a/core-foundation-sys/src/number.rs +++ b/core-foundation-sys/src/number.rs @@ -1,3 +1,12 @@ +// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use libc::c_void; use base::{CFAllocatorRef, CFTypeID}; diff --git a/core-foundation-sys/src/runloop.rs b/core-foundation-sys/src/runloop.rs index e0270e2..fc0e9c7 100644 --- a/core-foundation-sys/src/runloop.rs +++ b/core-foundation-sys/src/runloop.rs @@ -1,3 +1,12 @@ +// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use libc::c_void; use array::CFArrayRef; diff --git a/core-foundation-sys/src/set.rs b/core-foundation-sys/src/set.rs index 9ef4a24..9db6a37 100644 --- a/core-foundation-sys/src/set.rs +++ b/core-foundation-sys/src/set.rs @@ -1,3 +1,12 @@ +// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use libc::c_void; use base::{CFAllocatorRef, CFIndex, CFTypeID}; diff --git a/core-foundation-sys/src/string.rs b/core-foundation-sys/src/string.rs index 35975d0..cb7957b 100644 --- a/core-foundation-sys/src/string.rs +++ b/core-foundation-sys/src/string.rs @@ -1,3 +1,12 @@ +// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use libc::{c_char, c_void, c_ushort}; use base::{Boolean, CFOptionFlags, CFIndex, CFAllocatorRef, CFRange, CFTypeID}; diff --git a/core-foundation-sys/src/url.rs b/core-foundation-sys/src/url.rs index 6013183..abfe601 100644 --- a/core-foundation-sys/src/url.rs +++ b/core-foundation-sys/src/url.rs @@ -1,3 +1,12 @@ +// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use base::{CFOptionFlags, CFIndex, CFAllocatorRef, Boolean, CFTypeID}; use string::CFStringRef; From a3ce1d3ac30ee96992059e075ebdd73ee771987b Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 25 Aug 2015 21:31:41 -0700 Subject: [PATCH 13/19] Ensure back-compat --- core-foundation-sys/src/array.rs | 5 ++++- core-foundation-sys/src/base.rs | 10 ++++++++++ core-foundation-sys/src/bundle.rs | 5 ++++- core-foundation-sys/src/data.rs | 7 ++++--- core-foundation-sys/src/number.rs | 5 ++++- core-foundation-sys/src/string.rs | 9 ++++++--- core-foundation/src/array.rs | 2 +- core-foundation/src/base.rs | 2 +- core-foundation/src/boolean.rs | 2 +- core-foundation/src/bundle.rs | 2 +- core-foundation/src/data.rs | 2 +- core-foundation/src/dictionary.rs | 2 +- core-foundation/src/number.rs | 4 +--- core-foundation/src/runloop.rs | 2 +- core-foundation/src/set.rs | 2 +- core-foundation/src/string.rs | 3 +-- core-foundation/src/url.rs | 3 +-- 17 files changed, 43 insertions(+), 24 deletions(-) diff --git a/core-foundation-sys/src/array.rs b/core-foundation-sys/src/array.rs index 9c38cac..8fc5f69 100644 --- a/core-foundation-sys/src/array.rs +++ b/core-foundation-sys/src/array.rs @@ -33,7 +33,10 @@ pub struct CFArrayCallBacks { pub equal: CFArrayEqualCallBack, } -pub type CFArrayRef = *const c_void; +#[repr(C)] +struct __CFArray; + +pub type CFArrayRef = *const __CFArray; extern { /* diff --git a/core-foundation-sys/src/base.rs b/core-foundation-sys/src/base.rs index c3fbec3..89efe52 100644 --- a/core-foundation-sys/src/base.rs +++ b/core-foundation-sys/src/base.rs @@ -26,6 +26,16 @@ pub struct CFRange { pub length: CFIndex } +// for back-compat +impl CFRange { + pub fn init(location: CFIndex, length: CFIndex) -> CFRange { + CFRange { + location: location, + length: length, + } + } +} + extern { /* * CFBase.h diff --git a/core-foundation-sys/src/bundle.rs b/core-foundation-sys/src/bundle.rs index 0a8b48d..67edbd6 100644 --- a/core-foundation-sys/src/bundle.rs +++ b/core-foundation-sys/src/bundle.rs @@ -12,7 +12,10 @@ use libc::c_void; use base::CFTypeID; use string::CFStringRef; -pub type CFBundleRef = *const c_void; +#[repr(C)] +struct __CFBundle; + +pub type CFBundleRef = *const __CFBundle; extern { /* diff --git a/core-foundation-sys/src/data.rs b/core-foundation-sys/src/data.rs index a62da4b..5b47a62 100644 --- a/core-foundation-sys/src/data.rs +++ b/core-foundation-sys/src/data.rs @@ -1,8 +1,9 @@ -use libc::c_void; - use base::{CFAllocatorRef, CFTypeID, CFIndex}; -pub type CFDataRef = *const c_void; +#[repr(C)] +struct __CFData; + +pub type CFDataRef = *const __CFData; extern { /* diff --git a/core-foundation-sys/src/number.rs b/core-foundation-sys/src/number.rs index ce2bfc9..ab1184e 100644 --- a/core-foundation-sys/src/number.rs +++ b/core-foundation-sys/src/number.rs @@ -11,7 +11,10 @@ use libc::c_void; use base::{CFAllocatorRef, CFTypeID}; -pub type CFBooleanRef = *const c_void; +#[repr(C)] +struct __CFBoolean; + +pub type CFBooleanRef = *const __CFBoolean; pub type CFNumberType = u32; diff --git a/core-foundation-sys/src/string.rs b/core-foundation-sys/src/string.rs index cb7957b..ed10a92 100644 --- a/core-foundation-sys/src/string.rs +++ b/core-foundation-sys/src/string.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use libc::{c_char, c_void, c_ushort}; +use libc::{c_char, c_ushort}; use base::{Boolean, CFOptionFlags, CFIndex, CFAllocatorRef, CFRange, CFTypeID}; @@ -49,7 +49,7 @@ pub static kCFStringEncodingUTF8: CFStringEncoding = 0x08000100; // CFStringEncodingExt.h -type CFStringEncodings = CFIndex; +pub type CFStringEncodings = CFIndex; // External encodings, except those defined above. // Defined above: kCFStringEncodingMacRoman = 0 @@ -187,7 +187,10 @@ type CFStringEncodings = CFIndex; //static kCFStringEncodingUTF7_IMAP: CFStringEncoding = 0x0A10; //static kCFStringEncodingShiftJIS_X0213_00: CFStringEncoding = 0x0628; /* Deprecated */ -pub type CFStringRef = *const c_void; +#[repr(C)] +struct __CFString; + +pub type CFStringRef = *const __CFString; extern { /* diff --git a/core-foundation/src/array.rs b/core-foundation/src/array.rs index b077552..757725a 100644 --- a/core-foundation/src/array.rs +++ b/core-foundation/src/array.rs @@ -9,7 +9,7 @@ //! Heterogeneous immutable arrays. -use core_foundation_sys::array::*; +pub use core_foundation_sys::array::*; use core_foundation_sys::base::{CFIndex, CFRelease}; use core_foundation_sys::base::{CFTypeRef, kCFAllocatorDefault}; use libc::c_void; diff --git a/core-foundation/src/base.rs b/core-foundation/src/base.rs index 60fa4e1..3f4bcea 100644 --- a/core-foundation/src/base.rs +++ b/core-foundation/src/base.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core_foundation_sys::base::*; +pub use core_foundation_sys::base::*; pub trait CFIndexConvertible { /// Always use this method to construct a `CFIndex` value. It performs bounds checking to diff --git a/core-foundation/src/boolean.rs b/core-foundation/src/boolean.rs index b8d4288..20f4630 100644 --- a/core-foundation/src/boolean.rs +++ b/core-foundation/src/boolean.rs @@ -10,7 +10,7 @@ //! A Boolean type. use core_foundation_sys::base::{CFRelease}; -use core_foundation_sys::number::{CFBooleanRef, CFBooleanGetTypeID, kCFBooleanTrue, kCFBooleanFalse}; +pub use core_foundation_sys::number::{CFBooleanRef, CFBooleanGetTypeID, kCFBooleanTrue, kCFBooleanFalse}; use std::mem; use base::TCFType; diff --git a/core-foundation/src/bundle.rs b/core-foundation/src/bundle.rs index 7a25c77..2f42b26 100644 --- a/core-foundation/src/bundle.rs +++ b/core-foundation/src/bundle.rs @@ -9,8 +9,8 @@ //! Core Foundation Bundle Type +pub use core_foundation_sys::bundle::*; use core_foundation_sys::base::CFRelease; -use core_foundation_sys::bundle::{CFBundleRef, CFBundleGetTypeID}; use std::mem; use base::{TCFType}; diff --git a/core-foundation/src/data.rs b/core-foundation/src/data.rs index 4d6826b..9b6a65f 100644 --- a/core-foundation/src/data.rs +++ b/core-foundation/src/data.rs @@ -9,9 +9,9 @@ //! Core Foundation byte buffers. +pub use core_foundation_sys::data::*; use core_foundation_sys::base::{CFIndex, CFRelease}; use core_foundation_sys::base::{kCFAllocatorDefault}; -use core_foundation_sys::data::*; use std::mem; use std::ops::Deref; use std::slice; diff --git a/core-foundation/src/dictionary.rs b/core-foundation/src/dictionary.rs index b08bdc1..9540fba 100644 --- a/core-foundation/src/dictionary.rs +++ b/core-foundation/src/dictionary.rs @@ -9,9 +9,9 @@ //! Dictionaries of key-value pairs. +pub use core_foundation_sys::dictionary::*; use core_foundation_sys::base::CFRelease; use core_foundation_sys::base::{CFTypeRef, kCFAllocatorDefault}; -use core_foundation_sys::dictionary::*; use libc::c_void; use std::mem; use std::ptr; diff --git a/core-foundation/src/number.rs b/core-foundation/src/number.rs index 22869e8..771c75e 100644 --- a/core-foundation/src/number.rs +++ b/core-foundation/src/number.rs @@ -9,10 +9,8 @@ //! Immutable numbers. -#![allow(non_upper_case_globals)] - use core_foundation_sys::base::{CFRelease, kCFAllocatorDefault}; -use core_foundation_sys::number::*; +pub use core_foundation_sys::number::*; use std::mem; use base::{TCFType}; diff --git a/core-foundation/src/runloop.rs b/core-foundation/src/runloop.rs index 23b8f68..423ecd2 100644 --- a/core-foundation/src/runloop.rs +++ b/core-foundation/src/runloop.rs @@ -9,11 +9,11 @@ #![allow(non_upper_case_globals)] +pub use core_foundation_sys::runloop::*; use core_foundation_sys::base::{CFIndex, CFRelease}; use core_foundation_sys::base::{kCFAllocatorDefault, CFOptionFlags}; use core_foundation_sys::string::CFStringRef; use core_foundation_sys::date::{CFAbsoluteTime, CFTimeInterval}; -use core_foundation_sys::runloop::*; use std::mem; use base::{TCFType}; diff --git a/core-foundation/src/set.rs b/core-foundation/src/set.rs index 00f9190..8224a20 100644 --- a/core-foundation/src/set.rs +++ b/core-foundation/src/set.rs @@ -9,9 +9,9 @@ //! An immutable bag of elements. +pub use core_foundation_sys::set::*; use core_foundation_sys::base::CFRelease; use core_foundation_sys::base::{CFTypeRef, kCFAllocatorDefault}; -use core_foundation_sys::set::*; use base::{CFIndexConvertible, TCFType}; diff --git a/core-foundation/src/string.rs b/core-foundation/src/string.rs index 10ad735..37f06b4 100644 --- a/core-foundation/src/string.rs +++ b/core-foundation/src/string.rs @@ -9,13 +9,12 @@ //! Immutable strings. -#![allow(non_upper_case_globals)] +pub use core_foundation_sys::string::*; use base::{CFIndexConvertible, TCFType}; use core_foundation_sys::base::{Boolean, CFIndex, CFRange, CFRelease}; use core_foundation_sys::base::{kCFAllocatorDefault, kCFAllocatorNull}; -use core_foundation_sys::string::*; use std::fmt; use std::str::{self, FromStr}; use std::mem; diff --git a/core-foundation/src/url.rs b/core-foundation/src/url.rs index 3fba536..47f44cb 100644 --- a/core-foundation/src/url.rs +++ b/core-foundation/src/url.rs @@ -9,13 +9,12 @@ //! A URL type for Core Foundation. -#![allow(non_upper_case_globals)] +pub use core_foundation_sys::url::*; use base::{TCFType}; use string::{CFString}; use core_foundation_sys::base::{kCFAllocatorDefault, CFRelease}; -use core_foundation_sys::url::*; use std::fmt; use std::mem; From e67072221fb9dd1e21f590601c961fb4d216d2c5 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 25 Aug 2015 21:33:32 -0700 Subject: [PATCH 14/19] Fix tests --- core-foundation/src/runloop.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-foundation/src/runloop.rs b/core-foundation/src/runloop.rs index 423ecd2..ccf7b73 100644 --- a/core-foundation/src/runloop.rs +++ b/core-foundation/src/runloop.rs @@ -108,7 +108,7 @@ impl CFRunLoopTimer { #[cfg(test)] mod test { use super::*; - use date::{CFAbsoluteTime, CFAbsoluteTimeGetCurrent}; + use core_foundation_sys::date::{CFAbsoluteTime, CFAbsoluteTimeGetCurrent}; use std::mem; use libc::c_void; From 74d4ac7869e12a560c6c65c5408adab76f709b2b Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 25 Aug 2015 21:36:29 -0700 Subject: [PATCH 15/19] Fix travis build --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index d5979d3..bfb6c36 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,8 @@ language: rust rust: nightly os: osx + +script: + - cd core-foundation + - cargo build --verbose + - cargo test --verbose From 1928256b8621b2a2303a4333c5650ebd2539b909 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 25 Aug 2015 21:40:02 -0700 Subject: [PATCH 16/19] Suppress improper_ctypes warnings from zero sized pointer targets --- core-foundation-sys/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core-foundation-sys/src/lib.rs b/core-foundation-sys/src/lib.rs index 9ad0e9c..1561b94 100644 --- a/core-foundation-sys/src/lib.rs +++ b/core-foundation-sys/src/lib.rs @@ -6,8 +6,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. - -#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals, improper_ctypes)] extern crate libc; From 83a0c758bc5e235fe0965dcb4970e11bc37b033a Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 25 Aug 2015 22:02:11 -0700 Subject: [PATCH 17/19] Add OSStatus to base --- core-foundation-sys/src/base.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/core-foundation-sys/src/base.rs b/core-foundation-sys/src/base.rs index 89efe52..6cf8cb6 100644 --- a/core-foundation-sys/src/base.rs +++ b/core-foundation-sys/src/base.rs @@ -18,6 +18,7 @@ pub type CFHashCode = c_ulong; pub type CFTypeID = c_ulong; pub type CFTypeRef = *const c_void; pub type CFOptionFlags = u32; +pub type OSStatus = i32; #[repr(C)] #[derive(Clone, Copy)] From d9a3185edd0da468622b153ac94f9448ddd0e88d Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 5 Sep 2015 21:46:26 -0700 Subject: [PATCH 18/19] Reexport date for back compat --- core-foundation/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/core-foundation/src/lib.rs b/core-foundation/src/lib.rs index f8541e1..39b533a 100644 --- a/core-foundation/src/lib.rs +++ b/core-foundation/src/lib.rs @@ -52,6 +52,7 @@ pub mod array; pub mod base; pub mod boolean; pub mod data; +pub use core_foundation_sys::date; // back compat pub mod dictionary; pub mod number; pub mod set; From db4499d7b40c1c216e3fa3b71f3aef8ee3f47d4e Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 19 Sep 2015 19:16:18 -0700 Subject: [PATCH 19/19] Fix new ctype lint in 1.3 --- core-foundation-sys/src/array.rs | 2 +- core-foundation-sys/src/bundle.rs | 2 +- core-foundation-sys/src/data.rs | 4 +++- core-foundation-sys/src/dictionary.rs | 2 +- core-foundation-sys/src/number.rs | 2 +- core-foundation-sys/src/runloop.rs | 6 +++--- core-foundation-sys/src/set.rs | 2 +- core-foundation-sys/src/string.rs | 4 ++-- core-foundation-sys/src/url.rs | 3 ++- 9 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core-foundation-sys/src/array.rs b/core-foundation-sys/src/array.rs index 8fc5f69..910030d 100644 --- a/core-foundation-sys/src/array.rs +++ b/core-foundation-sys/src/array.rs @@ -34,7 +34,7 @@ pub struct CFArrayCallBacks { } #[repr(C)] -struct __CFArray; +struct __CFArray(c_void); pub type CFArrayRef = *const __CFArray; diff --git a/core-foundation-sys/src/bundle.rs b/core-foundation-sys/src/bundle.rs index 67edbd6..0999a83 100644 --- a/core-foundation-sys/src/bundle.rs +++ b/core-foundation-sys/src/bundle.rs @@ -13,7 +13,7 @@ use base::CFTypeID; use string::CFStringRef; #[repr(C)] -struct __CFBundle; +struct __CFBundle(c_void); pub type CFBundleRef = *const __CFBundle; diff --git a/core-foundation-sys/src/data.rs b/core-foundation-sys/src/data.rs index 5b47a62..0e333b5 100644 --- a/core-foundation-sys/src/data.rs +++ b/core-foundation-sys/src/data.rs @@ -1,7 +1,9 @@ +use libc::c_void; + use base::{CFAllocatorRef, CFTypeID, CFIndex}; #[repr(C)] -struct __CFData; +struct __CFData(c_void); pub type CFDataRef = *const __CFData; diff --git a/core-foundation-sys/src/dictionary.rs b/core-foundation-sys/src/dictionary.rs index bd2e8ce..daf22c7 100644 --- a/core-foundation-sys/src/dictionary.rs +++ b/core-foundation-sys/src/dictionary.rs @@ -42,7 +42,7 @@ pub struct CFDictionaryValueCallBacks { } #[repr(C)] -struct __CFDictionary; +struct __CFDictionary(c_void); pub type CFDictionaryRef = *const __CFDictionary; diff --git a/core-foundation-sys/src/number.rs b/core-foundation-sys/src/number.rs index ab1184e..31b91a0 100644 --- a/core-foundation-sys/src/number.rs +++ b/core-foundation-sys/src/number.rs @@ -12,7 +12,7 @@ use libc::c_void; use base::{CFAllocatorRef, CFTypeID}; #[repr(C)] -struct __CFBoolean; +struct __CFBoolean(c_void); pub type CFBooleanRef = *const __CFBoolean; diff --git a/core-foundation-sys/src/runloop.rs b/core-foundation-sys/src/runloop.rs index fc0e9c7..69d7579 100644 --- a/core-foundation-sys/src/runloop.rs +++ b/core-foundation-sys/src/runloop.rs @@ -15,17 +15,17 @@ use date::{CFAbsoluteTime, CFTimeInterval}; use string::CFStringRef; #[repr(C)] -struct __CFRunLoop; +struct __CFRunLoop(c_void); pub type CFRunLoopRef = *const __CFRunLoop; #[repr(C)] -struct __CFRunLoopSource; +struct __CFRunLoopSource(c_void); pub type CFRunLoopSourceRef = *const __CFRunLoopSource; #[repr(C)] -struct __CFRunLoopObserver; +struct __CFRunLoopObserver(c_void); pub type CFRunLoopObserverRef = *const __CFRunLoopObserver; diff --git a/core-foundation-sys/src/set.rs b/core-foundation-sys/src/set.rs index 9db6a37..e473da1 100644 --- a/core-foundation-sys/src/set.rs +++ b/core-foundation-sys/src/set.rs @@ -29,7 +29,7 @@ pub struct CFSetCallBacks { } #[repr(C)] -struct __CFSet; +struct __CFSet(c_void); pub type CFSetRef = *const __CFSet; diff --git a/core-foundation-sys/src/string.rs b/core-foundation-sys/src/string.rs index ed10a92..76655da 100644 --- a/core-foundation-sys/src/string.rs +++ b/core-foundation-sys/src/string.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use libc::{c_char, c_ushort}; +use libc::{c_char, c_ushort, c_void}; use base::{Boolean, CFOptionFlags, CFIndex, CFAllocatorRef, CFRange, CFTypeID}; @@ -188,7 +188,7 @@ pub type CFStringEncodings = CFIndex; //static kCFStringEncodingShiftJIS_X0213_00: CFStringEncoding = 0x0628; /* Deprecated */ #[repr(C)] -struct __CFString; +struct __CFString(c_void); pub type CFStringRef = *const __CFString; diff --git a/core-foundation-sys/src/url.rs b/core-foundation-sys/src/url.rs index abfe601..53fc456 100644 --- a/core-foundation-sys/src/url.rs +++ b/core-foundation-sys/src/url.rs @@ -6,12 +6,13 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. +use libc::c_void; use base::{CFOptionFlags, CFIndex, CFAllocatorRef, Boolean, CFTypeID}; use string::CFStringRef; #[repr(C)] -struct __CFURL; +struct __CFURL(c_void); pub type CFURLRef = *const __CFURL;