Skip to content

Commit 91eda4c

Browse files
committed
Properly mark NSEnumerator as unsafe to return
1 parent 4baf635 commit 91eda4c

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

crates/header-translator/src/rust_type.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,10 @@ impl PointeeTy {
10681068
} else if id.name == "NSObject" {
10691069
// `NSObject` has similar safety to `AnyObject`.
10701070
safety = TypeSafety::unknown_in_argument("should be of the correct type");
1071+
} else if id.name == "NSEnumerator" {
1072+
safety = TypeSafety::unsafe_in_return(
1073+
"enumerator's underlying collection should not be mutated while in use",
1074+
);
10711075
}
10721076

10731077
if id.name.contains("Mutable") {

framework-crates/objc2-foundation/translation-config.toml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -330,19 +330,8 @@ unsafe-default-safety.functions = true
330330
# Foundation's methods are bounds-checked and throw exceptions.
331331
unsafe-default-safety.not-bounds-affecting = false
332332

333-
# Collections may not be mutated while enumerating.
334-
class.NSArray.methods.objectEnumerator.unsafe = true
335-
class.NSArray.methods.reverseObjectEnumerator.unsafe = true
336-
class.NSDictionary.methods.objectEnumerator.unsafe = true
337-
class.NSDictionary.methods.keyEnumerator.unsafe = true
338-
class.NSSet.methods.objectEnumerator.unsafe = true
339-
class.NSCountedSet.methods.objectEnumerator.unsafe = true
340-
class.NSOrderedSet.methods.objectEnumerator.unsafe = true
341-
class.NSOrderedSet.methods.reverseObjectEnumerator.unsafe = true
342-
class.NSMapTable.methods.objectEnumerator.unsafe = true
343-
class.NSMapTable.methods.keyEnumerator.unsafe = true
344-
class.NSHashTable.methods.objectEnumerator.unsafe = true
345-
# Enumerators themselves are safe to use, we move unsoundness to their creation above.
333+
# Enumerators themselves are safe to use, we move unsoundness to their creation
334+
# in `header-translator`.
346335
class.NSEnumerator.methods.nextObject.unsafe = false
347336
class.NSEnumerator.methods.allObjects.unsafe = false
348337

framework-crates/objc2-metal-performance-shaders/translation-config.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ const.MPSNDArrayConstantMultiDestIndex1.skipped = false
3232
const.MPSNDArrayConstantMultiDestSrcAddressingIndex.skipped = false
3333
const.MPSNDArrayConstantMultiDestDstAddressingIndex.skipped = false
3434
const.MPSUserAvailableFunctionConstantStartIndex.skipped = false
35+
36+
##
37+
## Safety
38+
##
39+
40+
# Unarchival may be unsafe if not requiring secure encoding, so let's
41+
# be conservative in what we mark safe for now.
42+
class.MPSKeyedUnarchiver.unsafe = true

0 commit comments

Comments
 (0)