Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split a -sys crate out #68

Merged
merged 19 commits into from Oct 15, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Start splitting out a separate sys package

Moved array and base so far
  • Loading branch information
sfackler committed Sep 6, 2015
commit 3f725f97eb500aad7697b25e2ab2a40739428b36
@@ -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;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.