Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix renamed protocols
Browse files Browse the repository at this point in the history
madsmtm committed Sep 10, 2023
1 parent 864365e commit a5af864
Showing 5 changed files with 32 additions and 11 deletions.
22 changes: 18 additions & 4 deletions crates/header-translator/src/stmt.rs
Original file line number Diff line number Diff line change
@@ -369,6 +369,7 @@ pub enum Stmt {
/// extern_protocol!
ProtocolDecl {
id: ItemIdentifier,
actual_name: Option<String>,
availability: Availability,
protocols: BTreeSet<ItemIdentifier>,
methods: Vec<Method>,
@@ -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 {
2 changes: 2 additions & 0 deletions crates/icrate/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
8 changes: 2 additions & 6 deletions crates/icrate/src/fixes/Foundation/copying.rs
Original file line number Diff line number Diff line change
@@ -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 {}
);
2 changes: 1 addition & 1 deletion crates/icrate/src/generated
9 changes: 9 additions & 0 deletions crates/icrate/tests/renamed_protocols.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![cfg(feature = "AppKit")]
use icrate::AppKit::NSAccessibilityElementProtocol;
use objc2::ProtocolType;

#[test]
fn accessibility_element_protocol() {
let actual: &str = <dyn NSAccessibilityElementProtocol>::NAME;
assert_eq!(actual, "NSAccessibilityElement");
}

0 comments on commit a5af864

Please sign in to comment.