Skip to content

Commit fbe8282

Browse files
Azoylorentey
andauthored
Take test suggestion from Karoy
Co-authored-by: Karoy Lorentey <[email protected]>
1 parent c384b1c commit fbe8282

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

test/stdlib/Unmanaged.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,17 @@ UnmanagedTests.test("Opaque avoid retain/release") {
8080
// pointer. This test's expectEqual is kind of bogus, we're just checking that
8181
// it doesn't crash.
8282

83-
let ref = UnsafeMutablePointer<Int>(capacity: 1)
84-
let unmanaged = Unmanaged.fromOpaque(UnsafeRawPointer(ref))
83+
// Create a dangling pointer, usually to unmapped memory.
84+
let ref = UnsafeRawPointer(bitPattern: 1)!
85+
// Turn it into a dangling unmanaged reference.
86+
// We expect this not to crash, as this operation isn't
87+
// supposed to dereference the pointer in any way.
88+
let unmanaged = Unmanaged.fromOpaque(ref)
89+
// Similarly, converting the unmanaged reference back to a
90+
// pointer should not ever try to dereference it either.
8591
let ref2 = unmanaged.toOpaque()
86-
92+
// ...and we must get back the same pointer.
8793
expectEqual(ref, ref2)
88-
89-
ref.deallocate()
9094
}
9195

9296
runAllTests()

0 commit comments

Comments
 (0)