Start splitting out a separate sys package
Moved array and base so far
This commit is contained in:
+2
-2
@@ -1,3 +1,3 @@
|
||||
/Cargo.lock
|
||||
/target
|
||||
Cargo.lock
|
||||
target/
|
||||
|
||||
|
||||
@@ -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"
|
||||
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("cargo:rustc-link-lib=framework=CoreFoundation");
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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.
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#![allow(non_snake_case, non_camel_case_types)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
pub mod array;
|
||||
pub mod base;
|
||||
@@ -9,3 +9,4 @@ license = "MIT / Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
libc = "0.1"
|
||||
core-foundation-sys = { path = "../core-foundation-sys" }
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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<CFTypeRef> 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.
|
||||
}
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -6,12 +6,9 @@
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user