From 94478aeec3af106ff4ae80c50a236d9da7259ed7 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 16 Jun 2022 06:14:09 +0200 Subject: [PATCH] Implement Encode for most types Using new objc-encode crate --- cocoa-foundation/Cargo.toml | 4 +- cocoa-foundation/src/foundation.rs | 87 ++++++++++++++------ cocoa-foundation/src/lib.rs | 12 +++ cocoa/Cargo.toml | 4 +- cocoa/src/appkit.rs | 82 +++++++++++++++++- cocoa/src/lib.rs | 2 + cocoa/src/quartzcore.rs | 47 +++++++++++ core-foundation-sys/Cargo.toml | 1 + core-foundation-sys/src/array.rs | 4 + core-foundation-sys/src/attributed_string.rs | 4 + core-foundation-sys/src/dictionary.rs | 4 + core-foundation-sys/src/lib.rs | 2 + core-foundation-sys/src/string.rs | 4 + core-graphics-types/Cargo.toml | 1 + core-graphics-types/src/geometry.rs | 30 +++++++ core-graphics-types/src/lib.rs | 1 + core-graphics/Cargo.toml | 1 + core-graphics/src/lib.rs | 1 + core-graphics/src/sys.rs | 14 ++++ 19 files changed, 278 insertions(+), 27 deletions(-) diff --git a/cocoa-foundation/Cargo.toml b/cocoa-foundation/Cargo.toml index 3cedaf174..bfd5f3ba3 100644 --- a/cocoa-foundation/Cargo.toml +++ b/cocoa-foundation/Cargo.toml @@ -18,4 +18,6 @@ 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" -objc = "0.2.3" +# Current `master` of objc +objc = { version = "=0.3.0-alpha.0", package = "objc2" } +objc-encode = "1.1.0" diff --git a/cocoa-foundation/src/foundation.rs b/cocoa-foundation/src/foundation.rs index d64edac2b..f085e6633 100644 --- a/cocoa-foundation/src/foundation.rs +++ b/cocoa-foundation/src/foundation.rs @@ -14,6 +14,7 @@ use std::os::raw::c_void; use base::{id, BOOL, NO, SEL, nil}; use block::Block; use libc; +use objc_encode::{Encode, Encoding}; #[cfg(target_pointer_width = "32")] @@ -37,7 +38,7 @@ mod macos { use base::id; use core_graphics_types::base::CGFloat; use core_graphics_types::geometry::CGRect; - use objc; + use objc_encode::{Encode, Encoding}; #[repr(C)] #[derive(Copy, Clone)] @@ -56,13 +57,9 @@ mod macos { } } - unsafe impl objc::Encode for NSPoint { - fn encode() -> objc::Encoding { - let encoding = format!("{{CGPoint={}{}}}", - CGFloat::encode().as_str(), - CGFloat::encode().as_str()); - unsafe { objc::Encoding::from_str(&encoding) } - } + unsafe impl Encode for NSPoint { + const ENCODING: Encoding<'static> = + Encoding::Struct("CGPoint", &[CGFloat::ENCODING, CGFloat::ENCODING]); } #[repr(C)] @@ -82,13 +79,9 @@ mod macos { } } - unsafe impl objc::Encode for NSSize { - fn encode() -> objc::Encoding { - let encoding = format!("{{CGSize={}{}}}", - CGFloat::encode().as_str(), - CGFloat::encode().as_str()); - unsafe { objc::Encoding::from_str(&encoding) } - } + unsafe impl Encode for NSSize { + const ENCODING: Encoding<'static> = + Encoding::Struct("CGSize", &[CGFloat::ENCODING, CGFloat::ENCODING]); } #[repr(C)] @@ -122,13 +115,9 @@ mod macos { } } - unsafe impl objc::Encode for NSRect { - fn encode() -> objc::Encoding { - let encoding = format!("{{CGRect={}{}}}", - NSPoint::encode().as_str(), - NSSize::encode().as_str()); - unsafe { objc::Encoding::from_str(&encoding) } - } + unsafe impl Encode for NSRect { + const ENCODING: Encoding<'static> = + Encoding::Struct("CGRect", &[NSPoint::ENCODING, NSSize::ENCODING]); } // Same as CGRectEdge @@ -140,6 +129,8 @@ mod macos { NSRectMaxYEdge, } + impl_Encode!(NSRectEdge, u32); + #[link(name = "Foundation", kind = "framework")] extern { fn NSInsetRect(rect: NSRect, x: CGFloat, y: CGFloat) -> NSRect; @@ -169,6 +160,11 @@ pub struct NSRange { pub length: NSUInteger, } +unsafe impl Encode for NSRange { + const ENCODING: Encoding<'static> = + Encoding::Struct("_NSRange", &[NSUInteger::ENCODING, NSUInteger::ENCODING]); +} + impl NSRange { #[inline] pub fn new(location: NSUInteger, length: NSUInteger) -> NSRange { @@ -212,6 +208,17 @@ pub struct NSOperatingSystemVersion { pub patchVersion: NSUInteger, } +unsafe impl Encode for NSOperatingSystemVersion { + const ENCODING: Encoding<'static> = Encoding::Struct( + "NSOperatingSystemVersion", + &[ + NSUInteger::ENCODING, + NSUInteger::ENCODING, + NSUInteger::ENCODING, + ], + ); +} + impl NSOperatingSystemVersion { #[inline] pub fn new(majorVersion: NSUInteger, minorVersion: NSUInteger, patchVersion: NSUInteger) -> NSOperatingSystemVersion { @@ -593,6 +600,8 @@ bitflags! { } } +impl_Encode!(NSEnumerationOptions, libc::c_ulonglong); + pub type NSComparator = *mut Block<(id, id), NSComparisonResult>; #[repr(isize)] @@ -603,6 +612,8 @@ pub enum NSComparisonResult { NSOrderedDescending = 1 } +impl_Encode!(NSComparisonResult, isize); + pub trait NSString: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class!(NSString), alloc] @@ -669,6 +680,23 @@ struct NSFastEnumerationState { pub extra: [libc::c_ulong; 5] } +unsafe impl Encode for NSFastEnumerationState { + const ENCODING: Encoding<'static> = Encoding::Struct( + "?", + &[ + libc::c_ulong::ENCODING, + Encoding::Pointer(&Encoding::Object), + Encoding::Pointer(&libc::c_ulong::ENCODING), + Encoding::Array(5, &libc::c_ulong::ENCODING), + ], + ); +} + +unsafe impl Encode for &'_ NSFastEnumerationState { + const ENCODING: Encoding<'static> = + Encoding::Pointer(&NSFastEnumerationState::ENCODING); +} + const NS_FAST_ENUM_BUF_SIZE: usize = 16; pub struct NSFastIterator { @@ -677,7 +705,7 @@ pub struct NSFastIterator { mut_val: Option, len: usize, idx: usize, - object: id + object: id, } impl Iterator for NSFastIterator { @@ -774,6 +802,8 @@ bitflags! { } } +impl_Encode!(NSURLBookmarkCreationOptions, NSUInteger); + pub type NSURLBookmarkFileCreationOptions = NSURLBookmarkCreationOptions; bitflags! { @@ -784,6 +814,7 @@ bitflags! { } } +impl_Encode!(NSURLBookmarkResolutionOptions, NSUInteger); pub trait NSURL: Sized { unsafe fn alloc(_: Self) -> id; @@ -1337,6 +1368,8 @@ bitflags! { } } +impl_Encode!(NSDataReadingOptions, libc::c_ulonglong); + bitflags! { pub struct NSDataBase64EncodingOptions: libc::c_ulonglong { const NSDataBase64Encoding64CharacterLineLength = 1 << 0; @@ -1346,12 +1379,16 @@ bitflags! { } } +impl_Encode!(NSDataBase64EncodingOptions, libc::c_ulonglong); + bitflags! { pub struct NSDataBase64DecodingOptions: libc::c_ulonglong { const NSDataBase64DecodingIgnoreUnknownCharacters = 1 << 0; } } +impl_Encode!(NSDataBase64DecodingOptions, libc::c_ulonglong); + bitflags! { pub struct NSDataWritingOptions: libc::c_ulonglong { const NSDataWritingAtomic = 1 << 0; @@ -1359,6 +1396,8 @@ bitflags! { } } +impl_Encode!(NSDataWritingOptions, libc::c_ulonglong); + bitflags! { pub struct NSDataSearchOptions: libc::c_ulonglong { const NSDataSearchBackwards = 1 << 0; @@ -1366,6 +1405,8 @@ bitflags! { } } +impl_Encode!(NSDataSearchOptions, libc::c_ulonglong); + pub trait NSUserDefaults { unsafe fn standardUserDefaults() -> Self; diff --git a/cocoa-foundation/src/lib.rs b/cocoa-foundation/src/lib.rs index 6a23ccb88..4b26760eb 100644 --- a/cocoa-foundation/src/lib.rs +++ b/cocoa-foundation/src/lib.rs @@ -16,8 +16,20 @@ extern crate core_foundation; extern crate core_graphics_types; extern crate foreign_types; extern crate libc; +pub extern crate objc_encode; #[macro_use] extern crate objc; +pub use objc_encode as __objc_encode; + +#[macro_export] +macro_rules! impl_Encode { + ($t:ty, $delegation:ty) => { + unsafe impl $crate::__objc_encode::Encode for $t { + const ENCODING: $crate::__objc_encode::Encoding<'static> = <$delegation>::ENCODING; + } + } +} + pub mod base; pub mod foundation; diff --git a/cocoa/Cargo.toml b/cocoa/Cargo.toml index 8746773ee..ac690ac09 100644 --- a/cocoa/Cargo.toml +++ b/cocoa/Cargo.toml @@ -19,4 +19,6 @@ 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" -objc = "0.2.3" +# Current `master` of objc +objc = { version = "=0.3.0-alpha.0", package = "objc2" } +objc-encode = "1.1.0" diff --git a/cocoa/src/appkit.rs b/cocoa/src/appkit.rs index 3ed9e1e57..ea2b39c59 100644 --- a/cocoa/src/appkit.rs +++ b/cocoa/src/appkit.rs @@ -167,6 +167,8 @@ pub enum NSApplicationActivationPolicy { NSApplicationActivationPolicyERROR = -1 } +impl_Encode!(NSApplicationActivationPolicy, i64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSApplicationActivationOptions { @@ -174,6 +176,8 @@ pub enum NSApplicationActivationOptions { NSApplicationActivateIgnoringOtherApps = 1 << 1 } +impl_Encode!(NSApplicationActivationOptions, u64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSApplicationTerminateReply { @@ -182,6 +186,8 @@ pub enum NSApplicationTerminateReply { NSTerminateLater = 2, } +impl_Encode!(NSApplicationTerminateReply, u64); + bitflags! { pub struct NSApplicationPresentationOptions : NSUInteger { const NSApplicationPresentationDefault = 0; @@ -200,6 +206,8 @@ bitflags! { } } +impl_Encode!(NSApplicationPresentationOptions, NSUInteger); + bitflags! { pub struct NSWindowStyleMask: NSUInteger { const NSBorderlessWindowMask = 0; @@ -218,6 +226,8 @@ bitflags! { } } +impl_Encode!(NSWindowStyleMask, NSUInteger); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSWindowTitleVisibility { @@ -225,6 +235,8 @@ pub enum NSWindowTitleVisibility { NSWindowTitleHidden = 1 } +impl_Encode!(NSWindowTitleVisibility, u64); + #[repr(i64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSWindowTabbingMode { @@ -233,6 +245,8 @@ pub enum NSWindowTabbingMode { NSWindowTabbingModePreferred = 2 } +impl_Encode!(NSWindowTabbingMode, i64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSBackingStoreType { @@ -241,6 +255,8 @@ pub enum NSBackingStoreType { NSBackingStoreBuffered = 2 } +impl_Encode!(NSBackingStoreType, u64); + bitflags! { pub struct NSWindowOrderingMode: NSInteger { const NSWindowAbove = 1; @@ -249,6 +265,8 @@ bitflags! { } } +impl_Encode!(NSWindowOrderingMode, NSInteger); + bitflags! { pub struct NSAlignmentOptions: libc::c_ulonglong { const NSAlignMinXInward = 1 << 0; @@ -285,6 +303,8 @@ bitflags! { } } +impl_Encode!(NSAlignmentOptions, libc::c_ulonglong); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSOpenGLPixelFormatAttribute { @@ -329,6 +349,8 @@ pub enum NSOpenGLPixelFormatAttribute { NSOpenGLPFAVirtualScreenCount = 128, } +impl_Encode!(NSOpenGLPixelFormatAttribute, u64); + #[repr(u64)] #[allow(non_camel_case_types)] #[derive(Clone, Copy, Debug, PartialEq)] @@ -338,6 +360,8 @@ pub enum NSOpenGLPFAOpenGLProfiles { NSOpenGLProfileVersion4_1Core = 0x4100, } +impl_Encode!(NSOpenGLPFAOpenGLProfiles, u64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSOpenGLContextParameter { @@ -353,6 +377,8 @@ pub enum NSOpenGLContextParameter { NSOpenGLCPMPSwapsInFlight = 315, } +impl_Encode!(NSOpenGLContextParameter, u64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSWindowButton { @@ -365,6 +391,8 @@ pub enum NSWindowButton { NSWindowFullScreenButton = 7, } +impl_Encode!(NSWindowButton, u64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSBezelStyle { @@ -382,6 +410,8 @@ pub enum NSBezelStyle { NSRoundedDisclosureBezelStyle = 14, } +impl_Encode!(NSBezelStyle, u64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSRequestUserAttentionType { @@ -389,6 +419,8 @@ pub enum NSRequestUserAttentionType { NSInformationalRequest = 10, } +impl_Encode!(NSRequestUserAttentionType, u64); + pub static NSMainMenuWindowLevel: i32 = 24; pub trait NSApplication: Sized { @@ -783,12 +815,16 @@ pub enum NSPasteboardReadingOptions { NSPasteboardReadingAsKeyedArchive = 1 << 2 } +impl_Encode!(NSPasteboardReadingOptions, u64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSPasteboardWritingOptions { NSPasteboardWritingPromised = 1 << 9, } +impl_Encode!(NSPasteboardWritingOptions, u64); + pub trait NSMenu: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class!(NSMenu), alloc] @@ -885,12 +921,16 @@ bitflags! { } } +impl_Encode!(NSWindowCollectionBehavior, NSUInteger); + bitflags! { pub struct NSWindowOcclusionState: NSUInteger { const NSWindowOcclusionStateVisible = 1 << 1; } } +impl_Encode!(NSWindowOcclusionState, NSUInteger); + pub trait NSWindow: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class!(NSWindow), alloc] @@ -1847,6 +1887,8 @@ pub enum NSModalResponse { NSModalResponseCancel = 0, } +impl_Encode!(NSModalResponse, i64); + pub trait NSSavePanel: Sized { unsafe fn savePanel(_: Self) -> id { msg_send![class!(NSSavePanel), savePanel] @@ -1927,6 +1969,8 @@ pub enum NSViewLayerContentsPlacement { NSViewLayerContentsPlacementTopLeft = 11, } +impl_Encode!(NSViewLayerContentsPlacement, usize); + pub trait NSView: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class!(NSView), alloc] @@ -2240,6 +2284,8 @@ bitflags! { } } +impl_Encode!(NSEventSwipeTrackingOptions, NSUInteger); + #[repr(i64)] // NSInteger pub enum NSEventGestureAxis { NSEventGestureAxisNone = 0, @@ -2247,6 +2293,8 @@ pub enum NSEventGestureAxis { NSEventGestureAxisVertical, } +impl_Encode!(NSEventGestureAxis, i64); + bitflags! { pub struct NSEventPhase: NSUInteger { const NSEventPhaseNone = 0; @@ -2259,6 +2307,8 @@ bitflags! { } } +impl_Encode!(NSEventPhase, NSUInteger); + bitflags! { pub struct NSTouchPhase: NSUInteger { const NSTouchPhaseBegan = 1 << 0; @@ -2273,6 +2323,8 @@ bitflags! { } } +impl_Encode!(NSTouchPhase, NSUInteger); + #[derive(Clone, Copy, Debug, PartialEq)] #[repr(u64)] // NSUInteger pub enum NSEventType { @@ -2308,6 +2360,8 @@ pub enum NSEventType { NSEventTypePressure = 34, } +impl_Encode!(NSEventType, u64); + bitflags! { pub struct NSEventMask: libc::c_ulonglong { const NSLeftMouseDownMask = 1 << NSLeftMouseDown as libc::c_ulonglong; @@ -2343,6 +2397,8 @@ bitflags! { } } +impl_Encode!(NSEventMask, libc::c_ulonglong); + impl NSEventMask { pub fn from_type(ty: NSEventType) -> NSEventMask { NSEventMask { bits: 1 << ty as libc::c_ulonglong } @@ -2363,8 +2419,11 @@ bitflags! { } } -// Not sure of the type here +impl_Encode!(NSEventModifierFlags, NSUInteger); + +#[repr(usize)] // NSUInteger pub enum NSPointingDeviceType { + __Unknown = 0, // TODO: Not sure what these values are // NSUnknownPointingDevice = NX_TABLET_POINTER_UNKNOWN, // NSPenPointingDevice = NX_TABLET_POINTER_PEN, @@ -2372,14 +2431,19 @@ pub enum NSPointingDeviceType { // NSEraserPointingDevice = NX_TABLET_POINTER_ERASER, } -// Not sure of the type here +impl_Encode!(NSPointingDeviceType, usize); + +#[repr(usize)] // NSUInteger pub enum NSEventButtonMask { + __Unknown = 0, // TODO: Not sure what these values are // NSPenTipMask = NX_TABLET_BUTTON_PENTIPMASK, // NSPenLowerSideMask = NX_TABLET_BUTTON_PENLOWERSIDEMASK, // NSPenUpperSideMask = NX_TABLET_BUTTON_PENUPPERSIDEMASK, } +impl_Encode!(NSEventButtonMask, usize); + #[repr(i16)] pub enum NSEventSubtype { // TODO: Not sure what these values are @@ -2395,6 +2459,8 @@ pub enum NSEventSubtype { NSAWTEventType = 16, } +impl_Encode!(NSEventSubtype, i16); + pub const NSUpArrowFunctionKey: libc::c_ushort = 0xF700; pub const NSDownArrowFunctionKey: libc::c_ushort = 0xF701; pub const NSLeftArrowFunctionKey: libc::c_ushort = 0xF702; @@ -3550,6 +3616,8 @@ pub enum NSCompositingOperation { NSCompositePlusLighter = 13 } +impl_Encode!(NSCompositingOperation, usize); + #[repr(usize)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum NSImageCacheMode { @@ -3559,6 +3627,8 @@ pub enum NSImageCacheMode { NSImageCacheNever } +impl_Encode!(NSImageCacheMode, usize); + #[repr(usize)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum NSTIFFCompression { @@ -3572,6 +3642,8 @@ pub enum NSTIFFCompression { NSTIFFCompressionOldJPEG = 32865 } +impl_Encode!(NSTIFFCompression, usize); + #[repr(usize)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum NSImageLoadStatus { @@ -3582,6 +3654,8 @@ pub enum NSImageLoadStatus { NSImageLoadStatusReadError } +impl_Encode!(NSImageLoadStatus, usize); + pub trait NSSound: Sized { unsafe fn canInitWithPasteboard_(_: Self, pasteboard: id) -> BOOL { msg_send![class!(NSSound), canInitWithPasteboard:pasteboard] @@ -3786,6 +3860,8 @@ pub enum NSTabViewType { NSNoTabsNoBorder = 6 } +impl_Encode!(NSTabViewType, u64); + pub trait NSTabView: Sized { unsafe fn new(_: Self) -> id { msg_send![class!(NSTabView), new] @@ -3961,6 +4037,8 @@ pub enum NSTabState { NSPressedTab = 2 } +impl_Encode!(NSTabState, u64); + pub trait NSTabViewItem: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class!(NSTabViewItem), alloc] diff --git a/cocoa/src/lib.rs b/cocoa/src/lib.rs index afc053a7d..b7c2c2d14 100644 --- a/cocoa/src/lib.rs +++ b/cocoa/src/lib.rs @@ -17,9 +17,11 @@ extern crate block; extern crate bitflags; extern crate core_foundation; extern crate core_graphics; +#[macro_use] extern crate cocoa_foundation; extern crate foreign_types; extern crate libc; +extern crate objc_encode; #[macro_use] extern crate objc; diff --git a/cocoa/src/quartzcore.rs b/cocoa/src/quartzcore.rs index 48cf601b4..24d9e3e83 100644 --- a/cocoa/src/quartzcore.rs +++ b/cocoa/src/quartzcore.rs @@ -40,6 +40,8 @@ pub fn current_media_time() -> CFTimeInterval { pub struct CALayer(id); +impl_Encode!(CALayer, id); + unsafe impl Send for CALayer {} unsafe impl Sync for CALayer {} @@ -1372,6 +1374,8 @@ bitflags! { pub struct CARenderer(id); +impl_Encode!(CARenderer, id); + unsafe impl Send for CARenderer {} unsafe impl Sync for CARenderer {} @@ -1663,6 +1667,10 @@ pub struct CATransform3D { pub m41: CGFloat, pub m42: CGFloat, pub m43: CGFloat, pub m44: CGFloat, } +unsafe impl ::objc_encode::Encode for CATransform3D { + const ENCODING: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Array(16, &CGFloat::ENCODING); +} + impl PartialEq for CATransform3D { #[inline] fn eq(&self, other: &CATransform3D) -> bool { @@ -1815,6 +1823,28 @@ pub struct CVTimeStamp { pub reserved: u64, } +unsafe impl ::objc_encode::Encode for CVTimeStamp { + const ENCODING: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Struct( + "CVTimeStamp", + &[ + u32::ENCODING, + i32::ENCODING, + i64::ENCODING, + u64::ENCODING, + f64::ENCODING, + i64::ENCODING, + CVSMPTETime::ENCODING, + u64::ENCODING, + u64::ENCODING, + ], + ); +} + +unsafe impl ::objc_encode::Encode for &'_ CVTimeStamp { + const ENCODING: ::objc_encode::Encoding<'static> = + ::objc_encode::Encoding::Pointer(&::ENCODING); +} + pub type CVTimeStampFlags = u64; pub const kCVTimeStampVideoTimeValid: CVTimeStampFlags = 1 << 0; @@ -1843,6 +1873,23 @@ pub struct CVSMPTETime { pub frames: i16, } +unsafe impl ::objc_encode::Encode for CVSMPTETime { + const ENCODING: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Struct( + "CVSMPTETime", + &[ + i16::ENCODING, + i16::ENCODING, + u32::ENCODING, + u32::ENCODING, + u32::ENCODING, + i16::ENCODING, + i16::ENCODING, + i16::ENCODING, + i16::ENCODING, + ], + ); +} + pub type CVSMPTETimeType = u32; pub const kCVSMPTETimeType24: CVSMPTETimeType = 0; diff --git a/core-foundation-sys/Cargo.toml b/core-foundation-sys/Cargo.toml index 6bbbc6ab3..c1a509408 100644 --- a/core-foundation-sys/Cargo.toml +++ b/core-foundation-sys/Cargo.toml @@ -8,6 +8,7 @@ authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" [dependencies] +objc-encode = "1.1.0" [features] mac_os_10_7_support = [] # backwards compatibility diff --git a/core-foundation-sys/src/array.rs b/core-foundation-sys/src/array.rs index c73896125..e29fd5e1f 100644 --- a/core-foundation-sys/src/array.rs +++ b/core-foundation-sys/src/array.rs @@ -35,6 +35,10 @@ pub struct __CFArray(c_void); pub type CFArrayRef = *const __CFArray; pub type CFMutableArrayRef = *mut __CFArray; +unsafe impl ::objc_encode::Encode for &'_ __CFArray { + const ENCODING: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object; +} + extern { /* * CFArray.h diff --git a/core-foundation-sys/src/attributed_string.rs b/core-foundation-sys/src/attributed_string.rs index c91bf5be3..0b02e4915 100644 --- a/core-foundation-sys/src/attributed_string.rs +++ b/core-foundation-sys/src/attributed_string.rs @@ -18,6 +18,10 @@ pub struct __CFAttributedString(c_void); pub type CFAttributedStringRef = *const __CFAttributedString; pub type CFMutableAttributedStringRef = *const __CFAttributedString; +unsafe impl ::objc_encode::Encode for &'_ __CFAttributedString { + const ENCODING: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object; +} + extern { /* CFAttributedString */ diff --git a/core-foundation-sys/src/dictionary.rs b/core-foundation-sys/src/dictionary.rs index d10e9c120..aadc9cf5d 100644 --- a/core-foundation-sys/src/dictionary.rs +++ b/core-foundation-sys/src/dictionary.rs @@ -47,6 +47,10 @@ pub struct __CFDictionary(c_void); pub type CFDictionaryRef = *const __CFDictionary; pub type CFMutableDictionaryRef = *mut __CFDictionary; +unsafe impl ::objc_encode::Encode for &'_ __CFDictionary { + const ENCODING: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object; +} + extern { /* * CFDictionary.h diff --git a/core-foundation-sys/src/lib.rs b/core-foundation-sys/src/lib.rs index 48c08878b..e98f21d38 100644 --- a/core-foundation-sys/src/lib.rs +++ b/core-foundation-sys/src/lib.rs @@ -10,6 +10,8 @@ #![cfg_attr(all(feature="mac_os_10_7_support", feature="mac_os_10_8_features"), feature(linkage))] // back-compat requires weak linkage +extern crate objc_encode; + // Link to CoreFoundation on any Apple device. // // We don't use `target_vendor` since that is going to be deprecated: diff --git a/core-foundation-sys/src/string.rs b/core-foundation-sys/src/string.rs index d4f655078..78856b320 100644 --- a/core-foundation-sys/src/string.rs +++ b/core-foundation-sys/src/string.rs @@ -192,6 +192,10 @@ pub struct __CFString(c_void); pub type CFStringRef = *const __CFString; +unsafe impl ::objc_encode::Encode for &'_ __CFString { + const ENCODING: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object; +} + extern { /* * CFString.h diff --git a/core-graphics-types/Cargo.toml b/core-graphics-types/Cargo.toml index baf273d9b..af75c610c 100644 --- a/core-graphics-types/Cargo.toml +++ b/core-graphics-types/Cargo.toml @@ -12,6 +12,7 @@ bitflags = "1.0" core-foundation = { path = "../core-foundation", version = "0.9" } foreign-types = "0.3.0" libc = "0.2" +objc-encode = "1.1.0" [package.metadata.docs.rs] default-target = "x86_64-apple-darwin" diff --git a/core-graphics-types/src/geometry.rs b/core-graphics-types/src/geometry.rs index 906c605ec..878dfc7a4 100644 --- a/core-graphics-types/src/geometry.rs +++ b/core-graphics-types/src/geometry.rs @@ -10,6 +10,7 @@ use base::CGFloat; use core_foundation::base::TCFType; use core_foundation::dictionary::CFDictionary; +use objc_encode::{Encode, Encoding}; pub const CG_ZERO_POINT: CGPoint = CGPoint { x: 0.0, @@ -39,6 +40,11 @@ pub struct CGSize { pub height: CGFloat, } +unsafe impl Encode for CGSize { + const ENCODING: Encoding<'static> = + Encoding::Struct("CGSize", &[CGFloat::ENCODING, CGFloat::ENCODING]); +} + impl CGSize { #[inline] pub fn new(width: CGFloat, height: CGFloat) -> CGSize { @@ -63,6 +69,11 @@ pub struct CGPoint { pub y: CGFloat, } +unsafe impl Encode for CGPoint { + const ENCODING: Encoding<'static> = + Encoding::Struct("CGPoint", &[CGFloat::ENCODING, CGFloat::ENCODING]); +} + impl CGPoint { #[inline] pub fn new(x: CGFloat, y: CGFloat) -> CGPoint { @@ -87,6 +98,11 @@ pub struct CGRect { pub size: CGSize } +unsafe impl Encode for CGRect { + const ENCODING: Encoding<'static> = + Encoding::Struct("CGRect", &[CGPoint::ENCODING, CGSize::ENCODING]); +} + impl CGRect { #[inline] pub fn new(origin: &CGPoint, size: &CGSize) -> CGRect { @@ -151,6 +167,20 @@ pub struct CGAffineTransform { pub ty: CGFloat, } +unsafe impl Encode for CGAffineTransform { + const ENCODING: Encoding<'static> = Encoding::Struct( + "CGAffineTransform", + &[ + CGFloat::ENCODING, + CGFloat::ENCODING, + CGFloat::ENCODING, + CGFloat::ENCODING, + CGFloat::ENCODING, + CGFloat::ENCODING, + ] + ); +} + impl CGAffineTransform { #[inline] pub fn new( diff --git a/core-graphics-types/src/lib.rs b/core-graphics-types/src/lib.rs index f34bf0120..8c3b202d2 100644 --- a/core-graphics-types/src/lib.rs +++ b/core-graphics-types/src/lib.rs @@ -9,6 +9,7 @@ extern crate libc; extern crate core_foundation; +extern crate objc_encode; pub mod base; pub mod geometry; diff --git a/core-graphics/Cargo.toml b/core-graphics/Cargo.toml index 79b0eb266..202f1ce18 100644 --- a/core-graphics/Cargo.toml +++ b/core-graphics/Cargo.toml @@ -18,6 +18,7 @@ core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } foreign-types = "0.3.0" libc = "0.2" +objc-encode = "1.1.0" [package.metadata.docs.rs] default-target = "x86_64-apple-darwin" diff --git a/core-graphics/src/lib.rs b/core-graphics/src/lib.rs index 5238774e7..91fadde61 100644 --- a/core-graphics/src/lib.rs +++ b/core-graphics/src/lib.rs @@ -8,6 +8,7 @@ // except according to those terms. extern crate libc; +extern crate objc_encode; #[macro_use] extern crate core_foundation; diff --git a/core-graphics/src/sys.rs b/core-graphics/src/sys.rs index 85df442d5..80f24a13e 100644 --- a/core-graphics/src/sys.rs +++ b/core-graphics/src/sys.rs @@ -1,11 +1,17 @@ use std::os::raw::c_void; +use objc_encode::{Encode, Encoding}; + pub enum CGImage {} pub type CGImageRef = *mut CGImage; #[repr(C)] pub struct __CGColor(c_void); +unsafe impl Encode for &'_ __CGColor { + const ENCODING: Encoding<'static> = Encoding::Unknown; +} + pub type CGColorRef = *const __CGColor; pub enum CGColorSpace {} @@ -14,6 +20,10 @@ pub type CGColorSpaceRef = *mut CGColorSpace; pub enum CGPath {} pub type CGPathRef = *mut CGPath; +unsafe impl Encode for &'_ CGPath { + const ENCODING: Encoding<'static> = Encoding::Unknown; +} + pub enum CGDataProvider {} pub type CGDataProviderRef = *mut CGDataProvider; @@ -23,6 +33,10 @@ pub type CGFontRef = *mut CGFont; pub enum CGContext {} pub type CGContextRef = *mut CGContext; +unsafe impl Encode for &'_ CGContext { + const ENCODING: Encoding<'static> = Encoding::Unknown; +} + pub enum CGGradient {} pub type CGGradientRef = *mut CGGradient;