Start splitting out a separate sys package

Moved array and base so far
This commit is contained in:
Steven Fackler
2015-08-24 23:08:37 -07:00
parent 93cd6c6639
commit 3f725f97eb
19 changed files with 175 additions and 172 deletions
+2 -2
View File
@@ -1,3 +1,3 @@
/Cargo.lock Cargo.lock
/target target/
+13
View File
@@ -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"
+3
View File
@@ -0,0 +1,3 @@
fn main() {
println!("cargo:rustc-link-lib=framework=CoreFoundation");
}
+48
View File
@@ -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;
}
+54
View File
@@ -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.
}
+6
View File
@@ -0,0 +1,6 @@
#![allow(non_snake_case, non_camel_case_types)]
extern crate libc;
pub mod array;
pub mod base;
+1
View File
@@ -9,3 +9,4 @@ license = "MIT / Apache-2.0"
[dependencies] [dependencies]
libc = "0.1" libc = "0.1"
core-foundation-sys = { path = "../core-foundation-sys" }
+4 -52
View File
@@ -9,39 +9,13 @@
//! Heterogeneous immutable arrays. //! Heterogeneous immutable arrays.
use base::{CFAllocatorRef, CFIndex, CFIndexConvertible, CFRelease}; use core_foundation_sys::array::*;
use base::{CFTypeID, CFTypeRef, TCFType}; use core_foundation_sys::base::{CFIndex, CFRelease};
use base::{kCFAllocatorDefault}; use core_foundation_sys::base::{CFTypeRef, kCFAllocatorDefault};
use libc::c_void; use libc::c_void;
use std::mem; use std::mem;
/// FIXME(pcwalton): This is wrong. use base::{CFIndexConvertible, TCFType};
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;
/// A heterogeneous immutable array. /// A heterogeneous immutable array.
pub struct CFArray(CFArrayRef); 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] #[test]
fn should_box_and_unbox() { fn should_box_and_unbox() {
use number::{CFNumber, number}; use number::{CFNumber, number};
+1 -83
View File
@@ -7,14 +7,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use libc::{c_long, c_ulong, c_uint}; use core_foundation_sys::base::*;
pub type Boolean = u8;
pub type CFIndex = c_long;
#[allow(non_camel_case_types)]
pub type mach_port_t = c_uint;
pub trait CFIndexConvertible { pub trait CFIndexConvertible {
/// Always use this method to construct a `CFIndex` value. It performs bounds checking to /// 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. /// Superclass of all Core Foundation objects.
pub struct CFType(CFTypeRef); pub struct CFType(CFTypeRef);
@@ -185,40 +140,3 @@ impl TCFType<CFTypeRef> for CFType {
true 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.
}
+3 -1
View File
@@ -9,9 +9,11 @@
//! A Boolean type. //! A Boolean type.
use base::{CFRelease, CFTypeID, TCFType}; use core_foundation_sys::base::{CFRelease, CFTypeID};
use std::mem; use std::mem;
use base::TCFType;
pub type Boolean = u32; pub type Boolean = u32;
#[repr(C)] #[repr(C)]
+2 -1
View File
@@ -9,9 +9,10 @@
//! Core Foundation Bundle Type //! Core Foundation Bundle Type
use base::{CFRelease, CFTypeID, TCFType}; use core_foundation_sys::base::{CFRelease, CFTypeID};
use std::mem; use std::mem;
use base::{TCFType};
use string::CFStringRef; use string::CFStringRef;
use libc::c_void; use libc::c_void;
+4 -3
View File
@@ -9,13 +9,14 @@
//! Core Foundation byte buffers. //! Core Foundation byte buffers.
use base::{CFAllocatorRef, CFIndex, CFIndexConvertible, CFRelease}; use core_foundation_sys::base::{CFAllocatorRef, CFIndex, CFRelease};
use base::{CFTypeID, TCFType, kCFAllocatorDefault}; use core_foundation_sys::base::{CFTypeID, kCFAllocatorDefault};
use std::mem; use std::mem;
use std::ops::Deref; use std::ops::Deref;
use std::slice; use std::slice;
use base::{CFIndexConvertible, TCFType};
#[repr(C)] #[repr(C)]
struct __CFData; struct __CFData;
+4 -3
View File
@@ -9,13 +9,14 @@
//! Dictionaries of key-value pairs. //! Dictionaries of key-value pairs.
use base::{Boolean, CFAllocatorRef, CFIndex, CFIndexConvertible, CFRelease}; use core_foundation_sys::base::{Boolean, CFAllocatorRef, CFIndex, CFRelease};
use base::{CFType, CFTypeID, CFTypeRef, TCFType, kCFAllocatorDefault}; use core_foundation_sys::base::{CFTypeID, CFTypeRef, kCFAllocatorDefault};
use libc::c_void; use libc::c_void;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use base::{CFType, CFIndexConvertible, TCFType};
pub type CFDictionaryApplierFunction = *const u8; pub type CFDictionaryApplierFunction = *const u8;
pub type CFDictionaryCopyDescriptionCallBack = *const u8; pub type CFDictionaryCopyDescriptionCallBack = *const u8;
pub type CFDictionaryEqualCallBack = *const u8; pub type CFDictionaryEqualCallBack = *const u8;
+4 -7
View File
@@ -6,12 +6,9 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![crate_name = "core_foundation"]
#![crate_type = "rlib"]
#![allow(non_snake_case)] #![allow(non_snake_case)]
extern crate core_foundation_sys;
extern crate libc; extern crate libc;
#[macro_export] #[macro_export]
@@ -25,12 +22,12 @@ macro_rules! impl_TCFType {
#[inline] #[inline]
unsafe fn wrap_under_get_rule(reference: $raw) -> $ty { 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) $crate::base::TCFType::wrap_under_create_rule(reference)
} }
#[inline] #[inline]
fn as_CFTypeRef(&self) -> $crate::base::CFTypeRef { fn as_CFTypeRef(&self) -> ::core_foundation_sys::base::CFTypeRef {
unsafe { unsafe {
mem::transmute(self.as_concrete_TypeRef()) mem::transmute(self.as_concrete_TypeRef())
} }
@@ -42,7 +39,7 @@ macro_rules! impl_TCFType {
} }
#[inline] #[inline]
fn type_id() -> $crate::base::CFTypeID { fn type_id() -> ::core_foundation_sys::base::CFTypeID {
unsafe { unsafe {
$ty_id() $ty_id()
} }
+4 -3
View File
@@ -11,12 +11,13 @@
#![allow(non_upper_case_globals)] #![allow(non_upper_case_globals)]
use base::{CFAllocatorRef, CFRelease, CFTypeID}; use core_foundation_sys::base::{CFAllocatorRef, CFRelease, CFTypeID};
use base::{TCFType, kCFAllocatorDefault}; use core_foundation_sys::base::{kCFAllocatorDefault};
use libc::c_void; use libc::c_void;
use std::mem; use std::mem;
use base::{TCFType};
pub type CFNumberType = u32; pub type CFNumberType = u32;
// members of enum CFNumberType // members of enum CFNumberType
+9 -7
View File
@@ -9,16 +9,18 @@
#![allow(non_upper_case_globals)] #![allow(non_upper_case_globals)]
use base::{CFAllocatorRef, CFIndex, CFOptionFlags, CFRelease};
use base::{CFTypeID, TCFType, CFHashCode, mach_port_t}; use core_foundation_sys::base::{CFAllocatorRef, CFIndex, CFRelease};
use base::{kCFAllocatorDefault}; use core_foundation_sys::base::{CFTypeID, CFHashCode, mach_port_t};
use base::{Boolean}; use core_foundation_sys::base::{kCFAllocatorDefault, Boolean, CFOptionFlags};
use array::{CFArrayRef}; use core_foundation_sys::array::{CFArrayRef};
use string::{CFString, CFStringRef};
use date::{CFAbsoluteTime, CFTimeInterval};
use libc::c_void; use libc::c_void;
use std::mem; use std::mem;
use base::{TCFType};
use string::{CFString, CFStringRef};
use date::{CFAbsoluteTime, CFTimeInterval};
pub struct CFRunLoop(CFRunLoopRef); pub struct CFRunLoop(CFRunLoopRef);
impl Drop for CFRunLoop { impl Drop for CFRunLoop {
+4 -2
View File
@@ -9,8 +9,10 @@
//! An immutable bag of elements. //! An immutable bag of elements.
use base::{CFAllocatorRef, CFIndex, CFIndexConvertible, CFRelease}; use core_foundation_sys::base::{CFAllocatorRef, CFIndex, CFRelease};
use base::{CFTypeID, CFTypeRef, TCFType, kCFAllocatorDefault}; use core_foundation_sys::base::{CFTypeID, CFTypeRef, kCFAllocatorDefault};
use base::{CFIndexConvertible, TCFType};
use libc::c_void; use libc::c_void;
use std::mem; use std::mem;
+6 -5
View File
@@ -11,10 +11,11 @@
#![allow(non_upper_case_globals)] #![allow(non_upper_case_globals)]
use base::{Boolean, CFAllocatorRef, CFIndex, CFIndexConvertible, CFOptionFlags, CFRange}; use base::{CFIndexConvertible, TCFType};
use base::{CFRelease, CFTypeID, TCFType};
use base::{kCFAllocatorDefault, kCFAllocatorNull};
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 libc;
use std::ffi::CStr; use std::ffi::CStr;
use std::fmt; use std::fmt;
@@ -250,7 +251,7 @@ impl fmt::Display for CFString {
// First, ask how big the buffer ought to be. // First, ask how big the buffer ought to be.
let mut bytes_required: CFIndex = 0; let mut bytes_required: CFIndex = 0;
CFStringGetBytes(self.0, CFStringGetBytes(self.0,
CFRange::init(0, char_len), CFRange { location: 0, length: char_len },
kCFStringEncodingUTF8, kCFStringEncodingUTF8,
0, 0,
false as Boolean, false as Boolean,
@@ -264,7 +265,7 @@ impl fmt::Display for CFString {
let mut bytes_used: CFIndex = 0; let mut bytes_used: CFIndex = 0;
let chars_written = CFStringGetBytes(self.0, let chars_written = CFStringGetBytes(self.0,
CFRange::init(0, char_len), CFRange { location: 0, length: char_len },
kCFStringEncodingUTF8, kCFStringEncodingUTF8,
0, 0,
false as Boolean, false as Boolean,
+3 -3
View File
@@ -11,11 +11,11 @@
#![allow(non_upper_case_globals)] #![allow(non_upper_case_globals)]
use base::{CFAllocatorRef, CFIndex, CFOptionFlags, CFRelease}; use base::{TCFType};
use base::{Boolean, CFTypeID, TCFType};
use base::{kCFAllocatorDefault};
use string::{CFString, CFStringRef}; 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::fmt;
use std::mem; use std::mem;