From 9918693037dce8aa4bb6f08741b6812923486c18 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 19 Jun 2024 11:26:03 +0200 Subject: Merging upstream version 1.76.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/core-foundation/src/array.rs | 97 ++++++----- vendor/core-foundation/src/attributed_string.rs | 51 +++--- vendor/core-foundation/src/base.rs | 84 +++++----- vendor/core-foundation/src/boolean.rs | 17 +- vendor/core-foundation/src/bundle.rs | 65 ++++---- vendor/core-foundation/src/characterset.rs | 4 +- vendor/core-foundation/src/data.rs | 53 +++--- vendor/core-foundation/src/date.rs | 25 +-- vendor/core-foundation/src/dictionary.rs | 204 ++++++++++++++++-------- vendor/core-foundation/src/error.rs | 15 +- vendor/core-foundation/src/filedescriptor.rs | 90 +++++------ vendor/core-foundation/src/lib.rs | 24 +-- vendor/core-foundation/src/mach_port.rs | 13 +- vendor/core-foundation/src/number.rs | 54 +++++-- vendor/core-foundation/src/propertylist.rs | 109 +++++++------ vendor/core-foundation/src/runloop.rs | 128 ++++++++++++--- vendor/core-foundation/src/set.rs | 32 ++-- vendor/core-foundation/src/string.rs | 100 +++++++----- vendor/core-foundation/src/timezone.rs | 25 ++- vendor/core-foundation/src/url.rs | 75 ++++++--- vendor/core-foundation/src/uuid.rs | 32 +--- 21 files changed, 769 insertions(+), 528 deletions(-) (limited to 'vendor/core-foundation/src') diff --git a/vendor/core-foundation/src/array.rs b/vendor/core-foundation/src/array.rs index d66ffc5b8..b6f5d5c74 100644 --- a/vendor/core-foundation/src/array.rs +++ b/vendor/core-foundation/src/array.rs @@ -9,17 +9,17 @@ //! Heterogeneous immutable arrays. +use crate::ConcreteCFType; pub use core_foundation_sys::array::*; pub use core_foundation_sys::base::CFIndex; -use core_foundation_sys::base::{CFTypeRef, CFRelease, kCFAllocatorDefault}; -use std::mem; +use core_foundation_sys::base::{kCFAllocatorDefault, CFRelease, CFTypeRef}; use std::marker::PhantomData; +use std::mem; use std::os::raw::c_void; use std::ptr; -use ConcreteCFType; -use base::{CFIndexConvertible, TCFType, CFRange}; -use base::{FromVoid, ItemRef}; +use crate::base::{CFIndexConvertible, CFRange, TCFType}; +use crate::base::{FromVoid, ItemRef}; /// A heterogeneous immutable array. pub struct CFArray(CFArrayRef, PhantomData); @@ -63,24 +63,34 @@ unsafe impl ConcreteCFType for CFArray<*const c_void> {} impl CFArray { /// Creates a new `CFArray` with the given elements, which must implement `Copy`. - pub fn from_copyable(elems: &[T]) -> CFArray where T: Copy { + pub fn from_copyable(elems: &[T]) -> CFArray + where + T: Copy, + { unsafe { - let array_ref = CFArrayCreate(kCFAllocatorDefault, - elems.as_ptr() as *const *const c_void, - elems.len().to_CFIndex(), - ptr::null()); + let array_ref = CFArrayCreate( + kCFAllocatorDefault, + elems.as_ptr() as *const *const c_void, + elems.len().to_CFIndex(), + ptr::null(), + ); TCFType::wrap_under_create_rule(array_ref) } } /// Creates a new `CFArray` with the given elements, which must be `CFType` objects. - pub fn from_CFTypes(elems: &[T]) -> CFArray where T: TCFType { + pub fn from_CFTypes(elems: &[T]) -> CFArray + where + T: TCFType, + { unsafe { let elems: Vec = elems.iter().map(|elem| elem.as_CFTypeRef()).collect(); - let array_ref = CFArrayCreate(kCFAllocatorDefault, - elems.as_ptr(), - elems.len().to_CFIndex(), - &kCFTypeArrayCallBacks); + let array_ref = CFArrayCreate( + kCFAllocatorDefault, + elems.as_ptr(), + elems.len().to_CFIndex(), + &kCFTypeArrayCallBacks, + ); TCFType::wrap_under_create_rule(array_ref) } } @@ -105,7 +115,7 @@ impl CFArray { /// Core Foundation objects (not always true), they need to be wrapped with /// `TCFType::wrap_under_get_rule()`. #[inline] - pub fn iter<'a>(&'a self) -> CFArrayIterator<'a, T> { + pub fn iter(&self) -> CFArrayIterator<'_, T> { CFArrayIterator { array: self, index: 0, @@ -115,20 +125,30 @@ impl CFArray { #[inline] pub fn len(&self) -> CFIndex { - unsafe { - CFArrayGetCount(self.0) - } + unsafe { CFArrayGetCount(self.0) } } + /// Returns `true` if the array contains no elements. #[inline] - pub unsafe fn get_unchecked<'a>(&'a self, index: CFIndex) -> ItemRef<'a, T> where T: FromVoid { + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + + #[inline] + pub unsafe fn get_unchecked(&self, index: CFIndex) -> ItemRef<'_, T> + where + T: FromVoid, + { T::from_void(CFArrayGetValueAtIndex(self.0, index)) } #[inline] - pub fn get<'a>(&'a self, index: CFIndex) -> Option> where T: FromVoid { + pub fn get(&self, index: CFIndex) -> Option> + where + T: FromVoid, + { if index < self.len() { - Some(unsafe { T::from_void(CFArrayGetValueAtIndex(self.0, index)) } ) + Some(unsafe { T::from_void(CFArrayGetValueAtIndex(self.0, index)) }) } else { None } @@ -146,7 +166,7 @@ impl CFArray { pub fn get_all_values(&self) -> Vec<*const c_void> { self.get_values(CFRange { location: 0, - length: self.len() + length: self.len(), }) } } @@ -162,13 +182,15 @@ impl<'a, T: FromVoid> IntoIterator for &'a CFArray { #[cfg(test)] mod tests { + use crate::number::CFNumber; + use super::*; + use crate::base::CFType; use std::mem; - use base::CFType; #[test] fn to_untyped_correct_retain_count() { - let array = CFArray::::from_CFTypes(&[]); + let array = CFArray::::from_CFTypes(&[CFNumber::from(4).as_CFType()]); assert_eq!(array.retain_count(), 1); let untyped_array = array.to_untyped(); @@ -181,7 +203,7 @@ mod tests { #[test] fn into_untyped() { - let array = CFArray::::from_CFTypes(&[]); + let array = CFArray::::from_CFTypes(&[CFNumber::from(4).as_CFType()]); let array2 = array.to_untyped(); assert_eq!(array.retain_count(), 2); @@ -194,9 +216,9 @@ mod tests { #[test] fn borrow() { - use string::CFString; + use crate::string::CFString; - let string = CFString::from_static_string("bar"); + let string = CFString::from_static_string("alongerstring"); assert_eq!(string.retain_count(), 1); let x; { @@ -208,7 +230,7 @@ mod tests { { x = arr.get(0).unwrap().clone(); assert_eq!(x.retain_count(), 2); - assert_eq!(x.to_string(), "bar"); + assert_eq!(x.to_string(), "alongerstring"); } } assert_eq!(x.retain_count(), 1); @@ -216,23 +238,24 @@ mod tests { #[test] fn iter_untyped_array() { - use string::{CFString, CFStringRef}; - use base::TCFTypeRef; + use crate::base::TCFTypeRef; + use crate::string::{CFString, CFStringRef}; - let cf_string = CFString::from_static_string("bar"); + let cf_string = CFString::from_static_string("alongerstring"); let array: CFArray = CFArray::from_CFTypes(&[cf_string.clone()]).into_untyped(); - let cf_strings = array.iter().map(|ptr| { - unsafe { CFString::wrap_under_get_rule(CFStringRef::from_void_ptr(*ptr)) } - }).collect::>(); + let cf_strings = array + .iter() + .map(|ptr| unsafe { CFString::wrap_under_get_rule(CFStringRef::from_void_ptr(*ptr)) }) + .collect::>(); let strings = cf_strings.iter().map(|s| s.to_string()).collect::>(); assert_eq!(cf_string.retain_count(), 3); - assert_eq!(&strings[..], &["bar"]); + assert_eq!(&strings[..], &["alongerstring"]); } #[test] fn should_box_and_unbox() { - use number::CFNumber; + use crate::number::CFNumber; let n0 = CFNumber::from(0); let n1 = CFNumber::from(1); diff --git a/vendor/core-foundation/src/attributed_string.rs b/vendor/core-foundation/src/attributed_string.rs index d4a467946..6a2b349f1 100644 --- a/vendor/core-foundation/src/attributed_string.rs +++ b/vendor/core-foundation/src/attributed_string.rs @@ -9,22 +9,26 @@ pub use core_foundation_sys::attributed_string::*; -use base::TCFType; -use core_foundation_sys::base::{CFIndex, CFRange, kCFAllocatorDefault}; +use crate::base::TCFType; +use crate::string::{CFString, CFStringRef}; +use core_foundation_sys::base::{kCFAllocatorDefault, CFIndex, CFRange}; use std::ptr::null; -use string::{CFString, CFStringRef}; -declare_TCFType!{ +declare_TCFType! { CFAttributedString, CFAttributedStringRef } -impl_TCFType!(CFAttributedString, CFAttributedStringRef, CFAttributedStringGetTypeID); +impl_TCFType!( + CFAttributedString, + CFAttributedStringRef, + CFAttributedStringGetTypeID +); impl CFAttributedString { #[inline] pub fn new(string: &CFString) -> Self { unsafe { - let astr_ref = CFAttributedStringCreate( - kCFAllocatorDefault, string.as_concrete_TypeRef(), null()); + let astr_ref = + CFAttributedStringCreate(kCFAllocatorDefault, string.as_concrete_TypeRef(), null()); CFAttributedString::wrap_under_create_rule(astr_ref) } @@ -32,23 +36,24 @@ impl CFAttributedString { #[inline] pub fn char_len(&self) -> CFIndex { - unsafe { - CFAttributedStringGetLength(self.0) - } + unsafe { CFAttributedStringGetLength(self.0) } } } -declare_TCFType!{ +declare_TCFType! { CFMutableAttributedString, CFMutableAttributedStringRef } -impl_TCFType!(CFMutableAttributedString, CFMutableAttributedStringRef, CFAttributedStringGetTypeID); +impl_TCFType!( + CFMutableAttributedString, + CFMutableAttributedStringRef, + CFAttributedStringGetTypeID +); impl CFMutableAttributedString { #[inline] pub fn new() -> Self { unsafe { - let astr_ref = CFAttributedStringCreateMutable( - kCFAllocatorDefault, 0); + let astr_ref = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0); CFMutableAttributedString::wrap_under_create_rule(astr_ref) } @@ -56,24 +61,20 @@ impl CFMutableAttributedString { #[inline] pub fn char_len(&self) -> CFIndex { - unsafe { - CFAttributedStringGetLength(self.0) - } + unsafe { CFAttributedStringGetLength(self.0) } } #[inline] pub fn replace_str(&mut self, string: &CFString, range: CFRange) { unsafe { - CFAttributedStringReplaceString( - self.0, range, string.as_concrete_TypeRef()); + CFAttributedStringReplaceString(self.0, range, string.as_concrete_TypeRef()); } } #[inline] pub fn set_attribute(&mut self, range: CFRange, name: CFStringRef, value: &T) { unsafe { - CFAttributedStringSetAttribute( - self.0, range, name, value.as_CFTypeRef()); + CFAttributedStringSetAttribute(self.0, range, name, value.as_CFTypeRef()); } } } @@ -84,7 +85,6 @@ impl Default for CFMutableAttributedString { } } - #[cfg(test)] mod tests { use super::*; @@ -93,6 +93,9 @@ mod tests { fn attributed_string_type_id_comparison() { // CFMutableAttributedString TypeID must be equal to CFAttributedString TypeID. // Compilation must not fail. - assert_eq!(::type_id(), ::type_id()); + assert_eq!( + ::type_id(), + ::type_id() + ); } -} \ No newline at end of file +} diff --git a/vendor/core-foundation/src/base.rs b/vendor/core-foundation/src/base.rs index f08f2b2e8..b44c1262a 100644 --- a/vendor/core-foundation/src/base.rs +++ b/vendor/core-foundation/src/base.rs @@ -17,8 +17,8 @@ use std::os::raw::c_void; pub use core_foundation_sys::base::*; -use string::CFString; -use ConcreteCFType; +use crate::string::CFString; +use crate::ConcreteCFType; pub trait CFIndexConvertible { /// Always use this method to construct a `CFIndex` value. It performs bounds checking to @@ -37,7 +37,7 @@ impl CFIndexConvertible for usize { } } -declare_TCFType!{ +declare_TCFType! { /// Superclass of all Core Foundation objects. CFType, CFTypeRef } @@ -111,13 +111,11 @@ impl CFType { } impl fmt::Debug for CFType { - /// Formats the value using [`CFCopyDescription`]. - /// - /// [`CFCopyDescription`]: https://developer.apple.com/documentation/corefoundation/1521252-cfcopydescription?language=objc + /// Formats the value using [`CFCopyDescription`]. + /// + /// [`CFCopyDescription`]: https://developer.apple.com/documentation/corefoundation/1521252-cfcopydescription?language=objc fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let desc = unsafe { - CFString::wrap_under_create_rule(CFCopyDescription(self.0)) - }; + let desc = unsafe { CFString::wrap_under_create_rule(CFCopyDescription(self.0)) }; desc.fmt(f) } } @@ -125,18 +123,14 @@ impl fmt::Debug for CFType { impl Clone for CFType { #[inline] fn clone(&self) -> CFType { - unsafe { - TCFType::wrap_under_get_rule(self.0) - } + unsafe { TCFType::wrap_under_get_rule(self.0) } } } impl PartialEq for CFType { #[inline] fn eq(&self, other: &CFType) -> bool { - unsafe { - CFEqual(self.as_CFTypeRef(), other.as_CFTypeRef()) != 0 - } + unsafe { CFEqual(self.as_CFTypeRef(), other.as_CFTypeRef()) != 0 } } } @@ -153,7 +147,6 @@ impl CFAllocator { } } - /// All Core Foundation types implement this trait. The associated type `Ref` specifies the /// associated Core Foundation type: e.g. for `CFType` this is `CFTypeRef`; for `CFArray` this is /// `CFArrayRef`. @@ -165,7 +158,7 @@ pub trait TCFType { /// The reference type wrapped inside this type. type Ref: TCFTypeRef; - /// Returns the object as its concrete TypeRef. + /// Returns the object as its concrete `TypeRef`. fn as_concrete_TypeRef(&self) -> Self::Ref; /// Returns an instance of the object, wrapping the underlying `CFTypeRef` subclass. Use this @@ -178,9 +171,7 @@ pub trait TCFType { /// Returns the object as a wrapped `CFType`. The reference count is incremented by one. #[inline] fn as_CFType(&self) -> CFType { - unsafe { - TCFType::wrap_under_get_rule(self.as_CFTypeRef()) - } + unsafe { TCFType::wrap_under_get_rule(self.as_CFTypeRef()) } } /// Returns the object as a wrapped `CFType`. Consumes self and avoids changing the reference @@ -206,27 +197,21 @@ pub trait TCFType { /// whether the return value of this method is greater than zero. #[inline] fn retain_count(&self) -> CFIndex { - unsafe { - CFGetRetainCount(self.as_CFTypeRef()) - } + unsafe { CFGetRetainCount(self.as_CFTypeRef()) } } /// Returns the type ID of this object. #[inline] fn type_of(&self) -> CFTypeID { - unsafe { - CFGetTypeID(self.as_CFTypeRef()) - } + unsafe { CFGetTypeID(self.as_CFTypeRef()) } } /// Writes a debugging version of this object on standard error. fn show(&self) { - unsafe { - CFShow(self.as_CFTypeRef()) - } + unsafe { CFShow(self.as_CFTypeRef()) } } - /// Returns true if this value is an instance of another type. + /// Returns `true` if this value is an instance of another type. #[inline] fn instance_of(&self) -> bool { self.type_of() == OtherCFType::type_id() @@ -318,9 +303,11 @@ impl<'a, T: PartialEq> PartialEq for ItemMutRef<'a, T> { } } -/// A trait describing how to convert from the stored *mut c_void to the desired T +/// A trait describing how to convert from the stored `*mut c_void` to the desired `T` pub unsafe trait FromMutVoid { - unsafe fn from_mut_void<'a>(x: *mut c_void) -> ItemMutRef<'a, Self> where Self: std::marker::Sized; + unsafe fn from_mut_void<'a>(x: *mut c_void) -> ItemMutRef<'a, Self> + where + Self: std::marker::Sized; } unsafe impl FromMutVoid for u32 { @@ -337,13 +324,18 @@ unsafe impl FromMutVoid for *const c_void { unsafe impl FromMutVoid for T { unsafe fn from_mut_void<'a>(x: *mut c_void) -> ItemMutRef<'a, Self> { - ItemMutRef(ManuallyDrop::new(TCFType::wrap_under_create_rule(T::Ref::from_void_ptr(x))), PhantomData) + ItemMutRef( + ManuallyDrop::new(TCFType::wrap_under_create_rule(T::Ref::from_void_ptr(x))), + PhantomData, + ) } } -/// A trait describing how to convert from the stored *const c_void to the desired T +/// A trait describing how to convert from the stored `*const c_void` to the desired `T` pub unsafe trait FromVoid { - unsafe fn from_void<'a>(x: *const c_void) -> ItemRef<'a, Self> where Self: std::marker::Sized; + unsafe fn from_void<'a>(x: *const c_void) -> ItemRef<'a, Self> + where + Self: std::marker::Sized; } unsafe impl FromVoid for u32 { @@ -362,11 +354,14 @@ unsafe impl FromVoid for *const c_void { unsafe impl FromVoid for T { unsafe fn from_void<'a>(x: *const c_void) -> ItemRef<'a, Self> { - ItemRef(ManuallyDrop::new(TCFType::wrap_under_create_rule(T::Ref::from_void_ptr(x))), PhantomData) + ItemRef( + ManuallyDrop::new(TCFType::wrap_under_create_rule(T::Ref::from_void_ptr(x))), + PhantomData, + ) } } -/// A trait describing how to convert from the stored *const c_void to the desired T +/// A trait describing how to convert from the stored `*const c_void` to the desired `T` pub unsafe trait ToVoid { fn to_void(&self) -> *const c_void; } @@ -395,12 +390,11 @@ unsafe impl ToVoid for CFTypeRef { } } - #[cfg(test)] mod tests { use super::*; + use crate::boolean::CFBoolean; use std::mem; - use boolean::CFBoolean; #[test] fn cftype_instance_of() { @@ -413,7 +407,7 @@ mod tests { #[test] fn as_cftype_retain_count() { - let string = CFString::from_static_string("bar"); + let string = CFString::from_static_string("alongerstring"); assert_eq!(string.retain_count(), 1); let cftype = string.as_CFType(); assert_eq!(cftype.retain_count(), 2); @@ -423,7 +417,7 @@ mod tests { #[test] fn into_cftype_retain_count() { - let string = CFString::from_static_string("bar"); + let string = CFString::from_static_string("alongerstring"); assert_eq!(string.retain_count(), 1); let cftype = string.into_CFType(); assert_eq!(cftype.retain_count(), 1); @@ -431,10 +425,10 @@ mod tests { #[test] fn as_cftype_and_downcast() { - let string = CFString::from_static_string("bar"); + let string = CFString::from_static_string("alongerstring"); let cftype = string.as_CFType(); let string2 = cftype.downcast::().unwrap(); - assert_eq!(string2.to_string(), "bar"); + assert_eq!(string2.to_string(), "alongerstring"); assert_eq!(string.retain_count(), 3); assert_eq!(cftype.retain_count(), 3); @@ -443,10 +437,10 @@ mod tests { #[test] fn into_cftype_and_downcast_into() { - let string = CFString::from_static_string("bar"); + let string = CFString::from_static_string("alongerstring"); let cftype = string.into_CFType(); let string2 = cftype.downcast_into::().unwrap(); - assert_eq!(string2.to_string(), "bar"); + assert_eq!(string2.to_string(), "alongerstring"); assert_eq!(string2.retain_count(), 1); } } diff --git a/vendor/core-foundation/src/boolean.rs b/vendor/core-foundation/src/boolean.rs index 8c13b907d..e0e2ff762 100644 --- a/vendor/core-foundation/src/boolean.rs +++ b/vendor/core-foundation/src/boolean.rs @@ -9,12 +9,13 @@ //! A Boolean type. -pub use core_foundation_sys::number::{CFBooleanRef, CFBooleanGetTypeID, kCFBooleanTrue, kCFBooleanFalse}; +pub use core_foundation_sys::number::{ + kCFBooleanFalse, kCFBooleanTrue, CFBooleanGetTypeID, CFBooleanRef, +}; -use base::TCFType; +use crate::base::TCFType; - -declare_TCFType!{ +declare_TCFType! { /// A Boolean type. /// /// FIXME(pcwalton): Should be a newtype struct, but that fails due to a Rust compiler bug. @@ -25,15 +26,11 @@ impl_CFTypeDescription!(CFBoolean); impl CFBoolean { pub fn true_value() -> CFBoolean { - unsafe { - TCFType::wrap_under_get_rule(kCFBooleanTrue) - } + unsafe { TCFType::wrap_under_get_rule(kCFBooleanTrue) } } pub fn false_value() -> CFBoolean { - unsafe { - TCFType::wrap_under_get_rule(kCFBooleanFalse) - } + unsafe { TCFType::wrap_under_get_rule(kCFBooleanFalse) } } } diff --git a/vendor/core-foundation/src/bundle.rs b/vendor/core-foundation/src/bundle.rs index b9ab1f65f..f6d53a991 100644 --- a/vendor/core-foundation/src/bundle.rs +++ b/vendor/core-foundation/src/bundle.rs @@ -14,13 +14,13 @@ pub use core_foundation_sys::bundle::*; use core_foundation_sys::url::kCFURLPOSIXPathStyle; use std::path::PathBuf; -use base::{CFType, TCFType}; -use url::CFURL; -use dictionary::CFDictionary; +use crate::base::{CFType, TCFType}; +use crate::dictionary::CFDictionary; +use crate::string::CFString; +use crate::url::CFURL; use std::os::raw::c_void; -use string::CFString; -declare_TCFType!{ +declare_TCFType! { /// A Bundle type. CFBundle, CFBundleRef } @@ -51,8 +51,10 @@ impl CFBundle { pub fn function_pointer_for_name(&self, function_name: CFString) -> *const c_void { unsafe { - CFBundleGetFunctionPointerForName(self.as_concrete_TypeRef(), - function_name.as_concrete_TypeRef()) + CFBundleGetFunctionPointerForName( + self.as_concrete_TypeRef(), + function_name.as_concrete_TypeRef(), + ) } } @@ -96,7 +98,9 @@ impl CFBundle { /// Bundle's own location pub fn path(&self) -> Option { let url = self.bundle_url()?; - Some(PathBuf::from(url.get_file_system_path(kCFURLPOSIXPathStyle).to_string())) + Some(PathBuf::from( + url.get_file_system_path(kCFURLPOSIXPathStyle).to_string(), + )) } /// Bundle's resources location @@ -114,7 +118,9 @@ impl CFBundle { /// Bundle's resources location pub fn resources_path(&self) -> Option { let url = self.bundle_resources_url()?; - Some(PathBuf::from(url.get_file_system_path(kCFURLPOSIXPathStyle).to_string())) + Some(PathBuf::from( + url.get_file_system_path(kCFURLPOSIXPathStyle).to_string(), + )) } pub fn private_frameworks_url(&self) -> Option { @@ -140,11 +146,10 @@ impl CFBundle { } } - #[test] fn safari_executable_url() { - use string::CFString; - use url::{CFURL, kCFURLPOSIXPathStyle}; + use crate::string::CFString; + use crate::url::{kCFURLPOSIXPathStyle, CFURL}; let cfstr_path = CFString::from_static_string("/Applications/Safari.app"); let cfurl_path = CFURL::from_file_system_path(cfstr_path, kCFURLPOSIXPathStyle, true); @@ -152,18 +157,20 @@ fn safari_executable_url() { .expect("Safari not present") .executable_url(); assert!(cfurl_executable.is_some()); - assert_eq!(cfurl_executable - .unwrap() - .absolute() - .get_file_system_path(kCFURLPOSIXPathStyle) - .to_string(), - "/Applications/Safari.app/Contents/MacOS/Safari"); + assert_eq!( + cfurl_executable + .unwrap() + .absolute() + .get_file_system_path(kCFURLPOSIXPathStyle) + .to_string(), + "/Applications/Safari.app/Contents/MacOS/Safari" + ); } #[test] fn safari_private_frameworks_url() { - use string::CFString; - use url::{CFURL, kCFURLPOSIXPathStyle}; + use crate::string::CFString; + use crate::url::{kCFURLPOSIXPathStyle, CFURL}; let cfstr_path = CFString::from_static_string("/Applications/Safari.app"); let cfurl_path = CFURL::from_file_system_path(cfstr_path, kCFURLPOSIXPathStyle, true); @@ -171,18 +178,20 @@ fn safari_private_frameworks_url() { .expect("Safari not present") .private_frameworks_url(); assert!(cfurl_executable.is_some()); - assert_eq!(cfurl_executable - .unwrap() - .absolute() - .get_file_system_path(kCFURLPOSIXPathStyle) - .to_string(), - "/Applications/Safari.app/Contents/Frameworks"); + assert_eq!( + cfurl_executable + .unwrap() + .absolute() + .get_file_system_path(kCFURLPOSIXPathStyle) + .to_string(), + "/Applications/Safari.app/Contents/Frameworks" + ); } #[test] fn non_existant_bundle() { - use string::CFString; - use url::{CFURL, kCFURLPOSIXPathStyle}; + use crate::string::CFString; + use crate::url::{kCFURLPOSIXPathStyle, CFURL}; let cfstr_path = CFString::from_static_string("/usr/local/foo"); let cfurl_path = CFURL::from_file_system_path(cfstr_path, kCFURLPOSIXPathStyle, true); diff --git a/vendor/core-foundation/src/characterset.rs b/vendor/core-foundation/src/characterset.rs index d1b9439d6..2a05a931d 100644 --- a/vendor/core-foundation/src/characterset.rs +++ b/vendor/core-foundation/src/characterset.rs @@ -11,9 +11,9 @@ pub use core_foundation_sys::characterset::*; -use base::TCFType; +use crate::base::TCFType; -declare_TCFType!{ +declare_TCFType! { /// An immutable set of Unicde characters. CFCharacterSet, CFCharacterSetRef } diff --git a/vendor/core-foundation/src/data.rs b/vendor/core-foundation/src/data.rs index c510c7434..9f952199a 100644 --- a/vendor/core-foundation/src/data.rs +++ b/vendor/core-foundation/src/data.rs @@ -9,18 +9,16 @@ //! Core Foundation byte buffers. -pub use core_foundation_sys::data::*; +use core_foundation_sys::base::kCFAllocatorDefault; use core_foundation_sys::base::CFIndex; -use core_foundation_sys::base::{kCFAllocatorDefault}; +pub use core_foundation_sys::data::*; use std::ops::Deref; use std::slice; use std::sync::Arc; +use crate::base::{CFIndexConvertible, TCFType}; -use base::{CFIndexConvertible, TCFType}; - - -declare_TCFType!{ +declare_TCFType! { /// A byte buffer. CFData, CFDataRef } @@ -28,20 +26,22 @@ impl_TCFType!(CFData, CFDataRef, CFDataGetTypeID); impl_CFTypeDescription!(CFData); impl CFData { - /// Creates a CFData around a copy `buffer` + /// Creates a [`CFData`] around a copy `buffer` pub fn from_buffer(buffer: &[u8]) -> CFData { unsafe { - let data_ref = CFDataCreate(kCFAllocatorDefault, - buffer.as_ptr(), - buffer.len().to_CFIndex()); + let data_ref = CFDataCreate( + kCFAllocatorDefault, + buffer.as_ptr(), + buffer.len().to_CFIndex(), + ); TCFType::wrap_under_create_rule(data_ref) } } - /// Creates a CFData referencing `buffer` without creating a copy + /// Creates a [`CFData`] referencing `buffer` without creating a copy pub fn from_arc + Sync + Send>(buffer: Arc) -> Self { - use std::os::raw::c_void; use crate::base::{CFAllocator, CFAllocatorContext}; + use std::os::raw::c_void; unsafe { let ptr = (*buffer).as_ref().as_ptr() as *const _; @@ -67,8 +67,12 @@ impl CFData { deallocate: Some(deallocate::), preferredSize: None, }); - let data_ref = - CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, ptr, len, allocator.as_CFTypeRef()); + let data_ref = CFDataCreateWithBytesNoCopy( + kCFAllocatorDefault, + ptr, + len, + allocator.as_CFTypeRef(), + ); TCFType::wrap_under_create_rule(data_ref) } } @@ -76,18 +80,20 @@ impl CFData { /// Returns a pointer to the underlying bytes in this data. Note that this byte buffer is /// read-only. #[inline] - pub fn bytes<'a>(&'a self) -> &'a [u8] { - unsafe { - slice::from_raw_parts(CFDataGetBytePtr(self.0), self.len() as usize) - } + pub fn bytes(&self) -> &[u8] { + unsafe { slice::from_raw_parts(CFDataGetBytePtr(self.0), self.len() as usize) } } /// Returns the length of this byte buffer. #[inline] pub fn len(&self) -> CFIndex { - unsafe { - CFDataGetLength(self.0) - } + unsafe { CFDataGetLength(self.0) } + } + + /// Returns `true` if this byte buffer is empty. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 } } @@ -133,7 +139,10 @@ mod test { } let dropped = Arc::new(AtomicBool::default()); - let l = Arc::new(VecWrapper {inner: vec![5], dropped: dropped.clone() }); + let l = Arc::new(VecWrapper { + inner: vec![5], + dropped: dropped.clone(), + }); let m = l.clone(); let dp = CFData::from_arc(l); drop(m); diff --git a/vendor/core-foundation/src/date.rs b/vendor/core-foundation/src/date.rs index 57ee7211e..c27bad25d 100644 --- a/vendor/core-foundation/src/date.rs +++ b/vendor/core-foundation/src/date.rs @@ -9,16 +9,15 @@ //! Core Foundation date objects. -pub use core_foundation_sys::date::*; use core_foundation_sys::base::kCFAllocatorDefault; +pub use core_foundation_sys::date::*; -use base::TCFType; +use crate::base::TCFType; #[cfg(feature = "with-chrono")] use chrono::NaiveDateTime; - -declare_TCFType!{ +declare_TCFType! { /// A date. CFDate, CFDateRef } @@ -42,16 +41,12 @@ impl CFDate { #[inline] pub fn abs_time(&self) -> CFAbsoluteTime { - unsafe { - CFDateGetAbsoluteTime(self.0) - } + unsafe { CFDateGetAbsoluteTime(self.0) } } #[cfg(feature = "with-chrono")] pub fn naive_utc(&self) -> NaiveDateTime { - let ts = unsafe { - self.abs_time() + kCFAbsoluteTimeIntervalSince1970 - }; + let ts = unsafe { self.abs_time() + kCFAbsoluteTimeIntervalSince1970 }; let (secs, nanos) = if ts.is_sign_positive() { (ts.trunc() as i64, ts.fract()) } else { @@ -65,9 +60,7 @@ impl CFDate { pub fn from_naive_utc(time: NaiveDateTime) -> CFDate { let secs = time.timestamp(); let nanos = time.timestamp_subsec_nanos(); - let ts = unsafe { - secs as f64 + (nanos as f64 / 1e9) - kCFAbsoluteTimeIntervalSince1970 - }; + let ts = unsafe { secs as f64 + (nanos as f64 / 1e9) - kCFAbsoluteTimeIntervalSince1970 }; CFDate::new(ts) } } @@ -86,7 +79,7 @@ mod test { let same_sign = a.is_sign_positive() == b.is_sign_positive(); let equal = ((a - b).abs() / f64::min(a.abs() + b.abs(), f64::MAX)) < f64::EPSILON; - (same_sign && equal) + same_sign && equal } #[test] @@ -119,9 +112,7 @@ mod test { fn date_chrono_conversion_negative() { use super::kCFAbsoluteTimeIntervalSince1970; - let ts = unsafe { - kCFAbsoluteTimeIntervalSince1970 - 420.0 - }; + let ts = unsafe { kCFAbsoluteTimeIntervalSince1970 - 420.0 }; let date = CFDate::new(ts); let datetime: NaiveDateTime = date.naive_utc(); let converted = CFDate::from_naive_utc(datetime); diff --git a/vendor/core-foundation/src/dictionary.rs b/vendor/core-foundation/src/dictionary.rs index efcbba117..aad37f3c8 100644 --- a/vendor/core-foundation/src/dictionary.rs +++ b/vendor/core-foundation/src/dictionary.rs @@ -11,18 +11,22 @@ pub use core_foundation_sys::dictionary::*; -use core_foundation_sys::base::{CFTypeRef, CFRelease, kCFAllocatorDefault}; +use core_foundation_sys::base::{kCFAllocatorDefault, CFRelease, CFTypeRef}; +use std::marker::PhantomData; use std::mem; use std::os::raw::c_void; use std::ptr; -use std::marker::PhantomData; -use base::{ItemRef, FromVoid, ToVoid}; -use base::{CFIndexConvertible, TCFType}; -use ConcreteCFType; +use crate::base::{CFIndexConvertible, TCFType}; +use crate::base::{FromVoid, ItemRef, ToVoid}; +use crate::ConcreteCFType; // consume the type parameters with PhantomDatas -pub struct CFDictionary(CFDictionaryRef, PhantomData, PhantomData); +pub struct CFDictionary( + CFDictionaryRef, + PhantomData, + PhantomData, +); impl Drop for CFDictionary { fn drop(&mut self) { @@ -36,19 +40,25 @@ impl_CFTypeDescription!(CFDictionary); unsafe impl ConcreteCFType for CFDictionary<*const c_void, *const c_void> {} impl CFDictionary { - pub fn from_CFType_pairs(pairs: &[(K, V)]) -> CFDictionary where K: TCFType, V: TCFType { + pub fn from_CFType_pairs(pairs: &[(K, V)]) -> CFDictionary + where + K: TCFType, + V: TCFType, + { let (keys, values): (Vec, Vec) = pairs .iter() - .map(|&(ref key, ref value)| (key.as_CFTypeRef(), value.as_CFTypeRef())) + .map(|(key, value)| (key.as_CFTypeRef(), value.as_CFTypeRef())) .unzip(); unsafe { - let dictionary_ref = CFDictionaryCreate(kCFAllocatorDefault, - keys.as_ptr(), - values.as_ptr(), - keys.len().to_CFIndex(), - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); + let dictionary_ref = CFDictionaryCreate( + kCFAllocatorDefault, + keys.as_ptr(), + values.as_ptr(), + keys.len().to_CFIndex(), + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks, + ); TCFType::wrap_under_create_rule(dictionary_ref) } } @@ -76,9 +86,7 @@ impl CFDictionary { #[inline] pub fn len(&self) -> usize { - unsafe { - CFDictionaryGetCount(self.0) as usize - } + unsafe { CFDictionaryGetCount(self.0) as usize } } #[inline] @@ -87,12 +95,19 @@ impl CFDictionary { } #[inline] - pub fn contains_key(&self, key: &K) -> bool where K: ToVoid { + pub fn contains_key(&self, key: &K) -> bool + where + K: ToVoid, + { unsafe { CFDictionaryContainsKey(self.0, key.to_void()) != 0 } } #[inline] - pub fn find<'a, T: ToVoid>(&'a self, key: T) -> Option> where V: FromVoid, K: ToVoid { + pub fn find>(&self, key: T) -> Option> + where + V: FromVoid, + K: ToVoid, + { unsafe { let mut value: *const c_void = ptr::null(); if CFDictionaryGetValueIfPresent(self.0, key.to_void(), &mut value) != 0 { @@ -108,9 +123,14 @@ impl CFDictionary { /// Panics if the key is not present in the dictionary. Use `find` to get an `Option` instead /// of panicking. #[inline] - pub fn get<'a, T: ToVoid>(&'a self, key: T) -> ItemRef<'a, V> where V: FromVoid, K: ToVoid { + pub fn get>(&self, key: T) -> ItemRef<'_, V> + where + V: FromVoid, + K: ToVoid, + { let ptr = key.to_void(); - self.find(key).unwrap_or_else(|| panic!("No entry found for key {:p}", ptr)) + self.find(key) + .unwrap_or_else(|| panic!("No entry found for key {:p}", ptr)) } pub fn get_keys_and_values(&self) -> (Vec<*const c_void>, Vec<*const c_void>) { @@ -129,7 +149,11 @@ impl CFDictionary { } // consume the type parameters with PhantomDatas -pub struct CFMutableDictionary(CFMutableDictionaryRef, PhantomData, PhantomData); +pub struct CFMutableDictionary( + CFMutableDictionaryRef, + PhantomData, + PhantomData, +); impl Drop for CFMutableDictionary { fn drop(&mut self) { @@ -147,24 +171,31 @@ impl CFMutableDictionary { pub fn with_capacity(capacity: isize) -> Self { unsafe { - let dictionary_ref = CFDictionaryCreateMutable(kCFAllocatorDefault, - capacity as _, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); + let dictionary_ref = CFDictionaryCreateMutable( + kCFAllocatorDefault, + capacity as _, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks, + ); TCFType::wrap_under_create_rule(dictionary_ref) } } pub fn copy_with_capacity(&self, capacity: isize) -> Self { unsafe { - let dictionary_ref = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, capacity as _, self.0); + let dictionary_ref = + CFDictionaryCreateMutableCopy(kCFAllocatorDefault, capacity as _, self.0); TCFType::wrap_under_get_rule(dictionary_ref) } } - pub fn from_CFType_pairs(pairs: &[(K, V)]) -> CFMutableDictionary where K: ToVoid, V: ToVoid { + pub fn from_CFType_pairs(pairs: &[(K, V)]) -> CFMutableDictionary + where + K: ToVoid, + V: ToVoid, + { let mut result = Self::with_capacity(pairs.len() as _); - for &(ref key, ref value) in pairs { + for (key, value) in pairs { result.add(key, value); } result @@ -194,9 +225,7 @@ impl CFMutableDictionary { #[inline] pub fn len(&self) -> usize { - unsafe { - CFDictionaryGetCount(self.0) as usize - } + unsafe { CFDictionaryGetCount(self.0) as usize } } #[inline] @@ -206,13 +235,15 @@ impl CFMutableDictionary { #[inline] pub fn contains_key(&self, key: *const c_void) -> bool { - unsafe { - CFDictionaryContainsKey(self.0, key) != 0 - } + unsafe { CFDictionaryContainsKey(self.0, key) != 0 } } #[inline] - pub fn find<'a>(&'a self, key: &K) -> Option> where V: FromVoid, K: ToVoid { + pub fn find<'a>(&'a self, key: &K) -> Option> + where + V: FromVoid, + K: ToVoid, + { unsafe { let mut value: *const c_void = ptr::null(); if CFDictionaryGetValueIfPresent(self.0, key.to_void(), &mut value) != 0 { @@ -228,9 +259,14 @@ impl CFMutableDictionary { /// Panics if the key is not present in the dictionary. Use `find` to get an `Option` instead /// of panicking. #[inline] - pub fn get<'a>(&'a self, key: &K) -> ItemRef<'a, V> where V: FromVoid, K: ToVoid { + pub fn get<'a>(&'a self, key: &K) -> ItemRef<'a, V> + where + V: FromVoid, + K: ToVoid, + { let ptr = key.to_void(); - self.find(&key).unwrap_or_else(|| panic!("No entry found for key {:p}", ptr)) + self.find(key) + .unwrap_or_else(|| panic!("No entry found for key {:p}", ptr)) } pub fn get_keys_and_values(&self) -> (Vec<*const c_void>, Vec<*const c_void>) { @@ -251,25 +287,40 @@ impl CFMutableDictionary { /// Adds the key-value pair to the dictionary if no such key already exist. #[inline] - pub fn add(&mut self, key: &K, value: &V) where K: ToVoid, V: ToVoid { + pub fn add(&mut self, key: &K, value: &V) + where + K: ToVoid, + V: ToVoid, + { unsafe { CFDictionaryAddValue(self.0, key.to_void(), value.to_void()) } } /// Sets the value of the key in the dictionary. #[inline] - pub fn set(&mut self, key: K, value: V) where K: ToVoid, V: ToVoid { + pub fn set(&mut self, key: K, value: V) + where + K: ToVoid, + V: ToVoid, + { unsafe { CFDictionarySetValue(self.0, key.to_void(), value.to_void()) } } /// Replaces the value of the key in the dictionary. #[inline] - pub fn replace(&mut self, key: K, value: V) where K: ToVoid, V: ToVoid { + pub fn replace(&mut self, key: K, value: V) + where + K: ToVoid, + V: ToVoid, + { unsafe { CFDictionaryReplaceValue(self.0, key.to_void(), value.to_void()) } } /// Removes the value of the key from the dictionary. #[inline] - pub fn remove(&mut self, key: K) where K: ToVoid { + pub fn remove(&mut self, key: K) + where + K: ToVoid, + { unsafe { CFDictionaryRemoveValue(self.0, key.to_void()) } } @@ -296,15 +347,13 @@ impl<'a, K, V> From<&'a CFDictionary> for CFMutableDictionary { } } - #[cfg(test)] pub mod test { use super::*; - use base::{CFType, TCFType}; - use boolean::CFBoolean; - use number::CFNumber; - use string::CFString; - + use crate::base::{CFType, TCFType}; + use crate::boolean::CFBoolean; + use crate::number::CFNumber; + use crate::string::CFString; #[test] fn dictionary() { @@ -322,8 +371,14 @@ pub mod test { ]); let (v1, v2) = d.get_keys_and_values(); - assert_eq!(v1, &[bar.as_CFTypeRef(), baz.as_CFTypeRef(), foo.as_CFTypeRef()]); - assert_eq!(v2, &[boo.as_CFTypeRef(), tru.as_CFTypeRef(), n42.as_CFTypeRef()]); + assert_eq!( + v1, + &[bar.as_CFTypeRef(), baz.as_CFTypeRef(), foo.as_CFTypeRef()] + ); + assert_eq!( + v2, + &[boo.as_CFTypeRef(), tru.as_CFTypeRef(), n42.as_CFTypeRef()] + ); } #[test] @@ -342,8 +397,14 @@ pub mod test { assert_eq!(d.len(), 3); let (v1, v2) = d.get_keys_and_values(); - assert_eq!(v1, &[bar.as_CFTypeRef(), baz.as_CFTypeRef(), foo.as_CFTypeRef()]); - assert_eq!(v2, &[boo.as_CFTypeRef(), tru.as_CFTypeRef(), n42.as_CFTypeRef()]); + assert_eq!( + v1, + &[bar.as_CFTypeRef(), baz.as_CFTypeRef(), foo.as_CFTypeRef()] + ); + assert_eq!( + v2, + &[boo.as_CFTypeRef(), tru.as_CFTypeRef(), n42.as_CFTypeRef()] + ); d.remove(baz); assert_eq!(d.len(), 2); @@ -358,12 +419,10 @@ pub mod test { #[test] fn dict_find_and_contains_key() { - let dict = CFDictionary::from_CFType_pairs(&[ - ( - CFString::from_static_string("hello"), - CFBoolean::true_value(), - ), - ]); + let dict = CFDictionary::from_CFType_pairs(&[( + CFString::from_static_string("hello"), + CFBoolean::true_value(), + )]); let key = CFString::from_static_string("hello"); let invalid_key = CFString::from_static_string("foobar"); @@ -377,17 +436,24 @@ pub mod test { #[test] fn convert_immutable_to_mutable_dict() { - let dict: CFDictionary = CFDictionary::from_CFType_pairs(&[ - (CFString::from_static_string("Foo"), CFBoolean::true_value()), - ]); + let dict: CFDictionary = CFDictionary::from_CFType_pairs(&[( + CFString::from_static_string("Foo"), + CFBoolean::true_value(), + )]); let mut mut_dict = CFMutableDictionary::from(&dict); assert_eq!(dict.retain_count(), 1); assert_eq!(mut_dict.retain_count(), 1); assert_eq!(mut_dict.len(), 1); - assert_eq!(*mut_dict.get(&CFString::from_static_string("Foo")), CFBoolean::true_value()); - - mut_dict.add(&CFString::from_static_string("Bar"), &CFBoolean::false_value()); + assert_eq!( + *mut_dict.get(&CFString::from_static_string("Foo")), + CFBoolean::true_value() + ); + + mut_dict.add( + &CFString::from_static_string("Bar"), + &CFBoolean::false_value(), + ); assert_eq!(dict.len(), 1); assert_eq!(mut_dict.len(), 2); } @@ -395,13 +461,19 @@ pub mod test { #[test] fn mutable_dictionary_as_immutable() { let mut mut_dict: CFMutableDictionary = CFMutableDictionary::new(); - mut_dict.add(&CFString::from_static_string("Bar"), &CFBoolean::false_value()); + mut_dict.add( + &CFString::from_static_string("Bar"), + &CFBoolean::false_value(), + ); assert_eq!(mut_dict.retain_count(), 1); let dict = mut_dict.to_immutable(); assert_eq!(mut_dict.retain_count(), 2); assert_eq!(dict.retain_count(), 2); - assert_eq!(*dict.get(&CFString::from_static_string("Bar")), CFBoolean::false_value()); + assert_eq!( + *dict.get(&CFString::from_static_string("Bar")), + CFBoolean::false_value() + ); mem::drop(dict); assert_eq!(mut_dict.retain_count(), 1); diff --git a/vendor/core-foundation/src/error.rs b/vendor/core-foundation/src/error.rs index f100171bc..e5a224259 100644 --- a/vendor/core-foundation/src/error.rs +++ b/vendor/core-foundation/src/error.rs @@ -14,11 +14,10 @@ pub use core_foundation_sys::error::*; use std::error::Error; use std::fmt; -use base::{CFIndex, TCFType}; -use string::CFString; +use crate::base::{CFIndex, TCFType}; +use crate::string::CFString; - -declare_TCFType!{ +declare_TCFType! { /// An error value. CFError, CFErrorRef } @@ -27,10 +26,10 @@ impl_TCFType!(CFError, CFErrorRef, CFErrorGetTypeID); impl fmt::Debug for CFError { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_struct("CFError") - .field("domain", &self.domain()) - .field("code", &self.code()) - .field("description", &self.description()) - .finish() + .field("domain", &self.domain()) + .field("code", &self.code()) + .field("description", &self.description()) + .finish() } } diff --git a/vendor/core-foundation/src/filedescriptor.rs b/vendor/core-foundation/src/filedescriptor.rs index e153c70b2..876d1cec0 100644 --- a/vendor/core-foundation/src/filedescriptor.rs +++ b/vendor/core-foundation/src/filedescriptor.rs @@ -9,33 +9,41 @@ pub use core_foundation_sys::filedescriptor::*; -use core_foundation_sys::base::{Boolean, CFIndex}; use core_foundation_sys::base::{kCFAllocatorDefault, CFOptionFlags}; +use core_foundation_sys::base::{Boolean, CFIndex}; -use base::TCFType; -use runloop::CFRunLoopSource; +use crate::base::TCFType; +use crate::runloop::CFRunLoopSource; use std::mem::MaybeUninit; use std::os::unix::io::{AsRawFd, RawFd}; use std::ptr; -declare_TCFType!{ +declare_TCFType! { CFFileDescriptor, CFFileDescriptorRef } -impl_TCFType!(CFFileDescriptor, CFFileDescriptorRef, CFFileDescriptorGetTypeID); +impl_TCFType!( + CFFileDescriptor, + CFFileDescriptorRef, + CFFileDescriptorGetTypeID +); impl CFFileDescriptor { - pub fn new(fd: RawFd, - closeOnInvalidate: bool, - callout: CFFileDescriptorCallBack, - context: Option<&CFFileDescriptorContext>) -> Option { + pub fn new( + fd: RawFd, + closeOnInvalidate: bool, + callout: CFFileDescriptorCallBack, + context: Option<&CFFileDescriptorContext>, + ) -> Option { let context = context.map_or(ptr::null(), |c| c as *const _); unsafe { - let fd_ref = CFFileDescriptorCreate(kCFAllocatorDefault, - fd, - closeOnInvalidate as Boolean, - callout, - context); + let fd_ref = CFFileDescriptorCreate( + kCFAllocatorDefault, + fd, + closeOnInvalidate as Boolean, + callout, + context, + ); if fd_ref.is_null() { None } else { @@ -53,36 +61,25 @@ impl CFFileDescriptor { } pub fn enable_callbacks(&self, callback_types: CFOptionFlags) { - unsafe { - CFFileDescriptorEnableCallBacks(self.0, callback_types) - } + unsafe { CFFileDescriptorEnableCallBacks(self.0, callback_types) } } pub fn disable_callbacks(&self, callback_types: CFOptionFlags) { - unsafe { - CFFileDescriptorDisableCallBacks(self.0, callback_types) - } + unsafe { CFFileDescriptorDisableCallBacks(self.0, callback_types) } } pub fn valid(&self) -> bool { - unsafe { - CFFileDescriptorIsValid(self.0) != 0 - } + unsafe { CFFileDescriptorIsValid(self.0) != 0 } } pub fn invalidate(&self) { - unsafe { - CFFileDescriptorInvalidate(self.0) - } + unsafe { CFFileDescriptorInvalidate(self.0) } } pub fn to_run_loop_source(&self, order: CFIndex) -> Option { unsafe { - let source_ref = CFFileDescriptorCreateRunLoopSource( - kCFAllocatorDefault, - self.0, - order - ); + let source_ref = + CFFileDescriptorCreateRunLoopSource(kCFAllocatorDefault, self.0, order); if source_ref.is_null() { None } else { @@ -94,24 +91,21 @@ impl CFFileDescriptor { impl AsRawFd for CFFileDescriptor { fn as_raw_fd(&self) -> RawFd { - unsafe { - CFFileDescriptorGetNativeDescriptor(self.0) - } + unsafe { CFFileDescriptorGetNativeDescriptor(self.0) } } } - #[cfg(test)] mod test { extern crate libc; use super::*; + use crate::runloop::CFRunLoop; + use core_foundation_sys::base::CFOptionFlags; + use core_foundation_sys::runloop::kCFRunLoopDefaultMode; + use libc::O_RDWR; use std::ffi::CString; use std::os::raw::c_void; - use core_foundation_sys::base::{CFOptionFlags}; - use core_foundation_sys::runloop::{kCFRunLoopDefaultMode}; - use libc::O_RDWR; - use runloop::{CFRunLoop}; #[test] fn test_unconsumed() { @@ -129,14 +123,16 @@ mod test { assert_eq!(unsafe { libc::close(raw_fd) }, 0); } - extern "C" fn never_callback(_f: CFFileDescriptorRef, - _callback_types: CFOptionFlags, - _info_ptr: *mut c_void) { + extern "C" fn never_callback( + _f: CFFileDescriptorRef, + _callback_types: CFOptionFlags, + _info_ptr: *mut c_void, + ) { unreachable!(); } struct TestInfo { - value: CFOptionFlags + value: CFOptionFlags, } #[test] @@ -147,7 +143,7 @@ mod test { info: &mut info as *mut _ as *mut c_void, retain: None, release: None, - copyDescription: None + copyDescription: None, }; let path = CString::new("/dev/null").unwrap(); @@ -182,7 +178,11 @@ mod test { assert!(!cf_fd.valid()); } - extern "C" fn callback(_f: CFFileDescriptorRef, callback_types: CFOptionFlags, info_ptr: *mut c_void) { + extern "C" fn callback( + _f: CFFileDescriptorRef, + callback_types: CFOptionFlags, + info_ptr: *mut c_void, + ) { assert!(!info_ptr.is_null()); let info: *mut TestInfo = info_ptr as *mut TestInfo; diff --git a/vendor/core-foundation/src/lib.rs b/vendor/core-foundation/src/lib.rs index b93593899..767d45aad 100644 --- a/vendor/core-foundation/src/lib.rs +++ b/vendor/core-foundation/src/lib.rs @@ -21,7 +21,7 @@ extern crate libc; #[cfg(feature = "with-chrono")] extern crate chrono; -use base::TCFType; +use crate::base::TCFType; pub unsafe trait ConcreteCFType: TCFType {} @@ -165,7 +165,6 @@ macro_rules! impl_TCFType { (@Phantom $x:ident) => { ::std::marker::PhantomData }; } - /// Implement `std::fmt::Debug` for the given type. /// /// This will invoke the implementation of `Debug` for [`CFType`] @@ -200,7 +199,14 @@ macro_rules! impl_CFComparison { #[inline] fn partial_cmp(&self, other: &$ty) -> Option<::std::cmp::Ordering> { unsafe { - Some($compare(self.as_concrete_TypeRef(), other.as_concrete_TypeRef(), ::std::ptr::null_mut()).into()) + Some( + $compare( + self.as_concrete_TypeRef(), + other.as_concrete_TypeRef(), + ::std::ptr::null_mut(), + ) + .into(), + ) } } } @@ -211,26 +217,26 @@ macro_rules! impl_CFComparison { self.partial_cmp(other).unwrap() } } - } + }; } pub mod array; pub mod attributed_string; pub mod base; pub mod boolean; +pub mod bundle; pub mod characterset; pub mod data; pub mod date; pub mod dictionary; pub mod error; pub mod filedescriptor; +pub mod mach_port; pub mod number; -pub mod set; -pub mod string; -pub mod url; -pub mod bundle; pub mod propertylist; pub mod runloop; +pub mod set; +pub mod string; pub mod timezone; +pub mod url; pub mod uuid; -pub mod mach_port; diff --git a/vendor/core-foundation/src/mach_port.rs b/vendor/core-foundation/src/mach_port.rs index 6112e3aae..f01847fff 100644 --- a/vendor/core-foundation/src/mach_port.rs +++ b/vendor/core-foundation/src/mach_port.rs @@ -1,9 +1,8 @@ -use base::TCFType; +use crate::base::TCFType; +use crate::runloop::CFRunLoopSource; use core_foundation_sys::base::kCFAllocatorDefault; -use runloop::CFRunLoopSource; pub use core_foundation_sys::mach_port::*; - declare_TCFType! { /// An immutable numeric value. CFMachPort, CFMachPortRef @@ -12,12 +11,10 @@ impl_TCFType!(CFMachPort, CFMachPortRef, CFMachPortGetTypeID); impl_CFTypeDescription!(CFMachPort); impl CFMachPort { - pub fn create_runloop_source( - &self, - order: CFIndex, - ) -> Result { + pub fn create_runloop_source(&self, order: CFIndex) -> Result { unsafe { - let runloop_source_ref = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, self.0, order); + let runloop_source_ref = + CFMachPortCreateRunLoopSource(kCFAllocatorDefault, self.0, order); if runloop_source_ref.is_null() { Err(()) } else { diff --git a/vendor/core-foundation/src/number.rs b/vendor/core-foundation/src/number.rs index a4b2affaa..c3b6fab96 100644 --- a/vendor/core-foundation/src/number.rs +++ b/vendor/core-foundation/src/number.rs @@ -13,10 +13,9 @@ use core_foundation_sys::base::kCFAllocatorDefault; pub use core_foundation_sys::number::*; use std::os::raw::c_void; -use base::TCFType; +use crate::base::TCFType; - -declare_TCFType!{ +declare_TCFType! { /// An immutable numeric value. CFNumber, CFNumberRef } @@ -25,13 +24,20 @@ impl_CFTypeDescription!(CFNumber); impl_CFComparison!(CFNumber, CFNumberCompare); impl CFNumber { - #[inline] pub fn to_i32(&self) -> Option { unsafe { let mut value: i32 = 0; - let ok = CFNumberGetValue(self.0, kCFNumberSInt32Type, &mut value as *mut i32 as *mut c_void); - if ok { Some(value) } else { None } + let ok = CFNumberGetValue( + self.0, + kCFNumberSInt32Type, + &mut value as *mut i32 as *mut c_void, + ); + if ok { + Some(value) + } else { + None + } } } @@ -39,8 +45,16 @@ impl CFNumber { pub fn to_i64(&self) -> Option { unsafe { let mut value: i64 = 0; - let ok = CFNumberGetValue(self.0, kCFNumberSInt64Type, &mut value as *mut i64 as *mut c_void); - if ok { Some(value) } else { None } + let ok = CFNumberGetValue( + self.0, + kCFNumberSInt64Type, + &mut value as *mut i64 as *mut c_void, + ); + if ok { + Some(value) + } else { + None + } } } @@ -48,8 +62,16 @@ impl CFNumber { pub fn to_f32(&self) -> Option { unsafe { let mut value: f32 = 0.0; - let ok = CFNumberGetValue(self.0, kCFNumberFloat32Type, &mut value as *mut f32 as *mut c_void); - if ok { Some(value) } else { None } + let ok = CFNumberGetValue( + self.0, + kCFNumberFloat32Type, + &mut value as *mut f32 as *mut c_void, + ); + if ok { + Some(value) + } else { + None + } } } @@ -57,8 +79,16 @@ impl CFNumber { pub fn to_f64(&self) -> Option { unsafe { let mut value: f64 = 0.0; - let ok = CFNumberGetValue(self.0, kCFNumberFloat64Type, &mut value as *mut f64 as *mut c_void); - if ok { Some(value) } else { None } + let ok = CFNumberGetValue( + self.0, + kCFNumberFloat64Type, + &mut value as *mut f64 as *mut c_void, + ); + if ok { + Some(value) + } else { + None + } } } } diff --git a/vendor/core-foundation/src/propertylist.rs b/vendor/core-foundation/src/propertylist.rs index e8fceac58..de5d1d87b 100644 --- a/vendor/core-foundation/src/propertylist.rs +++ b/vendor/core-foundation/src/propertylist.rs @@ -9,30 +9,34 @@ //! Core Foundation property lists -use std::ptr; use std::mem; use std::os::raw::c_void; +use std::ptr; -use error::CFError; -use data::CFData; -use base::{CFType, TCFType, TCFTypeRef}; +use crate::base::{CFType, TCFType, TCFTypeRef}; +use crate::data::CFData; +use crate::error::CFError; -pub use core_foundation_sys::propertylist::*; +use core_foundation_sys::base::{ + kCFAllocatorDefault, CFGetRetainCount, CFGetTypeID, CFIndex, CFRetain, CFShow, CFTypeID, +}; use core_foundation_sys::error::CFErrorRef; -use core_foundation_sys::base::{CFGetRetainCount, CFGetTypeID, CFIndex, CFRetain, - CFShow, CFTypeID, kCFAllocatorDefault}; +pub use core_foundation_sys::propertylist::*; -pub fn create_with_data(data: CFData, - options: CFPropertyListMutabilityOptions) - -> Result<(*const c_void, CFPropertyListFormat), CFError> { +pub fn create_with_data( + data: CFData, + options: CFPropertyListMutabilityOptions, +) -> Result<(*const c_void, CFPropertyListFormat), CFError> { unsafe { let mut error: CFErrorRef = ptr::null_mut(); let mut format: CFPropertyListFormat = 0; - let property_list = CFPropertyListCreateWithData(kCFAllocatorDefault, - data.as_concrete_TypeRef(), - options, - &mut format, - &mut error); + let property_list = CFPropertyListCreateWithData( + kCFAllocatorDefault, + data.as_concrete_TypeRef(), + options, + &mut format, + &mut error, + ); if property_list.is_null() { Err(TCFType::wrap_under_create_rule(error)) } else { @@ -41,14 +45,14 @@ pub fn create_with_data(data: CFData, } } -pub fn create_data(property_list: *const c_void, format: CFPropertyListFormat) -> Result { +pub fn create_data( + property_list: *const c_void, + format: CFPropertyListFormat, +) -> Result { unsafe { let mut error: CFErrorRef = ptr::null_mut(); - let data_ref = CFPropertyListCreateData(kCFAllocatorDefault, - property_list, - format, - 0, - &mut error); + let data_ref = + CFPropertyListCreateData(kCFAllocatorDefault, property_list, format, 0, &mut error); if data_ref.is_null() { Err(TCFType::wrap_under_create_rule(error)) } else { @@ -57,7 +61,6 @@ pub fn create_data(property_list: *const c_void, format: CFPropertyListFormat) - } } - /// Trait for all subclasses of [`CFPropertyList`]. /// /// [`CFPropertyList`]: struct.CFPropertyList.html @@ -84,16 +87,15 @@ pub trait CFPropertyListSubClass: TCFType { } } -impl CFPropertyListSubClass for ::data::CFData {} -impl CFPropertyListSubClass for ::string::CFString {} -impl CFPropertyListSubClass for ::array::CFArray {} -impl CFPropertyListSubClass for ::dictionary::CFDictionary {} -impl CFPropertyListSubClass for ::date::CFDate {} -impl CFPropertyListSubClass for ::boolean::CFBoolean {} -impl CFPropertyListSubClass for ::number::CFNumber {} - +impl CFPropertyListSubClass for crate::data::CFData {} +impl CFPropertyListSubClass for crate::string::CFString {} +impl CFPropertyListSubClass for crate::array::CFArray {} +impl CFPropertyListSubClass for crate::dictionary::CFDictionary {} +impl CFPropertyListSubClass for crate::date::CFDate {} +impl CFPropertyListSubClass for crate::boolean::CFBoolean {} +impl CFPropertyListSubClass for crate::number::CFNumber {} -declare_TCFType!{ +declare_TCFType! { /// A CFPropertyList struct. This is superclass to [`CFData`], [`CFString`], [`CFArray`], /// [`CFDictionary`], [`CFDate`], [`CFBoolean`], and [`CFNumber`]. /// @@ -161,8 +163,8 @@ impl CFPropertyList { unsafe { CFGetRetainCount(self.as_CFTypeRef()) } } - /// Returns the type ID of this object. Will be one of CFData, CFString, CFArray, CFDictionary, - /// CFDate, CFBoolean, or CFNumber. + /// Returns the type ID of this object. Will be one of `CFData`, `CFString`, `CFArray`, + /// `CFDictionary`, `CFDate`, `CFBoolean`, or `CFNumber`. #[inline] pub fn type_of(&self) -> CFTypeID { unsafe { CFGetTypeID(self.as_CFTypeRef()) } @@ -173,7 +175,7 @@ impl CFPropertyList { unsafe { CFShow(self.as_CFTypeRef()) } } - /// Returns true if this value is an instance of another type. + /// Returns `true` if this value is an instance of another type. #[inline] pub fn instance_of(&self) -> bool { self.type_of() == OtherCFType::type_id() @@ -244,33 +246,33 @@ impl CFPropertyList { } } - - #[cfg(test)] pub mod test { use super::*; - use string::CFString; - use boolean::CFBoolean; + use crate::boolean::CFBoolean; + use crate::string::CFString; #[test] fn test_property_list_serialization() { - use base::{TCFType, CFEqual}; - use boolean::CFBoolean; - use number::CFNumber; - use dictionary::CFDictionary; - use string::CFString; use super::*; + use crate::base::{CFEqual, TCFType}; + use crate::boolean::CFBoolean; + use crate::dictionary::CFDictionary; + use crate::number::CFNumber; + use crate::string::CFString; let bar = CFString::from_static_string("Bar"); let baz = CFString::from_static_string("Baz"); let boo = CFString::from_static_string("Boo"); let foo = CFString::from_static_string("Foo"); let tru = CFBoolean::true_value(); - let n42 = CFNumber::from(1i64<<33); + let n42 = CFNumber::from(1i64 << 33); - let dict1 = CFDictionary::from_CFType_pairs(&[(bar.as_CFType(), boo.as_CFType()), - (baz.as_CFType(), tru.as_CFType()), - (foo.as_CFType(), n42.as_CFType())]); + let dict1 = CFDictionary::from_CFType_pairs(&[ + (bar.as_CFType(), boo.as_CFType()), + (baz.as_CFType(), tru.as_CFType()), + (foo.as_CFType(), n42.as_CFType()), + ]); let data = create_data(dict1.as_CFTypeRef(), kCFPropertyListXMLFormat_v1_0).unwrap(); let (dict2, _) = create_with_data(data, kCFPropertyListImmutable).unwrap(); @@ -281,7 +283,7 @@ pub mod test { #[test] fn to_propertylist_retain_count() { - let string = CFString::from_static_string("Bar"); + let string = CFString::from_static_string("alongerstring"); assert_eq!(string.retain_count(), 1); let propertylist = string.to_CFPropertyList(); @@ -295,7 +297,10 @@ pub mod test { #[test] fn downcast_string() { let propertylist = CFString::from_static_string("Bar").to_CFPropertyList(); - assert_eq!(propertylist.downcast::().unwrap().to_string(), "Bar"); + assert_eq!( + propertylist.downcast::().unwrap().to_string(), + "Bar" + ); assert!(propertylist.downcast::().is_none()); } @@ -308,7 +313,7 @@ pub mod test { #[test] fn downcast_into_fail() { - let string = CFString::from_static_string("Bar"); + let string = CFString::from_static_string("alongerstring"); let propertylist = string.to_CFPropertyList(); assert_eq!(string.retain_count(), 2); @@ -318,12 +323,12 @@ pub mod test { #[test] fn downcast_into() { - let string = CFString::from_static_string("Bar"); + let string = CFString::from_static_string("alongerstring"); let propertylist = string.to_CFPropertyList(); assert_eq!(string.retain_count(), 2); let string2 = propertylist.downcast_into::().unwrap(); - assert_eq!(string2.to_string(), "Bar"); + assert_eq!(string2.to_string(), "alongerstring"); assert_eq!(string2.retain_count(), 2); } } diff --git a/vendor/core-foundation/src/runloop.rs b/vendor/core-foundation/src/runloop.rs index be06f4ec7..304c0716d 100644 --- a/vendor/core-foundation/src/runloop.rs +++ b/vendor/core-foundation/src/runloop.rs @@ -9,23 +9,26 @@ #![allow(non_upper_case_globals)] -pub use core_foundation_sys::runloop::*; use core_foundation_sys::base::CFIndex; use core_foundation_sys::base::{kCFAllocatorDefault, CFOptionFlags}; +pub use core_foundation_sys::runloop::*; use core_foundation_sys::string::CFStringRef; -use base::{TCFType}; -use date::{CFAbsoluteTime, CFTimeInterval}; -use filedescriptor::CFFileDescriptor; -use string::{CFString}; +use crate::base::TCFType; +use crate::date::{CFAbsoluteTime, CFTimeInterval}; +use crate::filedescriptor::CFFileDescriptor; +use crate::string::CFString; pub type CFRunLoopMode = CFStringRef; - declare_TCFType!(CFRunLoop, CFRunLoopRef); impl_TCFType!(CFRunLoop, CFRunLoopRef, CFRunLoopGetTypeID); impl_CFTypeDescription!(CFRunLoop); +// https://github.com/servo/core-foundation-rs/issues/550 +unsafe impl Send for CFRunLoop {} +unsafe impl Sync for CFRunLoop {} + #[derive(Copy, Clone, Debug, PartialEq)] pub enum CFRunLoopRunResult { Finished = 1, @@ -92,9 +95,7 @@ impl CFRunLoop { } pub fn contains_timer(&self, timer: &CFRunLoopTimer, mode: CFRunLoopMode) -> bool { - unsafe { - CFRunLoopContainsTimer(self.0, timer.0, mode) != 0 - } + unsafe { CFRunLoopContainsTimer(self.0, timer.0, mode) != 0 } } pub fn add_timer(&self, timer: &CFRunLoopTimer, mode: CFRunLoopMode) { @@ -110,9 +111,7 @@ impl CFRunLoop { } pub fn contains_source(&self, source: &CFRunLoopSource, mode: CFRunLoopMode) -> bool { - unsafe { - CFRunLoopContainsSource(self.0, source.0, mode) != 0 - } + unsafe { CFRunLoopContainsSource(self.0, source.0, mode) != 0 } } pub fn add_source(&self, source: &CFRunLoopSource, mode: CFRunLoopMode) { @@ -128,9 +127,7 @@ impl CFRunLoop { } pub fn contains_observer(&self, observer: &CFRunLoopObserver, mode: CFRunLoopMode) -> bool { - unsafe { - CFRunLoopContainsObserver(self.0, observer.0, mode) != 0 - } + unsafe { CFRunLoopContainsObserver(self.0, observer.0, mode) != 0 } } pub fn add_observer(&self, observer: &CFRunLoopObserver, mode: CFRunLoopMode) { @@ -144,25 +141,41 @@ impl CFRunLoop { CFRunLoopRemoveObserver(self.0, observer.0, mode); } } - } - declare_TCFType!(CFRunLoopTimer, CFRunLoopTimerRef); impl_TCFType!(CFRunLoopTimer, CFRunLoopTimerRef, CFRunLoopTimerGetTypeID); impl CFRunLoopTimer { - pub fn new(fireDate: CFAbsoluteTime, interval: CFTimeInterval, flags: CFOptionFlags, order: CFIndex, callout: CFRunLoopTimerCallBack, context: *mut CFRunLoopTimerContext) -> CFRunLoopTimer { + pub fn new( + fireDate: CFAbsoluteTime, + interval: CFTimeInterval, + flags: CFOptionFlags, + order: CFIndex, + callout: CFRunLoopTimerCallBack, + context: *mut CFRunLoopTimerContext, + ) -> CFRunLoopTimer { unsafe { - let timer_ref = CFRunLoopTimerCreate(kCFAllocatorDefault, fireDate, interval, flags, order, callout, context); + let timer_ref = CFRunLoopTimerCreate( + kCFAllocatorDefault, + fireDate, + interval, + flags, + order, + callout, + context, + ); TCFType::wrap_under_create_rule(timer_ref) } } } - declare_TCFType!(CFRunLoopSource, CFRunLoopSourceRef); -impl_TCFType!(CFRunLoopSource, CFRunLoopSourceRef, CFRunLoopSourceGetTypeID); +impl_TCFType!( + CFRunLoopSource, + CFRunLoopSourceRef, + CFRunLoopSourceGetTypeID +); impl CFRunLoopSource { pub fn from_file_descriptor(fd: &CFFileDescriptor, order: CFIndex) -> Option { @@ -171,15 +184,23 @@ impl CFRunLoopSource { } declare_TCFType!(CFRunLoopObserver, CFRunLoopObserverRef); -impl_TCFType!(CFRunLoopObserver, CFRunLoopObserverRef, CFRunLoopObserverGetTypeID); +impl_TCFType!( + CFRunLoopObserver, + CFRunLoopObserverRef, + CFRunLoopObserverGetTypeID +); #[cfg(test)] mod test { use super::*; - use date::{CFDate, CFAbsoluteTime}; + use crate::base::Boolean; + use crate::date::{CFAbsoluteTime, CFDate}; use std::mem; use std::os::raw::c_void; + use std::ptr::null_mut; use std::sync::mpsc; + use std::thread::spawn; + use std::time::Duration; #[test] fn wait_200_milliseconds() { @@ -199,7 +220,8 @@ mod test { copyDescription: None, }; - let run_loop_timer = CFRunLoopTimer::new(now + 0.20f64, 0f64, 0, 0, timer_popped, &mut context); + let run_loop_timer = + CFRunLoopTimer::new(now + 0.20f64, 0f64, 0, 0, timer_popped, &mut context); unsafe { run_loop.add_timer(&run_loop_timer, kCFRunLoopDefaultMode); } @@ -221,4 +243,62 @@ mod test { let _ = unsafe { (*info).elapsed_tx.send(elapsed) }; CFRunLoop::get_current().stop(); } + + extern "C" fn observe(_: CFRunLoopObserverRef, _: CFRunLoopActivity, context: *mut c_void) { + let tx: &mpsc::Sender = unsafe { &*(context as *const _) }; + let _ = tx.send(CFRunLoop::get_current()); + } + + extern "C" fn observe_timer_popped(_: CFRunLoopTimerRef, _: *mut c_void) { + panic!("timer popped unexpectedly"); + } + + #[test] + fn observe_runloop() { + let (tx, rx) = mpsc::channel(); + spawn(move || { + let mut context = CFRunLoopObserverContext { + version: 0, + info: &tx as *const _ as *mut c_void, + retain: None, + release: None, + copyDescription: None, + }; + + let observer = unsafe { + CFRunLoopObserver::wrap_under_create_rule(CFRunLoopObserverCreate( + kCFAllocatorDefault, + kCFRunLoopEntry, + false as Boolean, + 0, + observe, + &mut context, + )) + }; + + let runloop = CFRunLoop::get_current(); + runloop.add_observer(&observer, unsafe { kCFRunLoopDefaultMode }); + + let timer = CFRunLoopTimer::new( + CFDate::now().abs_time() + 1f64, + 0f64, + 0, + 0, + observe_timer_popped, + null_mut(), + ); + runloop.add_timer(&timer, unsafe { kCFRunLoopDefaultMode }); + + let result = unsafe { + CFRunLoop::run_in_mode(kCFRunLoopDefaultMode, Duration::from_secs(10), false) + }; + + assert_eq!(result, CFRunLoopRunResult::Stopped); + + drop(tx); + }); + + let runloop: CFRunLoop = rx.recv().unwrap(); + runloop.stop(); + } } diff --git a/vendor/core-foundation/src/set.rs b/vendor/core-foundation/src/set.rs index eb1d357a0..641202de8 100644 --- a/vendor/core-foundation/src/set.rs +++ b/vendor/core-foundation/src/set.rs @@ -9,13 +9,13 @@ //! An immutable bag of elements. +use core_foundation_sys::base::{kCFAllocatorDefault, CFRelease, CFTypeRef}; pub use core_foundation_sys::set::*; -use core_foundation_sys::base::{CFTypeRef, CFRelease, kCFAllocatorDefault}; -use base::{CFIndexConvertible, TCFType}; +use crate::base::{CFIndexConvertible, TCFType}; -use std::os::raw::c_void; use std::marker::PhantomData; +use std::os::raw::c_void; /// An immutable bag of elements. pub struct CFSet(CFSetRef, PhantomData); @@ -31,23 +31,31 @@ impl_CFTypeDescription!(CFSet); impl CFSet { /// Creates a new set from a list of `CFType` instances. - pub fn from_slice(elems: &[T]) -> CFSet where T: TCFType { + pub fn from_slice(elems: &[T]) -> CFSet + where + T: TCFType, + { unsafe { let elems: Vec = elems.iter().map(|elem| elem.as_CFTypeRef()).collect(); - let set_ref = CFSetCreate(kCFAllocatorDefault, - elems.as_ptr(), - elems.len().to_CFIndex(), - &kCFTypeSetCallBacks); + let set_ref = CFSetCreate( + kCFAllocatorDefault, + elems.as_ptr(), + elems.len().to_CFIndex(), + &kCFTypeSetCallBacks, + ); TCFType::wrap_under_create_rule(set_ref) } } } impl CFSet { - /// Get the number of elements in the CFSet + /// Get the number of elements in the `CFSet`. pub fn len(&self) -> usize { - unsafe { - CFSetGetCount(self.0) as usize - } + unsafe { CFSetGetCount(self.0) as usize } + } + + /// Returns `true` if the set contains no elements. + pub fn is_empty(&self) -> bool { + self.len() == 0 } } diff --git a/vendor/core-foundation/src/string.rs b/vendor/core-foundation/src/string.rs index 3f5994bc5..3358bab55 100644 --- a/vendor/core-foundation/src/string.rs +++ b/vendor/core-foundation/src/string.rs @@ -11,18 +11,17 @@ pub use core_foundation_sys::string::*; -use base::{CFIndexConvertible, TCFType}; +use crate::base::{CFIndexConvertible, TCFType}; -use core_foundation_sys::base::{Boolean, CFIndex, CFRange}; use core_foundation_sys::base::{kCFAllocatorDefault, kCFAllocatorNull}; +use core_foundation_sys::base::{Boolean, CFIndex, CFRange}; use std::borrow::Cow; +use std::ffi::CStr; use std::fmt; -use std::str::{self, FromStr}; use std::ptr; -use std::ffi::CStr; - +use std::str::{self, FromStr}; -declare_TCFType!{ +declare_TCFType! { /// An immutable string in one of a variety of encodings. CFString, CFStringRef } @@ -31,7 +30,7 @@ impl_TCFType!(CFString, CFStringRef, CFStringGetTypeID); impl FromStr for CFString { type Err = (); - /// See also CFString::new for a variant of this which does not return a Result + /// See also [`CFString::new()`] for a variant of this which does not return a `Result`. #[inline] fn from_str(string: &str) -> Result { Ok(CFString::new(string)) @@ -58,27 +57,37 @@ impl<'a> From<&'a CFString> for Cow<'a, str> { // First, ask how big the buffer ought to be. let mut bytes_required: CFIndex = 0; - CFStringGetBytes(cf_str.0, - CFRange { location: 0, length: char_len }, - kCFStringEncodingUTF8, - 0, - false as Boolean, - ptr::null_mut(), - 0, - &mut bytes_required); + CFStringGetBytes( + cf_str.0, + CFRange { + location: 0, + length: char_len, + }, + kCFStringEncodingUTF8, + 0, + false as Boolean, + ptr::null_mut(), + 0, + &mut bytes_required, + ); // Then, allocate the buffer and actually copy. let mut buffer = vec![b'\x00'; bytes_required as usize]; let mut bytes_used: CFIndex = 0; - let chars_written = CFStringGetBytes(cf_str.0, - CFRange { location: 0, length: char_len }, - kCFStringEncodingUTF8, - 0, - false as Boolean, - buffer.as_mut_ptr(), - buffer.len().to_CFIndex(), - &mut bytes_used); + let chars_written = CFStringGetBytes( + cf_str.0, + CFRange { + location: 0, + length: char_len, + }, + kCFStringEncodingUTF8, + 0, + false as Boolean, + buffer.as_mut_ptr(), + buffer.len().to_CFIndex(), + &mut bytes_used, + ); assert_eq!(chars_written, char_len); // This is dangerous; we over-allocate and null-terminate the string (during @@ -102,17 +111,18 @@ impl fmt::Debug for CFString { } } - impl CFString { /// Creates a new `CFString` instance from a Rust string. #[inline] pub fn new(string: &str) -> CFString { unsafe { - let string_ref = CFStringCreateWithBytes(kCFAllocatorDefault, - string.as_ptr(), - string.len().to_CFIndex(), - kCFStringEncodingUTF8, - false as Boolean); + let string_ref = CFStringCreateWithBytes( + kCFAllocatorDefault, + string.as_ptr(), + string.len().to_CFIndex(), + kCFStringEncodingUTF8, + false as Boolean, + ); CFString::wrap_under_create_rule(string_ref) } } @@ -122,12 +132,14 @@ impl CFString { #[inline] pub fn from_static_string(string: &'static str) -> CFString { unsafe { - let string_ref = CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, - string.as_ptr(), - string.len().to_CFIndex(), - kCFStringEncodingUTF8, - false as Boolean, - kCFAllocatorNull); + let string_ref = CFStringCreateWithBytesNoCopy( + kCFAllocatorDefault, + string.as_ptr(), + string.len().to_CFIndex(), + kCFStringEncodingUTF8, + false as Boolean, + kCFAllocatorNull, + ); TCFType::wrap_under_create_rule(string_ref) } } @@ -135,21 +147,21 @@ impl CFString { /// Returns the number of characters in the string. #[inline] pub fn char_len(&self) -> CFIndex { - unsafe { - CFStringGetLength(self.0) - } + unsafe { CFStringGetLength(self.0) } } } impl<'a> PartialEq<&'a str> for CFString { fn eq(&self, other: &&str) -> bool { unsafe { - let temp = CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, - other.as_ptr(), - other.len().to_CFIndex(), - kCFStringEncodingUTF8, - false as Boolean, - kCFAllocatorNull); + let temp = CFStringCreateWithBytesNoCopy( + kCFAllocatorDefault, + other.as_ptr(), + other.len().to_CFIndex(), + kCFStringEncodingUTF8, + false as Boolean, + kCFAllocatorNull, + ); self.eq(&CFString::wrap_under_create_rule(temp)) } } diff --git a/vendor/core-foundation/src/timezone.rs b/vendor/core-foundation/src/timezone.rs index a8bb2ed1d..46123dcc2 100644 --- a/vendor/core-foundation/src/timezone.rs +++ b/vendor/core-foundation/src/timezone.rs @@ -9,18 +9,17 @@ //! Core Foundation time zone objects. -pub use core_foundation_sys::timezone::*; use core_foundation_sys::base::kCFAllocatorDefault; +pub use core_foundation_sys::timezone::*; -use base::TCFType; -use date::{CFDate, CFTimeInterval}; -use string::CFString; +use crate::base::TCFType; +use crate::date::{CFDate, CFTimeInterval}; +use crate::string::CFString; #[cfg(feature = "with-chrono")] use chrono::{FixedOffset, NaiveDateTime}; - -declare_TCFType!{ +declare_TCFType! { /// A time zone. CFTimeZone, CFTimeZoneRef } @@ -54,9 +53,7 @@ impl CFTimeZone { } pub fn seconds_from_gmt(&self, date: CFDate) -> CFTimeInterval { - unsafe { - CFTimeZoneGetSecondsFromGMT(self.0, date.abs_time()) - } + unsafe { CFTimeZoneGetSecondsFromGMT(self.0, date.abs_time()) } } #[cfg(feature = "with-chrono")] @@ -70,12 +67,10 @@ impl CFTimeZone { CFTimeZone::new(offset.local_minus_utc() as f64) } - /// The timezone database ID that identifies the time zone. E.g. "America/Los_Angeles" or - /// "Europe/Paris". + /// The timezone database ID that identifies the time zone. E.g. `"America/Los_Angeles" `or + /// `"Europe/Paris"`. pub fn name(&self) -> CFString { - unsafe { - CFString::wrap_under_get_rule(CFTimeZoneGetName(self.0)) - } + unsafe { CFString::wrap_under_get_rule(CFTimeZoneGetName(self.0)) } } } @@ -84,7 +79,7 @@ mod test { use super::CFTimeZone; #[cfg(feature = "with-chrono")] - use chrono::{NaiveDateTime, FixedOffset}; + use chrono::{FixedOffset, NaiveDateTime}; #[test] fn timezone_comparison() { diff --git a/vendor/core-foundation/src/url.rs b/vendor/core-foundation/src/url.rs index 064dd7b5e..b92984438 100644 --- a/vendor/core-foundation/src/url.rs +++ b/vendor/core-foundation/src/url.rs @@ -11,21 +11,20 @@ pub use core_foundation_sys::url::*; -use base::{TCFType, CFIndex}; -use string::{CFString}; +use crate::base::{CFIndex, TCFType}; +use crate::string::CFString; use core_foundation_sys::base::{kCFAllocatorDefault, Boolean}; use std::fmt; -use std::ptr; use std::path::{Path, PathBuf}; +use std::ptr; use libc::{c_char, strlen, PATH_MAX}; -#[cfg(unix)] -use std::os::unix::ffi::OsStrExt; #[cfg(unix)] use std::ffi::OsStr; - +#[cfg(unix)] +use std::os::unix::ffi::OsStrExt; declare_TCFType!(CFURL, CFURLRef); impl_TCFType!(CFURL, CFURLRef, CFURLGetTypeID); @@ -35,7 +34,7 @@ impl fmt::Debug for CFURL { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { unsafe { let string: CFString = TCFType::wrap_under_get_rule(CFURLGetString(self.0)); - write!(f, "{}", string.to_string()) + write!(f, "{}", string) } } } @@ -58,7 +57,12 @@ impl CFURL { } unsafe { - let url_ref = CFURLCreateFromFileSystemRepresentation(ptr::null_mut(), path_bytes.as_ptr(), path_bytes.len() as CFIndex, isDirectory as u8); + let url_ref = CFURLCreateFromFileSystemRepresentation( + ptr::null_mut(), + path_bytes.as_ptr(), + path_bytes.len() as CFIndex, + isDirectory as u8, + ); if url_ref.is_null() { return None; } @@ -66,9 +70,18 @@ impl CFURL { } } - pub fn from_file_system_path(filePath: CFString, pathStyle: CFURLPathStyle, isDirectory: bool) -> CFURL { + pub fn from_file_system_path( + filePath: CFString, + pathStyle: CFURLPathStyle, + isDirectory: bool, + ) -> CFURL { unsafe { - let url_ref = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, filePath.as_concrete_TypeRef(), pathStyle, isDirectory as u8); + let url_ref = CFURLCreateWithFileSystemPath( + kCFAllocatorDefault, + filePath.as_concrete_TypeRef(), + pathStyle, + isDirectory as u8, + ); TCFType::wrap_under_create_rule(url_ref) } } @@ -78,7 +91,12 @@ impl CFURL { // implementing this on Windows is more complicated because of the different OsStr representation unsafe { let mut buf = [0u8; PATH_MAX as usize]; - let result = CFURLGetFileSystemRepresentation(self.0, true as Boolean, buf.as_mut_ptr(), buf.len() as CFIndex); + let result = CFURLGetFileSystemRepresentation( + self.0, + true as Boolean, + buf.as_mut_ptr(), + buf.len() as CFIndex, + ); if result == false as Boolean { return None; } @@ -89,21 +107,20 @@ impl CFURL { } pub fn get_string(&self) -> CFString { - unsafe { - TCFType::wrap_under_get_rule(CFURLGetString(self.0)) - } + unsafe { TCFType::wrap_under_get_rule(CFURLGetString(self.0)) } } pub fn get_file_system_path(&self, pathStyle: CFURLPathStyle) -> CFString { unsafe { - TCFType::wrap_under_create_rule(CFURLCopyFileSystemPath(self.as_concrete_TypeRef(), pathStyle)) + TCFType::wrap_under_create_rule(CFURLCopyFileSystemPath( + self.as_concrete_TypeRef(), + pathStyle, + )) } } pub fn absolute(&self) -> CFURL { - unsafe { - TCFType::wrap_under_create_rule(CFURLCopyAbsoluteURL(self.as_concrete_TypeRef())) - } + unsafe { TCFType::wrap_under_create_rule(CFURLCopyAbsoluteURL(self.as_concrete_TypeRef())) } } } @@ -138,18 +155,30 @@ fn absolute_file_url() { let cfstr_file = CFString::from_static_string(file); let cfurl_base = CFURL::from_file_system_path(cfstr_path, kCFURLPOSIXPathStyle, true); let cfurl_relative: CFURL = unsafe { - let url_ref = CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorDefault, + let url_ref = CFURLCreateWithFileSystemPathRelativeToBase( + kCFAllocatorDefault, cfstr_file.as_concrete_TypeRef(), kCFURLPOSIXPathStyle, false as u8, - cfurl_base.as_concrete_TypeRef()); + cfurl_base.as_concrete_TypeRef(), + ); TCFType::wrap_under_create_rule(url_ref) }; let mut absolute_path = PathBuf::from(path); absolute_path.push(file); - assert_eq!(cfurl_relative.get_file_system_path(kCFURLPOSIXPathStyle).to_string(), file); - assert_eq!(cfurl_relative.absolute().get_file_system_path(kCFURLPOSIXPathStyle).to_string(), - absolute_path.to_str().unwrap()); + assert_eq!( + cfurl_relative + .get_file_system_path(kCFURLPOSIXPathStyle) + .to_string(), + file + ); + assert_eq!( + cfurl_relative + .absolute() + .get_file_system_path(kCFURLPOSIXPathStyle) + .to_string(), + absolute_path.to_str().unwrap() + ); } diff --git a/vendor/core-foundation/src/uuid.rs b/vendor/core-foundation/src/uuid.rs index 6be734dab..834a6dd9d 100644 --- a/vendor/core-foundation/src/uuid.rs +++ b/vendor/core-foundation/src/uuid.rs @@ -12,15 +12,14 @@ #[cfg(feature = "with-uuid")] extern crate uuid; -pub use core_foundation_sys::uuid::*; use core_foundation_sys::base::kCFAllocatorDefault; +pub use core_foundation_sys::uuid::*; -use base::TCFType; +use crate::base::TCFType; #[cfg(feature = "with-uuid")] use self::uuid::Uuid; - declare_TCFType! { /// A UUID. CFUUID, CFUUIDRef @@ -45,28 +44,12 @@ impl Default for CFUUID { } #[cfg(feature = "with-uuid")] -impl Into for CFUUID { - fn into(self) -> Uuid { - let b = unsafe { - CFUUIDGetUUIDBytes(self.0) - }; +impl From for Uuid { + fn from(val: CFUUID) -> Self { + let b = unsafe { CFUUIDGetUUIDBytes(val.0) }; let bytes = [ - b.byte0, - b.byte1, - b.byte2, - b.byte3, - b.byte4, - b.byte5, - b.byte6, - b.byte7, - b.byte8, - b.byte9, - b.byte10, - b.byte11, - b.byte12, - b.byte13, - b.byte14, - b.byte15, + b.byte0, b.byte1, b.byte2, b.byte3, b.byte4, b.byte5, b.byte6, b.byte7, b.byte8, + b.byte9, b.byte10, b.byte11, b.byte12, b.byte13, b.byte14, b.byte15, ]; Uuid::from_bytes(&bytes).unwrap() } @@ -101,7 +84,6 @@ impl From for CFUUID { } } - #[cfg(test)] #[cfg(feature = "with-uuid")] mod test { -- cgit v1.2.3