1 // Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 use std
::cmp
::Ordering
;
11 use std
::os
::raw
::{c_uint, c_void, c_int}
;
12 use string
::CFStringRef
;
14 pub type Boolean
= u8;
15 pub type mach_port_t
= c_uint
;
16 pub type CFAllocatorRef
= *const c_void
;
17 pub type CFNullRef
= *const c_void
;
18 pub type CFTypeRef
= *const c_void
;
19 pub type OSStatus
= i32;
20 pub type SInt32
= c_int
;
21 pub type CFTypeID
= usize;
22 pub type CFOptionFlags
= usize;
23 pub type CFHashCode
= usize;
24 pub type CFIndex
= isize;
27 #[derive(Clone, Copy, Debug, PartialEq)]
28 pub enum CFComparisonResult
{
34 impl Into
<Ordering
> for CFComparisonResult
{
35 fn into(self) -> Ordering
{
37 CFComparisonResult
::LessThan
=> Ordering
::Less
,
38 CFComparisonResult
::EqualTo
=> Ordering
::Equal
,
39 CFComparisonResult
::GreaterThan
=> Ordering
::Greater
45 #[derive(Clone, Copy)]
47 pub location
: CFIndex
,
53 pub fn init(location
: CFIndex
, length
: CFIndex
) -> CFRange
{
61 pub type CFAllocatorRetainCallBack
= extern "C" fn(info
: *mut c_void
) -> *mut c_void
;
62 pub type CFAllocatorReleaseCallBack
= extern "C" fn(info
: *mut c_void
);
63 pub type CFAllocatorCopyDescriptionCallBack
= extern "C" fn(info
: *mut c_void
) -> CFStringRef
;
64 pub type CFAllocatorAllocateCallBack
= extern "C" fn(allocSize
: CFIndex
, hint
: CFOptionFlags
, info
: *mut c_void
) -> *mut c_void
;
65 pub type CFAllocatorReallocateCallBack
= extern "C" fn(ptr
: *mut c_void
, newsize
: CFIndex
, hint
: CFOptionFlags
, info
: *mut c_void
) -> *mut c_void
;
66 pub type CFAllocatorDeallocateCallBack
= extern "C" fn(ptr
: *mut c_void
, info
: *mut c_void
);
67 pub type CFAllocatorPreferredSizeCallBack
= extern "C" fn(size
: CFIndex
, hint
: CFOptionFlags
, info
: *mut c_void
) -> CFIndex
;
70 #[derive(Clone, Copy)]
71 pub struct CFAllocatorContext
{
73 pub info
: *mut c_void
,
74 pub retain
: Option
<CFAllocatorRetainCallBack
>,
75 pub release
: Option
<CFAllocatorReleaseCallBack
>,
76 pub copyDescription
: Option
<CFAllocatorCopyDescriptionCallBack
>,
77 pub allocate
: Option
<CFAllocatorAllocateCallBack
>,
78 pub reallocate
: Option
<CFAllocatorReallocateCallBack
>,
79 pub deallocate
: Option
<CFAllocatorDeallocateCallBack
>,
80 pub preferredSize
: Option
<CFAllocatorPreferredSizeCallBack
>
83 /// Trait for all types which are Core Foundation reference types.
84 pub trait TCFTypeRef
{
85 fn as_void_ptr(&self) -> *const c_void
;
87 unsafe fn from_void_ptr(ptr
: *const c_void
) -> Self;
90 impl<T
> TCFTypeRef
for *const T
{
91 fn as_void_ptr(&self) -> *const c_void
{
92 (*self) as *const c_void
95 unsafe fn from_void_ptr(ptr
: *const c_void
) -> Self {
100 impl<T
> TCFTypeRef
for *mut T
{
101 fn as_void_ptr(&self) -> *const c_void
{
102 (*self) as *const T
as *const c_void
105 unsafe fn from_void_ptr(ptr
: *const c_void
) -> Self {
106 ptr
as *const T
as *mut T
110 /// Constant used by some functions to indicate failed searches.
111 pub static kCFNotFound
: CFIndex
= -1;
118 /* CFAllocator Reference */
120 pub static kCFAllocatorDefault
: CFAllocatorRef
;
121 pub static kCFAllocatorSystemDefault
: CFAllocatorRef
;
122 pub static kCFAllocatorMalloc
: CFAllocatorRef
;
123 pub static kCFAllocatorMallocZone
: CFAllocatorRef
;
124 pub static kCFAllocatorNull
: CFAllocatorRef
;
125 pub static kCFAllocatorUseContext
: CFAllocatorRef
;
127 pub fn CFAllocatorCreate(allocator
: CFAllocatorRef
, context
: *mut CFAllocatorContext
) -> CFAllocatorRef
;
128 pub fn CFAllocatorAllocate(allocator
: CFAllocatorRef
, size
: CFIndex
, hint
: CFOptionFlags
) -> *mut c_void
;
129 pub fn CFAllocatorDeallocate(allocator
: CFAllocatorRef
, ptr
: *mut c_void
);
130 pub fn CFAllocatorGetPreferredSizeForSize(allocator
: CFAllocatorRef
, size
: CFIndex
, hint
: CFOptionFlags
) -> CFIndex
;
131 pub fn CFAllocatorReallocate(allocator
: CFAllocatorRef
, ptr
: *mut c_void
, newsize
: CFIndex
, hint
: CFOptionFlags
) -> *mut c_void
;
132 pub fn CFAllocatorGetDefault() -> CFAllocatorRef
;
133 pub fn CFAllocatorSetDefault(allocator
: CFAllocatorRef
);
134 pub fn CFAllocatorGetContext(allocator
: CFAllocatorRef
, context
: *mut CFAllocatorContext
);
135 pub fn CFAllocatorGetTypeID() -> CFTypeID
;
137 /* CFNull Reference */
139 pub static kCFNull
: CFNullRef
;
141 /* CFType Reference */
143 //fn CFCopyTypeIDDescription
145 pub fn CFCopyDescription(cf
: CFTypeRef
) -> CFStringRef
;
146 pub fn CFEqual(cf1
: CFTypeRef
, cf2
: CFTypeRef
) -> Boolean
;
147 pub fn CFGetRetainCount(cf
: CFTypeRef
) -> CFIndex
;
148 pub fn CFGetTypeID(cf
: CFTypeRef
) -> CFTypeID
;
149 pub fn CFHash(cf
: CFTypeRef
) -> CFHashCode
;
150 //fn CFMakeCollectable
151 pub fn CFRelease(cf
: CFTypeRef
);
152 pub fn CFRetain(cf
: CFTypeRef
) -> CFTypeRef
;
153 pub fn CFShow(obj
: CFTypeRef
);
155 /* Base Utilities Reference */
156 // N.B. Some things missing here.