Skip to content

Commit e3b2c44

Browse files
[stdlib] Fix calling convention mismatch for debugger utility functions
The functions `swift_retainCount`, `swift_unownedRetainCount`, and `swift_weakRetainCount` are declared in `HeapObject.h` as using the C calling convention, but the Swift declarations referenced them by `@_silgen_name`, which uses the Swift calling convention. This patch fixes the mismatch without any ABI/API breakage by calling the utility functions through C interop.
1 parent 888a43e commit e3b2c44

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

stdlib/public/core/DebuggerSupport.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,12 @@ public func _stringForPrintObject(_ value: Any) -> String {
269269
public func _debuggerTestingCheckExpect(_: String, _: String) { }
270270

271271
// Utilities to get refcount(s) of class objects.
272-
@_silgen_name("swift_retainCount")
273-
public func _getRetainCount(_ Value: AnyObject) -> UInt
274-
@_silgen_name("swift_unownedRetainCount")
275-
public func _getUnownedRetainCount(_ Value: AnyObject) -> UInt
276-
@_silgen_name("swift_weakRetainCount")
277-
public func _getWeakRetainCount(_ Value: AnyObject) -> UInt
272+
public func _getRetainCount(_ Value: AnyObject) -> UInt {
273+
return UInt(swift_retainCount(unsafeBitCast(Value, to: UnsafeMutablePointer<HeapObject>.self)))
274+
}
275+
public func _getUnownedRetainCount(_ Value: AnyObject) -> UInt {
276+
return UInt(swift_unownedRetainCount(unsafeBitCast(Value, to: UnsafeMutablePointer<HeapObject>.self)))
277+
}
278+
public func _getWeakRetainCount(_ Value: AnyObject) -> UInt {
279+
return UInt(swift_weakRetainCount(unsafeBitCast(Value, to: UnsafeMutablePointer<HeapObject>.self)))
280+
}

0 commit comments

Comments
 (0)