Skip to content

Commit

Permalink
apacheGH-42087: [Swift] refactored to remove build warnings (apache#4…
Browse files Browse the repository at this point in the history
…2088)

### Rationale for this change
Building warnings were being generated from the swift code.

### What changes are included in this PR?
Refactored the code in ArrowCExporter and CodableTests to remove the build warnings.  

### Are these changes tested?
Yes, also ran CDataWGo tests locally to test CData interface changes.

* GitHub Issue: apache#42087

Authored-by: Alva Bandy <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
  • Loading branch information
abandy authored Jun 18, 2024
1 parent 4413110 commit eec6f17
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
17 changes: 14 additions & 3 deletions swift/Arrow/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,27 @@ let package = Package(
targets: [
.target(
name: "ArrowC",
path: "Sources/ArrowC"
path: "Sources/ArrowC",
swiftSettings: [
.unsafeFlags(["-warnings-as-errors"])
]
),
.target(
name: "Arrow",
dependencies: ["ArrowC",
.product(name: "FlatBuffers", package: "flatbuffers"),
.product(name: "Atomics", package: "swift-atomics")
]),
],
swiftSettings: [
.unsafeFlags(["-warnings-as-errors"])
]
),
.testTarget(
name: "ArrowTests",
dependencies: ["Arrow", "ArrowC"])
dependencies: ["Arrow", "ArrowC"],
swiftSettings: [
.unsafeFlags(["-warnings-as-errors"])
]
)
]
)
10 changes: 8 additions & 2 deletions swift/Arrow/Sources/Arrow/ArrowCExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ public class ArrowCExporter {
// deallocated
self.arrowData = arrowData
for arrowBuffer in arrowData.buffers {
data.append(arrowBuffer.rawPointer)
self.data.append(arrowBuffer.rawPointer)
}

self.buffers = UnsafeMutablePointer(mutating: data)
self.buffers = UnsafeMutablePointer<UnsafeRawPointer?>.allocate(capacity: self.data.count)
self.buffers.initialize(from: &self.data, count: self.data.count)
super.init()
}

deinit {
self.buffers.deinitialize(count: self.data.count)
self.buffers.deallocate()
}
}

private static var exportedData = [Int: ExportData]()
Expand Down
2 changes: 1 addition & 1 deletion swift/Arrow/Tests/ArrowTests/CodableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ final class CodableTests: XCTestCase {
switch result {
case .success(let rb):
let decoder = ArrowDecoder(rb)
var testClasses = try decoder.decode(TestClass.self)
let testClasses = try decoder.decode(TestClass.self)
for index in 0..<testClasses.count {
let testClass = testClasses[index]
XCTAssertEqual(testClass.propBool, index % 2 == 0 ? false : true)
Expand Down
12 changes: 10 additions & 2 deletions swift/ArrowFlight/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ let package = Package(
.product(name: "Arrow", package: "Arrow"),
.product(name: "GRPC", package: "grpc-swift"),
.product(name: "SwiftProtobuf", package: "swift-protobuf")
]),
],
swiftSettings: [
.unsafeFlags(["-warnings-as-errors"])
]
),
.testTarget(
name: "ArrowFlightTests",
dependencies: ["ArrowFlight"])
dependencies: ["ArrowFlight"],
swiftSettings: [
.unsafeFlags(["-warnings-as-errors"])
]
)
]
)

0 comments on commit eec6f17

Please sign in to comment.