From a5af864887bafedfaab1f844bb30d2a25392a473 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 11 Sep 2023 00:42:27 +0200 Subject: [PATCH] Fix renamed protocols --- crates/header-translator/src/stmt.rs | 22 +++++++++++++++---- crates/icrate/CHANGELOG.md | 2 ++ crates/icrate/src/fixes/Foundation/copying.rs | 8 ++----- crates/icrate/src/generated | 2 +- crates/icrate/tests/renamed_protocols.rs | 9 ++++++++ 5 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 crates/icrate/tests/renamed_protocols.rs diff --git a/crates/header-translator/src/stmt.rs b/crates/header-translator/src/stmt.rs index ff06650d3..a1ac445e7 100644 --- a/crates/header-translator/src/stmt.rs +++ b/crates/header-translator/src/stmt.rs @@ -369,6 +369,7 @@ pub enum Stmt { /// extern_protocol! ProtocolDecl { id: ItemIdentifier, + actual_name: Option, availability: Availability, protocols: BTreeSet, methods: Vec, @@ -797,9 +798,14 @@ impl Stmt { .collect() } EntityKind::ObjCProtocolDecl => { - let id = ItemIdentifier::new(entity, context) - .map_name(|name| context.replace_protocol_name(name)); - let data = context.protocol_data.get(&id.name); + let actual_id = ItemIdentifier::new(entity, context); + let data = context.protocol_data.get(&actual_id.name); + let actual_name = data + .map(|data| data.renamed.is_some()) + .unwrap_or_default() + .then(|| actual_id.name.clone()); + + let id = actual_id.map_name(|name| context.replace_protocol_name(name)); if data.map(|data| data.skipped).unwrap_or_default() { return vec![]; @@ -830,6 +836,7 @@ impl Stmt { vec![Self::ProtocolDecl { id, + actual_name, availability, protocols, methods, @@ -1616,6 +1623,7 @@ impl fmt::Display for Stmt { } Self::ProtocolDecl { id, + actual_name, availability, protocols, methods, @@ -1683,7 +1691,13 @@ impl fmt::Display for Stmt { } writeln!(f, " }}")?; writeln!(f)?; - writeln!(f, " unsafe impl ProtocolType for dyn {} {{}}", id.name)?; + writeln!(f, " unsafe impl ProtocolType for dyn {} {{", id.name)?; + if let Some(actual_name) = actual_name { + writeln!(f)?; + writeln!(f, " const NAME: &'static str = {actual_name:?};")?; + write!(f, " ")?; + } + writeln!(f, "}}")?; writeln!(f, ");")?; } Self::StructDecl { diff --git a/crates/icrate/CHANGELOG.md b/crates/icrate/CHANGELOG.md index 01a0f4da0..162306d76 100644 --- a/crates/icrate/CHANGELOG.md +++ b/crates/icrate/CHANGELOG.md @@ -65,6 +65,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). to use in such hashing collections. * **BREAKING**: Added `HasStableHash` requirement on `NSDictionary` and `NSSet` creation methods, fixing a long-standing soundess issue. +* Fixed the protocol names of `NSAccessibilityElementProtocol`, + `NSTextAttachmentCellProtocol` and `NSFileProviderItemProtocol`. ## icrate 0.0.4 - 2023-07-31 diff --git a/crates/icrate/src/fixes/Foundation/copying.rs b/crates/icrate/src/fixes/Foundation/copying.rs index 5117ae079..b0d7c8ef4 100644 --- a/crates/icrate/src/fixes/Foundation/copying.rs +++ b/crates/icrate/src/fixes/Foundation/copying.rs @@ -41,9 +41,7 @@ extern_protocol!( Self: CounterpartOrSelf; } - unsafe impl ProtocolType for dyn NSCopying { - const NAME: &'static str = "NSCopying"; - } + unsafe impl ProtocolType for dyn NSCopying {} ); // FIXME: Remove this hack which makes NSMutableDictionary tests work @@ -86,7 +84,5 @@ extern_protocol!( Self: CounterpartOrSelf; } - unsafe impl ProtocolType for dyn NSMutableCopying { - const NAME: &'static str = "NSMutableCopying"; - } + unsafe impl ProtocolType for dyn NSMutableCopying {} ); diff --git a/crates/icrate/src/generated b/crates/icrate/src/generated index 316a9c6f9..845c371d2 160000 --- a/crates/icrate/src/generated +++ b/crates/icrate/src/generated @@ -1 +1 @@ -Subproject commit 316a9c6f9640f34f859c0d9bf0da8973f03a3a00 +Subproject commit 845c371d2154a052e9adb70f952266ce81e2a13f diff --git a/crates/icrate/tests/renamed_protocols.rs b/crates/icrate/tests/renamed_protocols.rs new file mode 100644 index 000000000..57277240c --- /dev/null +++ b/crates/icrate/tests/renamed_protocols.rs @@ -0,0 +1,9 @@ +#![cfg(feature = "AppKit")] +use icrate::AppKit::NSAccessibilityElementProtocol; +use objc2::ProtocolType; + +#[test] +fn accessibility_element_protocol() { + let actual: &str = ::NAME; + assert_eq!(actual, "NSAccessibilityElement"); +}