Skip to content

Commit ba19162

Browse files
authored
Merge pull request #3121 from CodaFi/up-and-atom
2 parents 11b894d + c8d9720 commit ba19162

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

stdlib/public/core/Runtime.swift.gyb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func _stdlib_atomicCompareExchangeStrongPtrImpl(
3636
return Bool(won)
3737
}
3838

39+
% for optional in ['', '?']:
3940
/// Atomic compare and exchange of `UnsafeMutablePointer<T>` with sequentially
4041
/// consistent memory ordering. Precise semantics are defined in C++11 or C11.
4142
///
@@ -66,14 +67,15 @@ func _stdlib_atomicCompareExchangeStrongPtrImpl(
6667
@_transparent
6768
public // @testable
6869
func _stdlib_atomicCompareExchangeStrongPtr<T>(
69-
object target: UnsafeMutablePointer<UnsafeMutablePointer<T>>,
70-
expected: UnsafeMutablePointer<UnsafeMutablePointer<T>>,
71-
desired: UnsafeMutablePointer<T>) -> Bool {
70+
object target: UnsafeMutablePointer<UnsafeMutablePointer<T>${optional}>,
71+
expected: UnsafeMutablePointer<UnsafeMutablePointer<T>${optional}>,
72+
desired: UnsafeMutablePointer<T>${optional}) -> Bool {
7273
return _stdlib_atomicCompareExchangeStrongPtrImpl(
7374
object: UnsafeMutablePointer(target),
7475
expected: UnsafeMutablePointer(expected),
7576
desired: UnsafeMutablePointer(desired))
7677
}
78+
% end
7779

7880
@_transparent
7981
@discardableResult

test/1_stdlib/Runtime.swift renamed to test/1_stdlib/Runtime.swift.gyb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: rm -rf %t && mkdir %t
22
//
3-
// RUN: %target-build-swift -parse-stdlib -module-name a %s -o %t.out
3+
// RUN: %gyb %s -o %t/Runtime.swift
4+
// RUN: %target-build-swift -parse-stdlib -module-name a %t/Runtime.swift -o %t.out
45
// RUN: %target-run %t.out
56
// REQUIRES: executable_test
67

@@ -356,11 +357,12 @@ Runtime.test("demangleName") {
356357
expectEqual("Foobar", _stdlib_demangleName("_TtC13__lldb_expr_46Foobar"))
357358
}
358359

360+
% for optionality in ['', '?']:
359361
Runtime.test("_stdlib_atomicCompareExchangeStrongPtr") {
360362
typealias IntPtr = UnsafeMutablePointer<Int>
361-
var origP1 = IntPtr(bitPattern: 0x10101010)!
362-
var origP2 = IntPtr(bitPattern: 0x20202020)!
363-
var origP3 = IntPtr(bitPattern: 0x30303030)!
363+
var origP1: IntPtr${optionality} = IntPtr(bitPattern: 0x10101010)!
364+
var origP2: IntPtr${optionality} = IntPtr(bitPattern: 0x20202020)!
365+
var origP3: IntPtr${optionality} = IntPtr(bitPattern: 0x30303030)!
364366

365367
do {
366368
var object = origP1
@@ -383,32 +385,33 @@ Runtime.test("_stdlib_atomicCompareExchangeStrongPtr") {
383385

384386
struct FooStruct {
385387
var i: Int
386-
var object: IntPtr
387-
var expected: IntPtr
388+
var object: IntPtr${optionality}
389+
var expected: IntPtr${optionality}
388390

389-
init(_ object: IntPtr, _ expected: IntPtr) {
391+
init(object: IntPtr${optionality}, expected: IntPtr${optionality}) {
390392
self.i = 0
391393
self.object = object
392394
self.expected = expected
393395
}
394396
}
395397
do {
396-
var foo = FooStruct(origP1, origP1)
398+
var foo = FooStruct(object: origP1, expected: origP1)
397399
let r = _stdlib_atomicCompareExchangeStrongPtr(
398400
object: &foo.object, expected: &foo.expected, desired: origP2)
399401
expectTrue(r)
400402
expectEqual(origP2, foo.object)
401403
expectEqual(origP1, foo.expected)
402404
}
403405
do {
404-
var foo = FooStruct(origP1, origP2)
406+
var foo = FooStruct(object: origP1, expected: origP2)
405407
let r = _stdlib_atomicCompareExchangeStrongPtr(
406408
object: &foo.object, expected: &foo.expected, desired: origP3)
407409
expectFalse(r)
408410
expectEqual(origP1, foo.object)
409411
expectEqual(origP1, foo.expected)
410412
}
411413
}
414+
% end
412415

413416
Runtime.test("casting AnyObject to class metatypes") {
414417
do {

0 commit comments

Comments
 (0)