forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pinning.swift
66 lines (47 loc) · 1.52 KB
/
pinning.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// RUN: rm -rf %t && mkdir -p %t
// RUN: %target-build-swift -parse-stdlib %s -o %t/a.out
// RUN: %target-run %t/a.out | FileCheck %s
// REQUIRES: executable_test
import Swift
import SwiftShims
typealias _HeapObject = SwiftShims.HeapObject
class C {
var value: AnyObject? = nil
deinit { print("deallocated") }
}
print("starting")
var ptr = Builtin.castToNativeObject(C())
//CHECK: 1. true
print(" 1. \(_getBool(Builtin.isUnique(&ptr))))")
//CHECK: 2. true
print(" 2. \(_getBool(Builtin.isUniqueOrPinned(&ptr))))")
var ptr2 : Builtin.NativeObject? = ptr
//CHECK: 3. false
print(" 3. \(_getBool(Builtin.isUnique(&ptr))))")
//CHECK: 4. false
print(" 4. \(_getBool(Builtin.isUniqueOrPinned(&ptr))))")
ptr2 = nil
//CHECK: 5. true
print(" 5. \(_getBool(Builtin.isUnique(&ptr)))")
//CHECK: 6. true
print(" 6. \(_getBool(Builtin.isUniqueOrPinned(&ptr)))")
ptr2 = ptr
//CHECK: 7. false
print(" 7. \(_getBool(Builtin.isUnique(&ptr)))")
//CHECK: 8. false
print(" 8. \(_getBool(Builtin.isUniqueOrPinned(&ptr)))")
let token : Builtin.NativeObject? = Builtin.tryPin(ptr)
//CHECK: 9. false
print(" 9. \(_getBool(Builtin.isUnique(&ptr)))")
//CHECK: 10. true
print("10. \(_getBool(Builtin.isUniqueOrPinned(&ptr)))")
Builtin.unpin(token)
//CHECK: 11. false
print("11. \(_getBool(Builtin.isUnique(&ptr)))")
//CHECK: 12. false
print("12. \(_getBool(Builtin.isUniqueOrPinned(&ptr)))")
ptr2 = ptr
//CHECK: 13. false
print("13. \(_getBool(Builtin.isUnique(&ptr)))")
//CHECK: 14. false
print("14. \(_getBool(Builtin.isUniqueOrPinned(&ptr)))")