From 3b9868a819d6cbdb5546bb8c35d0e6787d8a586b Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 31 Jul 2023 13:14:33 +0200 Subject: [PATCH 01/14] Fix invalid msg_send! --- cocoa-foundation/src/foundation.rs | 7 ++++--- cocoa/src/appkit.rs | 2 +- cocoa/src/quartzcore.rs | 9 +++++---- core-text/src/font.rs | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cocoa-foundation/src/foundation.rs b/cocoa-foundation/src/foundation.rs index 26da47e6..02ec7925 100644 --- a/cocoa-foundation/src/foundation.rs +++ b/cocoa-foundation/src/foundation.rs @@ -248,7 +248,8 @@ impl NSProcessInfo for id { } unsafe fn isOperatingSystemAtLeastVersion(self, version: NSOperatingSystemVersion) -> bool { - msg_send![self, isOperatingSystemAtLeastVersion: version] + let res: BOOL = msg_send![self, isOperatingSystemAtLeastVersion: version]; + res != NO } } @@ -664,9 +665,9 @@ impl NSString for id { unsafe fn init_str(self, string: &str) -> id { return msg_send![self, - initWithBytes:string.as_ptr() + initWithBytes:string.as_ptr() as *const c_void length:string.len() - encoding:UTF8_ENCODING as id]; + encoding:UTF8_ENCODING]; } unsafe fn len(self) -> usize { diff --git a/cocoa/src/appkit.rs b/cocoa/src/appkit.rs index c73839f9..f1b71f8f 100644 --- a/cocoa/src/appkit.rs +++ b/cocoa/src/appkit.rs @@ -2378,7 +2378,7 @@ impl NSOpenGLPixelFormat for id { // Creating an NSOpenGLPixelFormat Object unsafe fn initWithAttributes_(self, attributes: &[u32]) -> id { - msg_send![self, initWithAttributes: attributes] + msg_send![self, initWithAttributes:attributes.as_ptr()] } // Managing the Pixel Format diff --git a/cocoa/src/quartzcore.rs b/cocoa/src/quartzcore.rs index 5f4c6da2..c6fd5fab 100644 --- a/cocoa/src/quartzcore.rs +++ b/cocoa/src/quartzcore.rs @@ -940,12 +940,12 @@ impl CALayer { #[inline] pub fn actions(&self) -> CFDictionary { - unsafe { msg_send![self.id(), actions] } + unsafe { CFDictionary::wrap_under_get_rule(msg_send![self.id(), actions]) } } #[inline] pub unsafe fn set_actions(&self, actions: CFDictionary) { - msg_send![self.id(), setActions: actions] + msg_send![self.id(), setActions: actions.as_concrete_TypeRef()] } // TODO(pcwalton): Wrap `CAAnimation`. @@ -1353,6 +1353,7 @@ impl CARenderer { // really just a module. pub mod transaction { use block::{Block, ConcreteBlock, IntoConcreteBlock, RcBlock}; + use core_foundation::base::TCFType; use core_foundation::date::CFTimeInterval; use core_foundation::string::CFString; @@ -1444,7 +1445,7 @@ pub mod transaction { pub fn value_for_key(key: &str) -> id { unsafe { let key: CFString = CFString::from(key); - msg_send![class!(CATransaction), valueForKey: key] + msg_send![class!(CATransaction), valueForKey: key.as_concrete_TypeRef()] } } @@ -1452,7 +1453,7 @@ pub mod transaction { pub fn set_value_for_key(value: id, key: &str) { unsafe { let key: CFString = CFString::from(key); - msg_send![class!(CATransaction), setValue:value forKey:key] + msg_send![class!(CATransaction), setValue: value forKey: key.as_concrete_TypeRef()] } } } diff --git a/core-text/src/font.rs b/core-text/src/font.rs index 6df9750b..67662e9d 100644 --- a/core-text/src/font.rs +++ b/core-text/src/font.rs @@ -206,7 +206,7 @@ pub fn new_ui_font_for_language( unsafe { let font_ref = CTFontCreateUIFontForLanguage( ui_type, - size, + size as CGFloat, language .as_ref() .map(|x| x.as_concrete_TypeRef()) From 38bd8990ad9d99c77b24b972000a3ff7fe38d595 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 31 Jul 2023 13:22:34 +0200 Subject: [PATCH 02/14] Implement Encode for most types Using new objc-encode crate --- cocoa-foundation/Cargo.toml | 4 +- cocoa-foundation/src/foundation.rs | 91 +++++++++++++------ cocoa-foundation/src/lib.rs | 12 +++ cocoa/Cargo.toml | 4 +- cocoa/src/appkit.rs | 93 +++++++++++++++++++- cocoa/src/lib.rs | 2 + cocoa/src/quartzcore.rs | 48 ++++++++++ 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/base.rs | 2 - core-graphics-types/src/geometry.rs | 30 +++++++ core-graphics-types/src/lib.rs | 2 +- core-graphics/Cargo.toml | 1 + core-graphics/src/lib.rs | 1 + core-graphics/src/sys.rs | 14 +++ 20 files changed, 288 insertions(+), 36 deletions(-) diff --git a/cocoa-foundation/Cargo.toml b/cocoa-foundation/Cargo.toml index d6e99aff..e25bd6bd 100644 --- a/cocoa-foundation/Cargo.toml +++ b/cocoa-foundation/Cargo.toml @@ -17,4 +17,6 @@ bitflags = "1.0" libc = "0.2" core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } -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 02ec7925..3c79584f 100644 --- a/cocoa-foundation/src/foundation.rs +++ b/cocoa-foundation/src/foundation.rs @@ -12,6 +12,7 @@ use base::{id, nil, BOOL, NO, SEL}; use block::Block; use libc; +use objc_encode::{Encode, Encoding}; use std::os::raw::c_void; use std::ptr; @@ -35,7 +36,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}; use std::mem; #[repr(C)] @@ -52,15 +53,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)] @@ -80,15 +75,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)] @@ -118,15 +107,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 @@ -138,6 +121,8 @@ mod macos { NSRectMaxYEdge, } + impl_Encode!(NSRectEdge, u32); + #[link(name = "Foundation", kind = "framework")] extern "C" { fn NSInsetRect(rect: NSRect, x: CGFloat, y: CGFloat) -> NSRect; @@ -166,6 +151,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 { @@ -208,6 +198,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( @@ -629,6 +630,8 @@ bitflags! { } } +impl_Encode!(NSEnumerationOptions, libc::c_ulonglong); + pub type NSComparator = *mut Block<(id, id), NSComparisonResult>; #[repr(isize)] @@ -639,6 +642,8 @@ pub enum NSComparisonResult { NSOrderedDescending = 1, } +impl_Encode!(NSComparisonResult, isize); + pub trait NSString: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class!(NSString), alloc] @@ -703,6 +708,22 @@ 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 { @@ -811,6 +832,8 @@ bitflags! { } } +impl_Encode!(NSURLBookmarkCreationOptions, NSUInteger); + pub type NSURLBookmarkFileCreationOptions = NSURLBookmarkCreationOptions; bitflags! { @@ -821,6 +844,8 @@ bitflags! { } } +impl_Encode!(NSURLBookmarkResolutionOptions, NSUInteger); + pub trait NSURL: Sized { unsafe fn alloc(_: Self) -> id; @@ -1607,6 +1632,8 @@ bitflags! { } } +impl_Encode!(NSDataReadingOptions, libc::c_ulonglong); + bitflags! { pub struct NSDataBase64EncodingOptions: libc::c_ulonglong { const NSDataBase64Encoding64CharacterLineLength = 1 << 0; @@ -1616,12 +1643,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; @@ -1629,6 +1660,8 @@ bitflags! { } } +impl_Encode!(NSDataWritingOptions, libc::c_ulonglong); + bitflags! { pub struct NSDataSearchOptions: libc::c_ulonglong { const NSDataSearchBackwards = 1 << 0; @@ -1636,6 +1669,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 7cd0350f..25ff73ca 100644 --- a/cocoa-foundation/src/lib.rs +++ b/cocoa-foundation/src/lib.rs @@ -15,8 +15,20 @@ extern crate bitflags; extern crate core_foundation; extern crate core_graphics_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 96b0f424..672cf9fa 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.23" } foreign-types = "0.5" -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 f1b71f8f..a92e1375 100644 --- a/cocoa/src/appkit.rs +++ b/cocoa/src/appkit.rs @@ -168,6 +168,8 @@ pub enum NSApplicationActivationPolicy { NSApplicationActivationPolicyERROR = -1, } +impl_Encode!(NSApplicationActivationPolicy, i64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSApplicationActivationOptions { @@ -175,6 +177,8 @@ pub enum NSApplicationActivationOptions { NSApplicationActivateIgnoringOtherApps = 1 << 1, } +impl_Encode!(NSApplicationActivationOptions, u64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSApplicationTerminateReply { @@ -183,6 +187,8 @@ pub enum NSApplicationTerminateReply { NSTerminateLater = 2, } +impl_Encode!(NSApplicationTerminateReply, u64); + bitflags! { pub struct NSApplicationPresentationOptions : NSUInteger { const NSApplicationPresentationDefault = 0; @@ -201,6 +207,8 @@ bitflags! { } } +impl_Encode!(NSApplicationPresentationOptions, NSUInteger); + bitflags! { pub struct NSWindowStyleMask: NSUInteger { const NSBorderlessWindowMask = 0; @@ -219,6 +227,8 @@ bitflags! { } } +impl_Encode!(NSWindowStyleMask, NSUInteger); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSWindowTitleVisibility { @@ -226,6 +236,8 @@ pub enum NSWindowTitleVisibility { NSWindowTitleHidden = 1, } +impl_Encode!(NSWindowTitleVisibility, u64); + #[repr(i64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSWindowTabbingMode { @@ -234,6 +246,8 @@ pub enum NSWindowTabbingMode { NSWindowTabbingModePreferred = 2, } +impl_Encode!(NSWindowTabbingMode, i64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSBackingStoreType { @@ -242,6 +256,9 @@ pub enum NSBackingStoreType { NSBackingStoreBuffered = 2, } +impl_Encode!(NSBackingStoreType, u64); + +#[repr(isize)] pub enum NSWindowToolbarStyle { NSWindowToolbarStyleAutomatic = 0, NSWindowToolbarStyleExpanded = 1, @@ -250,6 +267,8 @@ pub enum NSWindowToolbarStyle { NSWindowToolbarStyleUnifiedCompact = 4, } +impl_Encode!(NSWindowToolbarStyle, NSInteger); + bitflags! { pub struct NSWindowOrderingMode: NSInteger { const NSWindowAbove = 1; @@ -258,6 +277,8 @@ bitflags! { } } +impl_Encode!(NSWindowOrderingMode, NSInteger); + bitflags! { pub struct NSAlignmentOptions: libc::c_ulonglong { const NSAlignMinXInward = 1 << 0; @@ -294,6 +315,8 @@ bitflags! { } } +impl_Encode!(NSAlignmentOptions, libc::c_ulonglong); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSOpenGLPixelFormatAttribute { @@ -338,6 +361,8 @@ pub enum NSOpenGLPixelFormatAttribute { NSOpenGLPFAVirtualScreenCount = 128, } +impl_Encode!(NSOpenGLPixelFormatAttribute, u64); + #[repr(u64)] #[allow(non_camel_case_types)] #[derive(Clone, Copy, Debug, PartialEq)] @@ -347,6 +372,8 @@ pub enum NSOpenGLPFAOpenGLProfiles { NSOpenGLProfileVersion4_1Core = 0x4100, } +impl_Encode!(NSOpenGLPFAOpenGLProfiles, u64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSOpenGLContextParameter { @@ -362,6 +389,8 @@ pub enum NSOpenGLContextParameter { NSOpenGLCPMPSwapsInFlight = 315, } +impl_Encode!(NSOpenGLContextParameter, u64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSWindowButton { @@ -374,6 +403,8 @@ pub enum NSWindowButton { NSWindowFullScreenButton = 7, } +impl_Encode!(NSWindowButton, u64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSBezelStyle { @@ -391,6 +422,8 @@ pub enum NSBezelStyle { NSRoundedDisclosureBezelStyle = 14, } +impl_Encode!(NSBezelStyle, u64); + // https://developer.apple.com/documentation/appkit/nsvisualeffectview/blendingmode #[allow(dead_code)] #[repr(u64)] @@ -400,6 +433,8 @@ pub enum NSVisualEffectBlendingMode { WithinWindow = 1, } +impl_Encode!(NSVisualEffectBlendingMode, u64); + // https://developer.apple.com/documentation/appkit/nsvisualeffectview/state #[allow(dead_code)] #[repr(u64)] @@ -410,6 +445,8 @@ pub enum NSVisualEffectState { Inactive = 2, } +impl_Encode!(NSVisualEffectState, u64); + /// #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -447,6 +484,8 @@ pub enum NSVisualEffectMaterial { UnderPageBackground = 22, } +impl_Encode!(NSVisualEffectMaterial, u64); + // macOS 10.10+ - https://developer.apple.com/documentation/appkit/nsvisualeffectview #[allow(non_snake_case)] pub trait NSVisualEffectView: Sized { @@ -537,6 +576,8 @@ pub enum NSRequestUserAttentionType { NSInformationalRequest = 10, } +impl_Encode!(NSRequestUserAttentionType, u64); + pub static NSMainMenuWindowLevel: i32 = 24; pub trait NSApplication: Sized { @@ -956,12 +997,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] @@ -1058,12 +1103,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] @@ -2108,6 +2157,8 @@ pub enum NSModalResponse { NSModalResponseCancel = 0, } +impl_Encode!(NSModalResponse, i64); + pub trait NSSavePanel: Sized { unsafe fn savePanel(_: Self) -> id { msg_send![class!(NSSavePanel), savePanel] @@ -2188,6 +2239,8 @@ pub enum NSViewLayerContentsPlacement { NSViewLayerContentsPlacementTopLeft = 11, } +impl_Encode!(NSViewLayerContentsPlacement, usize); + pub trait NSView: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class!(NSView), alloc] @@ -2523,6 +2576,8 @@ bitflags! { } } +impl_Encode!(NSEventSwipeTrackingOptions, NSUInteger); + #[repr(i64)] // NSInteger pub enum NSEventGestureAxis { NSEventGestureAxisNone = 0, @@ -2530,6 +2585,8 @@ pub enum NSEventGestureAxis { NSEventGestureAxisVertical, } +impl_Encode!(NSEventGestureAxis, i64); + bitflags! { pub struct NSEventPhase: NSUInteger { const NSEventPhaseNone = 0; @@ -2542,6 +2599,8 @@ bitflags! { } } +impl_Encode!(NSEventPhase, NSUInteger); + bitflags! { pub struct NSTouchPhase: NSUInteger { const NSTouchPhaseBegan = 1 << 0; @@ -2556,6 +2615,8 @@ bitflags! { } } +impl_Encode!(NSTouchPhase, NSUInteger); + #[derive(Clone, Copy, Debug, PartialEq)] #[repr(u64)] // NSUInteger pub enum NSEventType { @@ -2591,6 +2652,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; @@ -2626,6 +2689,8 @@ bitflags! { } } +impl_Encode!(NSEventMask, libc::c_ulonglong); + impl NSEventMask { pub fn from_type(ty: NSEventType) -> NSEventMask { NSEventMask { @@ -2648,8 +2713,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, @@ -2657,14 +2725,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 @@ -2680,6 +2753,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; @@ -3929,6 +4004,8 @@ pub enum NSCompositingOperation { NSCompositePlusLighter = 13, } +impl_Encode!(NSCompositingOperation, usize); + #[repr(usize)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum NSImageCacheMode { @@ -3938,6 +4015,8 @@ pub enum NSImageCacheMode { NSImageCacheNever, } +impl_Encode!(NSImageCacheMode, usize); + #[repr(usize)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum NSTIFFCompression { @@ -3951,6 +4030,8 @@ pub enum NSTIFFCompression { NSTIFFCompressionOldJPEG = 32865, } +impl_Encode!(NSTIFFCompression, usize); + #[repr(usize)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum NSImageLoadStatus { @@ -3961,6 +4042,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] @@ -4165,6 +4248,8 @@ pub enum NSTabViewType { NSNoTabsNoBorder = 6, } +impl_Encode!(NSTabViewType, u64); + pub trait NSTabView: Sized { unsafe fn new(_: Self) -> id { msg_send![class!(NSTabView), new] @@ -4343,6 +4428,8 @@ pub enum NSTabState { NSPressedTab = 2, } +impl_Encode!(NSTabState, u64); + pub trait NSTabViewItem: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class!(NSTabViewItem), alloc] @@ -4941,7 +5028,7 @@ impl NSDockTile for id { } pub unsafe fn NSAppearance(named: id /* NSAppearanceName */) -> id { - objc::msg_send![class!(NSAppearance), appearanceNamed: named] + msg_send![class!(NSAppearance), appearanceNamed: named] } #[cfg(test)] diff --git a/cocoa/src/lib.rs b/cocoa/src/lib.rs index 0d75b762..61e9e645 100644 --- a/cocoa/src/lib.rs +++ b/cocoa/src/lib.rs @@ -14,11 +14,13 @@ extern crate block; #[macro_use] extern crate bitflags; +#[macro_use] extern crate cocoa_foundation; extern crate core_foundation; extern crate core_graphics; 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 c6fd5fab..aaa64184 100644 --- a/cocoa/src/quartzcore.rs +++ b/cocoa/src/quartzcore.rs @@ -38,6 +38,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 {} @@ -1209,6 +1211,8 @@ bitflags! { pub struct CARenderer(id); +impl_Encode!(CARenderer, id); + unsafe impl Send for CARenderer {} unsafe impl Sync for CARenderer {} @@ -1481,6 +1485,11 @@ pub struct CATransform3D { 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 { @@ -1632,6 +1641,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; @@ -1660,6 +1691,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 81ed52a1..da80729e 100644 --- a/core-foundation-sys/Cargo.toml +++ b/core-foundation-sys/Cargo.toml @@ -8,6 +8,7 @@ authors = ["The Servo Project Developers"] license = "MIT OR 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 b9ce43c3..06c1e2f0 100644 --- a/core-foundation-sys/src/array.rs +++ b/core-foundation-sys/src/array.rs @@ -36,6 +36,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 "C" { /* * CFArray.h diff --git a/core-foundation-sys/src/attributed_string.rs b/core-foundation-sys/src/attributed_string.rs index 93fbf63f..fd2fa147 100644 --- a/core-foundation-sys/src/attributed_string.rs +++ b/core-foundation-sys/src/attributed_string.rs @@ -19,6 +19,10 @@ pub struct __CFAttributedString(c_void); pub type CFAttributedStringRef = *const __CFAttributedString; pub type CFMutableAttributedStringRef = *mut __CFAttributedString; +unsafe impl ::objc_encode::Encode for &__CFAttributedString { + const ENCODING: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object; +} + extern "C" { /* * CFAttributedString.h diff --git a/core-foundation-sys/src/dictionary.rs b/core-foundation-sys/src/dictionary.rs index f243c5ba..7a796836 100644 --- a/core-foundation-sys/src/dictionary.rs +++ b/core-foundation-sys/src/dictionary.rs @@ -51,6 +51,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 "C" { /* * CFDictionary.h diff --git a/core-foundation-sys/src/lib.rs b/core-foundation-sys/src/lib.rs index edd6dd0f..fbaab9c4 100644 --- a/core-foundation-sys/src/lib.rs +++ b/core-foundation-sys/src/lib.rs @@ -17,6 +17,8 @@ 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 03e54ded..8f976bc5 100644 --- a/core-foundation-sys/src/string.rs +++ b/core-foundation-sys/src/string.rs @@ -206,6 +206,10 @@ pub fn CFStringInitInlineBuffer(str: CFStringRef, buf: *mut CFStringInlineBuffer pub fn CFStringGetCharacterFromInlineBuffer(buf: *mut CFStringInlineBuffer, idx: CFIndex) -> UniChar; */ +unsafe impl ::objc_encode::Encode for &__CFString { + const ENCODING: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object; +} + extern "C" { /* * CFString.h diff --git a/core-graphics-types/Cargo.toml b/core-graphics-types/Cargo.toml index ce4598a0..0f5a86d1 100644 --- a/core-graphics-types/Cargo.toml +++ b/core-graphics-types/Cargo.toml @@ -11,6 +11,7 @@ license = "MIT OR Apache-2.0" bitflags = "1.0" core-foundation = { path = "../core-foundation", version = "0.9" } 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/base.rs b/core-graphics-types/src/base.rs index 4d872331..33abaa43 100644 --- a/core-graphics-types/src/base.rs +++ b/core-graphics-types/src/base.rs @@ -12,8 +12,6 @@ #![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] -use libc; - #[cfg(any(target_arch = "x86", target_arch = "arm", target_arch = "aarch64"))] pub type boolean_t = libc::c_int; #[cfg(target_arch = "x86_64")] diff --git a/core-graphics-types/src/geometry.rs b/core-graphics-types/src/geometry.rs index de94b0da..c04cfb57 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, y: 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 { @@ -61,6 +67,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 { @@ -80,6 +91,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 { @@ -145,6 +161,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 94a4eb97..2d6c2c9a 100644 --- a/core-graphics-types/src/lib.rs +++ b/core-graphics-types/src/lib.rs @@ -8,7 +8,7 @@ // except according to those terms. extern crate core_foundation; -extern crate libc; +extern crate objc_encode; pub mod base; pub mod geometry; diff --git a/core-graphics/Cargo.toml b/core-graphics/Cargo.toml index f8d5d3b2..3dfe5cae 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.5.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 3c1b6443..b0201738 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 9e0e8000..4e9d5d13 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; From 4726ff55f30900ec7cbf886980d376eb25a97971 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 31 Jul 2023 13:49:36 +0200 Subject: [PATCH 03/14] Use objc2 --- cocoa-foundation/Cargo.toml | 7 +++---- cocoa-foundation/src/base.rs | 4 ++-- cocoa-foundation/src/foundation.rs | 6 +++--- cocoa-foundation/src/lib.rs | 2 +- cocoa-foundation/tests/foundation.rs | 8 +++++--- cocoa/Cargo.toml | 7 +++---- cocoa/examples/fullscreen.rs | 13 ++++++------- cocoa/examples/nsvisualeffectview_blur.rs | 4 ++-- cocoa/src/appkit.rs | 4 ++-- cocoa/src/lib.rs | 2 +- cocoa/src/macros.rs | 8 ++++---- cocoa/src/quartzcore.rs | 6 +++--- core-foundation-sys/Cargo.toml | 2 +- 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/string.rs | 4 ++-- core-graphics-types/Cargo.toml | 2 +- core-graphics/Cargo.toml | 2 +- core-graphics/src/sys.rs | 14 +++++++------- 20 files changed, 53 insertions(+), 54 deletions(-) diff --git a/cocoa-foundation/Cargo.toml b/cocoa-foundation/Cargo.toml index e25bd6bd..3774ba26 100644 --- a/cocoa-foundation/Cargo.toml +++ b/cocoa-foundation/Cargo.toml @@ -12,11 +12,10 @@ license = "MIT OR Apache-2.0" default-target = "x86_64-apple-darwin" [dependencies] -block = "0.1" +block = { version = "=0.2.0-alpha.5", package = "block2" } bitflags = "1.0" libc = "0.2" core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } -# Current `master` of objc -objc = { version = "=0.3.0-alpha.0", package = "objc2" } -objc-encode = "1.1.0" +objc2 = { version = "=0.3.0-beta.1" } +objc-encode = { version = "=2.0.0-pre.1", package = "objc2-encode" } diff --git a/cocoa-foundation/src/base.rs b/cocoa-foundation/src/base.rs index 028205e8..4cebe99b 100644 --- a/cocoa-foundation/src/base.rs +++ b/cocoa-foundation/src/base.rs @@ -7,9 +7,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use objc::runtime; +use objc2::runtime; -pub use objc::runtime::{BOOL, NO, YES}; +pub use objc2::runtime::{BOOL, NO, YES}; pub type Class = *mut runtime::Class; #[allow(non_camel_case_types)] diff --git a/cocoa-foundation/src/foundation.rs b/cocoa-foundation/src/foundation.rs index 3c79584f..a0adde2e 100644 --- a/cocoa-foundation/src/foundation.rs +++ b/cocoa-foundation/src/foundation.rs @@ -12,7 +12,7 @@ use base::{id, nil, BOOL, NO, SEL}; use block::Block; use libc; -use objc_encode::{Encode, Encoding}; +use objc_encode::{Encode, Encoding, RefEncode}; use std::os::raw::c_void; use std::ptr; @@ -720,8 +720,8 @@ unsafe impl Encode for NSFastEnumerationState { ); } -unsafe impl Encode for &'_ NSFastEnumerationState { - const ENCODING: Encoding<'static> = Encoding::Pointer(&NSFastEnumerationState::ENCODING); +unsafe impl RefEncode for NSFastEnumerationState { + const ENCODING_REF: Encoding<'static> = Encoding::Pointer(&Self::ENCODING); } const NS_FAST_ENUM_BUF_SIZE: usize = 16; diff --git a/cocoa-foundation/src/lib.rs b/cocoa-foundation/src/lib.rs index 25ff73ca..708e465b 100644 --- a/cocoa-foundation/src/lib.rs +++ b/cocoa-foundation/src/lib.rs @@ -17,7 +17,7 @@ extern crate core_graphics_types; extern crate libc; pub extern crate objc_encode; #[macro_use] -extern crate objc; +extern crate objc2; pub use objc_encode as __objc_encode; diff --git a/cocoa-foundation/tests/foundation.rs b/cocoa-foundation/tests/foundation.rs index 19d7b15c..5d87a7dc 100644 --- a/cocoa-foundation/tests/foundation.rs +++ b/cocoa-foundation/tests/foundation.rs @@ -1,5 +1,5 @@ #[macro_use] -extern crate objc; +extern crate objc2; extern crate block; extern crate cocoa_foundation; @@ -164,16 +164,18 @@ mod foundation { } // First test cocoa sorting... - let mut comparator = + let comparator = ConcreteBlock::new(|s0: id, s1: id| match compare_function(&s0, &s1) { Ordering::Less => NSComparisonResult::NSOrderedAscending, Ordering::Equal => NSComparisonResult::NSOrderedSame, Ordering::Greater => NSComparisonResult::NSOrderedDescending, }); + let comparator_ptr: *const _ = &*comparator; + let comparator_ptr = comparator_ptr as *mut _; let associated_iter = keys.iter().zip(objects.iter()); for (k_id, (k, v)) in dict - .keysSortedByValueUsingComparator_(&mut *comparator) + .keysSortedByValueUsingComparator_(comparator_ptr) .iter() .zip(associated_iter) { diff --git a/cocoa/Cargo.toml b/cocoa/Cargo.toml index 672cf9fa..96f81af6 100644 --- a/cocoa/Cargo.toml +++ b/cocoa/Cargo.toml @@ -12,13 +12,12 @@ license = "MIT OR Apache-2.0" default-target = "x86_64-apple-darwin" [dependencies] -block = "0.1" +block = { version = "=0.2.0-alpha.5", package = "block2" } bitflags = "1.0" 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.23" } foreign-types = "0.5" -# Current `master` of objc -objc = { version = "=0.3.0-alpha.0", package = "objc2" } -objc-encode = "1.1.0" +objc2 = { version = "=0.3.0-beta.1" } +objc-encode = { version = "=2.0.0-pre.1", package = "objc2-encode" } diff --git a/cocoa/examples/fullscreen.rs b/cocoa/examples/fullscreen.rs index e3772e47..4d5ace62 100644 --- a/cocoa/examples/fullscreen.rs +++ b/cocoa/examples/fullscreen.rs @@ -2,7 +2,7 @@ extern crate cocoa; extern crate core_graphics; #[macro_use] -extern crate objc; +extern crate objc2; use cocoa::appkit::{ NSApp, NSApplication, NSApplicationActivateIgnoringOtherApps, @@ -17,8 +17,8 @@ use cocoa::foundation::{ use core_graphics::display::CGDisplay; -use objc::declare::ClassDecl; -use objc::runtime::{Object, Sel}; +use objc2::declare::ClassDecl; +use objc2::runtime::{Object, Sel}; fn main() { unsafe { @@ -75,16 +75,15 @@ fn main() { decl.add_method( sel!(window:willUseFullScreenPresentationOptions:), - will_use_fillscreen_presentation_options - as extern "C" fn(&Object, Sel, id, NSUInteger) -> NSUInteger, + will_use_fillscreen_presentation_options as extern "C" fn(_, _, _, _) -> _, ); decl.add_method( sel!(windowWillEnterFullScreen:), - window_entering_fullscreen as extern "C" fn(&Object, Sel, id), + window_entering_fullscreen as extern "C" fn(_, _, _), ); decl.add_method( sel!(windowDidEnterFullScreen:), - window_entering_fullscreen as extern "C" fn(&Object, Sel, id), + window_entering_fullscreen as extern "C" fn(_, _, _), ); let delegate_class = decl.register(); diff --git a/cocoa/examples/nsvisualeffectview_blur.rs b/cocoa/examples/nsvisualeffectview_blur.rs index b3fb07cd..7a3245f1 100644 --- a/cocoa/examples/nsvisualeffectview_blur.rs +++ b/cocoa/examples/nsvisualeffectview_blur.rs @@ -1,8 +1,8 @@ extern crate cocoa; -extern crate objc; +extern crate objc2; use cocoa::base::{nil, selector, NO}; -use objc::*; +use objc2::*; use cocoa::appkit::{ NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSBackingStoreType, NSColor, diff --git a/cocoa/src/appkit.rs b/cocoa/src/appkit.rs index a92e1375..aad5c89c 100644 --- a/cocoa/src/appkit.rs +++ b/cocoa/src/appkit.rs @@ -3536,7 +3536,7 @@ pub trait NSButton: Sized { } unsafe fn initWithFrame_(self, frameRect: NSRect) -> id; unsafe fn setTarget_(self, target: id /* Instance */); - unsafe fn setAction_(self, selector: objc::runtime::Sel /* (Instance *) */); + unsafe fn setAction_(self, selector: objc2::runtime::Sel /* (Instance *) */); } impl NSButton for id { @@ -3556,7 +3556,7 @@ impl NSButton for id { msg_send![self, setTarget: target] } - unsafe fn setAction_(self, selector: objc::runtime::Sel /* (Instance method *) */) { + unsafe fn setAction_(self, selector: objc2::runtime::Sel /* (Instance method *) */) { msg_send![self, setAction: selector] } } diff --git a/cocoa/src/lib.rs b/cocoa/src/lib.rs index 61e9e645..ab1dd4b4 100644 --- a/cocoa/src/lib.rs +++ b/cocoa/src/lib.rs @@ -22,7 +22,7 @@ extern crate foreign_types; extern crate libc; extern crate objc_encode; #[macro_use] -extern crate objc; +extern crate objc2; #[cfg(target_os = "macos")] pub mod appkit; diff --git a/cocoa/src/macros.rs b/cocoa/src/macros.rs index 77c6a16d..d6d0b5f9 100644 --- a/cocoa/src/macros.rs +++ b/cocoa/src/macros.rs @@ -13,12 +13,12 @@ /// # Example with NSWindowDelegate /// ``` no_run /// #[macro_use] extern crate cocoa; -/// #[macro_use] extern crate objc; +/// #[macro_use] extern crate objc2; /// /// use cocoa::appkit::NSWindow; /// use cocoa::base::{id, nil}; /// -/// use objc::runtime::{Object, Sel}; +/// use objc2::runtime::{Object, Sel}; /// /// # fn main() { /// unsafe { @@ -33,7 +33,7 @@ /// /// my_window.setDelegate_(delegate!("MyWindowDelegate", { /// window: id = my_window, // Declare instance variable(s) -/// (onWindowWillEnterFullscreen:) => on_enter_fullscreen as extern fn(&Object, Sel, id) // Declare function(s) +/// (onWindowWillEnterFullscreen:) => on_enter_fullscreen as extern fn(_, _, _) // Declare function(s) /// })); /// } /// # } @@ -57,7 +57,7 @@ macro_rules! delegate { $( ($($sel:ident :)+) => $func:expr),* } ) => ({ - let mut decl = objc::declare::ClassDecl::new($name, class!(NSObject)).unwrap(); + let mut decl = objc2::declare::ClassDecl::new($name, class!(NSObject)).unwrap(); $( decl.add_ivar::<$var_type>(stringify!($var)); diff --git a/cocoa/src/quartzcore.rs b/cocoa/src/quartzcore.rs index aaa64184..f9295552 100644 --- a/cocoa/src/quartzcore.rs +++ b/cocoa/src/quartzcore.rs @@ -1658,9 +1658,9 @@ unsafe impl ::objc_encode::Encode for CVTimeStamp { ); } -unsafe impl ::objc_encode::Encode for &'_ CVTimeStamp { - const ENCODING: ::objc_encode::Encoding<'static> = - ::objc_encode::Encoding::Pointer(&::ENCODING); +unsafe impl ::objc_encode::RefEncode for CVTimeStamp { + const ENCODING_REF: ::objc_encode::Encoding<'static> = + ::objc_encode::Encoding::Pointer(&::ENCODING); } pub type CVTimeStampFlags = u64; diff --git a/core-foundation-sys/Cargo.toml b/core-foundation-sys/Cargo.toml index da80729e..a9889b6a 100644 --- a/core-foundation-sys/Cargo.toml +++ b/core-foundation-sys/Cargo.toml @@ -8,7 +8,7 @@ authors = ["The Servo Project Developers"] license = "MIT OR Apache-2.0" [dependencies] -objc-encode = "1.1.0" +objc-encode = { version = "=2.0.0-pre.1", package = "objc2-encode" } [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 06c1e2f0..3b299503 100644 --- a/core-foundation-sys/src/array.rs +++ b/core-foundation-sys/src/array.rs @@ -36,8 +36,8 @@ 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; +unsafe impl ::objc_encode::RefEncode for __CFArray { + const ENCODING_REF: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object; } extern "C" { diff --git a/core-foundation-sys/src/attributed_string.rs b/core-foundation-sys/src/attributed_string.rs index fd2fa147..bbeef172 100644 --- a/core-foundation-sys/src/attributed_string.rs +++ b/core-foundation-sys/src/attributed_string.rs @@ -19,8 +19,8 @@ pub struct __CFAttributedString(c_void); pub type CFAttributedStringRef = *const __CFAttributedString; pub type CFMutableAttributedStringRef = *mut __CFAttributedString; -unsafe impl ::objc_encode::Encode for &__CFAttributedString { - const ENCODING: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object; +unsafe impl ::objc_encode::RefEncode for __CFAttributedString { + const ENCODING_REF: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object; } extern "C" { diff --git a/core-foundation-sys/src/dictionary.rs b/core-foundation-sys/src/dictionary.rs index 7a796836..34f57f08 100644 --- a/core-foundation-sys/src/dictionary.rs +++ b/core-foundation-sys/src/dictionary.rs @@ -51,8 +51,8 @@ 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; +unsafe impl ::objc_encode::RefEncode for __CFDictionary { + const ENCODING_REF: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object; } extern "C" { diff --git a/core-foundation-sys/src/string.rs b/core-foundation-sys/src/string.rs index 8f976bc5..41080edc 100644 --- a/core-foundation-sys/src/string.rs +++ b/core-foundation-sys/src/string.rs @@ -206,8 +206,8 @@ pub fn CFStringInitInlineBuffer(str: CFStringRef, buf: *mut CFStringInlineBuffer pub fn CFStringGetCharacterFromInlineBuffer(buf: *mut CFStringInlineBuffer, idx: CFIndex) -> UniChar; */ -unsafe impl ::objc_encode::Encode for &__CFString { - const ENCODING: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object; +unsafe impl ::objc_encode::RefEncode for __CFString { + const ENCODING_REF: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object; } extern "C" { diff --git a/core-graphics-types/Cargo.toml b/core-graphics-types/Cargo.toml index 0f5a86d1..94759a0a 100644 --- a/core-graphics-types/Cargo.toml +++ b/core-graphics-types/Cargo.toml @@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0" bitflags = "1.0" core-foundation = { path = "../core-foundation", version = "0.9" } libc = "0.2" -objc-encode = "1.1.0" +objc-encode = { version = "=2.0.0-pre.1", package = "objc2-encode" } [package.metadata.docs.rs] default-target = "x86_64-apple-darwin" diff --git a/core-graphics/Cargo.toml b/core-graphics/Cargo.toml index 3dfe5cae..01ee24b3 100644 --- a/core-graphics/Cargo.toml +++ b/core-graphics/Cargo.toml @@ -18,7 +18,7 @@ core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } foreign-types = "0.5.0" libc = "0.2" -objc-encode = "1.1.0" +objc-encode = { version = "=2.0.0-pre.1", package = "objc2-encode" } [package.metadata.docs.rs] default-target = "x86_64-apple-darwin" diff --git a/core-graphics/src/sys.rs b/core-graphics/src/sys.rs index 4e9d5d13..4ac9a12a 100644 --- a/core-graphics/src/sys.rs +++ b/core-graphics/src/sys.rs @@ -1,6 +1,6 @@ use std::os::raw::c_void; -use objc_encode::{Encode, Encoding}; +use objc_encode::{Encoding, RefEncode}; pub enum CGImage {} pub type CGImageRef = *mut CGImage; @@ -8,8 +8,8 @@ pub type CGImageRef = *mut CGImage; #[repr(C)] pub struct __CGColor(c_void); -unsafe impl Encode for &'_ __CGColor { - const ENCODING: Encoding<'static> = Encoding::Unknown; +unsafe impl RefEncode for __CGColor { + const ENCODING_REF: Encoding<'static> = Encoding::Unknown; } pub type CGColorRef = *const __CGColor; @@ -20,8 +20,8 @@ pub type CGColorSpaceRef = *mut CGColorSpace; pub enum CGPath {} pub type CGPathRef = *mut CGPath; -unsafe impl Encode for &'_ CGPath { - const ENCODING: Encoding<'static> = Encoding::Unknown; +unsafe impl RefEncode for CGPath { + const ENCODING_REF: Encoding<'static> = Encoding::Unknown; } pub enum CGDataProvider {} @@ -33,8 +33,8 @@ pub type CGFontRef = *mut CGFont; pub enum CGContext {} pub type CGContextRef = *mut CGContext; -unsafe impl Encode for &'_ CGContext { - const ENCODING: Encoding<'static> = Encoding::Unknown; +unsafe impl RefEncode for CGContext { + const ENCODING_REF: Encoding<'static> = Encoding::Unknown; } pub enum CGGradient {} From 812338c66a96f899b516c0507051513337cb1fb8 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 16 Jun 2022 06:16:54 +0200 Subject: [PATCH 04/14] Use proper name of objc2_encode --- cocoa-foundation/Cargo.toml | 2 +- cocoa-foundation/src/foundation.rs | 4 ++-- cocoa-foundation/src/lib.rs | 8 ++++---- cocoa/Cargo.toml | 2 +- cocoa/src/lib.rs | 2 +- cocoa/src/quartzcore.rs | 20 ++++++++++---------- core-foundation-sys/Cargo.toml | 2 +- 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 | 2 +- core-graphics-types/src/geometry.rs | 2 +- core-graphics-types/src/lib.rs | 2 +- core-graphics/Cargo.toml | 2 +- core-graphics/src/lib.rs | 2 +- core-graphics/src/sys.rs | 2 +- 18 files changed, 35 insertions(+), 35 deletions(-) diff --git a/cocoa-foundation/Cargo.toml b/cocoa-foundation/Cargo.toml index 3774ba26..7fefff24 100644 --- a/cocoa-foundation/Cargo.toml +++ b/cocoa-foundation/Cargo.toml @@ -18,4 +18,4 @@ libc = "0.2" core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } objc2 = { version = "=0.3.0-beta.1" } -objc-encode = { version = "=2.0.0-pre.1", package = "objc2-encode" } +objc2-encode = { version = "=2.0.0-pre.1" } diff --git a/cocoa-foundation/src/foundation.rs b/cocoa-foundation/src/foundation.rs index a0adde2e..4f0e555d 100644 --- a/cocoa-foundation/src/foundation.rs +++ b/cocoa-foundation/src/foundation.rs @@ -12,7 +12,7 @@ use base::{id, nil, BOOL, NO, SEL}; use block::Block; use libc; -use objc_encode::{Encode, Encoding, RefEncode}; +use objc2_encode::{Encode, Encoding, RefEncode}; use std::os::raw::c_void; use std::ptr; @@ -36,7 +36,7 @@ mod macos { use base::id; use core_graphics_types::base::CGFloat; use core_graphics_types::geometry::CGRect; - use objc_encode::{Encode, Encoding}; + use objc2_encode::{Encode, Encoding}; use std::mem; #[repr(C)] diff --git a/cocoa-foundation/src/lib.rs b/cocoa-foundation/src/lib.rs index 708e465b..504e8855 100644 --- a/cocoa-foundation/src/lib.rs +++ b/cocoa-foundation/src/lib.rs @@ -15,17 +15,17 @@ extern crate bitflags; extern crate core_foundation; extern crate core_graphics_types; extern crate libc; -pub extern crate objc_encode; +pub extern crate objc2_encode; #[macro_use] extern crate objc2; -pub use objc_encode as __objc_encode; +pub use objc2_encode as __objc2_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; + unsafe impl $crate::__objc2_encode::Encode for $t { + const ENCODING: $crate::__objc2_encode::Encoding<'static> = <$delegation>::ENCODING; } }; } diff --git a/cocoa/Cargo.toml b/cocoa/Cargo.toml index 96f81af6..a2c08857 100644 --- a/cocoa/Cargo.toml +++ b/cocoa/Cargo.toml @@ -20,4 +20,4 @@ core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics = { path = "../core-graphics", version = "0.23" } foreign-types = "0.5" objc2 = { version = "=0.3.0-beta.1" } -objc-encode = { version = "=2.0.0-pre.1", package = "objc2-encode" } +objc2-encode = { version = "=2.0.0-pre.1" } diff --git a/cocoa/src/lib.rs b/cocoa/src/lib.rs index ab1dd4b4..8678dbcd 100644 --- a/cocoa/src/lib.rs +++ b/cocoa/src/lib.rs @@ -20,7 +20,7 @@ extern crate core_foundation; extern crate core_graphics; extern crate foreign_types; extern crate libc; -extern crate objc_encode; +extern crate objc2_encode; #[macro_use] extern crate objc2; diff --git a/cocoa/src/quartzcore.rs b/cocoa/src/quartzcore.rs index f9295552..9f356fe4 100644 --- a/cocoa/src/quartzcore.rs +++ b/cocoa/src/quartzcore.rs @@ -1485,9 +1485,9 @@ pub struct CATransform3D { pub m44: CGFloat, } -unsafe impl ::objc_encode::Encode for CATransform3D { - const ENCODING: ::objc_encode::Encoding<'static> = - ::objc_encode::Encoding::Array(16, &CGFloat::ENCODING); +unsafe impl ::objc2_encode::Encode for CATransform3D { + const ENCODING: ::objc2_encode::Encoding<'static> = + ::objc2_encode::Encoding::Array(16, &CGFloat::ENCODING); } impl PartialEq for CATransform3D { @@ -1641,8 +1641,8 @@ pub struct CVTimeStamp { pub reserved: u64, } -unsafe impl ::objc_encode::Encode for CVTimeStamp { - const ENCODING: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Struct( +unsafe impl ::objc2_encode::Encode for CVTimeStamp { + const ENCODING: ::objc2_encode::Encoding<'static> = ::objc2_encode::Encoding::Struct( "CVTimeStamp", &[ u32::ENCODING, @@ -1658,9 +1658,9 @@ unsafe impl ::objc_encode::Encode for CVTimeStamp { ); } -unsafe impl ::objc_encode::RefEncode for CVTimeStamp { - const ENCODING_REF: ::objc_encode::Encoding<'static> = - ::objc_encode::Encoding::Pointer(&::ENCODING); +unsafe impl ::objc2_encode::RefEncode for CVTimeStamp { + const ENCODING_REF: ::objc2_encode::Encoding<'static> = + ::objc2_encode::Encoding::Pointer(&::ENCODING); } pub type CVTimeStampFlags = u64; @@ -1691,8 +1691,8 @@ pub struct CVSMPTETime { pub frames: i16, } -unsafe impl ::objc_encode::Encode for CVSMPTETime { - const ENCODING: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Struct( +unsafe impl ::objc2_encode::Encode for CVSMPTETime { + const ENCODING: ::objc2_encode::Encoding<'static> = ::objc2_encode::Encoding::Struct( "CVSMPTETime", &[ i16::ENCODING, diff --git a/core-foundation-sys/Cargo.toml b/core-foundation-sys/Cargo.toml index a9889b6a..d61a1277 100644 --- a/core-foundation-sys/Cargo.toml +++ b/core-foundation-sys/Cargo.toml @@ -8,7 +8,7 @@ authors = ["The Servo Project Developers"] license = "MIT OR Apache-2.0" [dependencies] -objc-encode = { version = "=2.0.0-pre.1", package = "objc2-encode" } +objc2-encode = { version = "=2.0.0-pre.1" } [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 3b299503..a3457d41 100644 --- a/core-foundation-sys/src/array.rs +++ b/core-foundation-sys/src/array.rs @@ -36,8 +36,8 @@ pub struct __CFArray(c_void); pub type CFArrayRef = *const __CFArray; pub type CFMutableArrayRef = *mut __CFArray; -unsafe impl ::objc_encode::RefEncode for __CFArray { - const ENCODING_REF: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object; +unsafe impl ::objc2_encode::RefEncode for __CFArray { + const ENCODING_REF: ::objc2_encode::Encoding<'static> = ::objc2_encode::Encoding::Object; } extern "C" { diff --git a/core-foundation-sys/src/attributed_string.rs b/core-foundation-sys/src/attributed_string.rs index bbeef172..f76b8d4d 100644 --- a/core-foundation-sys/src/attributed_string.rs +++ b/core-foundation-sys/src/attributed_string.rs @@ -19,8 +19,8 @@ pub struct __CFAttributedString(c_void); pub type CFAttributedStringRef = *const __CFAttributedString; pub type CFMutableAttributedStringRef = *mut __CFAttributedString; -unsafe impl ::objc_encode::RefEncode for __CFAttributedString { - const ENCODING_REF: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object; +unsafe impl ::objc2_encode::RefEncode for __CFAttributedString { + const ENCODING_REF: ::objc2_encode::Encoding<'static> = ::objc2_encode::Encoding::Object; } extern "C" { diff --git a/core-foundation-sys/src/dictionary.rs b/core-foundation-sys/src/dictionary.rs index 34f57f08..659f436c 100644 --- a/core-foundation-sys/src/dictionary.rs +++ b/core-foundation-sys/src/dictionary.rs @@ -51,8 +51,8 @@ pub struct __CFDictionary(c_void); pub type CFDictionaryRef = *const __CFDictionary; pub type CFMutableDictionaryRef = *mut __CFDictionary; -unsafe impl ::objc_encode::RefEncode for __CFDictionary { - const ENCODING_REF: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object; +unsafe impl ::objc2_encode::RefEncode for __CFDictionary { + const ENCODING_REF: ::objc2_encode::Encoding<'static> = ::objc2_encode::Encoding::Object; } extern "C" { diff --git a/core-foundation-sys/src/lib.rs b/core-foundation-sys/src/lib.rs index fbaab9c4..4f1e7441 100644 --- a/core-foundation-sys/src/lib.rs +++ b/core-foundation-sys/src/lib.rs @@ -17,7 +17,7 @@ feature(linkage) )] // back-compat requires weak linkage -extern crate objc_encode; +extern crate objc2_encode; // Link to CoreFoundation on any Apple device. // diff --git a/core-foundation-sys/src/string.rs b/core-foundation-sys/src/string.rs index 41080edc..d0f2e6af 100644 --- a/core-foundation-sys/src/string.rs +++ b/core-foundation-sys/src/string.rs @@ -206,8 +206,8 @@ pub fn CFStringInitInlineBuffer(str: CFStringRef, buf: *mut CFStringInlineBuffer pub fn CFStringGetCharacterFromInlineBuffer(buf: *mut CFStringInlineBuffer, idx: CFIndex) -> UniChar; */ -unsafe impl ::objc_encode::RefEncode for __CFString { - const ENCODING_REF: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object; +unsafe impl ::objc2_encode::RefEncode for __CFString { + const ENCODING_REF: ::objc2_encode::Encoding<'static> = ::objc2_encode::Encoding::Object; } extern "C" { diff --git a/core-graphics-types/Cargo.toml b/core-graphics-types/Cargo.toml index 94759a0a..0f466d14 100644 --- a/core-graphics-types/Cargo.toml +++ b/core-graphics-types/Cargo.toml @@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0" bitflags = "1.0" core-foundation = { path = "../core-foundation", version = "0.9" } libc = "0.2" -objc-encode = { version = "=2.0.0-pre.1", package = "objc2-encode" } +objc2-encode = { version = "=2.0.0-pre.1" } [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 c04cfb57..aba9f36e 100644 --- a/core-graphics-types/src/geometry.rs +++ b/core-graphics-types/src/geometry.rs @@ -10,7 +10,7 @@ use base::CGFloat; use core_foundation::base::TCFType; use core_foundation::dictionary::CFDictionary; -use objc_encode::{Encode, Encoding}; +use objc2_encode::{Encode, Encoding}; pub const CG_ZERO_POINT: CGPoint = CGPoint { x: 0.0, y: 0.0 }; diff --git a/core-graphics-types/src/lib.rs b/core-graphics-types/src/lib.rs index 2d6c2c9a..e19ae740 100644 --- a/core-graphics-types/src/lib.rs +++ b/core-graphics-types/src/lib.rs @@ -8,7 +8,7 @@ // except according to those terms. extern crate core_foundation; -extern crate objc_encode; +extern crate objc2_encode; pub mod base; pub mod geometry; diff --git a/core-graphics/Cargo.toml b/core-graphics/Cargo.toml index 01ee24b3..55e04ac3 100644 --- a/core-graphics/Cargo.toml +++ b/core-graphics/Cargo.toml @@ -18,7 +18,7 @@ core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } foreign-types = "0.5.0" libc = "0.2" -objc-encode = { version = "=2.0.0-pre.1", package = "objc2-encode" } +objc2-encode = { version = "=2.0.0-pre.1" } [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 b0201738..ee178d7a 100644 --- a/core-graphics/src/lib.rs +++ b/core-graphics/src/lib.rs @@ -8,7 +8,7 @@ // except according to those terms. extern crate libc; -extern crate objc_encode; +extern crate objc2_encode; #[macro_use] extern crate core_foundation; diff --git a/core-graphics/src/sys.rs b/core-graphics/src/sys.rs index 4ac9a12a..df840119 100644 --- a/core-graphics/src/sys.rs +++ b/core-graphics/src/sys.rs @@ -1,6 +1,6 @@ use std::os::raw::c_void; -use objc_encode::{Encoding, RefEncode}; +use objc2_encode::{Encoding, RefEncode}; pub enum CGImage {} pub type CGImageRef = *mut CGImage; From 7d593d016175755e492a92ef89edca68ac3bd5cd Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 29 Aug 2022 03:35:43 +0200 Subject: [PATCH 05/14] Update objc2 to v0.3.0-beta.2 --- cocoa-foundation/Cargo.toml | 6 +++--- cocoa-foundation/src/foundation.rs | 14 +++++++------- cocoa-foundation/src/lib.rs | 2 +- cocoa/Cargo.toml | 6 +++--- cocoa/src/quartzcore.rs | 10 +++++----- core-foundation-sys/Cargo.toml | 2 +- core-foundation-sys/src/array.rs | 2 +- core-foundation-sys/src/attributed_string.rs | 2 +- core-foundation-sys/src/dictionary.rs | 2 +- core-foundation-sys/src/string.rs | 2 +- core-graphics-types/Cargo.toml | 2 +- core-graphics-types/src/geometry.rs | 11 ++++------- core-graphics/Cargo.toml | 2 +- core-graphics/src/sys.rs | 6 +++--- 14 files changed, 33 insertions(+), 36 deletions(-) diff --git a/cocoa-foundation/Cargo.toml b/cocoa-foundation/Cargo.toml index 7fefff24..00d57a51 100644 --- a/cocoa-foundation/Cargo.toml +++ b/cocoa-foundation/Cargo.toml @@ -12,10 +12,10 @@ license = "MIT OR Apache-2.0" default-target = "x86_64-apple-darwin" [dependencies] -block = { version = "=0.2.0-alpha.5", package = "block2" } +block = { version = "=0.2.0-alpha.6", package = "block2" } bitflags = "1.0" libc = "0.2" core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } -objc2 = { version = "=0.3.0-beta.1" } -objc2-encode = { version = "=2.0.0-pre.1" } +objc2 = { version = "=0.3.0-beta.2" } +objc2-encode = { version = "=2.0.0-pre.2" } diff --git a/cocoa-foundation/src/foundation.rs b/cocoa-foundation/src/foundation.rs index 4f0e555d..0e6854a1 100644 --- a/cocoa-foundation/src/foundation.rs +++ b/cocoa-foundation/src/foundation.rs @@ -54,7 +54,7 @@ mod macos { } unsafe impl Encode for NSPoint { - const ENCODING: Encoding<'static> = + const ENCODING: Encoding = Encoding::Struct("CGPoint", &[CGFloat::ENCODING, CGFloat::ENCODING]); } @@ -76,7 +76,7 @@ mod macos { } unsafe impl Encode for NSSize { - const ENCODING: Encoding<'static> = + const ENCODING: Encoding = Encoding::Struct("CGSize", &[CGFloat::ENCODING, CGFloat::ENCODING]); } @@ -108,7 +108,7 @@ mod macos { } unsafe impl Encode for NSRect { - const ENCODING: Encoding<'static> = + const ENCODING: Encoding = Encoding::Struct("CGRect", &[NSPoint::ENCODING, NSSize::ENCODING]); } @@ -152,7 +152,7 @@ pub struct NSRange { } unsafe impl Encode for NSRange { - const ENCODING: Encoding<'static> = + const ENCODING: Encoding = Encoding::Struct("_NSRange", &[NSUInteger::ENCODING, NSUInteger::ENCODING]); } @@ -199,7 +199,7 @@ pub struct NSOperatingSystemVersion { } unsafe impl Encode for NSOperatingSystemVersion { - const ENCODING: Encoding<'static> = Encoding::Struct( + const ENCODING: Encoding = Encoding::Struct( "NSOperatingSystemVersion", &[ NSUInteger::ENCODING, @@ -709,7 +709,7 @@ struct NSFastEnumerationState { } unsafe impl Encode for NSFastEnumerationState { - const ENCODING: Encoding<'static> = Encoding::Struct( + const ENCODING: Encoding = Encoding::Struct( "?", &[ libc::c_ulong::ENCODING, @@ -721,7 +721,7 @@ unsafe impl Encode for NSFastEnumerationState { } unsafe impl RefEncode for NSFastEnumerationState { - const ENCODING_REF: Encoding<'static> = Encoding::Pointer(&Self::ENCODING); + const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING); } const NS_FAST_ENUM_BUF_SIZE: usize = 16; diff --git a/cocoa-foundation/src/lib.rs b/cocoa-foundation/src/lib.rs index 504e8855..c8ee9156 100644 --- a/cocoa-foundation/src/lib.rs +++ b/cocoa-foundation/src/lib.rs @@ -25,7 +25,7 @@ pub use objc2_encode as __objc2_encode; macro_rules! impl_Encode { ($t:ty, $delegation:ty) => { unsafe impl $crate::__objc2_encode::Encode for $t { - const ENCODING: $crate::__objc2_encode::Encoding<'static> = <$delegation>::ENCODING; + const ENCODING: $crate::__objc2_encode::Encoding = <$delegation>::ENCODING; } }; } diff --git a/cocoa/Cargo.toml b/cocoa/Cargo.toml index a2c08857..3b3f1a47 100644 --- a/cocoa/Cargo.toml +++ b/cocoa/Cargo.toml @@ -12,12 +12,12 @@ license = "MIT OR Apache-2.0" default-target = "x86_64-apple-darwin" [dependencies] -block = { version = "=0.2.0-alpha.5", package = "block2" } +block = { version = "=0.2.0-alpha.6", package = "block2" } bitflags = "1.0" 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.23" } foreign-types = "0.5" -objc2 = { version = "=0.3.0-beta.1" } -objc2-encode = { version = "=2.0.0-pre.1" } +objc2 = { version = "=0.3.0-beta.2" } +objc2-encode = { version = "=2.0.0-pre.2" } diff --git a/cocoa/src/quartzcore.rs b/cocoa/src/quartzcore.rs index 9f356fe4..298910ec 100644 --- a/cocoa/src/quartzcore.rs +++ b/cocoa/src/quartzcore.rs @@ -1437,7 +1437,7 @@ pub mod transaction { #[inline] pub fn set_completion_block(block: ConcreteBlock<(), (), F>) where - F: 'static + IntoConcreteBlock<(), Ret = ()>, + F: 'static + IntoConcreteBlock<(), Output = ()>, { unsafe { let block = block.copy(); @@ -1486,7 +1486,7 @@ pub struct CATransform3D { } unsafe impl ::objc2_encode::Encode for CATransform3D { - const ENCODING: ::objc2_encode::Encoding<'static> = + const ENCODING: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Array(16, &CGFloat::ENCODING); } @@ -1642,7 +1642,7 @@ pub struct CVTimeStamp { } unsafe impl ::objc2_encode::Encode for CVTimeStamp { - const ENCODING: ::objc2_encode::Encoding<'static> = ::objc2_encode::Encoding::Struct( + const ENCODING: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Struct( "CVTimeStamp", &[ u32::ENCODING, @@ -1659,7 +1659,7 @@ unsafe impl ::objc2_encode::Encode for CVTimeStamp { } unsafe impl ::objc2_encode::RefEncode for CVTimeStamp { - const ENCODING_REF: ::objc2_encode::Encoding<'static> = + const ENCODING_REF: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Pointer(&::ENCODING); } @@ -1692,7 +1692,7 @@ pub struct CVSMPTETime { } unsafe impl ::objc2_encode::Encode for CVSMPTETime { - const ENCODING: ::objc2_encode::Encoding<'static> = ::objc2_encode::Encoding::Struct( + const ENCODING: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Struct( "CVSMPTETime", &[ i16::ENCODING, diff --git a/core-foundation-sys/Cargo.toml b/core-foundation-sys/Cargo.toml index d61a1277..c77f0077 100644 --- a/core-foundation-sys/Cargo.toml +++ b/core-foundation-sys/Cargo.toml @@ -8,7 +8,7 @@ authors = ["The Servo Project Developers"] license = "MIT OR Apache-2.0" [dependencies] -objc2-encode = { version = "=2.0.0-pre.1" } +objc2-encode = { version = "=2.0.0-pre.2" } [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 a3457d41..45935098 100644 --- a/core-foundation-sys/src/array.rs +++ b/core-foundation-sys/src/array.rs @@ -37,7 +37,7 @@ pub type CFArrayRef = *const __CFArray; pub type CFMutableArrayRef = *mut __CFArray; unsafe impl ::objc2_encode::RefEncode for __CFArray { - const ENCODING_REF: ::objc2_encode::Encoding<'static> = ::objc2_encode::Encoding::Object; + const ENCODING_REF: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Object; } extern "C" { diff --git a/core-foundation-sys/src/attributed_string.rs b/core-foundation-sys/src/attributed_string.rs index f76b8d4d..e1f7727c 100644 --- a/core-foundation-sys/src/attributed_string.rs +++ b/core-foundation-sys/src/attributed_string.rs @@ -20,7 +20,7 @@ pub type CFAttributedStringRef = *const __CFAttributedString; pub type CFMutableAttributedStringRef = *mut __CFAttributedString; unsafe impl ::objc2_encode::RefEncode for __CFAttributedString { - const ENCODING_REF: ::objc2_encode::Encoding<'static> = ::objc2_encode::Encoding::Object; + const ENCODING_REF: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Object; } extern "C" { diff --git a/core-foundation-sys/src/dictionary.rs b/core-foundation-sys/src/dictionary.rs index 659f436c..f58943c4 100644 --- a/core-foundation-sys/src/dictionary.rs +++ b/core-foundation-sys/src/dictionary.rs @@ -52,7 +52,7 @@ pub type CFDictionaryRef = *const __CFDictionary; pub type CFMutableDictionaryRef = *mut __CFDictionary; unsafe impl ::objc2_encode::RefEncode for __CFDictionary { - const ENCODING_REF: ::objc2_encode::Encoding<'static> = ::objc2_encode::Encoding::Object; + const ENCODING_REF: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Object; } extern "C" { diff --git a/core-foundation-sys/src/string.rs b/core-foundation-sys/src/string.rs index d0f2e6af..662370ee 100644 --- a/core-foundation-sys/src/string.rs +++ b/core-foundation-sys/src/string.rs @@ -207,7 +207,7 @@ pub fn CFStringGetCharacterFromInlineBuffer(buf: *mut CFStringInlineBuffer, idx: */ unsafe impl ::objc2_encode::RefEncode for __CFString { - const ENCODING_REF: ::objc2_encode::Encoding<'static> = ::objc2_encode::Encoding::Object; + const ENCODING_REF: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Object; } extern "C" { diff --git a/core-graphics-types/Cargo.toml b/core-graphics-types/Cargo.toml index 0f466d14..94a7ad8a 100644 --- a/core-graphics-types/Cargo.toml +++ b/core-graphics-types/Cargo.toml @@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0" bitflags = "1.0" core-foundation = { path = "../core-foundation", version = "0.9" } libc = "0.2" -objc2-encode = { version = "=2.0.0-pre.1" } +objc2-encode = { version = "=2.0.0-pre.2" } [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 aba9f36e..d7e3aab7 100644 --- a/core-graphics-types/src/geometry.rs +++ b/core-graphics-types/src/geometry.rs @@ -41,8 +41,7 @@ pub struct CGSize { } unsafe impl Encode for CGSize { - const ENCODING: Encoding<'static> = - Encoding::Struct("CGSize", &[CGFloat::ENCODING, CGFloat::ENCODING]); + const ENCODING: Encoding = Encoding::Struct("CGSize", &[CGFloat::ENCODING, CGFloat::ENCODING]); } impl CGSize { @@ -68,8 +67,7 @@ pub struct CGPoint { } unsafe impl Encode for CGPoint { - const ENCODING: Encoding<'static> = - Encoding::Struct("CGPoint", &[CGFloat::ENCODING, CGFloat::ENCODING]); + const ENCODING: Encoding = Encoding::Struct("CGPoint", &[CGFloat::ENCODING, CGFloat::ENCODING]); } impl CGPoint { @@ -92,8 +90,7 @@ pub struct CGRect { } unsafe impl Encode for CGRect { - const ENCODING: Encoding<'static> = - Encoding::Struct("CGRect", &[CGPoint::ENCODING, CGSize::ENCODING]); + const ENCODING: Encoding = Encoding::Struct("CGRect", &[CGPoint::ENCODING, CGSize::ENCODING]); } impl CGRect { @@ -162,7 +159,7 @@ pub struct CGAffineTransform { } unsafe impl Encode for CGAffineTransform { - const ENCODING: Encoding<'static> = Encoding::Struct( + const ENCODING: Encoding = Encoding::Struct( "CGAffineTransform", &[ CGFloat::ENCODING, diff --git a/core-graphics/Cargo.toml b/core-graphics/Cargo.toml index 55e04ac3..989e4943 100644 --- a/core-graphics/Cargo.toml +++ b/core-graphics/Cargo.toml @@ -18,7 +18,7 @@ core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } foreign-types = "0.5.0" libc = "0.2" -objc2-encode = { version = "=2.0.0-pre.1" } +objc2-encode = { version = "=2.0.0-pre.2" } [package.metadata.docs.rs] default-target = "x86_64-apple-darwin" diff --git a/core-graphics/src/sys.rs b/core-graphics/src/sys.rs index df840119..50caf001 100644 --- a/core-graphics/src/sys.rs +++ b/core-graphics/src/sys.rs @@ -9,7 +9,7 @@ pub type CGImageRef = *mut CGImage; pub struct __CGColor(c_void); unsafe impl RefEncode for __CGColor { - const ENCODING_REF: Encoding<'static> = Encoding::Unknown; + const ENCODING_REF: Encoding = Encoding::Unknown; } pub type CGColorRef = *const __CGColor; @@ -21,7 +21,7 @@ pub enum CGPath {} pub type CGPathRef = *mut CGPath; unsafe impl RefEncode for CGPath { - const ENCODING_REF: Encoding<'static> = Encoding::Unknown; + const ENCODING_REF: Encoding = Encoding::Unknown; } pub enum CGDataProvider {} @@ -34,7 +34,7 @@ pub enum CGContext {} pub type CGContextRef = *mut CGContext; unsafe impl RefEncode for CGContext { - const ENCODING_REF: Encoding<'static> = Encoding::Unknown; + const ENCODING_REF: Encoding = Encoding::Unknown; } pub enum CGGradient {} From c8194e59478ef6e3c9a84a57fde4d96cfa5eb367 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Fri, 2 Sep 2022 15:17:27 +0200 Subject: [PATCH 06/14] Update objc2 to v0.3.0-beta.4 --- cocoa-foundation/Cargo.toml | 6 +++--- cocoa-foundation/src/foundation.rs | 4 ++-- cocoa/Cargo.toml | 5 ++--- cocoa/src/lib.rs | 1 - cocoa/src/quartzcore.rs | 19 +++++++++---------- core-foundation-sys/Cargo.toml | 2 +- core-graphics-types/Cargo.toml | 2 +- core-graphics/Cargo.toml | 2 +- 8 files changed, 19 insertions(+), 22 deletions(-) diff --git a/cocoa-foundation/Cargo.toml b/cocoa-foundation/Cargo.toml index 00d57a51..94a32bac 100644 --- a/cocoa-foundation/Cargo.toml +++ b/cocoa-foundation/Cargo.toml @@ -12,10 +12,10 @@ license = "MIT OR Apache-2.0" default-target = "x86_64-apple-darwin" [dependencies] -block = { version = "=0.2.0-alpha.6", package = "block2" } +block = { version = "=0.2.0-alpha.7", package = "block2" } bitflags = "1.0" libc = "0.2" core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } -objc2 = { version = "=0.3.0-beta.2" } -objc2-encode = { version = "=2.0.0-pre.2" } +objc2 = { version = "=0.3.0-beta.4" } +objc2-encode = { version = "=2.0.0-pre.3" } diff --git a/cocoa-foundation/src/foundation.rs b/cocoa-foundation/src/foundation.rs index 0e6854a1..e586d912 100644 --- a/cocoa-foundation/src/foundation.rs +++ b/cocoa-foundation/src/foundation.rs @@ -12,7 +12,7 @@ use base::{id, nil, BOOL, NO, SEL}; use block::Block; use libc; -use objc2_encode::{Encode, Encoding, RefEncode}; +use objc2::encode::{Encode, Encoding, RefEncode}; use std::os::raw::c_void; use std::ptr; @@ -36,7 +36,7 @@ mod macos { use base::id; use core_graphics_types::base::CGFloat; use core_graphics_types::geometry::CGRect; - use objc2_encode::{Encode, Encoding}; + use objc2::encode::{Encode, Encoding}; use std::mem; #[repr(C)] diff --git a/cocoa/Cargo.toml b/cocoa/Cargo.toml index 3b3f1a47..1821644a 100644 --- a/cocoa/Cargo.toml +++ b/cocoa/Cargo.toml @@ -12,12 +12,11 @@ license = "MIT OR Apache-2.0" default-target = "x86_64-apple-darwin" [dependencies] -block = { version = "=0.2.0-alpha.6", package = "block2" } +block = { version = "=0.2.0-alpha.7", package = "block2" } bitflags = "1.0" 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.23" } foreign-types = "0.5" -objc2 = { version = "=0.3.0-beta.2" } -objc2-encode = { version = "=2.0.0-pre.2" } +objc2 = { version = "=0.3.0-beta.4" } diff --git a/cocoa/src/lib.rs b/cocoa/src/lib.rs index 8678dbcd..e2a56414 100644 --- a/cocoa/src/lib.rs +++ b/cocoa/src/lib.rs @@ -20,7 +20,6 @@ extern crate core_foundation; extern crate core_graphics; extern crate foreign_types; extern crate libc; -extern crate objc2_encode; #[macro_use] extern crate objc2; diff --git a/cocoa/src/quartzcore.rs b/cocoa/src/quartzcore.rs index 298910ec..d66b6b04 100644 --- a/cocoa/src/quartzcore.rs +++ b/cocoa/src/quartzcore.rs @@ -21,6 +21,7 @@ use core_graphics::context::CGContext; use core_graphics::geometry::{CGAffineTransform, CGPoint, CGRect, CGSize}; use core_graphics::path::{CGPath, SysCGPathRef}; use foreign_types::ForeignType; +use objc2::encode::{Encode, Encoding, RefEncode}; use std::ops::Mul; use std::ptr; @@ -1485,9 +1486,8 @@ pub struct CATransform3D { pub m44: CGFloat, } -unsafe impl ::objc2_encode::Encode for CATransform3D { - const ENCODING: ::objc2_encode::Encoding = - ::objc2_encode::Encoding::Array(16, &CGFloat::ENCODING); +unsafe impl Encode for CATransform3D { + const ENCODING: Encoding = Encoding::Array(16, &CGFloat::ENCODING); } impl PartialEq for CATransform3D { @@ -1641,8 +1641,8 @@ pub struct CVTimeStamp { pub reserved: u64, } -unsafe impl ::objc2_encode::Encode for CVTimeStamp { - const ENCODING: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Struct( +unsafe impl Encode for CVTimeStamp { + const ENCODING: Encoding = Encoding::Struct( "CVTimeStamp", &[ u32::ENCODING, @@ -1658,9 +1658,8 @@ unsafe impl ::objc2_encode::Encode for CVTimeStamp { ); } -unsafe impl ::objc2_encode::RefEncode for CVTimeStamp { - const ENCODING_REF: ::objc2_encode::Encoding = - ::objc2_encode::Encoding::Pointer(&::ENCODING); +unsafe impl RefEncode for CVTimeStamp { + const ENCODING_REF: Encoding = Encoding::Pointer(&::ENCODING); } pub type CVTimeStampFlags = u64; @@ -1691,8 +1690,8 @@ pub struct CVSMPTETime { pub frames: i16, } -unsafe impl ::objc2_encode::Encode for CVSMPTETime { - const ENCODING: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Struct( +unsafe impl Encode for CVSMPTETime { + const ENCODING: Encoding = Encoding::Struct( "CVSMPTETime", &[ i16::ENCODING, diff --git a/core-foundation-sys/Cargo.toml b/core-foundation-sys/Cargo.toml index c77f0077..b8591806 100644 --- a/core-foundation-sys/Cargo.toml +++ b/core-foundation-sys/Cargo.toml @@ -8,7 +8,7 @@ authors = ["The Servo Project Developers"] license = "MIT OR Apache-2.0" [dependencies] -objc2-encode = { version = "=2.0.0-pre.2" } +objc2-encode = { version = "=2.0.0-pre.3" } [features] mac_os_10_7_support = [] # backwards compatibility diff --git a/core-graphics-types/Cargo.toml b/core-graphics-types/Cargo.toml index 94a7ad8a..41d94e0d 100644 --- a/core-graphics-types/Cargo.toml +++ b/core-graphics-types/Cargo.toml @@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0" bitflags = "1.0" core-foundation = { path = "../core-foundation", version = "0.9" } libc = "0.2" -objc2-encode = { version = "=2.0.0-pre.2" } +objc2-encode = { version = "=2.0.0-pre.3" } [package.metadata.docs.rs] default-target = "x86_64-apple-darwin" diff --git a/core-graphics/Cargo.toml b/core-graphics/Cargo.toml index 989e4943..7611dfb4 100644 --- a/core-graphics/Cargo.toml +++ b/core-graphics/Cargo.toml @@ -18,7 +18,7 @@ core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } foreign-types = "0.5.0" libc = "0.2" -objc2-encode = { version = "=2.0.0-pre.2" } +objc2-encode = { version = "=2.0.0-pre.3" } [package.metadata.docs.rs] default-target = "x86_64-apple-darwin" From 1421a5c3d1383c91523ab0c24a4c211eb8000911 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 31 Jul 2023 13:41:00 +0200 Subject: [PATCH 07/14] Update objc2 to v0.3.0-beta.5 --- cocoa-foundation/Cargo.toml | 5 ++--- cocoa-foundation/src/lib.rs | 9 +++------ cocoa/Cargo.toml | 4 ++-- core-foundation-sys/Cargo.toml | 2 +- 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 | 2 +- core-graphics-types/src/geometry.rs | 2 +- core-graphics-types/src/lib.rs | 2 +- core-graphics/Cargo.toml | 2 +- core-graphics/src/lib.rs | 2 +- core-graphics/src/sys.rs | 2 +- 15 files changed, 23 insertions(+), 27 deletions(-) diff --git a/cocoa-foundation/Cargo.toml b/cocoa-foundation/Cargo.toml index 94a32bac..7fc95efe 100644 --- a/cocoa-foundation/Cargo.toml +++ b/cocoa-foundation/Cargo.toml @@ -12,10 +12,9 @@ license = "MIT OR Apache-2.0" default-target = "x86_64-apple-darwin" [dependencies] -block = { version = "=0.2.0-alpha.7", package = "block2" } +block = { version = "=0.2.0-alpha.8", package = "block2" } bitflags = "1.0" libc = "0.2" core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } -objc2 = { version = "=0.3.0-beta.4" } -objc2-encode = { version = "=2.0.0-pre.3" } +objc2 = "=0.3.0-beta.5" diff --git a/cocoa-foundation/src/lib.rs b/cocoa-foundation/src/lib.rs index c8ee9156..f6ee4d21 100644 --- a/cocoa-foundation/src/lib.rs +++ b/cocoa-foundation/src/lib.rs @@ -15,17 +15,14 @@ extern crate bitflags; extern crate core_foundation; extern crate core_graphics_types; extern crate libc; -pub extern crate objc2_encode; #[macro_use] -extern crate objc2; - -pub use objc2_encode as __objc2_encode; +pub extern crate objc2; #[macro_export] macro_rules! impl_Encode { ($t:ty, $delegation:ty) => { - unsafe impl $crate::__objc2_encode::Encode for $t { - const ENCODING: $crate::__objc2_encode::Encoding = <$delegation>::ENCODING; + unsafe impl $crate::objc2::encode::Encode for $t { + const ENCODING: $crate::objc2::encode::Encoding = <$delegation>::ENCODING; } }; } diff --git a/cocoa/Cargo.toml b/cocoa/Cargo.toml index 1821644a..86a9da15 100644 --- a/cocoa/Cargo.toml +++ b/cocoa/Cargo.toml @@ -12,11 +12,11 @@ license = "MIT OR Apache-2.0" default-target = "x86_64-apple-darwin" [dependencies] -block = { version = "=0.2.0-alpha.7", package = "block2" } +block = { version = "=0.2.0-alpha.8", package = "block2" } bitflags = "1.0" 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.23" } foreign-types = "0.5" -objc2 = { version = "=0.3.0-beta.4" } +objc2 = "=0.3.0-beta.5" diff --git a/core-foundation-sys/Cargo.toml b/core-foundation-sys/Cargo.toml index b8591806..7b481bf9 100644 --- a/core-foundation-sys/Cargo.toml +++ b/core-foundation-sys/Cargo.toml @@ -8,7 +8,7 @@ authors = ["The Servo Project Developers"] license = "MIT OR Apache-2.0" [dependencies] -objc2-encode = { version = "=2.0.0-pre.3" } +objc2 = "=0.3.0-beta.5" [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 45935098..6cc5947e 100644 --- a/core-foundation-sys/src/array.rs +++ b/core-foundation-sys/src/array.rs @@ -36,8 +36,8 @@ pub struct __CFArray(c_void); pub type CFArrayRef = *const __CFArray; pub type CFMutableArrayRef = *mut __CFArray; -unsafe impl ::objc2_encode::RefEncode for __CFArray { - const ENCODING_REF: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Object; +unsafe impl ::objc2::encode::RefEncode for __CFArray { + const ENCODING_REF: ::objc2::encode::Encoding = ::objc2::encode::Encoding::Object; } extern "C" { diff --git a/core-foundation-sys/src/attributed_string.rs b/core-foundation-sys/src/attributed_string.rs index e1f7727c..bc9b5b68 100644 --- a/core-foundation-sys/src/attributed_string.rs +++ b/core-foundation-sys/src/attributed_string.rs @@ -19,8 +19,8 @@ pub struct __CFAttributedString(c_void); pub type CFAttributedStringRef = *const __CFAttributedString; pub type CFMutableAttributedStringRef = *mut __CFAttributedString; -unsafe impl ::objc2_encode::RefEncode for __CFAttributedString { - const ENCODING_REF: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Object; +unsafe impl ::objc2::encode::RefEncode for __CFAttributedString { + const ENCODING_REF: ::objc2::encode::Encoding = ::objc2::encode::Encoding::Object; } extern "C" { diff --git a/core-foundation-sys/src/dictionary.rs b/core-foundation-sys/src/dictionary.rs index f58943c4..67421dfa 100644 --- a/core-foundation-sys/src/dictionary.rs +++ b/core-foundation-sys/src/dictionary.rs @@ -51,8 +51,8 @@ pub struct __CFDictionary(c_void); pub type CFDictionaryRef = *const __CFDictionary; pub type CFMutableDictionaryRef = *mut __CFDictionary; -unsafe impl ::objc2_encode::RefEncode for __CFDictionary { - const ENCODING_REF: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Object; +unsafe impl ::objc2::encode::RefEncode for __CFDictionary { + const ENCODING_REF: ::objc2::encode::Encoding = ::objc2::encode::Encoding::Object; } extern "C" { diff --git a/core-foundation-sys/src/lib.rs b/core-foundation-sys/src/lib.rs index 4f1e7441..dfd5896e 100644 --- a/core-foundation-sys/src/lib.rs +++ b/core-foundation-sys/src/lib.rs @@ -17,7 +17,7 @@ feature(linkage) )] // back-compat requires weak linkage -extern crate objc2_encode; +extern crate objc2; // Link to CoreFoundation on any Apple device. // diff --git a/core-foundation-sys/src/string.rs b/core-foundation-sys/src/string.rs index 662370ee..67334db7 100644 --- a/core-foundation-sys/src/string.rs +++ b/core-foundation-sys/src/string.rs @@ -206,8 +206,8 @@ pub fn CFStringInitInlineBuffer(str: CFStringRef, buf: *mut CFStringInlineBuffer pub fn CFStringGetCharacterFromInlineBuffer(buf: *mut CFStringInlineBuffer, idx: CFIndex) -> UniChar; */ -unsafe impl ::objc2_encode::RefEncode for __CFString { - const ENCODING_REF: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Object; +unsafe impl ::objc2::encode::RefEncode for __CFString { + const ENCODING_REF: ::objc2::encode::Encoding = ::objc2::encode::Encoding::Object; } extern "C" { diff --git a/core-graphics-types/Cargo.toml b/core-graphics-types/Cargo.toml index 41d94e0d..043aa63a 100644 --- a/core-graphics-types/Cargo.toml +++ b/core-graphics-types/Cargo.toml @@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0" bitflags = "1.0" core-foundation = { path = "../core-foundation", version = "0.9" } libc = "0.2" -objc2-encode = { version = "=2.0.0-pre.3" } +objc2 = "=0.3.0-beta.5" [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 d7e3aab7..ec9e8283 100644 --- a/core-graphics-types/src/geometry.rs +++ b/core-graphics-types/src/geometry.rs @@ -10,7 +10,7 @@ use base::CGFloat; use core_foundation::base::TCFType; use core_foundation::dictionary::CFDictionary; -use objc2_encode::{Encode, Encoding}; +use objc2::encode::{Encode, Encoding}; pub const CG_ZERO_POINT: CGPoint = CGPoint { x: 0.0, y: 0.0 }; diff --git a/core-graphics-types/src/lib.rs b/core-graphics-types/src/lib.rs index e19ae740..944cfba2 100644 --- a/core-graphics-types/src/lib.rs +++ b/core-graphics-types/src/lib.rs @@ -8,7 +8,7 @@ // except according to those terms. extern crate core_foundation; -extern crate objc2_encode; +extern crate objc2; pub mod base; pub mod geometry; diff --git a/core-graphics/Cargo.toml b/core-graphics/Cargo.toml index 7611dfb4..763a62f5 100644 --- a/core-graphics/Cargo.toml +++ b/core-graphics/Cargo.toml @@ -18,7 +18,7 @@ core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } foreign-types = "0.5.0" libc = "0.2" -objc2-encode = { version = "=2.0.0-pre.3" } +objc2 = "=0.3.0-beta.5" [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 ee178d7a..cf5737d2 100644 --- a/core-graphics/src/lib.rs +++ b/core-graphics/src/lib.rs @@ -8,7 +8,7 @@ // except according to those terms. extern crate libc; -extern crate objc2_encode; +extern crate objc2; #[macro_use] extern crate core_foundation; diff --git a/core-graphics/src/sys.rs b/core-graphics/src/sys.rs index 50caf001..1cbf2f26 100644 --- a/core-graphics/src/sys.rs +++ b/core-graphics/src/sys.rs @@ -1,6 +1,6 @@ use std::os::raw::c_void; -use objc2_encode::{Encoding, RefEncode}; +use objc2::encode::{Encoding, RefEncode}; pub enum CGImage {} pub type CGImageRef = *mut CGImage; From 45d157d9cfd15609226204c7569123599b1b9a23 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 31 Jul 2023 13:43:48 +0200 Subject: [PATCH 08/14] Use proper name of block2 --- cocoa-foundation/Cargo.toml | 2 +- cocoa-foundation/src/foundation.rs | 2 +- cocoa-foundation/src/lib.rs | 2 +- cocoa-foundation/tests/foundation.rs | 4 ++-- cocoa/Cargo.toml | 2 +- cocoa/src/appkit.rs | 2 +- cocoa/src/lib.rs | 2 +- cocoa/src/quartzcore.rs | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cocoa-foundation/Cargo.toml b/cocoa-foundation/Cargo.toml index 7fc95efe..c2c9c5c5 100644 --- a/cocoa-foundation/Cargo.toml +++ b/cocoa-foundation/Cargo.toml @@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0" default-target = "x86_64-apple-darwin" [dependencies] -block = { version = "=0.2.0-alpha.8", package = "block2" } +block2 = "=0.2.0-alpha.8" bitflags = "1.0" libc = "0.2" core-foundation = { path = "../core-foundation", version = "0.9" } diff --git a/cocoa-foundation/src/foundation.rs b/cocoa-foundation/src/foundation.rs index e586d912..9760754e 100644 --- a/cocoa-foundation/src/foundation.rs +++ b/cocoa-foundation/src/foundation.rs @@ -10,7 +10,7 @@ #![allow(non_upper_case_globals)] use base::{id, nil, BOOL, NO, SEL}; -use block::Block; +use block2::Block; use libc; use objc2::encode::{Encode, Encoding, RefEncode}; use std::os::raw::c_void; diff --git a/cocoa-foundation/src/lib.rs b/cocoa-foundation/src/lib.rs index f6ee4d21..dc8cfc56 100644 --- a/cocoa-foundation/src/lib.rs +++ b/cocoa-foundation/src/lib.rs @@ -9,7 +9,7 @@ #![allow(non_snake_case)] -extern crate block; +extern crate block2; #[macro_use] extern crate bitflags; extern crate core_foundation; diff --git a/cocoa-foundation/tests/foundation.rs b/cocoa-foundation/tests/foundation.rs index 5d87a7dc..9051320d 100644 --- a/cocoa-foundation/tests/foundation.rs +++ b/cocoa-foundation/tests/foundation.rs @@ -1,6 +1,6 @@ #[macro_use] extern crate objc2; -extern crate block; +extern crate block2; extern crate cocoa_foundation; #[cfg(test)] @@ -108,7 +108,7 @@ mod foundation { } mod nsdictionary { - use block::ConcreteBlock; + use block2::ConcreteBlock; use cocoa_foundation::base::{id, nil}; use cocoa_foundation::foundation::{ NSArray, NSComparisonResult, NSDictionary, NSFastEnumeration, NSString, diff --git a/cocoa/Cargo.toml b/cocoa/Cargo.toml index 86a9da15..4986c635 100644 --- a/cocoa/Cargo.toml +++ b/cocoa/Cargo.toml @@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0" default-target = "x86_64-apple-darwin" [dependencies] -block = { version = "=0.2.0-alpha.8", package = "block2" } +block2 = "=0.2.0-alpha.8" bitflags = "1.0" libc = "0.2" cocoa-foundation = { path = "../cocoa-foundation", version = "0.1" } diff --git a/cocoa/src/appkit.rs b/cocoa/src/appkit.rs index aad5c89c..eb42f31d 100644 --- a/cocoa/src/appkit.rs +++ b/cocoa/src/appkit.rs @@ -10,7 +10,7 @@ #![allow(non_upper_case_globals)] use base::{id, BOOL, SEL}; -use block::Block; +use block2::Block; use foundation::{ NSInteger, NSPoint, NSRange, NSRect, NSRectEdge, NSSize, NSTimeInterval, NSUInteger, }; diff --git a/cocoa/src/lib.rs b/cocoa/src/lib.rs index e2a56414..7b73fbe4 100644 --- a/cocoa/src/lib.rs +++ b/cocoa/src/lib.rs @@ -11,7 +11,7 @@ #![crate_type = "rlib"] #![allow(non_snake_case)] -extern crate block; +extern crate block2; #[macro_use] extern crate bitflags; #[macro_use] diff --git a/cocoa/src/quartzcore.rs b/cocoa/src/quartzcore.rs index d66b6b04..52ad2cd0 100644 --- a/cocoa/src/quartzcore.rs +++ b/cocoa/src/quartzcore.rs @@ -1357,7 +1357,7 @@ impl CARenderer { // You can't actually construct any `CATransaction` objects, so that class is // really just a module. pub mod transaction { - use block::{Block, ConcreteBlock, IntoConcreteBlock, RcBlock}; + use block2::{Block, ConcreteBlock, IntoConcreteBlock, RcBlock}; use core_foundation::base::TCFType; use core_foundation::date::CFTimeInterval; use core_foundation::string::CFString; From 170dcce8d319ad2710277ddfa40a5d7ac91b4a4d Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 31 Jul 2023 13:46:03 +0200 Subject: [PATCH 09/14] Update objc2 to v0.4.0 --- cocoa-foundation/Cargo.toml | 4 ++-- cocoa/Cargo.toml | 4 ++-- core-foundation-sys/Cargo.toml | 2 +- core-graphics-types/Cargo.toml | 2 +- core-graphics/Cargo.toml | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cocoa-foundation/Cargo.toml b/cocoa-foundation/Cargo.toml index c2c9c5c5..a8d3b999 100644 --- a/cocoa-foundation/Cargo.toml +++ b/cocoa-foundation/Cargo.toml @@ -12,9 +12,9 @@ license = "MIT OR Apache-2.0" default-target = "x86_64-apple-darwin" [dependencies] -block2 = "=0.2.0-alpha.8" +block2 = "0.2.0" bitflags = "1.0" libc = "0.2" core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } -objc2 = "=0.3.0-beta.5" +objc2 = "0.4.0" diff --git a/cocoa/Cargo.toml b/cocoa/Cargo.toml index 4986c635..eae77b57 100644 --- a/cocoa/Cargo.toml +++ b/cocoa/Cargo.toml @@ -12,11 +12,11 @@ license = "MIT OR Apache-2.0" default-target = "x86_64-apple-darwin" [dependencies] -block2 = "=0.2.0-alpha.8" +block2 = "0.2.0" bitflags = "1.0" 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.23" } foreign-types = "0.5" -objc2 = "=0.3.0-beta.5" +objc2 = "0.4.0" diff --git a/core-foundation-sys/Cargo.toml b/core-foundation-sys/Cargo.toml index 7b481bf9..5740ec89 100644 --- a/core-foundation-sys/Cargo.toml +++ b/core-foundation-sys/Cargo.toml @@ -8,7 +8,7 @@ authors = ["The Servo Project Developers"] license = "MIT OR Apache-2.0" [dependencies] -objc2 = "=0.3.0-beta.5" +objc2 = "0.4.0" [features] mac_os_10_7_support = [] # backwards compatibility diff --git a/core-graphics-types/Cargo.toml b/core-graphics-types/Cargo.toml index 043aa63a..dc91244c 100644 --- a/core-graphics-types/Cargo.toml +++ b/core-graphics-types/Cargo.toml @@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0" bitflags = "1.0" core-foundation = { path = "../core-foundation", version = "0.9" } libc = "0.2" -objc2 = "=0.3.0-beta.5" +objc2 = "0.4.0" [package.metadata.docs.rs] default-target = "x86_64-apple-darwin" diff --git a/core-graphics/Cargo.toml b/core-graphics/Cargo.toml index 763a62f5..5def1b61 100644 --- a/core-graphics/Cargo.toml +++ b/core-graphics/Cargo.toml @@ -18,7 +18,7 @@ core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } foreign-types = "0.5.0" libc = "0.2" -objc2 = "=0.3.0-beta.5" +objc2 = "0.4.0" [package.metadata.docs.rs] default-target = "x86_64-apple-darwin" From 0eda34dc46034a8bd10cf69df248712cd3d2ac1f Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 31 Jul 2023 13:53:59 +0200 Subject: [PATCH 10/14] Silence deprecation warnings for now --- cocoa-foundation/src/base.rs | 4 +++- cocoa-foundation/src/lib.rs | 1 + cocoa/examples/fullscreen.rs | 7 +++---- cocoa/examples/nsvisualeffectview_blur.rs | 2 +- cocoa/src/lib.rs | 1 + 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cocoa-foundation/src/base.rs b/cocoa-foundation/src/base.rs index 4cebe99b..ae0dbf92 100644 --- a/cocoa-foundation/src/base.rs +++ b/cocoa-foundation/src/base.rs @@ -9,7 +9,9 @@ use objc2::runtime; -pub use objc2::runtime::{BOOL, NO, YES}; +pub type BOOL = runtime::BOOL; +pub const NO: BOOL = runtime::NO; +pub const YES: BOOL = runtime::YES; pub type Class = *mut runtime::Class; #[allow(non_camel_case_types)] diff --git a/cocoa-foundation/src/lib.rs b/cocoa-foundation/src/lib.rs index dc8cfc56..dcce624e 100644 --- a/cocoa-foundation/src/lib.rs +++ b/cocoa-foundation/src/lib.rs @@ -8,6 +8,7 @@ // except according to those terms. #![allow(non_snake_case)] +#![allow(deprecated)] // TODO(madsmtm): Remove this extern crate block2; #[macro_use] diff --git a/cocoa/examples/fullscreen.rs b/cocoa/examples/fullscreen.rs index 4d5ace62..fb80802b 100644 --- a/cocoa/examples/fullscreen.rs +++ b/cocoa/examples/fullscreen.rs @@ -1,7 +1,5 @@ extern crate cocoa; extern crate core_graphics; - -#[macro_use] extern crate objc2; use cocoa::appkit::{ @@ -17,8 +15,9 @@ use cocoa::foundation::{ use core_graphics::display::CGDisplay; -use objc2::declare::ClassDecl; +use objc2::declare::ClassBuilder; use objc2::runtime::{Object, Sel}; +use objc2::{class, msg_send, sel}; fn main() { unsafe { @@ -48,7 +47,7 @@ fn main() { // Create NSWindowDelegate let superclass = class!(NSObject); - let mut decl = ClassDecl::new("MyWindowDelegate", superclass).unwrap(); + let mut decl = ClassBuilder::new("MyWindowDelegate", superclass).unwrap(); extern "C" fn will_use_fillscreen_presentation_options( _: &Object, diff --git a/cocoa/examples/nsvisualeffectview_blur.rs b/cocoa/examples/nsvisualeffectview_blur.rs index 7a3245f1..b9538948 100644 --- a/cocoa/examples/nsvisualeffectview_blur.rs +++ b/cocoa/examples/nsvisualeffectview_blur.rs @@ -2,7 +2,7 @@ extern crate cocoa; extern crate objc2; use cocoa::base::{nil, selector, NO}; -use objc2::*; +use objc2::msg_send; use cocoa::appkit::{ NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSBackingStoreType, NSColor, diff --git a/cocoa/src/lib.rs b/cocoa/src/lib.rs index 7b73fbe4..eca26e77 100644 --- a/cocoa/src/lib.rs +++ b/cocoa/src/lib.rs @@ -10,6 +10,7 @@ #![crate_name = "cocoa"] #![crate_type = "rlib"] #![allow(non_snake_case)] +#![allow(deprecated)] // TODO(madsmtm): Remove this extern crate block2; #[macro_use] From 7383217fabe8bb8fcfe5fb9cca06cdc059e77cea Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 31 Jul 2023 14:13:39 +0200 Subject: [PATCH 11/14] Remove objc2 dependency from core-foundation-sys and core-graphics --- cocoa/src/quartzcore.rs | 153 +++++++++++-------- core-foundation-sys/Cargo.toml | 3 - 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/Cargo.toml | 1 - core-graphics/src/lib.rs | 1 - core-graphics/src/sys.rs | 14 -- 10 files changed, 93 insertions(+), 97 deletions(-) diff --git a/cocoa/src/quartzcore.rs b/cocoa/src/quartzcore.rs index 52ad2cd0..f14b65be 100644 --- a/cocoa/src/quartzcore.rs +++ b/cocoa/src/quartzcore.rs @@ -29,6 +29,38 @@ use appkit::CGLContextObj; use base::{id, nil, BOOL, YES}; use foundation::NSUInteger; +// Helper utilities for non-Encode types + +trait AsId { + fn as_id(&self) -> id; +} + +impl AsId for T { + fn as_id(&self) -> id { + self.as_CFTypeRef() as *mut _ + } +} + +fn array_ref(obj: id) -> CFArrayRef { + obj.cast() +} + +fn dictionary_ref(obj: id) -> CFDictionaryRef { + obj.cast() +} + +fn string_ref(obj: id) -> CFStringRef { + obj.cast() +} + +fn color_ref(obj: id) -> SysCGColorRef { + obj.cast() +} + +fn path_ref(obj: id) -> SysCGPathRef { + obj.cast() +} + // CABase.h pub fn current_media_time() -> CFTimeInterval { @@ -89,13 +121,13 @@ impl CALayer { #[inline] pub fn default_value_for_key(key: &CFString) -> id { - unsafe { msg_send![class!(CALayer), defaultValueForKey:(key.as_CFTypeRef())] } + unsafe { msg_send![class!(CALayer), defaultValueForKey: key.as_id()] } } #[inline] pub fn needs_display_for_key(key: &CFString) -> bool { unsafe { - let flag: BOOL = msg_send![class!(CALayer), needsDisplayForKey:(key.as_CFTypeRef())]; + let flag: BOOL = msg_send![class!(CALayer), needsDisplayForKey: key.as_id()]; flag == YES } } @@ -103,8 +135,7 @@ impl CALayer { #[inline] pub fn should_archive_value_for_key(key: &CFString) -> bool { unsafe { - let flag: BOOL = - msg_send![class!(CALayer), shouldArchiveValueForKey:(key.as_CFTypeRef())]; + let flag: BOOL = msg_send![class!(CALayer), shouldArchiveValueForKey: key.as_id()]; flag == YES } } @@ -256,7 +287,7 @@ impl CALayer { #[inline] pub fn sublayers(&self) -> CFArray { unsafe { - let sublayers: CFArrayRef = msg_send![self.id(), sublayers]; + let sublayers = array_ref(msg_send![self.id(), sublayers]); TCFType::wrap_under_create_rule(sublayers) } } @@ -448,7 +479,7 @@ impl CALayer { #[inline] pub fn contents_gravity(&self) -> ContentsGravity { unsafe { - let string: CFStringRef = msg_send![self.id(), contentsGravity]; + let string = string_ref(msg_send![self.id(), contentsGravity]); ContentsGravity::from_CFString(TCFType::wrap_under_create_rule(string)) } } @@ -457,7 +488,7 @@ impl CALayer { pub fn set_contents_gravity(&self, new_contents_gravity: ContentsGravity) { unsafe { let contents_gravity: CFString = new_contents_gravity.into_CFString(); - msg_send![self.id(), setContentsGravity:contents_gravity.as_CFTypeRef()] + msg_send![self.id(), setContentsGravity: contents_gravity.as_id()] } } @@ -484,7 +515,7 @@ impl CALayer { #[inline] pub fn contents_format(&self) -> ContentsFormat { unsafe { - let string: CFStringRef = msg_send![self.id(), contentsFormat]; + let string = string_ref(msg_send![self.id(), contentsFormat]); ContentsFormat::from_CFString(TCFType::wrap_under_create_rule(string)) } } @@ -493,14 +524,14 @@ impl CALayer { pub fn set_contents_format(&self, new_contents_format: ContentsFormat) { unsafe { let contents_format: CFString = new_contents_format.into_CFString(); - msg_send![self.id(), setContentsFormat:contents_format.as_CFTypeRef()] + msg_send![self.id(), setContentsFormat: contents_format.as_id()] } } #[inline] pub fn minification_filter(&self) -> Filter { unsafe { - let string: CFStringRef = msg_send![self.id(), minificationFilter]; + let string = string_ref(msg_send![self.id(), minificationFilter]); Filter::from_CFString(TCFType::wrap_under_create_rule(string)) } } @@ -509,14 +540,14 @@ impl CALayer { pub fn set_minification_filter(&self, new_filter: Filter) { unsafe { let filter: CFString = new_filter.into_CFString(); - msg_send![self.id(), setMinificationFilter:filter.as_CFTypeRef()] + msg_send![self.id(), setMinificationFilter: filter.as_id()] } } #[inline] pub fn magnification_filter(&self) -> Filter { unsafe { - let string: CFStringRef = msg_send![self.id(), magnificationFilter]; + let string = string_ref(msg_send![self.id(), magnificationFilter]); Filter::from_CFString(TCFType::wrap_under_create_rule(string)) } } @@ -525,7 +556,7 @@ impl CALayer { pub fn set_magnification_filter(&self, new_filter: Filter) { unsafe { let filter: CFString = new_filter.into_CFString(); - msg_send![self.id(), setMagnificationFilter:filter.as_CFTypeRef()] + msg_send![self.id(), setMagnificationFilter: filter.as_id()] } } @@ -608,12 +639,14 @@ impl CALayer { #[inline] pub fn draw_in_context(&self, context: &CGContext) { - unsafe { msg_send![self.id(), drawInContext:(*context).as_ptr()] } + let context: id = (*context).as_ptr().cast(); + unsafe { msg_send![self.id(), drawInContext: context] } } #[inline] pub fn render_in_context(&self, context: &CGContext) { - unsafe { msg_send![self.id(), renderInContext:(*context).as_ptr()] } + let context: id = (*context).as_ptr().cast(); + unsafe { msg_send![self.id(), renderInContext: context] } } #[inline] @@ -631,7 +664,7 @@ impl CALayer { #[inline] pub fn background_color(&self) -> Option { unsafe { - let color: SysCGColorRef = msg_send![self.id(), backgroundColor]; + let color = color_ref(msg_send![self.id(), backgroundColor]); if color.is_null() { None } else { @@ -644,8 +677,8 @@ impl CALayer { pub fn set_background_color(&self, color: Option) { unsafe { let color = match color { - None => ptr::null(), - Some(color) => color.as_CFTypeRef(), + None => ptr::null_mut(), + Some(color) => color.as_id(), }; msg_send![self.id(), setBackgroundColor: color] } @@ -684,7 +717,7 @@ impl CALayer { #[inline] pub fn border_color(&self) -> Option { unsafe { - let color: SysCGColorRef = msg_send![self.id(), borderColor]; + let color = color_ref(msg_send![self.id(), borderColor]); if color.is_null() { None } else { @@ -697,8 +730,8 @@ impl CALayer { pub fn set_border_color(&self, color: Option) { unsafe { let color = match color { - None => ptr::null(), - Some(color) => color.as_CFTypeRef(), + None => ptr::null_mut(), + Some(color) => color.as_id(), }; msg_send![self.id(), setBorderColor: color] } @@ -726,7 +759,7 @@ impl CALayer { #[inline] pub unsafe fn filters(&self) -> Option { - let filters: CFArrayRef = msg_send![self.id(), filters]; + let filters = array_ref(msg_send![self.id(), filters]); if filters.is_null() { None } else { @@ -736,16 +769,16 @@ impl CALayer { #[inline] pub unsafe fn set_filters(&self, filters: Option) { - let filters: CFTypeRef = match filters { - Some(ref filters) => filters.as_CFTypeRef(), - None => ptr::null(), + let filters = match filters { + Some(ref filters) => filters.as_id(), + None => ptr::null_mut(), }; msg_send![self.id(), setFilters: filters] } #[inline] pub unsafe fn background_filters(&self) -> Option { - let filters: CFArrayRef = msg_send![self.id(), backgroundFilters]; + let filters = array_ref(msg_send![self.id(), backgroundFilters]); if filters.is_null() { None } else { @@ -755,9 +788,9 @@ impl CALayer { #[inline] pub unsafe fn set_background_filters(&self, filters: Option) { - let filters: CFTypeRef = match filters { - Some(ref filters) => filters.as_CFTypeRef(), - None => ptr::null(), + let filters = match filters { + Some(ref filters) => filters.as_id(), + None => ptr::null_mut(), }; msg_send![self.id(), setBackgroundFilters: filters] } @@ -790,7 +823,7 @@ impl CALayer { #[inline] pub fn shadow_color(&self) -> Option { unsafe { - let color: SysCGColorRef = msg_send![self.id(), shadowColor]; + let color = color_ref(msg_send![self.id(), shadowColor]); if color.is_null() { None } else { @@ -803,8 +836,8 @@ impl CALayer { pub fn set_shadow_color(&self, color: Option) { unsafe { let color = match color { - None => ptr::null(), - Some(color) => color.as_CFTypeRef(), + None => ptr::null_mut(), + Some(color) => color.as_id(), }; msg_send![self.id(), setShadowColor: color] } @@ -843,7 +876,7 @@ impl CALayer { #[inline] pub fn shadow_path(&self) -> Option { unsafe { - let path: SysCGPathRef = msg_send![self.id(), shadowPath]; + let path = path_ref(msg_send![self.id(), shadowPath]); if path.is_null() { None } else { @@ -855,9 +888,9 @@ impl CALayer { #[inline] pub fn set_shadow_path(&self, path: Option) { unsafe { - let sys_path_ref = match path { - None => ptr::null(), - Some(path) => path.as_ptr(), + let sys_path_ref: id = match path { + None => ptr::null_mut(), + Some(path) => path.as_ptr().cast(), }; msg_send![self.id(), setShadowPath: sys_path_ref] } @@ -929,7 +962,7 @@ impl CALayer { pub fn default_action_for_key(event: &str) -> id { unsafe { let event: CFString = CFString::from(event); - msg_send![class!(CALayer), defaultActionForKey:event.as_CFTypeRef()] + msg_send![class!(CALayer), defaultActionForKey: event.as_id()] } } @@ -937,29 +970,29 @@ impl CALayer { pub fn action_for_key(&self, event: &str) -> id { unsafe { let event: CFString = CFString::from(event); - msg_send![self.id(), actionForKey:event.as_CFTypeRef()] + msg_send![self.id(), actionForKey: event.as_id()] } } #[inline] pub fn actions(&self) -> CFDictionary { - unsafe { CFDictionary::wrap_under_get_rule(msg_send![self.id(), actions]) } + unsafe { CFDictionary::wrap_under_get_rule(dictionary_ref(msg_send![self.id(), actions])) } } #[inline] pub unsafe fn set_actions(&self, actions: CFDictionary) { - msg_send![self.id(), setActions: actions.as_concrete_TypeRef()] + msg_send![self.id(), setActions: actions.as_id()] } // TODO(pcwalton): Wrap `CAAnimation`. #[inline] pub unsafe fn add_animation_for_key(&self, animation: id, for_key: Option<&str>) { let for_key: Option = for_key.map(CFString::from); - let for_key: CFTypeRef = match for_key { - Some(ref for_key) => for_key.as_CFTypeRef(), - None => ptr::null(), + let for_key = match for_key { + Some(ref for_key) => for_key.as_id(), + None => ptr::null_mut(), }; - msg_send![self.id(), addAnimation:animation forKey:for_key] + msg_send![self.id(), addAnimation: animation forKey: for_key] } #[inline] @@ -971,14 +1004,14 @@ impl CALayer { pub fn remove_animation_for_key(&self, key: &str) { unsafe { let key = CFString::from(key); - msg_send![self.id(), removeAnimationForKey:key.as_CFTypeRef()] + msg_send![self.id(), removeAnimationForKey: key.as_id()] } } #[inline] pub fn animation_keys(&self) -> Vec { unsafe { - let keys: CFArrayRef = msg_send![self.id(), animationKeys]; + let keys = array_ref(msg_send![self.id(), animationKeys]); let keys: CFArray = TCFType::wrap_under_create_rule(keys); keys.into_iter() .map(|string| CFString::wrap_under_get_rule(*string as CFStringRef).to_string()) @@ -990,7 +1023,7 @@ impl CALayer { pub fn animation_for_key(&self, key: &str) -> id { unsafe { let key = CFString::from(key); - msg_send![self.id(), animationForKey:key.as_CFTypeRef()] + msg_send![self.id(), animationForKey: key.as_id()] } } @@ -999,7 +1032,7 @@ impl CALayer { #[inline] pub fn name(&self) -> String { unsafe { - let name: CFStringRef = msg_send![self.id(), name]; + let name = string_ref(msg_send![self.id(), name]); CFString::wrap_under_get_rule(name).to_string() } } @@ -1008,7 +1041,7 @@ impl CALayer { pub fn set_name(&self, name: &str) { unsafe { let name = CFString::from(name); - msg_send![self.id(), setName:name.as_CFTypeRef()] + msg_send![self.id(), setName: name.as_id()] } } @@ -1025,7 +1058,7 @@ impl CALayer { #[inline] pub fn style(&self) -> Option { unsafe { - let dictionary: CFDictionaryRef = msg_send![self.id(), style]; + let dictionary = dictionary_ref(msg_send![self.id(), style]); if dictionary.is_null() { None } else { @@ -1038,8 +1071,8 @@ impl CALayer { pub fn set_style(&self, dictionary: Option) { unsafe { let dictionary = match dictionary { - None => ptr::null(), - Some(ref dictionary) => dictionary.as_CFTypeRef(), + None => ptr::null_mut(), + Some(ref dictionary) => dictionary.as_id(), }; msg_send![self.id(), setStyle: dictionary] } @@ -1051,7 +1084,7 @@ impl CALayer { pub fn reload_value_for_key_path(&self, key: &str) { unsafe { let key = CFString::from(key); - msg_send![self.id(), reloadValueForKeyPath:key.as_CFTypeRef()] + msg_send![self.id(), reloadValueForKeyPath: key.as_id()] } } @@ -1252,8 +1285,8 @@ impl CARenderer { let options: CFDictionary = CFDictionary::from_CFType_pairs(&pairs); - let renderer: id = msg_send![class!(CARenderer), rendererWithCGLContext:context - options:options.as_CFTypeRef()]; + let renderer: id = msg_send![class!(CARenderer), rendererWithCGLContext: context + options: options.as_id()]; debug_assert!(renderer != nil); CARenderer(renderer) } @@ -1277,8 +1310,8 @@ impl CARenderer { let options: CFDictionary = CFDictionary::from_CFType_pairs(&pairs); - let renderer: id = msg_send![class!(CARenderer), rendererWithMTLTexture:metal_texture - options:options.as_CFTypeRef()]; + let renderer: id = msg_send![class!(CARenderer), rendererWithMTLTexture: metal_texture + options: options.as_id()]; debug_assert!(renderer != nil); CARenderer(renderer) } @@ -1358,10 +1391,10 @@ impl CARenderer { // really just a module. pub mod transaction { use block2::{Block, ConcreteBlock, IntoConcreteBlock, RcBlock}; - use core_foundation::base::TCFType; use core_foundation::date::CFTimeInterval; use core_foundation::string::CFString; + use super::AsId; use base::{id, BOOL, YES}; #[inline] @@ -1450,7 +1483,7 @@ pub mod transaction { pub fn value_for_key(key: &str) -> id { unsafe { let key: CFString = CFString::from(key); - msg_send![class!(CATransaction), valueForKey: key.as_concrete_TypeRef()] + msg_send![class!(CATransaction), valueForKey: key.as_id()] } } @@ -1458,7 +1491,7 @@ pub mod transaction { pub fn set_value_for_key(value: id, key: &str) { unsafe { let key: CFString = CFString::from(key); - msg_send![class!(CATransaction), setValue: value forKey: key.as_concrete_TypeRef()] + msg_send![class!(CATransaction), setValue: value forKey: key.as_id()] } } } diff --git a/core-foundation-sys/Cargo.toml b/core-foundation-sys/Cargo.toml index 5740ec89..be52bcbe 100644 --- a/core-foundation-sys/Cargo.toml +++ b/core-foundation-sys/Cargo.toml @@ -7,9 +7,6 @@ version = "0.8.6" authors = ["The Servo Project Developers"] license = "MIT OR Apache-2.0" -[dependencies] -objc2 = "0.4.0" - [features] mac_os_10_7_support = [] # backwards compatibility mac_os_10_8_features = [] # enables new features diff --git a/core-foundation-sys/src/array.rs b/core-foundation-sys/src/array.rs index 6cc5947e..b9ce43c3 100644 --- a/core-foundation-sys/src/array.rs +++ b/core-foundation-sys/src/array.rs @@ -36,10 +36,6 @@ pub struct __CFArray(c_void); pub type CFArrayRef = *const __CFArray; pub type CFMutableArrayRef = *mut __CFArray; -unsafe impl ::objc2::encode::RefEncode for __CFArray { - const ENCODING_REF: ::objc2::encode::Encoding = ::objc2::encode::Encoding::Object; -} - extern "C" { /* * CFArray.h diff --git a/core-foundation-sys/src/attributed_string.rs b/core-foundation-sys/src/attributed_string.rs index bc9b5b68..93fbf63f 100644 --- a/core-foundation-sys/src/attributed_string.rs +++ b/core-foundation-sys/src/attributed_string.rs @@ -19,10 +19,6 @@ pub struct __CFAttributedString(c_void); pub type CFAttributedStringRef = *const __CFAttributedString; pub type CFMutableAttributedStringRef = *mut __CFAttributedString; -unsafe impl ::objc2::encode::RefEncode for __CFAttributedString { - const ENCODING_REF: ::objc2::encode::Encoding = ::objc2::encode::Encoding::Object; -} - extern "C" { /* * CFAttributedString.h diff --git a/core-foundation-sys/src/dictionary.rs b/core-foundation-sys/src/dictionary.rs index 67421dfa..f243c5ba 100644 --- a/core-foundation-sys/src/dictionary.rs +++ b/core-foundation-sys/src/dictionary.rs @@ -51,10 +51,6 @@ pub struct __CFDictionary(c_void); pub type CFDictionaryRef = *const __CFDictionary; pub type CFMutableDictionaryRef = *mut __CFDictionary; -unsafe impl ::objc2::encode::RefEncode for __CFDictionary { - const ENCODING_REF: ::objc2::encode::Encoding = ::objc2::encode::Encoding::Object; -} - extern "C" { /* * CFDictionary.h diff --git a/core-foundation-sys/src/lib.rs b/core-foundation-sys/src/lib.rs index dfd5896e..edd6dd0f 100644 --- a/core-foundation-sys/src/lib.rs +++ b/core-foundation-sys/src/lib.rs @@ -17,8 +17,6 @@ feature(linkage) )] // back-compat requires weak linkage -extern crate objc2; - // 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 67334db7..03e54ded 100644 --- a/core-foundation-sys/src/string.rs +++ b/core-foundation-sys/src/string.rs @@ -206,10 +206,6 @@ pub fn CFStringInitInlineBuffer(str: CFStringRef, buf: *mut CFStringInlineBuffer pub fn CFStringGetCharacterFromInlineBuffer(buf: *mut CFStringInlineBuffer, idx: CFIndex) -> UniChar; */ -unsafe impl ::objc2::encode::RefEncode for __CFString { - const ENCODING_REF: ::objc2::encode::Encoding = ::objc2::encode::Encoding::Object; -} - extern "C" { /* * CFString.h diff --git a/core-graphics/Cargo.toml b/core-graphics/Cargo.toml index 5def1b61..f8d5d3b2 100644 --- a/core-graphics/Cargo.toml +++ b/core-graphics/Cargo.toml @@ -18,7 +18,6 @@ core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } foreign-types = "0.5.0" libc = "0.2" -objc2 = "0.4.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 cf5737d2..3c1b6443 100644 --- a/core-graphics/src/lib.rs +++ b/core-graphics/src/lib.rs @@ -8,7 +8,6 @@ // except according to those terms. extern crate libc; -extern crate objc2; #[macro_use] extern crate core_foundation; diff --git a/core-graphics/src/sys.rs b/core-graphics/src/sys.rs index 1cbf2f26..9e0e8000 100644 --- a/core-graphics/src/sys.rs +++ b/core-graphics/src/sys.rs @@ -1,17 +1,11 @@ use std::os::raw::c_void; -use objc2::encode::{Encoding, RefEncode}; - pub enum CGImage {} pub type CGImageRef = *mut CGImage; #[repr(C)] pub struct __CGColor(c_void); -unsafe impl RefEncode for __CGColor { - const ENCODING_REF: Encoding = Encoding::Unknown; -} - pub type CGColorRef = *const __CGColor; pub enum CGColorSpace {} @@ -20,10 +14,6 @@ pub type CGColorSpaceRef = *mut CGColorSpace; pub enum CGPath {} pub type CGPathRef = *mut CGPath; -unsafe impl RefEncode for CGPath { - const ENCODING_REF: Encoding = Encoding::Unknown; -} - pub enum CGDataProvider {} pub type CGDataProviderRef = *mut CGDataProvider; @@ -33,10 +23,6 @@ pub type CGFontRef = *mut CGFont; pub enum CGContext {} pub type CGContextRef = *mut CGContext; -unsafe impl RefEncode for CGContext { - const ENCODING_REF: Encoding = Encoding::Unknown; -} - pub enum CGGradient {} pub type CGGradientRef = *mut CGGradient; From cc744a2441209be1399e8d82581c9fba4bf4b23b Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 31 Jul 2023 14:29:31 +0200 Subject: [PATCH 12/14] Make objc2 optional in core-graphics-types --- cocoa-foundation/Cargo.toml | 2 +- core-graphics-types/Cargo.toml | 2 +- core-graphics-types/src/geometry.rs | 5 +++++ core-graphics-types/src/lib.rs | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cocoa-foundation/Cargo.toml b/cocoa-foundation/Cargo.toml index a8d3b999..01bd3d42 100644 --- a/cocoa-foundation/Cargo.toml +++ b/cocoa-foundation/Cargo.toml @@ -16,5 +16,5 @@ block2 = "0.2.0" bitflags = "1.0" libc = "0.2" core-foundation = { path = "../core-foundation", version = "0.9" } -core-graphics-types = { path = "../core-graphics-types", version = "0.1" } +core-graphics-types = { path = "../core-graphics-types", version = "0.1", features = ["objc2"] } objc2 = "0.4.0" diff --git a/core-graphics-types/Cargo.toml b/core-graphics-types/Cargo.toml index dc91244c..18c8a6c4 100644 --- a/core-graphics-types/Cargo.toml +++ b/core-graphics-types/Cargo.toml @@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0" bitflags = "1.0" core-foundation = { path = "../core-foundation", version = "0.9" } libc = "0.2" -objc2 = "0.4.0" +objc2 = { version = "0.4.0", optional = true } [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 ec9e8283..16ee09d3 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; +#[cfg(feature = "objc2")] use objc2::encode::{Encode, Encoding}; pub const CG_ZERO_POINT: CGPoint = CGPoint { x: 0.0, y: 0.0 }; @@ -40,6 +41,7 @@ pub struct CGSize { pub height: CGFloat, } +#[cfg(feature = "objc2")] unsafe impl Encode for CGSize { const ENCODING: Encoding = Encoding::Struct("CGSize", &[CGFloat::ENCODING, CGFloat::ENCODING]); } @@ -66,6 +68,7 @@ pub struct CGPoint { pub y: CGFloat, } +#[cfg(feature = "objc2")] unsafe impl Encode for CGPoint { const ENCODING: Encoding = Encoding::Struct("CGPoint", &[CGFloat::ENCODING, CGFloat::ENCODING]); } @@ -89,6 +92,7 @@ pub struct CGRect { pub size: CGSize, } +#[cfg(feature = "objc2")] unsafe impl Encode for CGRect { const ENCODING: Encoding = Encoding::Struct("CGRect", &[CGPoint::ENCODING, CGSize::ENCODING]); } @@ -158,6 +162,7 @@ pub struct CGAffineTransform { pub ty: CGFloat, } +#[cfg(feature = "objc2")] unsafe impl Encode for CGAffineTransform { const ENCODING: Encoding = Encoding::Struct( "CGAffineTransform", diff --git a/core-graphics-types/src/lib.rs b/core-graphics-types/src/lib.rs index 944cfba2..e58848a6 100644 --- a/core-graphics-types/src/lib.rs +++ b/core-graphics-types/src/lib.rs @@ -8,6 +8,7 @@ // except according to those terms. extern crate core_foundation; +#[cfg(feature = "objc2")] extern crate objc2; pub mod base; From a4c112c1168ee30cbbbfb2887eb1cb0c7328b69a Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 31 Jul 2023 14:38:13 +0200 Subject: [PATCH 13/14] Fix a few unsound message sends --- cocoa/examples/nsvisualeffectview_blur.rs | 2 +- cocoa/src/appkit.rs | 33 ++++++++++++++--------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/cocoa/examples/nsvisualeffectview_blur.rs b/cocoa/examples/nsvisualeffectview_blur.rs index b9538948..8918a954 100644 --- a/cocoa/examples/nsvisualeffectview_blur.rs +++ b/cocoa/examples/nsvisualeffectview_blur.rs @@ -73,7 +73,7 @@ fn main() { blurred_view.setState_(NSVisualEffectState::FollowsWindowActiveState); blurred_view.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable); - let _: () = msg_send![ns_view, addSubview: blurred_view positioned: NSWindowOrderingMode::NSWindowBelow relativeTo: 0]; + let _: () = msg_send![ns_view, addSubview: blurred_view positioned: NSWindowOrderingMode::NSWindowBelow relativeTo: nil]; app.run(); } diff --git a/cocoa/src/appkit.rs b/cocoa/src/appkit.rs index eb42f31d..60257728 100644 --- a/cocoa/src/appkit.rs +++ b/cocoa/src/appkit.rs @@ -14,6 +14,7 @@ use block2::Block; use foundation::{ NSInteger, NSPoint, NSRange, NSRect, NSRectEdge, NSSize, NSTimeInterval, NSUInteger, }; +use objc2::encode::{Encode, Encoding}; use libc; pub use core_graphics::base::CGFloat; @@ -426,18 +427,18 @@ impl_Encode!(NSBezelStyle, u64); // https://developer.apple.com/documentation/appkit/nsvisualeffectview/blendingmode #[allow(dead_code)] -#[repr(u64)] +#[repr(isize)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSVisualEffectBlendingMode { BehindWindow = 0, WithinWindow = 1, } -impl_Encode!(NSVisualEffectBlendingMode, u64); +impl_Encode!(NSVisualEffectBlendingMode, isize); // https://developer.apple.com/documentation/appkit/nsvisualeffectview/state #[allow(dead_code)] -#[repr(u64)] +#[repr(isize)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSVisualEffectState { FollowsWindowActiveState = 0, @@ -445,10 +446,10 @@ pub enum NSVisualEffectState { Inactive = 2, } -impl_Encode!(NSVisualEffectState, u64); +impl_Encode!(NSVisualEffectState, isize); /// -#[repr(u64)] +#[repr(isize)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum NSVisualEffectMaterial { /// A default material for the view's effectiveAppearance. @@ -484,7 +485,7 @@ pub enum NSVisualEffectMaterial { UnderPageBackground = 22, } -impl_Encode!(NSVisualEffectMaterial, u64); +impl_Encode!(NSVisualEffectMaterial, isize); // macOS 10.10+ - https://developer.apple.com/documentation/appkit/nsvisualeffectview #[allow(non_snake_case)] @@ -587,7 +588,7 @@ pub trait NSApplication: Sized { unsafe fn mainMenu(self) -> id; unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> BOOL; - unsafe fn setPresentationOptions_(self, options: NSApplicationPresentationOptions) -> BOOL; + unsafe fn setPresentationOptions_(self, options: NSApplicationPresentationOptions); unsafe fn presentationOptions_(self) -> NSApplicationPresentationOptions; unsafe fn setMainMenu_(self, menu: id); unsafe fn setServicesMenu_(self, menu: id); @@ -618,7 +619,7 @@ impl NSApplication for id { msg_send![self, setActivationPolicy: policy as NSInteger] } - unsafe fn setPresentationOptions_(self, options: NSApplicationPresentationOptions) -> BOOL { + unsafe fn setPresentationOptions_(self, options: NSApplicationPresentationOptions) { msg_send![self, setPresentationOptions:options.bits] } @@ -4580,6 +4581,13 @@ pub trait NSColorSpace: Sized { unsafe fn localizedName(self) -> id; } +#[repr(transparent)] +struct CGColorSpaceRef(*const c_void); + +unsafe impl Encode for CGColorSpaceRef { + const ENCODING: Encoding = Encoding::Pointer(&Encoding::Struct("CGColorSpace", &[])); +} + impl NSColorSpace for id { unsafe fn deviceRGBColorSpace(_: Self) -> id { msg_send![class!(NSColorSpace), deviceRGBColorSpace] @@ -4624,12 +4632,13 @@ impl NSColorSpace for id { unsafe fn initWithCGColorSpace_( self, - cg_color_space: *const c_void, /* (CGColorSpaceRef) */ + cg_color_space: *const c_void, ) -> id { - msg_send![self, initWithCGColorSpace: cg_color_space] + msg_send![self, initWithCGColorSpace: CGColorSpaceRef(cg_color_space)] } - unsafe fn CGColorSpace(self) -> *const c_void /* (CGColorSpaceRef) */ { - msg_send![self, CGColorSpace] + unsafe fn CGColorSpace(self) -> *const c_void { + let res: CGColorSpaceRef = msg_send![self, CGColorSpace]; + res.0 } unsafe fn localizedName(self) -> id { msg_send![self, localizedName] From 95c8a751c22b824858a94d7988477aaad200dbbe Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 31 Jul 2023 14:40:13 +0200 Subject: [PATCH 14/14] Bump MSRV to match objc2's MSRV --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index db1da771..1d52c751 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -34,7 +34,7 @@ jobs: - name: Install toolchain uses: actions-rs/toolchain@v1 with: - toolchain: 1.56.1 + toolchain: '1.60' override: true - name: Build run: cargo build --verbose