Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CoreFoundation/Collections.subproj/CFArray.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ void CFArrayAppendValue(CFMutableArrayRef array, const void *value) {
}

void CFArraySetValueAtIndex(CFMutableArrayRef array, CFIndex idx, const void *value) {
CF_SWIFT_FUNCDISPATCHV(CFArrayGetTypeID(), void, (CFSwiftRef)array, NSMutableArray.setObject, idx, value);
CF_SWIFT_FUNCDISPATCHV(CFArrayGetTypeID(), void, (CFSwiftRef)array, NSMutableArray.setObject, value, idx);
Copy link
Contributor

@millenomi millenomi Aug 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should really name all the arguments in order in the bridge struct field name to prevent this from occurring again. Is there any way I can convince you to add an edit so this reads NSMutableArray.setObjectAtIndex?

✅ whether this is done or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to do that as a different PR, if you don’t mind. It might be also kind of a big change.

CF_OBJC_FUNCDISPATCHV(CFArrayGetTypeID(), void, (NSMutableArray *)array, setObject:(id)value atIndex:(NSUInteger)idx);
__CFGenericValidateType(array, CFArrayGetTypeID());
CFAssert1(__CFArrayGetType(array) != __kCFArrayImmutable, __kCFLogAssertion, "%s(): array is immutable", __PRETTY_FUNCTION__);
Expand Down
11 changes: 11 additions & 0 deletions TestFoundation/TestNSArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//

import CoreFoundation

class TestNSArray : XCTestCase {

static var allTests: [(String, (TestNSArray) -> () throws -> Void)] {
Expand Down Expand Up @@ -42,6 +44,7 @@ class TestNSArray : XCTestCase {
("test_insertObjectsAtIndexes", test_insertObjectsAtIndexes),
("test_replaceObjectsAtIndexesWithObjects", test_replaceObjectsAtIndexesWithObjects),
("test_pathsMatchingExtensions", test_pathsMatchingExtensions),
("test_arrayUsedAsCFArrayInvokesArrayMethods", test_arrayUsedAsCFArrayInvokesArrayMethods),
]
}

Expand Down Expand Up @@ -794,6 +797,14 @@ class TestNSArray : XCTestCase {
XCTAssertEqual(match5, [])
}

func test_arrayUsedAsCFArrayInvokesArrayMethods() {
let number = 789 as NSNumber
let array = NSMutableArray(array: [123, 456])
CFArraySetValueAtIndex(unsafeBitCast(array, to: CFMutableArray.self), 1, UnsafeRawPointer(Unmanaged.passUnretained(number).toOpaque()))
XCTAssertEqual(array[0] as! NSNumber, 123 as NSNumber)
XCTAssertEqual(array[1] as! NSNumber, 789 as NSNumber)
}

private func createTestFile(_ path: String, _contents: Data) -> String? {
let tempDir = NSTemporaryDirectory() + "TestFoundation_Playground_" + NSUUID().uuidString + "/"
do {
Expand Down