@@ -3,55 +3,121 @@ import Foundation
3
3
4
4
@_spi ( WinRTInternal)
5
5
extension Array where Element: ToAbi {
6
- public func toABI( _ withAbi: ( _ length : UInt32 , _ bytes : UnsafeMutablePointer < Element . ABI > ? ) throws -> Void ) throws {
6
+ public func toABI( _ withAbi: ( WinRTArrayAbi < Element . ABI > ) throws -> Void ) throws {
7
7
let abiArray : [ Element . ABI ] = try map { try $0. toABI ( ) }
8
8
try abiArray. withUnsafeBytes { ( bytes: UnsafeRawBufferPointer ) in
9
9
let bytesPtr = bytes. baseAddress? . assumingMemoryBound ( to: Element . ABI. self)
10
- try withAbi ( UInt32 ( count) , . init( mutating: bytesPtr) )
10
+ try withAbi ( ( count: UInt32 ( count) , start: . init( mutating: bytesPtr) ) )
11
+ }
12
+ }
13
+
14
+ public func fill( abi: UnsafeMutablePointer < UnsafeMutablePointer < Element . ABI > ? > ? ) throws {
15
+ guard let abi else { return }
16
+ abi. pointee = CoTaskMemAlloc ( UInt64 ( MemoryLayout < Element . ABI > . size * count) ) . assumingMemoryBound ( to: Element . ABI. self)
17
+ do {
18
+ try fill ( abi: abi. pointee)
19
+ } catch {
20
+ CoTaskMemFree ( abi. pointee)
21
+ throw error
22
+ }
23
+ }
24
+
25
+ public func fill( abi: UnsafeMutablePointer < Element . ABI > ? ) throws {
26
+ guard let abi else { return }
27
+ for (index, element) in enumerated ( ) {
28
+ abi [ index] = try element. toABI ( )
11
29
}
12
30
}
13
31
}
14
32
15
33
@_spi ( WinRTInternal)
16
34
extension Array where Element: Numeric {
17
- public func toABI( _ withAbi: ( _ length : UInt32 , _ bytes : UnsafeMutablePointer < Element > ? ) throws -> Void ) throws {
35
+ public func toABI( _ withAbi: ( WinRTArrayAbi < Element > ) throws -> Void ) throws {
18
36
try withUnsafeBytes { ( bytes: UnsafeRawBufferPointer ) in
19
37
let bytesPtr = bytes. baseAddress? . assumingMemoryBound ( to: Element . self)
20
- try withAbi ( UInt32 ( count) , . init( mutating: bytesPtr) )
38
+ try withAbi ( ( count : UInt32 ( count) , start : . init( mutating: bytesPtr) ) )
21
39
}
22
40
}
41
+
42
+ public func fill( abi: UnsafeMutablePointer < Element > ? ) {
43
+ guard let abi else { return }
44
+ _ = UnsafeMutableBufferPointer ( start: abi, count: count) . update ( from: self )
45
+ }
46
+
47
+ public func fill( abi: UnsafeMutablePointer < UnsafeMutablePointer < Element > ? > ? ) {
48
+ guard let abi else { return }
49
+ abi. pointee = CoTaskMemAlloc ( UInt64 ( MemoryLayout < Element > . size * count) ) . assumingMemoryBound ( to: Element . self)
50
+ fill ( abi: abi. pointee)
51
+ }
23
52
}
24
53
25
54
@_spi ( WinRTInternal)
26
55
extension Array where Element: RawRepresentable , Element. RawValue: Numeric {
27
- public func toABI( _ withAbi: ( _ length : UInt32 , _ bytes : UnsafeMutablePointer < Element > ? ) throws -> Void ) throws {
56
+ public func toABI( _ withAbi: ( WinRTArrayAbi < Element > ) throws -> Void ) throws {
28
57
try withUnsafeBytes { ( bytes: UnsafeRawBufferPointer ) in
29
58
let bytesPtr = bytes. baseAddress? . assumingMemoryBound ( to: Element . self)
30
- try withAbi ( UInt32 ( count) , . init( mutating: bytesPtr) )
59
+ try withAbi ( ( count : UInt32 ( count) , start : . init( mutating: bytesPtr) ) )
31
60
}
32
61
}
62
+
63
+ public func fill( abi: UnsafeMutablePointer < Element > ? ) {
64
+ guard let abi else { return }
65
+ _ = UnsafeMutableBufferPointer ( start: abi, count: count) . update ( from: self )
66
+ }
67
+
68
+ public func fill( abi: UnsafeMutablePointer < UnsafeMutablePointer < Element > ? > ? ) {
69
+ guard let abi else { return }
70
+ abi. pointee = CoTaskMemAlloc ( UInt64 ( MemoryLayout < Element > . size * count) ) . assumingMemoryBound ( to: Element . self)
71
+ fill ( abi: abi. pointee)
72
+ }
33
73
}
34
74
35
75
@_spi ( WinRTInternal)
36
76
extension Array {
37
- public func toABI< Bridge: AbiInterfaceBridge > ( abiBridge: Bridge . Type , _ withAbi: ( _ length : UInt32 , _ bytes : UnsafeMutablePointer < UnsafeMutablePointer < Bridge . CABI > ? > ? ) throws -> Void ) throws where Element == Bridge . SwiftProjection ? {
77
+ public func toABI< Bridge: AbiInterfaceBridge > ( abiBridge: Bridge . Type , _ withAbi: ( WinRTArrayAbi < UnsafeMutablePointer < Bridge . CABI > ? > ) throws -> Void ) throws where Element == Bridge . SwiftProjection ? {
38
78
let abiWrapperArray : [ InterfaceWrapperBase < Bridge > ? ] = map { . init( $0) }
39
79
let abiArray = try abiWrapperArray. map { try $0? . toABI { $0 } }
40
80
try abiArray. withUnsafeBytes { ( bytes: UnsafeRawBufferPointer ) in
41
81
let bytesPtr = bytes. baseAddress? . assumingMemoryBound ( to: UnsafeMutablePointer< Bridge . CABI>? . self )
42
- try withAbi ( UInt32 ( count) , . init( mutating: bytesPtr) )
82
+ try withAbi ( ( count: UInt32 ( count) , start: . init( mutating: bytesPtr) ) )
83
+ }
84
+ }
85
+
86
+ public func fill< Bridge: AbiInterfaceBridge > ( abi: UnsafeMutablePointer < UnsafeMutablePointer < Bridge . CABI > ? > ? , abiBridge: Bridge . Type ) where Element == Bridge . SwiftProjection ? {
87
+ guard let abi else { return }
88
+ for (index, element) in enumerated ( ) {
89
+ let wrapper = InterfaceWrapperBase < Bridge > ( element)
90
+ wrapper? . copyTo ( & abi[ index] )
43
91
}
44
92
}
93
+
94
+ public func fill< Bridge: AbiInterfaceBridge > ( abi: UnsafeMutablePointer < UnsafeMutablePointer < UnsafeMutablePointer < Bridge . CABI > ? > ? > ? , abiBridge: Bridge . Type ) where Element == Bridge . SwiftProjection ? {
95
+ guard let abi else { return }
96
+ abi. pointee = CoTaskMemAlloc ( UInt64 ( MemoryLayout < UnsafeMutablePointer < Bridge . CABI > > . size * count) ) . assumingMemoryBound ( to: UnsafeMutablePointer< Bridge . CABI>? . self )
97
+ fill ( abi: abi. pointee, abiBridge: abiBridge)
98
+ }
45
99
}
46
100
47
101
@_spi ( WinRTInternal)
48
102
extension Array {
49
- public func toABI< Bridge: AbiBridge > ( abiBridge: Bridge . Type , _ withAbi: ( _ length : UInt32 , _ bytes : UnsafeMutablePointer < UnsafeMutablePointer < Bridge . CABI > ? > ? ) throws -> Void ) throws where Element == Bridge . SwiftProjection ? , Bridge. SwiftProjection: WinRTClass {
103
+ public func toABI< Bridge: AbiBridge > ( abiBridge: Bridge . Type , _ withAbi: ( WinRTArrayAbi < UnsafeMutablePointer < Bridge . CABI > ? > ) throws -> Void ) throws where Element == Bridge . SwiftProjection ? , Bridge. SwiftProjection: WinRTClass {
50
104
let abiArray : [ UnsafeMutablePointer < Bridge . CABI > ? ] = map { RawPointer ( $0) }
51
105
try abiArray. withUnsafeBytes { ( bytes: UnsafeRawBufferPointer ) in
52
106
let bytesPtr = bytes. baseAddress? . assumingMemoryBound ( to: UnsafeMutablePointer< Bridge . CABI>? . self )
53
- try withAbi ( UInt32 ( count) , . init( mutating: bytesPtr) )
107
+ try withAbi ( ( count: UInt32 ( count) , start: . init( mutating: bytesPtr) ) )
108
+ }
109
+ }
110
+
111
+ public func fill< Bridge: AbiBridge > ( abi: UnsafeMutablePointer < UnsafeMutablePointer < Bridge . CABI > ? > ? , abiBridge: Bridge . Type ) where Element == Bridge . SwiftProjection ? , Bridge. SwiftProjection: WinRTClass {
112
+ guard let abi else { return }
113
+ for (index, element) in enumerated ( ) {
114
+ abi [ index] = RawPointer ( element)
54
115
}
55
116
}
56
- }
57
117
118
+ public func fill< Bridge: AbiBridge > ( abi: UnsafeMutablePointer < UnsafeMutablePointer < UnsafeMutablePointer < Bridge . CABI > ? > ? > ? , abiBridge: Bridge . Type ) where Element == Bridge . SwiftProjection ? , Bridge. SwiftProjection: WinRTClass {
119
+ guard let abi else { return }
120
+ abi. pointee = CoTaskMemAlloc ( UInt64 ( MemoryLayout < UnsafeMutablePointer < Bridge . CABI > > . size * count) ) . assumingMemoryBound ( to: UnsafeMutablePointer< Bridge . CABI>? . self )
121
+ fill ( abi: abi. pointee, abiBridge: abiBridge)
122
+ }
123
+ }
0 commit comments