Additional Detail from JIRA
| | |
|------------------|-----------------|
|Votes | 1 |
|Component/s | Foundation |
|Labels | Bug |
|Assignee | None |
|Priority | Medium |
md5: b40c2cee60a72f9c6e5ee6f3a3ac56b7
Issue Description:
NSData.bytes is a straightforward translation of the Objective-C [NSData bytes] property accessor from Objective-C. The method returns an interior pointer to the buffer of an NSData object.
Recent improvements to the copy propagation optimization pass have made this property very dangerous on non-Apple platforms, including breaking [swift-corelibs-foundation| https://github.com/apple/swift-corelibs-foundation/pull/2994] in recent top-of-tree Swift versions.
To use this property safely will almost invariably require the use of withExtendedLifetime to keep the parent NSData object alive. We should consider deprecating this in favour of Data.withUnsafeBytes, or providing a diagnostic for using NSData.bytes as the last usage point, or at the very least making it clear that this Objective-C-ism is potentially much more dangerous than it looks.
Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 1 | |Component/s | Foundation | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: b40c2cee60a72f9c6e5ee6f3a3ac56b7Issue Description:
NSData.bytes
is a straightforward translation of the Objective-C[NSData bytes]
property accessor from Objective-C. The method returns an interior pointer to the buffer of anNSData
object.Recent improvements to the copy propagation optimization pass have made this property very dangerous on non-Apple platforms, including breaking [swift-corelibs-foundation| https://github.com/apple/swift-corelibs-foundation/pull/2994] in recent top-of-tree Swift versions.
To use this property safely will almost invariably require the use of
withExtendedLifetime
to keep the parentNSData
object alive. We should consider deprecating this in favour ofData.withUnsafeBytes
, or providing a diagnostic for usingNSData.bytes
as the last usage point, or at the very least making it clear that this Objective-C-ism is potentially much more dangerous than it looks.