From 252271d0fc10ba9e96af53ac70199a0b6ec77fda Mon Sep 17 00:00:00 2001
From: Li Feng
Date: Wed, 7 Aug 2024 13:30:57 +1000
Subject: [PATCH] fixes as per review comments
---
support-lib/swift/DJData.swift | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/support-lib/swift/DJData.swift b/support-lib/swift/DJData.swift
index 6a99b499..5d52cd4f 100644
--- a/support-lib/swift/DJData.swift
+++ b/support-lib/swift/DJData.swift
@@ -9,6 +9,9 @@ public enum DataViewMarshaller: Marshaller {
public typealias SwiftType = NSData
public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType {
let range = djinni.swift.getBinaryRange(v)
+ if (range.size == 0 || range.bytes == nil) {
+ return SwiftType()
+ }
return SwiftType(bytesNoCopy: UnsafeMutableRawPointer(mutating: range.bytes!), length: range.size, deallocator:.none)
}
public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue {
@@ -25,12 +28,12 @@ public enum DataRefMarshaller: Marshaller {
return cfdata as NSData
}
public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue {
- if s is CFMutableData {
- let cfdataref = Unmanaged.passRetained(s as! CFMutableData).toOpaque()
- return djinni.swift.makeRangeValue(cfdataref, 1)
+ if let nsMutableData = s as? NSMutableData {
+ let cfDataRef = Unmanaged.passRetained(nsMutableData).toOpaque()
+ return djinni.swift.makeRangeValue(cfDataRef, 1)
} else {
- let cfdataref = Unmanaged.passRetained(s as CFData).toOpaque()
- return djinni.swift.makeRangeValue(cfdataref, 0)
+ let cfDataRef = Unmanaged.passRetained(s as CFData).toOpaque()
+ return djinni.swift.makeRangeValue(cfDataRef, 0)
}
}
}