File tree Expand file tree Collapse file tree 2 files changed +44
-3
lines changed Expand file tree Collapse file tree 2 files changed +44
-3
lines changed Original file line number Diff line number Diff line change @@ -586,9 +586,8 @@ extension _ArrayBuffer {
586586 _storage. objCInstance,
587587 _ArrayBuffer. associationKey
588588 ) {
589- let buffer = assocPtr. load (
590- as: _ContiguousArrayStorage< Element> . self
591- )
589+ let buffer : _ContiguousArrayStorage < Element >
590+ buffer = Unmanaged . fromOpaque ( assocPtr) . takeUnretainedValue ( )
592591 return _ContiguousArrayBuffer ( buffer)
593592 }
594593 return nil
Original file line number Diff line number Diff line change 1+ //===--- BridgedArrayNonContiguous.swift ----------------------------------===//
2+ //
3+ // This source file is part of the Swift.org open source project
4+ //
5+ // Copyright (c) 2025 Apple Inc. and the Swift project authors
6+ // Licensed under Apache License v2.0 with Runtime Library Exception
7+ //
8+ // See https://swift.org/LICENSE.txt for license information
9+ // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+ //
11+ //===----------------------------------------------------------------------===//
12+
13+ // RUN: %target-run-stdlib-swift -enable-experimental-feature LifetimeDependence -enable-experimental-feature Span
14+
15+ // REQUIRES: executable_test
16+ // REQUIRES: objc_interop
17+ // REQUIRES: swift_feature_LifetimeDependence
18+ // REQUIRES: swift_feature_Span
19+
20+ import StdlibUnittest
21+
22+ import Foundation
23+
24+ var suite = TestSuite ( " EagerLazyBridgingTests " )
25+ defer { runAllTests ( ) }
26+
27+ var x : NSObject ? = nil
28+
29+ suite. test ( " Bridged NSArray without direct memory sharing " ) {
30+
31+ var arr = Array ( repeating: NSObject ( ) , count: 100 ) as [ AnyObject ]
32+ let nsArray : NSArray = NSArray ( objects: & arr, count: 100 )
33+ for _ in 0 ..< 5 {
34+ let tmp = nsArray as! [ NSObject ]
35+ x = tmp. withContiguousStorageIfAvailable {
36+ $0 [ 0 ]
37+ }
38+ expectNotNil ( x)
39+ }
40+
41+ x = nil
42+ }
You can’t perform that action at this time.
0 commit comments