Skip to content

Commit c125528

Browse files
committed
Use a UnsafeMutableRawPointer in SwiftNativeNSArray.getObjects()
In order to conform to the memory model.
1 parent 37c084b commit c125528

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

stdlib/public/core/SwiftNativeNSArray.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ extension _SwiftNativeNSArrayWithContiguousStorage : _NSArrayCore {
8282

8383
if objects.isEmpty { return }
8484

85-
// These objects are "returned" at +0, so treat them as values to
86-
// avoid retains.
87-
UnsafeMutablePointer<Int>(aBuffer).initialize(from:
88-
UnsafeMutablePointer(objects.baseAddress! + range.location),
89-
count: range.length)
85+
// These objects are "returned" at +0, so treat them as pointer values to
86+
// avoid retains. Copy bytes via a raw pointer to circumvent reference
87+
// counting while correctly aliasing with all other pointer types.
88+
UnsafeMutableRawPointer(aBuffer).copyBytes(
89+
from: objects.baseAddress! + range.location,
90+
count: range.length * strideof(AnyObject.self))
9091
}
9192
}
9293

0 commit comments

Comments
 (0)