From 6ddf5cadcc374111e44e4027ddfded78984d39b5 Mon Sep 17 00:00:00 2001 From: George Burton Date: Tue, 25 Apr 2023 22:15:52 +0100 Subject: [PATCH 1/2] Update `foreign-types` crate to v0.5 --- cocoa-foundation/Cargo.toml | 2 +- cocoa/Cargo.toml | 2 +- core-graphics-types/Cargo.toml | 1 - core-graphics/Cargo.toml | 2 +- core-graphics/src/color_space.rs | 10 ++++----- core-graphics/src/context.rs | 10 ++++----- core-graphics/src/data_provider.rs | 10 ++++----- core-graphics/src/display.rs | 10 ++++----- core-graphics/src/event.rs | 10 ++++----- core-graphics/src/event_source.rs | 10 ++++----- core-graphics/src/font.rs | 35 +++++++++++++----------------- core-graphics/src/gradient.rs | 10 ++++----- core-graphics/src/image.rs | 10 ++++----- core-graphics/src/path.rs | 12 +++++----- core-text/Cargo.toml | 2 +- 15 files changed, 65 insertions(+), 71 deletions(-) diff --git a/cocoa-foundation/Cargo.toml b/cocoa-foundation/Cargo.toml index 817b2ba..4e0e37a 100644 --- a/cocoa-foundation/Cargo.toml +++ b/cocoa-foundation/Cargo.toml @@ -17,5 +17,5 @@ bitflags = "1.0" libc = "0.2" core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } -foreign-types = "0.3" +foreign-types = "0.5" objc = "0.2.3" diff --git a/cocoa/Cargo.toml b/cocoa/Cargo.toml index 776c51d..0766e8e 100644 --- a/cocoa/Cargo.toml +++ b/cocoa/Cargo.toml @@ -18,5 +18,5 @@ libc = "0.2" cocoa-foundation = { path = "../cocoa-foundation", version = "0.1" } core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics = { path = "../core-graphics", version = "0.22" } -foreign-types = "0.3" +foreign-types = "0.5" objc = "0.2.3" diff --git a/core-graphics-types/Cargo.toml b/core-graphics-types/Cargo.toml index 6c7d0a5..5055dfd 100644 --- a/core-graphics-types/Cargo.toml +++ b/core-graphics-types/Cargo.toml @@ -10,7 +10,6 @@ license = "MIT OR Apache-2.0" [dependencies] bitflags = "1.0" core-foundation = { path = "../core-foundation", version = "0.9" } -foreign-types = "0.3.0" libc = "0.2" [package.metadata.docs.rs] diff --git a/core-graphics/Cargo.toml b/core-graphics/Cargo.toml index 95f4e49..35907d0 100644 --- a/core-graphics/Cargo.toml +++ b/core-graphics/Cargo.toml @@ -16,7 +16,7 @@ highsierra = [] bitflags = "1.0" core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } -foreign-types = "0.3.0" +foreign-types = "0.5.0" libc = "0.2" [package.metadata.docs.rs] diff --git a/core-graphics/src/color_space.rs b/core-graphics/src/color_space.rs index 3c4658c..2b29635 100644 --- a/core-graphics/src/color_space.rs +++ b/core-graphics/src/color_space.rs @@ -13,11 +13,11 @@ use foreign_types::ForeignType; foreign_type! { #[doc(hidden)] - type CType = ::sys::CGColorSpace; - fn drop = |p| CFRelease(p as *mut _); - fn clone = |p| CFRetain(p as *const _) as *mut _; - pub struct CGColorSpace; - pub struct CGColorSpaceRef; + pub unsafe type CGColorSpace { + type CType = ::sys::CGColorSpace; + fn drop = |p| CFRelease(p as *mut _); + fn clone = |p| CFRetain(p as *const _) as *mut _; + } } impl CGColorSpace { diff --git a/core-graphics/src/context.rs b/core-graphics/src/context.rs index 643c06c..aca5fb7 100644 --- a/core-graphics/src/context.rs +++ b/core-graphics/src/context.rs @@ -109,11 +109,11 @@ pub enum CGInterpolationQuality { foreign_type! { #[doc(hidden)] - type CType = ::sys::CGContext; - fn drop = |cs| CGContextRelease(cs); - fn clone = |p| CGContextRetain(p); - pub struct CGContext; - pub struct CGContextRef; + pub unsafe type CGContext { + type CType = ::sys::CGContext; + fn drop = |cs| CGContextRelease(cs); + fn clone = |p| CGContextRetain(p); + } } impl CGContext { diff --git a/core-graphics/src/data_provider.rs b/core-graphics/src/data_provider.rs index e8bb0a0..38d515e 100644 --- a/core-graphics/src/data_provider.rs +++ b/core-graphics/src/data_provider.rs @@ -32,11 +32,11 @@ pub type CGDataProviderGetBytesAtPositionCallback = Option CGEventTap<'tap_life> { foreign_type! { #[doc(hidden)] - type CType = ::sys::CGEvent; - fn drop = |p| CFRelease(p as *mut _); - fn clone = |p| CFRetain(p as *const _) as *mut _; - pub struct CGEvent; - pub struct CGEventRef; + pub unsafe type CGEvent { + type CType = ::sys::CGEvent; + fn drop = |p| CFRelease(p as *mut _); + fn clone = |p| CFRetain(p as *const _) as *mut _; + } } impl CGEvent { diff --git a/core-graphics/src/event_source.rs b/core-graphics/src/event_source.rs index ce13f5a..6db64a2 100644 --- a/core-graphics/src/event_source.rs +++ b/core-graphics/src/event_source.rs @@ -12,11 +12,11 @@ pub enum CGEventSourceStateID { foreign_type! { #[doc(hidden)] - type CType = ::sys::CGEventSource; - fn drop = |p| CFRelease(p as *mut _); - fn clone = |p| CFRetain(p as *const _) as *mut _; - pub struct CGEventSource; - pub struct CGEventSourceRef; + pub unsafe type CGEventSource { + type CType = ::sys::CGEventSource; + fn drop = |p| CFRelease(p as *mut _); + fn clone = |p| CFRetain(p as *const _) as *mut _; + } } impl CGEventSource { diff --git a/core-graphics/src/font.rs b/core-graphics/src/font.rs index adf7a14..739b8dd 100644 --- a/core-graphics/src/font.rs +++ b/core-graphics/src/font.rs @@ -15,6 +15,7 @@ use core_foundation::string::{CFString, CFStringRef}; use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; use data_provider::CGDataProvider; use geometry::CGRect; +use std::ptr::NonNull; use foreign_types::ForeignType; @@ -24,16 +25,13 @@ pub use core_graphics_types::base::CGGlyph; foreign_type! { #[doc(hidden)] - type CType = ::sys::CGFont; - fn drop = |p| CFRelease(p as *mut _); - fn clone = |p| CFRetain(p as *const _) as *mut _; - pub struct CGFont; - pub struct CGFontRef; + pub unsafe type CGFont: Send + Sync { + type CType = ::sys::CGFont; + fn drop = |p| CFRelease(p as *mut _); + fn clone = |p| CFRetain(p as *const _) as *mut _; + } } -unsafe impl Send for CGFont {} -unsafe impl Sync for CGFont {} - impl CGFont { pub fn type_id() -> CFTypeID { unsafe { @@ -44,10 +42,9 @@ impl CGFont { pub fn from_data_provider(provider: CGDataProvider) -> Result { unsafe { let font_ref = CGFontCreateWithDataProvider(provider.as_ptr()); - if !font_ref.is_null() { - Ok(CGFont::from_ptr(font_ref)) - } else { - Err(()) + match NonNull::new(font_ref) { + Some(font_ref) => Ok(CGFont(font_ref)), + None => Err(()), } } } @@ -55,10 +52,9 @@ impl CGFont { pub fn from_name(name: &CFString) -> Result { unsafe { let font_ref = CGFontCreateWithFontName(name.as_concrete_TypeRef()); - if !font_ref.is_null() { - Ok(CGFont::from_ptr(font_ref)) - } else { - Err(()) + match NonNull::new(font_ref) { + Some(font_ref) => Ok(CGFont(font_ref)), + None => Err(()), } } } @@ -67,10 +63,9 @@ impl CGFont { unsafe { let font_ref = CGFontCreateCopyWithVariations(self.as_ptr(), vars.as_concrete_TypeRef()); - if !font_ref.is_null() { - Ok(CGFont::from_ptr(font_ref)) - } else { - Err(()) + match NonNull::new(font_ref) { + Some(font_ref) => Ok(CGFont(font_ref)), + None => Err(()), } } } diff --git a/core-graphics/src/gradient.rs b/core-graphics/src/gradient.rs index 5c6cde8..a4fb2bf 100644 --- a/core-graphics/src/gradient.rs +++ b/core-graphics/src/gradient.rs @@ -29,11 +29,11 @@ bitflags! { foreign_type! { #[doc(hidden)] - type CType = ::sys::CGGradient; - fn drop = |p| CFRelease(p as *mut _); - fn clone = |p| CFRetain(p as *const _) as *mut _; - pub struct CGGradient; - pub struct CGGradientRef; + pub unsafe type CGGradient { + type CType = ::sys::CGGradient; + fn drop = |p| CFRelease(p as *mut _); + fn clone = |p| CFRetain(p as *const _) as *mut _; + } } impl CGGradient { diff --git a/core-graphics/src/image.rs b/core-graphics/src/image.rs index f1b9509..9e9323f 100644 --- a/core-graphics/src/image.rs +++ b/core-graphics/src/image.rs @@ -32,11 +32,11 @@ pub enum CGImageByteOrderInfo { foreign_type! { #[doc(hidden)] - type CType = ::sys::CGImage; - fn drop = CGImageRelease; - fn clone = |p| CFRetain(p as *const _) as *mut _; - pub struct CGImage; - pub struct CGImageRef; + pub unsafe type CGImage { + type CType = ::sys::CGImage; + fn drop = CGImageRelease; + fn clone = |p| CFRetain(p as *const _) as *mut _; + } } impl CGImage { diff --git a/core-graphics/src/path.rs b/core-graphics/src/path.rs index dc1c804..c5ac93f 100644 --- a/core-graphics/src/path.rs +++ b/core-graphics/src/path.rs @@ -21,11 +21,11 @@ use std::slice; foreign_type! { #[doc(hidden)] - type CType = ::sys::CGPath; - fn drop = |p| CFRelease(p as *mut _); - fn clone = |p| CFRetain(p as *const _) as *mut _; - pub struct CGPath; - pub struct CGPathRef; + pub unsafe type CGPath { + type CType = ::sys::CGPath; + fn drop = |p| CFRelease(p as *mut _); + fn clone = |p| CFRetain(p as *const _) as *mut _; + } } impl CGPath { @@ -35,7 +35,7 @@ impl CGPath { None => ptr::null(), Some(transform) => transform as *const CGAffineTransform, }; - CGPath(CGPathCreateWithRect(rect, transform)) + CGPath::from_ptr(CGPathCreateWithRect(rect, transform)) } } diff --git a/core-text/Cargo.toml b/core-text/Cargo.toml index 3c8ee96..c8fbff0 100644 --- a/core-text/Cargo.toml +++ b/core-text/Cargo.toml @@ -16,7 +16,7 @@ default = ["mountainlion"] mountainlion = [] [dependencies] -foreign-types = "0.3" +foreign-types = "0.5" libc = "0.2" core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics = { path = "../core-graphics", version = "0.22.0" } From 6215a8bb2b9d5cf604eec5997edd1198669547f8 Mon Sep 17 00:00:00 2001 From: George Burton Date: Tue, 25 Apr 2023 22:33:18 +0100 Subject: [PATCH 2/2] `cocoa-foundation` crate does not depend on `foreign-types` --- cocoa-foundation/Cargo.toml | 1 - cocoa-foundation/src/lib.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/cocoa-foundation/Cargo.toml b/cocoa-foundation/Cargo.toml index 4e0e37a..d6e99af 100644 --- a/cocoa-foundation/Cargo.toml +++ b/cocoa-foundation/Cargo.toml @@ -17,5 +17,4 @@ bitflags = "1.0" libc = "0.2" core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } -foreign-types = "0.5" objc = "0.2.3" diff --git a/cocoa-foundation/src/lib.rs b/cocoa-foundation/src/lib.rs index 6a23ccb..7cd0350 100644 --- a/cocoa-foundation/src/lib.rs +++ b/cocoa-foundation/src/lib.rs @@ -14,7 +14,6 @@ extern crate block; extern crate bitflags; extern crate core_foundation; extern crate core_graphics_types; -extern crate foreign_types; extern crate libc; #[macro_use] extern crate objc;