From eec6f17c8879b469dc3370dad4a7f68f11705a6b Mon Sep 17 00:00:00 2001 From: abandy Date: Mon, 17 Jun 2024 21:33:43 -0400 Subject: [PATCH] GH-42087: [Swift] refactored to remove build warnings (#42088) ### 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: #42087 Authored-by: Alva Bandy Signed-off-by: Sutou Kouhei --- swift/Arrow/Package.swift | 17 ++++++++++++++--- swift/Arrow/Sources/Arrow/ArrowCExporter.swift | 10 ++++++++-- swift/Arrow/Tests/ArrowTests/CodableTests.swift | 2 +- swift/ArrowFlight/Package.swift | 12 ++++++++++-- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/swift/Arrow/Package.swift b/swift/Arrow/Package.swift index 6f19136fd4292..6944d7b910656 100644 --- a/swift/Arrow/Package.swift +++ b/swift/Arrow/Package.swift @@ -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"]) + ] + ) ] ) diff --git a/swift/Arrow/Sources/Arrow/ArrowCExporter.swift b/swift/Arrow/Sources/Arrow/ArrowCExporter.swift index aa93f0cb7e389..f2dd8ab56d897 100644 --- a/swift/Arrow/Sources/Arrow/ArrowCExporter.swift +++ b/swift/Arrow/Sources/Arrow/ArrowCExporter.swift @@ -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.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]() diff --git a/swift/Arrow/Tests/ArrowTests/CodableTests.swift b/swift/Arrow/Tests/ArrowTests/CodableTests.swift index d7d3414cf6250..160beea17c9fa 100644 --- a/swift/Arrow/Tests/ArrowTests/CodableTests.swift +++ b/swift/Arrow/Tests/ArrowTests/CodableTests.swift @@ -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..