Skip to content

Commit

Permalink
Use objc2
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Jul 20, 2022
1 parent 94478ae commit 088bde8
Show file tree
Hide file tree
Showing 19 changed files with 47 additions and 48 deletions.
7 changes: 3 additions & 4 deletions cocoa-foundation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ license = "MIT / 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" }
foreign-types = "0.3"
# 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" }
4 changes: 2 additions & 2 deletions cocoa-foundation/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
7 changes: 3 additions & 4 deletions cocoa-foundation/src/foundation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::os::raw::c_void;
use base::{id, BOOL, NO, SEL, nil};
use block::Block;
use libc;
use objc_encode::{Encode, Encoding};
use objc_encode::{Encode, Encoding, RefEncode};


#[cfg(target_pointer_width = "32")]
Expand Down Expand Up @@ -692,9 +692,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;
Expand Down
2 changes: 1 addition & 1 deletion cocoa-foundation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extern crate foreign_types;
extern crate libc;
pub extern crate objc_encode;
#[macro_use]
extern crate objc;
extern crate objc2;

pub use objc_encode as __objc_encode;

Expand Down
8 changes: 5 additions & 3 deletions cocoa-foundation/tests/foundation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[macro_use]
extern crate objc;
extern crate objc2;
extern crate block;
extern crate cocoa_foundation;

Expand Down Expand Up @@ -160,16 +160,18 @@ mod foundation {
}

// First test cocoa sorting...
let mut comparator = ConcreteBlock::new(|s0: id, s1: id| {
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)
for (k_id, (k, v)) in dict.keysSortedByValueUsingComparator_(comparator_ptr)
.iter()
.zip(associated_iter) {
assert!(k_id.isEqualToString(k));
Expand Down
7 changes: 3 additions & 4 deletions cocoa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ license = "MIT / 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.22" }
foreign-types = "0.3"
# 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" }
6 changes: 3 additions & 3 deletions cocoa/examples/fullscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern crate cocoa;
extern crate core_graphics;

#[macro_use]
extern crate objc;
extern crate objc2;

use cocoa::base::{selector, nil, NO, id};
use cocoa::foundation::{NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo,
Expand All @@ -14,8 +14,8 @@ use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular,

use core_graphics::display::CGDisplay;

use objc::runtime::{Object, Sel};
use objc::declare::ClassDecl;
use objc2::runtime::{Object, Sel};
use objc2::declare::ClassDecl;

fn main() {
unsafe {
Expand Down
4 changes: 2 additions & 2 deletions cocoa/src/appkit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3214,7 +3214,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 {
Expand All @@ -3234,7 +3234,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]
}
}
Expand Down
2 changes: 1 addition & 1 deletion cocoa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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;
Expand Down
6 changes: 3 additions & 3 deletions cocoa/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions cocoa/src/quartzcore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1840,9 +1840,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(&<CVTimeStamp as ::objc_encode::Encode>::ENCODING);
unsafe impl ::objc_encode::RefEncode for CVTimeStamp {
const ENCODING_REF: ::objc_encode::Encoding<'static> =
::objc_encode::Encoding::Pointer(&<Self as ::objc_encode::Encode>::ENCODING);
}

pub type CVTimeStampFlags = u64;
Expand Down
2 changes: 1 addition & 1 deletion core-foundation-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = ["The Servo Project Developers"]
license = "MIT / 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
Expand Down
4 changes: 2 additions & 2 deletions core-foundation-sys/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,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 {
Expand Down
4 changes: 2 additions & 2 deletions core-foundation-sys/src/attributed_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub struct __CFAttributedString(c_void);
pub type CFAttributedStringRef = *const __CFAttributedString;
pub type CFMutableAttributedStringRef = *const __CFAttributedString;

unsafe impl ::objc_encode::Encode for &'_ __CFAttributedString {
const ENCODING: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object;
unsafe impl ::objc_encode::RefEncode for __CFAttributedString {
const ENCODING_REF: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object;
}

extern {
Expand Down
4 changes: 2 additions & 2 deletions core-foundation-sys/src/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,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 {
Expand Down
4 changes: 2 additions & 2 deletions core-foundation-sys/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ pub struct __CFString(c_void);

pub type CFStringRef = *const __CFString;

unsafe impl ::objc_encode::Encode for &'_ __CFString {
const ENCODING: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object;
unsafe impl ::objc_encode::RefEncode for __CFString {
const ENCODING_REF: ::objc_encode::Encoding<'static> = ::objc_encode::Encoding::Object;
}

extern {
Expand Down
2 changes: 1 addition & 1 deletion core-graphics-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bitflags = "1.0"
core-foundation = { path = "../core-foundation", version = "0.9" }
foreign-types = "0.3.0"
libc = "0.2"
objc-encode = "1.1.0"
objc-encode = { version = "=2.0.0-pre.1", package = "objc2-encode" }

[package.metadata.docs.rs]
default-target = "x86_64-apple-darwin"
2 changes: 1 addition & 1 deletion core-graphics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.3.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"
14 changes: 7 additions & 7 deletions core-graphics/src/sys.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::os::raw::c_void;

use objc_encode::{Encode, Encoding};
use objc_encode::{Encoding, RefEncode};

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;
unsafe impl RefEncode for __CGColor {
const ENCODING_REF: Encoding<'static> = Encoding::Unknown;
}

pub type CGColorRef = *const __CGColor;
Expand All @@ -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 {}
Expand All @@ -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 {}
Expand Down

0 comments on commit 088bde8

Please sign in to comment.