Skip to content

Commit 346704c

Browse files
authored
Merge pull request #78647 from glessard/rdar142867382
[stdlib] fix getting eager-lazy-bridged Array buffer
2 parents 1d8e48d + 42ee081 commit 346704c

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

stdlib/public/core/ArrayBuffer.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff 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
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
}

0 commit comments

Comments
 (0)