Skip to content

Commit

Permalink
Merge pull request #427 from madsmtm/refactor-modules
Browse files Browse the repository at this point in the history
Refactor modules
  • Loading branch information
madsmtm authored Feb 26, 2023
2 parents 797b146 + d5b5da9 commit dac2bc1
Show file tree
Hide file tree
Showing 60 changed files with 415 additions and 362 deletions.
10 changes: 4 additions & 6 deletions crates/header-translator/translation-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ imports = []
extra-features = [
"objective-c",
"block",
"Foundation_NSProxy",
# Temporary, since some structs and statics use these
"Foundation_NSError",
"Foundation_NSAppleEventDescriptor",
Expand Down Expand Up @@ -558,13 +557,12 @@ countForFetchRequest_error = { skipped = true }
[class.NSBundle.methods.localizedAttributedStringForKey_value_table]
skipped = true

# Root class
# Root classes, defined in `objc2` for now
[class.NSProxy]
definition-skipped = true

# Ignore categories on NSObject for now
[class.NSObject]
skipped = true
[class.NSObject]
skipped = true # Also ignore categories on NSObject for now

[protocol.NSObject]
renamed = "NSObjectProtocol"

Expand Down
3 changes: 3 additions & 0 deletions crates/icrate/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- `MetricKit`
- `PhotoKit`

### Removed
* **BREAKING**: Removed various redundant `NSProxy` methods.


## icrate 0.0.2 - 2023-02-07

Expand Down
1 change: 0 additions & 1 deletion crates/icrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2193,7 +2193,6 @@ FileProvider_all = [
Foundation = [
"objective-c",
"block",
"Foundation_NSProxy",
"Foundation_NSError",
"Foundation_NSAppleEventDescriptor",
"Foundation_NSHashTable",
Expand Down
4 changes: 2 additions & 2 deletions crates/icrate/examples/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use icrate::{
declare::{Ivar, IvarDrop},
declare_class, extern_methods, msg_send,
rc::{Allocated, Id},
runtime::{Object, Sel},
sel, ClassType, ProtocolObject,
runtime::{Object, ProtocolObject, Sel},
sel, ClassType,
},
AppKit::{
NSApplication, NSApplicationActivationPolicyRegular, NSBackingStoreBuffered,
Expand Down
62 changes: 0 additions & 62 deletions crates/icrate/src/Foundation/fixes/NSProxy.rs

This file was deleted.

4 changes: 0 additions & 4 deletions crates/icrate/src/Foundation/fixes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ mod NSUUID;
mod __NSDecimal;
#[path = "NSNotFound.rs"]
mod __NSNotFound;
#[path = "NSProxy.rs"]
mod __NSProxy;
mod copy;
mod debug;
mod generic_return;
Expand All @@ -13,8 +11,6 @@ mod ns_consumed;

pub use self::__NSDecimal::NSDecimal;
pub use self::__NSNotFound::NSNotFound;
#[cfg(feature = "Foundation_NSProxy")]
pub use self::__NSProxy::NSProxy;
#[cfg(feature = "Foundation_NSMapTable")]
pub use self::ns_consumed::NSFreeMapTable;
#[cfg(feature = "Foundation_NSUUID")]
Expand Down
3 changes: 3 additions & 0 deletions crates/icrate/src/Foundation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ pub use self::additions::*;
pub use self::fixes::*;
pub use self::generated::*;

#[doc(inline)]
#[cfg(feature = "Foundation_NSProxy")]
pub use objc2::runtime::__NSProxy as NSProxy;
pub use objc2::runtime::{NSObject, NSObjectProtocol, NSZone};
// Available under Foundation, so makes sense here as well:
// https://developer.apple.com/documentation/foundation/numbers_data_and_basic_values?language=objc
Expand Down
4 changes: 2 additions & 2 deletions crates/icrate/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ pub(crate) use objc2::rc::{Allocated, Id, Owned, Ownership, Shared};
#[cfg(feature = "objective-c")]
pub(crate) use objc2::runtime::{Bool, Class, Object, Sel};
#[cfg(feature = "objective-c")]
pub(crate) use objc2::runtime::{NSObject, NSObjectProtocol};
pub(crate) use objc2::runtime::{NSObject, NSObjectProtocol, ProtocolObject};
#[cfg(feature = "objective-c")]
pub(crate) use objc2::{
__inner_extern_class, extern_class, extern_methods, extern_protocol, ClassType, Message,
ProtocolObject, ProtocolType,
ProtocolType,
};

#[cfg(feature = "block")]
Expand Down
2 changes: 1 addition & 1 deletion crates/icrate/src/generated
8 changes: 8 additions & 0 deletions crates/icrate/tests/proxy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![cfg(feature = "Foundation_NSProxy")]
use icrate::Foundation::NSProxy;
use objc2::ClassType;

#[test]
fn dummy() {
let _cls = NSProxy::class();
}
4 changes: 3 additions & 1 deletion crates/objc-sys/src/image_info.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/// Note: While `objc2` relies on this, you can freely break this, since it is
/// only used behind experimental features (`unstable-static-*`).
#[repr(C)]
#[doc(hidden)] // Private for now
#[doc(hidden)]
pub struct __ImageInfo {
// These are not actually `unsigned int`, even though the docs say so
/// The version of the image info struct.
Expand Down
2 changes: 2 additions & 0 deletions crates/objc2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
called as `Id::autorelease(obj, pool)` instead of `obj.autorelease(pool)`.

Additionally, rename the mutable version to `Id::autorelease_mut`.
* **BREAKING**: Moved `VerificationError`, `ProtocolObject` and
`ImplementedBy` into the `runtime` module.

### Fixed
* Fixed using autorelease pools on 32bit macOS and older macOS versions.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ use crate::runtime::{Class, Object, Protocol, Sel};
use crate::{Message, MessageArguments, MessageReceiver};
use crate::{__sel_data, __sel_inner};

pub use crate::cache::CachedClass;
pub use crate::cache::CachedSel;

pub use core::borrow::{Borrow, BorrowMut};
pub use core::cell::UnsafeCell;
pub use core::convert::{AsMut, AsRef};
Expand All @@ -31,8 +28,10 @@ pub use core::{compile_error, concat, panic, stringify};
// TODO: Use `core::cell::LazyCell`
pub use std::sync::Once;

mod cache;
mod declare_class;

pub use self::cache::{CachedClass, CachedSel};
pub use self::declare_class::{MaybeOptionId, MessageRecieveId};

// Common selectors.
Expand Down
17 changes: 1 addition & 16 deletions crates/objc2/src/class_type.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::msg_send_id;
use crate::rc::{Allocated, Id, Ownership};
use crate::rc::Allocated;
use crate::runtime::Class;
use crate::Message;

Expand Down Expand Up @@ -107,18 +107,3 @@ pub unsafe trait ClassType: Message {
unsafe { msg_send_id![Self::class(), alloc] }
}
}

impl<T: ClassType + 'static, O: Ownership> Id<T, O>
where
T::Super: 'static,
{
/// Convert the object into its superclass.
#[inline]
pub fn into_super(this: Self) -> Id<T::Super, O> {
// SAFETY:
// - The casted-to type is a superclass of the type.
// - Both types are `'static` (this could maybe be relaxed a bit, but
// let's just be on the safe side)!
unsafe { Self::cast::<T::Super>(this) }
}
}
File renamed without changes.
3 changes: 3 additions & 0 deletions crates/objc2/src/encode/__unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ mod return_private {
///
/// We currently don't need a similar `EncodeArgument` trait, but we might in
/// the future.
//
// Note: While this is not public, it is still a breaking change to change,
// since `block2` relies on it.
pub trait EncodeReturn: return_private::Sealed {
/// The Objective-C type-encoding for this type.
const ENCODING_RETURN: Encoding;
Expand Down
File renamed without changes.
6 changes: 2 additions & 4 deletions crates/objc2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ pub use self::class_type::ClassType;
#[doc(no_inline)]
pub use self::encode::{Encode, Encoding, RefEncode};
pub use self::message::{Message, MessageArguments, MessageReceiver};
pub use self::protocol::{ImplementedBy, ProtocolObject, ProtocolType};
pub use self::verify::VerificationError;
pub use self::protocol_type::ProtocolType;

#[cfg(feature = "objc2-proc-macros")]
#[doc(hidden)]
Expand All @@ -207,14 +206,13 @@ macro_rules! __hash_idents {

#[doc(hidden)]
pub mod __macro_helpers;
mod cache;
mod class_type;
pub mod declare;
pub mod encode;
pub mod exception;
mod macros;
mod message;
mod protocol;
mod protocol_type;
pub mod rc;
pub mod runtime;
#[cfg(test)]
Expand Down
3 changes: 3 additions & 0 deletions crates/objc2/src/macros/__method_msg_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ macro_rules! __method_msg_send_id {
};

// Parse retain semantics
//
// Note: While this is not public, it is still a breaking change to change
// this, since `icrate` relies on it.
(
($receiver:expr)
(@__retain_semantics $retain_semantics:ident $($sel_rest:tt)*)
Expand Down
2 changes: 2 additions & 0 deletions crates/objc2/src/macros/extern_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ macro_rules! __impl_as_ref_borrow {
// TODO: Expose a generic variant of the macro.
}

/// Note: While this is not public, it is still a breaking change to change
/// this, since `icrate` relies on it.
#[doc(hidden)]
#[macro_export]
macro_rules! __inner_extern_class {
Expand Down
8 changes: 4 additions & 4 deletions crates/objc2/src/macros/extern_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
///
/// [protocols]: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProtocols.html
/// [working-with]: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithProtocols/WorkingwithProtocols.html
/// [`ProtocolObject`]: crate::ProtocolObject
/// [`ProtocolObject`]: crate::runtime::ProtocolObject
///
///
/// # Specification
Expand Down Expand Up @@ -46,7 +46,7 @@
/// [`extern_methods!`], if you are familiar with those, it should be fairly
/// straightforward to use.
///
/// [`ProtocolObject<dyn T>`]: crate::ProtocolObject
/// [`ProtocolObject<dyn T>`]: crate::runtime::ProtocolObject
/// [`ProtocolType`]: crate::ProtocolType
/// [`declare_class!`]: crate::declare_class
/// [`extern_class!`]: crate::extern_class
Expand Down Expand Up @@ -165,7 +165,7 @@ macro_rules! extern_protocol {
}

$(#[$impl_m])*
unsafe impl<T> $name for $crate::ProtocolObject<T>
unsafe impl<T> $name for $crate::runtime::ProtocolObject<T>
where
T: ?$crate::__macro_helpers::Sized + $crate::ProtocolType + $name
{}
Expand All @@ -181,7 +181,7 @@ macro_rules! extern_protocol {
// SAFETY: Anything that implements the protocol `$name` is valid to
// convert to `ProtocolObject<dyn $name>`.
$(#[$impl_m])*
unsafe impl<T> $crate::ImplementedBy<T> for dyn $for
unsafe impl<T> $crate::runtime::ImplementedBy<T> for dyn $for
where
T: ?$crate::__macro_helpers::Sized + $crate::Message + $name
{
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion crates/objc2/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn panic_null(sel: Sel) -> ! {

#[cfg(debug_assertions)]
#[track_caller]
fn panic_verify(cls: &Class, sel: Sel, err: crate::VerificationError) -> ! {
fn panic_verify(cls: &Class, sel: Sel, err: crate::runtime::VerificationError) -> ! {
panic!(
"invalid message send to {}[{cls:?} {sel:?}]: {err}",
if cls.is_metaclass() { "+" } else { "-" },
Expand Down
Loading

0 comments on commit dac2bc1

Please sign in to comment.