@@ -48,10 +48,10 @@ public struct HeapObject {
48
48
49
49
/// Forward declarations of C functions
50
50
51
- @_silgen_name ( " posix_memalign " )
51
+ @_extern ( c , " posix_memalign " )
52
52
func posix_memalign( _: UnsafeMutablePointer < UnsafeMutableRawPointer ? > , _: Int , _: Int ) -> CInt
53
53
54
- @_silgen_name ( " free " )
54
+ @_extern ( c , " free " )
55
55
func free( _ p: Builtin . RawPointer )
56
56
57
57
@@ -81,38 +81,58 @@ public func swift_slowDealloc(_ ptr: UnsafeMutableRawPointer, _ size: Int, _ ali
81
81
free ( ptr. _rawValue)
82
82
}
83
83
84
- @_silgen_name ( " swift_allocObject " )
85
- public func swift_allocObject( metadata: UnsafeMutablePointer < ClassMetadata > , requiredSize: Int , requiredAlignmentMask: Int ) -> UnsafeMutablePointer < HeapObject > {
84
+ @_cdecl ( " swift_allocObject " )
85
+ public func swift_allocObject( metadata: Builtin . RawPointer , requiredSize: Int , requiredAlignmentMask: Int ) -> Builtin . RawPointer {
86
+ return swift_allocObject ( metadata: UnsafeMutablePointer < ClassMetadata > ( metadata) , requiredSize: requiredSize, requiredAlignmentMask: requiredAlignmentMask) . _rawValue
87
+ }
88
+
89
+ func swift_allocObject( metadata: UnsafeMutablePointer < ClassMetadata > , requiredSize: Int , requiredAlignmentMask: Int ) -> UnsafeMutablePointer < HeapObject > {
86
90
let p = swift_slowAlloc ( requiredSize, requiredAlignmentMask) !
87
91
let object = p. assumingMemoryBound ( to: HeapObject . self)
88
92
_swift_embedded_set_heap_object_metadata_pointer ( object, metadata)
89
93
object. pointee. refcount = 1
90
94
return object
91
95
}
92
96
93
- @_silgen_name ( " swift_deallocObject " )
94
- public func swift_deallocObject( object: UnsafeMutablePointer < HeapObject > , allocatedSize: Int , allocatedAlignMask: Int ) {
97
+ @_cdecl ( " swift_deallocObject " )
98
+ public func swift_deallocObject( object: Builtin . RawPointer , allocatedSize: Int , allocatedAlignMask: Int ) {
99
+ swift_deallocObject ( object: UnsafeMutablePointer < HeapObject > ( object) , allocatedSize: allocatedSize, allocatedAlignMask: allocatedAlignMask)
100
+ }
101
+
102
+ func swift_deallocObject( object: UnsafeMutablePointer < HeapObject > , allocatedSize: Int , allocatedAlignMask: Int ) {
95
103
free ( object. _rawValue)
96
104
}
97
105
98
- @_silgen_name ( " swift_deallocClassInstance " )
99
- public func swift_deallocClassInstance( object: UnsafeMutablePointer < HeapObject > , allocatedSize: Int , allocatedAlignMask: Int ) {
106
+ @_cdecl ( " swift_deallocClassInstance " )
107
+ public func swift_deallocClassInstance( object: Builtin . RawPointer , allocatedSize: Int , allocatedAlignMask: Int ) {
108
+ swift_deallocClassInstance ( object: UnsafeMutablePointer < HeapObject > ( object) , allocatedSize: allocatedSize, allocatedAlignMask: allocatedAlignMask)
109
+ }
110
+
111
+ func swift_deallocClassInstance( object: UnsafeMutablePointer < HeapObject > , allocatedSize: Int , allocatedAlignMask: Int ) {
100
112
if ( object. pointee. refcount & HeapObject . doNotFreeBit) != 0 {
101
113
return
102
114
}
103
115
104
116
free ( object. _rawValue)
105
117
}
106
118
107
- @_silgen_name ( " swift_initStaticObject " )
108
- public func swift_initStaticObject( metadata: UnsafeMutablePointer < ClassMetadata > , object: UnsafeMutablePointer < HeapObject > ) -> UnsafeMutablePointer < HeapObject > {
119
+ @_cdecl ( " swift_initStaticObject " )
120
+ public func swift_initStaticObject( metadata: Builtin . RawPointer , object: Builtin . RawPointer ) -> Builtin . RawPointer {
121
+ return swift_initStaticObject ( metadata: UnsafeMutablePointer < ClassMetadata > ( metadata) , object: UnsafeMutablePointer < HeapObject > ( object) ) . _rawValue
122
+ }
123
+
124
+ func swift_initStaticObject( metadata: UnsafeMutablePointer < ClassMetadata > , object: UnsafeMutablePointer < HeapObject > ) -> UnsafeMutablePointer < HeapObject > {
109
125
_swift_embedded_set_heap_object_metadata_pointer ( object, metadata)
110
126
object. pointee. refcount = HeapObject . immortalRefCount
111
127
return object
112
128
}
113
129
114
- @_silgen_name ( " swift_initStackObject " )
115
- public func swift_initStackObject( metadata: UnsafeMutablePointer < ClassMetadata > , object: UnsafeMutablePointer < HeapObject > ) -> UnsafeMutablePointer < HeapObject > {
130
+ @_cdecl ( " swift_initStackObject " )
131
+ public func swift_initStackObject( metadata: Builtin . RawPointer , object: Builtin . RawPointer ) -> Builtin . RawPointer {
132
+ return swift_initStackObject ( metadata: UnsafeMutablePointer < ClassMetadata > ( metadata) , object: UnsafeMutablePointer < HeapObject > ( object) ) . _rawValue
133
+ }
134
+
135
+ func swift_initStackObject( metadata: UnsafeMutablePointer < ClassMetadata > , object: UnsafeMutablePointer < HeapObject > ) -> UnsafeMutablePointer < HeapObject > {
116
136
_swift_embedded_set_heap_object_metadata_pointer ( object, metadata)
117
137
object. pointee. refcount = 1 | HeapObject . doNotFreeBit
118
138
return object
@@ -122,25 +142,29 @@ public func swift_initStackObject(metadata: UnsafeMutablePointer<ClassMetadata>,
122
142
123
143
/// Refcounting
124
144
125
- @_silgen_name ( " swift_setDeallocating " )
126
- public func swift_setDeallocating( object: UnsafeMutablePointer < HeapObject > ) {
145
+ @_cdecl ( " swift_setDeallocating " )
146
+ public func swift_setDeallocating( object: Builtin . RawPointer ) {
147
+ }
148
+
149
+ @_cdecl ( " swift_isUniquelyReferenced_nonNull_native " )
150
+ public func swift_isUniquelyReferenced_nonNull_native( object: Builtin . RawPointer ) -> Bool {
151
+ return swift_isUniquelyReferenced_nonNull_native ( object: UnsafeMutablePointer < HeapObject > ( object) )
127
152
}
128
153
129
- @_silgen_name ( " swift_isUniquelyReferenced_nonNull_native " )
130
- public func swift_isUniquelyReferenced_nonNull_native( object: UnsafeMutablePointer < HeapObject > ) -> Bool {
154
+ func swift_isUniquelyReferenced_nonNull_native( object: UnsafeMutablePointer < HeapObject > ) -> Bool {
131
155
let refcount = refcountPointer ( for: object)
132
156
return loadAcquire ( refcount) == 1
133
157
}
134
158
135
- @_silgen_name ( " swift_retain " )
159
+ @_cdecl ( " swift_retain " )
136
160
public func swift_retain( object: Builtin . RawPointer ) -> Builtin . RawPointer {
137
161
if Int ( Builtin . ptrtoint_Word ( object) ) == 0 { return object }
138
162
let o = UnsafeMutablePointer < HeapObject > ( object)
139
163
return swift_retain_n_ ( object: o, n: 1 ) . _rawValue
140
164
}
141
165
142
166
// Cannot use UnsafeMutablePointer<HeapObject>? directly in the function argument or return value as it causes IRGen crashes
143
- @_silgen_name ( " swift_retain_n " )
167
+ @_cdecl ( " swift_retain_n " )
144
168
public func swift_retain_n( object: Builtin . RawPointer , n: UInt32 ) -> Builtin . RawPointer {
145
169
if Int ( Builtin . ptrtoint_Word ( object) ) == 0 { return object }
146
170
let o = UnsafeMutablePointer < HeapObject > ( object)
@@ -158,21 +182,21 @@ func swift_retain_n_(object: UnsafeMutablePointer<HeapObject>, n: UInt32) -> Uns
158
182
return object
159
183
}
160
184
161
- @_silgen_name ( " swift_release " )
185
+ @_cdecl ( " swift_release " )
162
186
public func swift_release( object: Builtin . RawPointer ) {
163
187
if Int ( Builtin . ptrtoint_Word ( object) ) == 0 { return }
164
188
let o = UnsafeMutablePointer < HeapObject > ( object)
165
189
swift_release_n_ ( object: o, n: 1 )
166
190
}
167
191
168
- @_silgen_name ( " swift_release_n " )
192
+ @_cdecl ( " swift_release_n " )
169
193
public func swift_release_n( object: Builtin . RawPointer , n: UInt32 ) {
170
194
if Int ( Builtin . ptrtoint_Word ( object) ) == 0 { return }
171
195
let o = UnsafeMutablePointer < HeapObject > ( object)
172
196
swift_release_n_ ( object: o, n: n)
173
197
}
174
198
175
- public func swift_release_n_( object: UnsafeMutablePointer < HeapObject > ? , n: UInt32 ) {
199
+ func swift_release_n_( object: UnsafeMutablePointer < HeapObject > ? , n: UInt32 ) {
176
200
guard let object else {
177
201
return
178
202
}
@@ -228,12 +252,12 @@ fileprivate func storeRelease(_ atomic: UnsafeMutablePointer<Int>, newValue: Int
228
252
229
253
/// Exclusivity checking
230
254
231
- @_silgen_name ( " swift_beginAccess " )
255
+ @_cdecl ( " swift_beginAccess " )
232
256
public func swift_beginAccess( pointer: UnsafeMutableRawPointer , buffer: UnsafeMutableRawPointer , flags: UInt , pc: UnsafeMutableRawPointer ) {
233
257
// TODO: Add actual exclusivity checking.
234
258
}
235
259
236
- @_silgen_name ( " swift_endAccess " )
260
+ @_cdecl ( " swift_endAccess " )
237
261
public func swift_endAccess( buffer: UnsafeMutableRawPointer ) {
238
262
// TODO: Add actual exclusivity checking.
239
263
}
@@ -242,7 +266,7 @@ public func swift_endAccess(buffer: UnsafeMutableRawPointer) {
242
266
243
267
// Once
244
268
245
- @_silgen_name ( " swift_once " )
269
+ @_cdecl ( " swift_once " )
246
270
public func swift_once( predicate: UnsafeMutablePointer < Int > , fn: ( @convention ( c) ( UnsafeMutableRawPointer ) -> ( ) ) , context: UnsafeMutableRawPointer ) {
247
271
let checkedLoadAcquire = { predicate in
248
272
let value = loadAcquire ( predicate)
@@ -269,12 +293,12 @@ public func swift_once(predicate: UnsafeMutablePointer<Int>, fn: (@convention(c)
269
293
270
294
// Misc
271
295
272
- @_silgen_name ( " swift_deletedMethodError " )
296
+ @_cdecl ( " swift_deletedMethodError " )
273
297
public func swift_deletedMethodError( ) -> Never {
274
298
Builtin . int_trap ( )
275
299
}
276
300
277
- @_silgen_name ( " swift_willThrow " )
301
+ @_silgen_name ( " swift_willThrow " ) // This is actually expected to be swiftcc (@_silgen_name and not @_cdecl).
278
302
public func swift_willThrow( ) throws {
279
303
}
280
304
0 commit comments